avo 3.0.1.beta8 → 3.0.1.beta11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +2 -0
  4. data/app/assets/builds/avo.base.css +17 -10
  5. data/app/components/avo/field_wrapper_component.html.erb +1 -1
  6. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  7. data/app/components/avo/fields/common/badge_viewer_component.html.erb +1 -25
  8. data/app/components/avo/fields/common/badge_viewer_component.rb +24 -0
  9. data/app/components/avo/fields/common/boolean_check_component.html.erb +1 -12
  10. data/app/components/avo/fields/common/boolean_check_component.rb +2 -1
  11. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  12. data/app/components/avo/fields/common/gravatar_viewer_component.rb +2 -2
  13. data/app/components/avo/fields/common/heading_component.html.erb +3 -8
  14. data/app/components/avo/fields/common/heading_component.rb +1 -3
  15. data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
  16. data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
  17. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  18. data/app/components/avo/fields/heading_field/edit_component.html.erb +1 -1
  19. data/app/components/avo/fields/heading_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  21. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  22. data/app/components/avo/index/resource_table_component.rb +2 -8
  23. data/app/components/avo/views/resource_edit_component.html.erb +9 -20
  24. data/app/controllers/avo/actions_controller.rb +8 -19
  25. data/app/controllers/avo/application_controller.rb +12 -0
  26. data/app/controllers/avo/search_controller.rb +2 -2
  27. data/app/views/layouts/avo/application.html.erb +1 -2
  28. data/avo.gemspec +1 -1
  29. data/bin/dev +2 -0
  30. data/lib/avo/base_action.rb +18 -23
  31. data/lib/avo/base_resource.rb +1 -1
  32. data/lib/avo/concerns/filters_session_handler.rb +3 -3
  33. data/lib/avo/concerns/has_items.rb +0 -4
  34. data/lib/avo/fields/badge_field.rb +1 -1
  35. data/lib/avo/fields/base_field.rb +12 -8
  36. data/lib/avo/fields/external_image_field.rb +2 -2
  37. data/lib/avo/fields/file_field.rb +2 -2
  38. data/lib/avo/fields/gravatar_field.rb +2 -2
  39. data/lib/avo/fields/heading_field.rb +5 -13
  40. data/lib/avo/fields/id_field.rb +2 -2
  41. data/lib/avo/fields/text_field.rb +2 -2
  42. data/lib/avo/resources/items/holder.rb +0 -6
  43. data/lib/avo/version.rb +1 -1
  44. data/lib/generators/avo/js/install_generator.rb +2 -2
  45. data/lib/generators/avo/tailwindcss/install_generator.rb +58 -12
  46. data/lib/generators/avo/templates/tailwindcss/avo.tailwind.css +5 -3
  47. data/lib/generators/avo/templates/tailwindcss/tailwind.config.js +11 -0
  48. data/lib/tasks/avo_tasks.rake +33 -5
  49. data/public/avo-assets/avo.base.css +51 -3962
  50. data/tailwind.preset.js +144 -0
  51. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba8ff92bd87d9e0b8cfa4eb41412cfa4e919deb61bbd81612082ba0d439b329d
4
- data.tar.gz: 9fb43629cf378585beb2d624f9fb9d83d1fdb60bc11053e3ea7f1fdfe9c868ec
3
+ metadata.gz: 022cb3e4cb686ce487ad3304f60e9971da143463b9adf66a710c40f483a2afb7
4
+ data.tar.gz: 1784442417d2bbe2204fa7e5ddfd08ecd07e6506e9850ca329d218025624540e
5
5
  SHA512:
6
- metadata.gz: e95a674b3c497843b0924d55021dee3480bfa86d7495d99c3aa7536340fc3dfcad258bd6aba6a5575f39bb6a4a714354a99bc3adf739dd8ab305f9f3a1d9fa1c
7
- data.tar.gz: eaf7a6e8a66b13160777724fe9ff8e1e9052f0376023c5ddeabb0a14033d28ab5b6d46f82e72d7f9a90fbec341a535a8a8d4dd2f925b1c6d46e31a887ebe8314
6
+ metadata.gz: 22417fabd06df79a9030be62f76f83585add1f3375fbccb9d0f089e1912a0a819a641302d826ed82611dabb7ffef5efc8c5d0949ed6e1c4a7ebe5129229a1542
7
+ data.tar.gz: 18f52cfabd9fa655fdf509021f898f425e3857b3e88b4b63c8be950bc25ae95fd64e6fc57b6883e83543c2414ac3e730f31515f75ef629115c17d25fd164d537
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.1.beta8)
4
+ avo (3.0.1.beta11)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
data/Rakefile CHANGED
@@ -19,6 +19,8 @@ load "rails/tasks/engine.rake"
19
19
 
20
20
  load "rails/tasks/statistics.rake"
21
21
 
22
+ load "lib/tasks/avo_tasks.rake"
23
+
22
24
  require "bundler/gem_tasks"
23
25
 
24
26
  require "rake/testtask"
@@ -3393,7 +3393,7 @@ body.dark,body[data-theme=dark]{
3393
3393
  transition:inherit
3394
3394
  }
3395
3395
 
3396
- /*! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com
3396
+ /*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com
3397
3397
  */
3398
3398
 
3399
3399
  /*
@@ -3583,6 +3583,10 @@ select,
3583
3583
  textarea {
3584
3584
  font-family: inherit;
3585
3585
  /* 1 */
3586
+ font-feature-settings: inherit;
3587
+ /* 1 */
3588
+ font-variation-settings: inherit;
3589
+ /* 1 */
3586
3590
  font-size: 100%;
3587
3591
  /* 1 */
3588
3592
  font-weight: inherit;
@@ -3733,6 +3737,14 @@ menu {
3733
3737
  padding: 0;
3734
3738
  }
3735
3739
 
3740
+ /*
3741
+ Reset default styling for dialogs.
3742
+ */
3743
+
3744
+ dialog {
3745
+ padding: 0;
3746
+ }
3747
+
3736
3748
  /*
3737
3749
  Prevent resizing textareas horizontally by default.
3738
3750
  */
@@ -6665,10 +6677,6 @@ tag.tagify__tag{
6665
6677
  float:right
6666
6678
  }
6667
6679
 
6668
- .float-left{
6669
- float:left
6670
- }
6671
-
6672
6680
  .m-0{
6673
6681
  margin:0px
6674
6682
  }
@@ -7809,11 +7817,6 @@ tag.tagify__tag{
7809
7817
  background-color:rgb(57 158 229 / var(--tw-bg-opacity))
7810
7818
  }
7811
7819
 
7812
- .bg-blue-50{
7813
- --tw-bg-opacity:1;
7814
- background-color:rgb(230 243 252 / var(--tw-bg-opacity))
7815
- }
7816
-
7817
7820
  .bg-blue-500{
7818
7821
  --tw-bg-opacity:1;
7819
7822
  background-color:rgb(8 134 222 / var(--tw-bg-opacity))
@@ -10226,6 +10229,10 @@ trix-editor {
10226
10229
  width:66.666667%
10227
10230
  }
10228
10231
 
10232
+ .md\:w-full{
10233
+ width:100%
10234
+ }
10235
+
10229
10236
  .md\:grid-cols-3{
10230
10237
  grid-template-columns:repeat(3, minmax(0, 1fr))
10231
10238
  }
@@ -2,7 +2,7 @@
2
2
  class: classes,
3
3
  style: style,
4
4
  data: data do %>
5
- <div class="h-full <% if stacked? %> md:pt-4 <% else %> md:pt-0 <% if short? %> md:h-10 <% else %> md:h-14 <% end %> <% end %> pt-4 flex self-start items-center flex-shrink-0 <%= @field.get_html(:classes, view: view, element: :label) %> w-48 <% if compact? %> md:w-48 xl:w-64 <% else %> md:w-64 <% end %> px-6 uppercase font-semibold text-gray-500 text-sm" data-slot="label">
5
+ <div class="h-full <% if stacked? %> md:pt-4 md:w-full <% else %> md:pt-0 <% if short? %> md:h-10 <% else %> md:h-14 <% end %> <% end %> pt-4 flex self-start items-center flex-shrink-0 <%= @field.get_html(:classes, view: view, element: :label) %> w-48 <% if compact? %> md:w-48 xl:w-64 <% else %> md:w-64 <% end %> px-6 uppercase font-semibold text-gray-500 text-sm" data-slot="label">
6
6
  <% if form.present? %>
7
7
  <%= form.label field.id, label %>
8
8
  <% else %>
@@ -1,3 +1,3 @@
1
- <%= index_field_wrapper **field_wrapper_args, dash_if_blank: false, center_content: true, flush: true do %>
1
+ <%= index_field_wrapper **field_wrapper_args, dash_if_blank: false, flush: true do %>
2
2
  <%= render Avo::Fields::Common::BooleanCheckComponent.new checked: @field.value %>
3
3
  <% end %>
@@ -1,25 +1 @@
1
- <%
2
- backgrounds = {
3
- info: 'bg-blue-500',
4
- success: 'bg-green-500',
5
- danger: 'bg-red-500',
6
- warning: 'bg-yellow-500',
7
- secondary: 'bg-gray-500',
8
- }
9
-
10
- label = @value
11
- background = :info
12
-
13
- @options.invert.each do |values, type|
14
- if [values].flatten.map { |value| value }.include? @value
15
- label = @value
16
- background = type.to_sym
17
- next
18
- end
19
- end
20
-
21
- classes = 'whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate '
22
-
23
- classes += "#{backgrounds[background]} text-white" if backgrounds[background].present?
24
- %>
25
- <span class="<%= classes %>" style="max-width: 120px;"><%= label %></span>
1
+ <span class="<%= classes %>" style="max-width: 120px;"><%= @value %></span>
@@ -4,5 +4,29 @@ class Avo::Fields::Common::BadgeViewerComponent < ViewComponent::Base
4
4
  def initialize(value:, options:)
5
5
  @value = value
6
6
  @options = options
7
+ @backgrounds = {
8
+ info: "bg-blue-500",
9
+ success: "bg-green-500",
10
+ danger: "bg-red-500",
11
+ warning: "bg-yellow-500",
12
+ neutral: "bg-gray-500"
13
+ }
14
+ end
15
+
16
+ def classes
17
+ background = :info
18
+
19
+ @options.invert.each do |values, type|
20
+ if [values].flatten.map { |value| value }.include? @value
21
+ background = type.to_sym
22
+ next
23
+ end
24
+ end
25
+
26
+ classes = "whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate "
27
+
28
+ classes += "#{@backgrounds[background]} text-white" if @backgrounds[background].present?
29
+
30
+ classes
7
31
  end
8
32
  end
@@ -1,12 +1 @@
1
- <%
2
- classes = 'h-6 float-left mr-1'
3
-
4
- if @checked
5
- classes += ' text-green-600'
6
- icon = 'heroicons/outline/check-circle'
7
- else
8
- classes += ' text-red-500'
9
- icon = 'heroicons/outline/x-circle'
10
- end
11
- %>
12
- <%= helpers.svg "#{icon}.svg", class: classes %>
1
+ <%= helpers.svg "#{@icon}.svg", class: @classes %>
@@ -2,6 +2,7 @@
2
2
 
3
3
  class Avo::Fields::Common::BooleanCheckComponent < ViewComponent::Base
4
4
  def initialize(checked: false)
5
- @checked = checked
5
+ @icon = checked ? "heroicons/outline/check-circle" : "heroicons/outline/x-circle"
6
+ @classes = "h-6 #{checked ? "text-green-600" : "text-red-500"}"
6
7
  end
7
8
  end
@@ -9,4 +9,4 @@
9
9
  url = URI::HTTPS.build(host: "www.gravatar.com", path: "/avatar/#{@md5}", query: query)
10
10
  classes = @rounded ? 'rounded-full' : ''
11
11
  %>
12
- <%= link_to_if @link_to_resource.present?, image_tag(url.to_s, class: classes, width: options[:size], height: options[:size]), @link, title: @title %>
12
+ <%= link_to_if @link_to_record.present?, image_tag(url.to_s, class: classes, width: options[:size], height: options[:size]), @link, title: @title %>
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Avo::Fields::Common::GravatarViewerComponent < ViewComponent::Base
4
- def initialize(md5: nil, link: nil, default: nil, size: nil, rounded: false, link_to_resource: false, title: nil)
4
+ def initialize(md5: nil, link: nil, default: nil, size: nil, rounded: false, link_to_record: false, title: nil)
5
5
  @md5 = md5
6
6
  @link = link
7
7
  @default = default
8
8
  @size = size
9
9
  @rounded = rounded
10
- @link_to_resource = link_to_resource
10
+ @link_to_record = link_to_record
11
11
  @title = title
12
12
  end
13
13
  end
@@ -1,14 +1,9 @@
1
1
  <div class="flex items-start py-1 leading-tight bg-gray-100 text-gray-500 text-xs">
2
2
  <div class="py-2 px-6 h-full w-full">
3
- <% if empty %>
4
- <% elsif value.present? %>
5
- <% if as_html %>
6
- <%= sanitize value %>
7
- <% else %>
8
- <div class="font-semibold uppercase"><%= value %></div>
9
- <% end %>
3
+ <% if as_html %>
4
+ <%= sanitize value %>
10
5
  <% else %>
11
-
6
+ <div class="font-semibold uppercase"><%= value %></div>
12
7
  <% end %>
13
8
  </div>
14
9
  </div>
@@ -3,11 +3,9 @@
3
3
  class Avo::Fields::Common::HeadingComponent < ViewComponent::Base
4
4
  attr_reader :value
5
5
  attr_reader :as_html
6
- attr_reader :empty
7
6
 
8
- def initialize(value:, as_html:, empty:)
7
+ def initialize(value:, as_html:)
9
8
  @value = value
10
9
  @as_html = as_html
11
- @empty = empty
12
10
  end
13
11
  end
@@ -1,6 +1,6 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, flush: true do %>
2
2
  <% if @field.value.present? %>
3
- <%= link_to_if @field.link_to_resource.present?,
3
+ <%= link_to_if @field.link_to_record.present?,
4
4
  image_tag(@field.value,
5
5
  height: @field.height,
6
6
  style: "border-radius: #{@field.radius}px; max-height: #{@field.height}#{@field.height.to_s&.ends_with?('px') ? '' : 'px'};"),
@@ -1,9 +1,9 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, flush: flush? do %>
2
2
  <% if @field.value.present? %>
3
3
  <% if @field.value.attached? && @field.value.representable? && @field.is_image %>
4
- <%= link_to_if @field.link_to_resource, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_view_path, class: 'block' %>
4
+ <%= link_to_if @field.link_to_record, image_tag(helpers.main_app.url_for(@field.value), class: 'h-10'), resource_view_path, class: 'block' %>
5
5
  <% elsif @field.value.attached? && @field.is_audio %>
6
- <%= link_to_if @field.link_to_resource, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'), resource_view_path, class: 'block h-8' %>
6
+ <%= link_to_if @field.link_to_record, audio_tag(helpers.main_app.url_for(@field.value), controls: true, preload: false, class: 'max-h-full h-10'), resource_view_path, class: 'block h-8' %>
7
7
  <% else %>
8
8
  <%= @field.value.filename %>
9
9
  <% end %>
@@ -4,7 +4,7 @@
4
4
  default: @field.default,
5
5
  size: @field.size,
6
6
  rounded: @field.rounded,
7
- link_to_resource: @field.link_to_resource,
7
+ link_to_record: @field.link_to_record,
8
8
  link: resource_view_path,
9
9
  title: t('avo.view_item', item: @resource.name).humanize
10
10
  )
@@ -1,3 +1,3 @@
1
1
  <div <% if @index == 0 %> class="overflow-hidden rounded-t" <% end %> data-field-id="<%= @field.id %>">
2
- <%= render Avo::Fields::Common::HeadingComponent.new value: @field.name, as_html: @field.as_html, empty: @field.empty %>
2
+ <%= render Avo::Fields::Common::HeadingComponent.new value: @field.value, as_html: @field.as_html %>
3
3
  </div>
@@ -1,3 +1,3 @@
1
1
  <div <% if @index == 0 %> class="overflow-hidden rounded-t" <% end %> data-field-id="<%= @field.id %>">
2
- <%= render Avo::Fields::Common::HeadingComponent.new value: @field.name, as_html: @field.as_html, empty: @field.empty %>
2
+ <%= render Avo::Fields::Common::HeadingComponent.new value: @field.value, as_html: @field.as_html %>
3
3
  </div>
@@ -1,3 +1,3 @@
1
1
  <%= index_field_wrapper **field_wrapper_args, class: 'whitespace-no-wrap w-[1%]' do %>
2
- <% link_to_if (@field.link_to_resource or Avo.configuration.id_links_to_resource), @field.value, resource_view_path, title: t('avo.view_item', item: @resource.name).humanize %>
2
+ <% link_to_if (@field.link_to_record or Avo.configuration.id_links_to_resource), @field.value, resource_view_path, title: t('avo.view_item', item: @resource.name).humanize %>
3
3
  <% end %>
@@ -4,6 +4,6 @@
4
4
  <% elsif @field.protocol.present? %>
5
5
  <%= link_to @field.value, "#{@field.protocol}:#{@field.value}" %>
6
6
  <% else %>
7
- <%= link_to_if @field.link_to_resource, @field.value, resource_view_path %>
7
+ <%= link_to_if @field.link_to_record, @field.value, resource_view_path %>
8
8
  <% end %>
9
9
  <% end %>
@@ -18,17 +18,11 @@ class Avo::Index::ResourceTableComponent < ViewComponent::Base
18
18
  def encrypted_query
19
19
  # TODO: move this to the resource where we can apply the adapter pattern
20
20
  if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
21
- @query = query.result
21
+ @query = @query.result
22
22
  end
23
23
 
24
- return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
25
-
26
- serialized_query = query.all.to_sql
27
-
28
- return if serialized_query.nil?
29
-
30
24
  Avo::Services::EncryptionService.encrypt(
31
- message: serialized_query,
25
+ message: Marshal.dump(@query),
32
26
  purpose: :select_all
33
27
  )
34
28
  end
@@ -44,26 +44,6 @@
44
44
  <%= render sidebar_component form: form %>
45
45
  <% end %>
46
46
  <% end %>
47
- <% if Avo.configuration.buttons_on_form_footers %>
48
- <% c.with_footer_tools do %>
49
- <div class="mt-4">
50
- <%= a_link back_path,
51
- style: :text,
52
- icon: 'arrow-left' do %>
53
- <%= t('avo.cancel').capitalize %>
54
- <% end %>
55
- <% if can_see_the_save_button? %>
56
- <%= a_button color: :primary,
57
- style: :primary,
58
- loading: true,
59
- type: :submit,
60
- icon: 'save' do %>
61
- <%= t('avo.save').capitalize %>
62
- <% end %>
63
- <% end %>
64
- </div>
65
- <% end %>
66
- <% end %>
67
47
  <% end %>
68
48
  <%= content_tag :div, class: 'space-y-12' do %>
69
49
  <% @resource.get_items.each_with_index do |item, index| %>
@@ -71,6 +51,15 @@
71
51
  <%= render Avo::ItemSwitcherComponent.new resource: @resource, item: item, index: index + 1, view: view, form: form %>
72
52
  <% end %>
73
53
  <% end %>
54
+ <% if Avo.configuration.buttons_on_form_footers %>
55
+ <%= render Avo::PanelComponent.new do |c| %>
56
+ <% c.with_footer_tools do %>
57
+ <% @resource.render_edit_controls.each do |control| %>
58
+ <%= render_control control %>
59
+ <% end %>
60
+ <% end %>
61
+ <% end %>
62
+ <% end %>
74
63
  <% end %>
75
64
  <% end %>
76
65
  <% end %>
@@ -21,23 +21,13 @@ module Avo
21
21
 
22
22
  def handle
23
23
  resource_ids = action_params[:fields][:avo_resource_ids].split(",")
24
- @selected_query = action_params[:fields][:avo_selected_query]
25
24
 
26
- fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query)
27
-
28
- args = {
29
- fields: fields,
25
+ performed_action = @action.handle_action(
26
+ fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query),
30
27
  current_user: _current_user,
31
- resource: resource
32
- }
33
-
34
- args[:records] = if @selected_query.present?
35
- @resource.model_class.find_by_sql decrypted_query
36
- else
37
- @resource.find_record resource_ids, params: params
38
- end
39
-
40
- performed_action = @action.handle_action(**args)
28
+ resource: resource,
29
+ query: decrypted_query || @resource.find_record(resource_ids, params: params)
30
+ )
41
31
 
42
32
  respond performed_action.response
43
33
  end
@@ -106,10 +96,9 @@ module Avo
106
96
  end
107
97
 
108
98
  def decrypted_query
109
- Avo::Services::EncryptionService.decrypt(
110
- message: @selected_query,
111
- purpose: :select_all
112
- )
99
+ return if (encrypted_query = action_params[:fields][:avo_selected_query]).blank?
100
+
101
+ Marshal.load(Avo::Services::EncryptionService.decrypt(message: encrypted_query, purpose: :select_all))
113
102
  end
114
103
 
115
104
  def decrypted_arguments
@@ -25,6 +25,7 @@ module Avo
25
25
  before_action :add_initial_breadcrumbs
26
26
  before_action :set_view
27
27
  before_action :set_sidebar_open
28
+ before_action :set_stylesheet_assets_path
28
29
 
29
30
  rescue_from Avo::NotAuthorizedError, with: :render_unauthorized
30
31
  rescue_from ActiveRecord::RecordInvalid, with: :exception_logger
@@ -314,5 +315,16 @@ module Avo
314
315
  rescue => exception
315
316
  Avo.logger.debug "Failed to set ActiveStorage::Current.url_options, #{exception.inspect}"
316
317
  end
318
+
319
+ def set_stylesheet_assets_path
320
+ # Prefer the user's tailwind config if it exists, otherwise use the default one from Avo
321
+ @stylesheet_assets_path = if Rails.root.join("config", "avo", "tailwind.config.js").exist?
322
+ "avo.tailwind"
323
+ elsif Avo::PACKED
324
+ "/avo-assets/avo.base"
325
+ else
326
+ "avo.base"
327
+ end
328
+ end
317
329
  end
318
330
  end
@@ -42,14 +42,14 @@ module Avo
42
42
  query: resource.query_scope
43
43
  ).handle
44
44
 
45
+ query = apply_scope(query) if should_apply_any_scope?
46
+
45
47
  # Get the count
46
48
  results_count = query.reselect(resource.model_class.primary_key).count
47
49
 
48
50
  # Get the results
49
51
  query = query.limit(8)
50
52
 
51
- query = apply_scope(query) if should_apply_any_scope?
52
-
53
53
  results = apply_search_metadata(query, resource)
54
54
 
55
55
  header = resource.plural_name
@@ -10,12 +10,11 @@
10
10
  <%= render partial: 'avo/partials/branding' %>
11
11
  <%= render partial: 'avo/partials/pre_head' %>
12
12
  <%= render Avo::AssetManager::StylesheetComponent.new asset_manager: Avo.asset_manager %>
13
+ <%= stylesheet_link_tag @stylesheet_assets_path, "data-turbo-track": "reload", defer: true %>
13
14
  <% if Avo::PACKED %>
14
15
  <%= javascript_include_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
15
- <%= stylesheet_link_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
16
16
  <% else %>
17
17
  <%= javascript_include_tag "avo.base", "data-turbo-track": "reload", defer: true %>
18
- <%= stylesheet_link_tag "avo.base", "data-turbo-track": "reload", defer: true %>
19
18
  <% if Rails.env.development? %>
20
19
  <%= javascript_include_tag "hotwire-livereload", defer: true %>
21
20
  <% end %>
data/avo.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.required_ruby_version = ">= 3.0.0"
31
31
  spec.post_install_message = "Thank you for using Avo 💪 Docs are available at https://docs.avohq.io"
32
32
 
33
- spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "avo.gemspec", "Gemfile", "Gemfile.lock"]
33
+ spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "avo.gemspec", "Gemfile", "Gemfile.lock", "tailwind.preset.js"]
34
34
 
35
35
  spec.add_dependency "activerecord", ">= 6.1"
36
36
  spec.add_dependency "activesupport", ">= 6.1"
data/bin/dev CHANGED
@@ -3,6 +3,8 @@
3
3
  PORT="${PORT:-3030}"
4
4
  export PORT
5
5
 
6
+ bundle exec rake avo:sym_link
7
+
6
8
  if command -v overmind &> /dev/null; then
7
9
  overmind start -f Procfile.dev "$@"
8
10
  else
@@ -101,39 +101,34 @@ module Avo
101
101
  end
102
102
 
103
103
  def handle_action(**args)
104
- records, fields, current_user, resource = args.values_at(:records, :fields, :current_user, :resource)
105
- # Fetching the field definitions and not the actual fields (get_fields) because they will break if the user uses a `visible` block and adds a condition using the `params` variable. The params are different in the show method and the handle method.
106
- action_fields = get_field_definitions.map { |field| [field.id, field] }.to_h
107
-
108
- # For some fields, like belongs_to, the id and database_id differ (user vs user_id).
109
- # That's why we need to fetch the database_id for when we process the action.
110
- action_fields_by_database_id = action_fields.map do |id, value|
111
- [value.database_id.to_sym, value]
112
- end.to_h
104
+ processed_fields = if args[:fields].present?
105
+ # Fetching the field definitions and not the actual fields (get_fields) because they will break if the user uses a `visible` block and adds a condition using the `params` variable. The params are different in the show method and the handle method.
106
+ action_fields = get_field_definitions.map { |field| [field.id, field] }.to_h
107
+
108
+ # For some fields, like belongs_to, the id and database_id differ (user vs user_id).
109
+ # That's why we need to fetch the database_id for when we process the action.
110
+ action_fields_by_database_id = action_fields.map do |id, value|
111
+ [value.database_id.to_sym, value]
112
+ end.to_h
113
113
 
114
- if fields.present?
115
- processed_fields = fields.to_unsafe_h.map do |name, value|
114
+ args[:fields].to_unsafe_h.map do |name, value|
116
115
  field = action_fields_by_database_id[name.to_sym]
117
116
 
118
117
  next if field.blank?
119
118
 
120
119
  [name, field.resolve_attribute(value)]
121
- end
122
-
123
- processed_fields = processed_fields.reject(&:blank?).to_h
120
+ end.reject(&:blank?).to_h
124
121
  else
125
- processed_fields = {}
122
+ {}
126
123
  end
127
124
 
128
- args = {
125
+ handle(
129
126
  fields: processed_fields.with_indifferent_access,
130
- current_user: current_user,
131
- resource: resource
132
- }
133
-
134
- args[:records] = records
135
-
136
- handle(**args)
127
+ current_user: args[:current_user],
128
+ resource: args[:resource],
129
+ records: args[:query],
130
+ query: args[:query]
131
+ )
137
132
 
138
133
  self
139
134
  end
@@ -446,7 +446,7 @@ module Avo
446
446
  def hydrate_model_with_default_values
447
447
  default_values = get_fields
448
448
  .select do |field|
449
- !field.computed
449
+ !field.computed && !field.is_a?(Avo::Fields::HeadingField)
450
450
  end
451
451
  .map do |field|
452
452
  value = field.value
@@ -26,16 +26,16 @@ module Avo
26
26
  end
27
27
 
28
28
  def filters_session_key
29
- @filters_session_key ||= '/filters/' << %w[
29
+ @filters_session_key ||= "/filters/" << %w[
30
30
  turbo_frame controller resource_name related_name
31
31
  action id
32
- ].map { |key| params[key] }.compact.join('/')
32
+ ].map { |key| params[key] }.compact.join("/")
33
33
  end
34
34
 
35
35
  def cache_resource_filters?
36
36
  Avo::ExecutionContext.new(
37
37
  target: Avo.configuration.cache_resource_filters,
38
- current_user: current_user,
38
+ current_user: _current_user,
39
39
  resource: @resource
40
40
  ).handle
41
41
  end
@@ -30,10 +30,6 @@ module Avo
30
30
  deprecated_dsl_api __method__, "fields"
31
31
  end
32
32
 
33
- def heading(body, **args)
34
- deprecated_dsl_api __method__, "fields"
35
- end
36
-
37
33
  def sidebar(**args, &block)
38
34
  deprecated_dsl_api __method__, "fields"
39
35
  end
@@ -8,7 +8,7 @@ module Avo
8
8
 
9
9
  hide_on [:edit, :new]
10
10
 
11
- default_options = {info: :info, success: :success, danger: :danger, warning: :warning, secondary: :secondary}
11
+ default_options = {info: :info, success: :success, danger: :danger, warning: :warning, neutral: :neutral}
12
12
  @options = args[:options].present? ? default_options.merge(args[:options]) : default_options
13
13
  end
14
14
  end
@@ -158,14 +158,7 @@ module Avo
158
158
 
159
159
  # Run computable callback block if present
160
160
  if computable && block.present?
161
- final_value = Avo::ExecutionContext.new(
162
- target: block,
163
- record: record,
164
- resource: @resource,
165
- view: @view,
166
- field: self,
167
- include: self.class.included_modules
168
- ).handle
161
+ final_value = execute_block
169
162
  end
170
163
 
171
164
  # Run the value through resolver if present
@@ -184,6 +177,17 @@ module Avo
184
177
  final_value
185
178
  end
186
179
 
180
+ def execute_block
181
+ Avo::ExecutionContext.new(
182
+ target: block,
183
+ record: record,
184
+ resource: resource,
185
+ view: view,
186
+ field: self,
187
+ include: self.class.included_modules
188
+ ).handle
189
+ end
190
+
187
191
  # Fills the record with the received value on create and update actions.
188
192
  def fill_field(record, key, value, params)
189
193
  return record unless record.methods.include? key.to_sym