avo 3.0.0.pre19 → 3.0.1.beta1

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +25 -23
  4. data/Rakefile +0 -2
  5. data/app/assets/stylesheets/avo.base.css +0 -1
  6. data/app/components/avo/actions_component.rb +1 -1
  7. data/app/components/avo/field_wrapper_component.html.erb +1 -1
  8. data/app/components/avo/field_wrapper_component.rb +7 -1
  9. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  10. data/app/components/avo/fields/common/badge_viewer_component.html.erb +24 -1
  11. data/app/components/avo/fields/common/badge_viewer_component.rb +0 -24
  12. data/app/components/avo/fields/common/boolean_check_component.html.erb +12 -1
  13. data/app/components/avo/fields/common/boolean_check_component.rb +1 -2
  14. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  15. data/app/components/avo/fields/common/gravatar_viewer_component.rb +2 -2
  16. data/app/components/avo/fields/common/heading_component.html.erb +8 -3
  17. data/app/components/avo/fields/common/heading_component.rb +3 -1
  18. data/app/components/avo/fields/common/key_value_component.html.erb +2 -2
  19. data/app/components/avo/fields/common/key_value_component.rb +2 -2
  20. data/app/components/avo/fields/common/progress_bar_component.rb +9 -3
  21. data/app/components/avo/fields/common/status_viewer_component.html.erb +0 -3
  22. data/app/components/avo/fields/edit_component.rb +1 -1
  23. data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
  24. data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
  25. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  26. data/app/components/avo/fields/heading_field/edit_component.html.erb +1 -1
  27. data/app/components/avo/fields/heading_field/show_component.html.erb +1 -1
  28. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  29. data/app/components/avo/fields/index_component.rb +1 -1
  30. data/app/components/avo/fields/show_component.rb +1 -1
  31. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  32. data/app/components/avo/index/field_wrapper_component.rb +1 -1
  33. data/app/components/avo/index/resource_controls_component.rb +1 -1
  34. data/app/components/avo/index/resource_table_component.rb +9 -3
  35. data/app/components/avo/resource_component.rb +4 -9
  36. data/app/components/avo/sidebar_profile_component.html.erb +4 -4
  37. data/app/components/avo/tab_group_component.html.erb +1 -1
  38. data/app/components/avo/tab_switcher_component.rb +2 -2
  39. data/app/components/avo/views/resource_edit_component.html.erb +20 -9
  40. data/app/components/avo/views/resource_edit_component.rb +5 -5
  41. data/app/components/avo/views/resource_index_component.rb +1 -1
  42. data/app/components/avo/views/resource_show_component.html.erb +1 -1
  43. data/app/components/avo/views/resource_show_component.rb +1 -1
  44. data/app/controllers/avo/actions_controller.rb +20 -9
  45. data/app/controllers/avo/application_controller.rb +5 -5
  46. data/app/controllers/avo/base_controller.rb +1 -39
  47. data/app/controllers/avo/search_controller.rb +2 -19
  48. data/app/controllers/concerns/avo/initializes_avo.rb +0 -1
  49. data/app/helpers/avo/resources_helper.rb +1 -1
  50. data/app/helpers/avo/url_helpers.rb +1 -1
  51. data/app/views/avo/base/edit.html.erb +1 -1
  52. data/app/views/avo/base/index.html.erb +1 -1
  53. data/app/views/avo/base/new.html.erb +1 -1
  54. data/app/views/avo/base/show.html.erb +1 -1
  55. data/app/views/layouts/avo/application.html.erb +2 -10
  56. data/bin/dev +0 -2
  57. data/config/master.key +1 -0
  58. data/config/routes.rb +3 -4
  59. data/db/factories.rb +1 -1
  60. data/lib/avo/base_action.rb +26 -21
  61. data/lib/avo/base_resource.rb +7 -13
  62. data/lib/avo/concerns/filters_session_handler.rb +3 -3
  63. data/lib/avo/concerns/has_items.rb +5 -1
  64. data/lib/avo/concerns/visible_in_different_views.rb +1 -7
  65. data/lib/avo/configuration.rb +4 -28
  66. data/lib/avo/current.rb +6 -1
  67. data/lib/avo/dsl/field_parser.rb +1 -1
  68. data/lib/avo/execution_context.rb +1 -4
  69. data/lib/avo/fields/badge_field.rb +1 -1
  70. data/lib/avo/fields/base_field.rb +44 -21
  71. data/lib/avo/fields/belongs_to_field.rb +1 -1
  72. data/lib/avo/fields/concerns/has_html_attributes.rb +0 -2
  73. data/lib/avo/fields/external_image_field.rb +2 -2
  74. data/lib/avo/fields/file_field.rb +2 -2
  75. data/lib/avo/fields/gravatar_field.rb +2 -2
  76. data/lib/avo/fields/has_base_field.rb +2 -2
  77. data/lib/avo/fields/heading_field.rb +13 -5
  78. data/lib/avo/fields/id_field.rb +2 -2
  79. data/lib/avo/fields/status_field.rb +1 -3
  80. data/lib/avo/fields/text_field.rb +2 -2
  81. data/lib/avo/filters/base_filter.rb +1 -1
  82. data/lib/avo/html/builder.rb +1 -1
  83. data/lib/avo/licensing/h_q.rb +1 -1
  84. data/lib/avo/licensing/license_manager.rb +1 -1
  85. data/lib/avo/resources/items/holder.rb +6 -0
  86. data/lib/avo/resources/items/item_group.rb +2 -2
  87. data/lib/avo/resources/items/row.rb +3 -3
  88. data/lib/avo/resources/items/sidebar.rb +1 -1
  89. data/lib/avo/resources/items/tab.rb +2 -2
  90. data/lib/avo/resources/items/tab_group.rb +1 -1
  91. data/lib/avo/resources/resource_manager.rb +1 -6
  92. data/lib/avo/version.rb +1 -1
  93. data/lib/avo.rb +0 -9
  94. data/lib/generators/avo/controller_generator.rb +0 -3
  95. data/lib/generators/avo/eject_generator.rb +15 -180
  96. data/lib/generators/avo/field_generator.rb +2 -49
  97. data/lib/generators/avo/js/install_generator.rb +2 -2
  98. data/lib/generators/avo/resource_generator.rb +7 -10
  99. data/lib/generators/avo/tailwindcss/install_generator.rb +12 -58
  100. data/lib/generators/avo/templates/initializer/avo.tt +1 -6
  101. data/lib/generators/avo/templates/resource/controller.tt +1 -1
  102. data/lib/generators/avo/templates/tailwindcss/avo.tailwind.css +3 -5
  103. data/lib/tasks/avo_tasks.rake +5 -33
  104. data/public/avo-assets/avo.base.css +4146 -75
  105. data/{app/assets/builds/avo.base.css → public/avo-assets/avo.css} +3808 -547
  106. data/public/avo-assets/avo.js +513 -0
  107. data/public/avo-assets/avo.js.map +7 -0
  108. metadata +6 -14
  109. data/app/assets/builds/avo.base.js +0 -124556
  110. data/app/assets/builds/avo.base.js.map +0 -7
  111. data/app/assets/builds/avo.custom.js +0 -6
  112. data/app/assets/builds/avo.custom.js.map +0 -7
  113. data/app/assets/stylesheets/css/fields/tags.css +0 -32
  114. data/lib/avo/concerns/has_helpers.rb +0 -18
  115. data/lib/avo/concerns/visible_items.rb +0 -43
  116. data/lib/avo/fields/concerns/use_view_components.rb +0 -45
  117. data/lib/avo/view_inquirer.rb +0 -36
  118. data/lib/generators/avo/concerns/parent_controller.rb +0 -20
  119. data/lib/generators/avo/templates/tailwindcss/tailwind.config.js +0 -11
@@ -33,11 +33,11 @@ class Avo::TabSwitcherComponent < Avo::BaseComponent
33
33
  end
34
34
 
35
35
  def is_edit?
36
- @view.in?(%w[edit update])
36
+ @view.in?([:edit, :update])
37
37
  end
38
38
 
39
39
  def is_new?
40
- @view.in?(%w[new create])
40
+ @view.in?([:new, :create])
41
41
  end
42
42
 
43
43
  def is_initial_load?
@@ -44,6 +44,26 @@
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 %>
47
67
  <% end %>
48
68
  <%= content_tag :div, class: 'space-y-12' do %>
49
69
  <% @resource.get_items.each_with_index do |item, index| %>
@@ -51,15 +71,6 @@
51
71
  <%= render Avo::ItemSwitcherComponent.new resource: @resource, item: item, index: index + 1, view: view, form: form %>
52
72
  <% end %>
53
73
  <% 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 %>
63
74
  <% end %>
64
75
  <% end %>
65
76
  <% end %>
@@ -3,11 +3,11 @@
3
3
  class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
4
4
  include Avo::ApplicationHelper
5
5
 
6
- def initialize(resource: nil, record: nil, actions: [], view: "edit")
6
+ def initialize(resource: nil, record: nil, actions: [], view: :edit)
7
7
  @resource = resource
8
8
  @record = record
9
9
  @actions = actions
10
- @view = Avo::ViewInquirer.new(view)
10
+ @view = view
11
11
  end
12
12
 
13
13
  def title
@@ -18,7 +18,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
18
18
  return resource_view_path if via_resource?
19
19
  return resources_path if via_index?
20
20
 
21
- if is_edit? && Avo.configuration.resource_default_view.show? # via resource show or edit page
21
+ if is_edit? && Avo.configuration.resource_default_view == :show # via resource show or edit page
22
22
  return helpers.resource_path(record: @resource.record, resource: @resource)
23
23
  end
24
24
 
@@ -34,7 +34,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
34
34
  end
35
35
 
36
36
  def can_see_the_destroy_button?
37
- return super if is_edit? && Avo.configuration.resource_default_view.edit?
37
+ return super if is_edit? && Avo.configuration.resource_default_view == :edit
38
38
 
39
39
  false
40
40
  end
@@ -52,7 +52,7 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
52
52
  end
53
53
 
54
54
  def is_edit?
55
- view.in?(%w[edit update])
55
+ view.in?([:edit, :update])
56
56
  end
57
57
 
58
58
  def form_method
@@ -34,7 +34,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
34
34
  @parent_record = parent_record
35
35
  @parent_resource = parent_resource
36
36
  @applied_filters = applied_filters
37
- @view = Avo::ViewInquirer.new("index")
37
+ @view = :index
38
38
  @query = query
39
39
  @scopes = scopes
40
40
  end
@@ -4,7 +4,7 @@
4
4
  resource_name: @resource.class.to_s,
5
5
  record_id: @resource.record.id,
6
6
  selected_resources_name: @resource.model_key,
7
- selected_resources: [@resource.record.to_param],
7
+ selected_resources: [@resource.record.id],
8
8
  **@resource.stimulus_data_attributes
9
9
  } do %>
10
10
  <%= render Avo::PanelComponent.new(name: title, description: @resource.description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %>
@@ -10,7 +10,7 @@ class Avo::Views::ResourceShowComponent < Avo::ResourceComponent
10
10
  @actions = actions
11
11
  @parent_record = parent_record
12
12
  @parent_resource = parent_resource
13
- @view = Avo::ViewInquirer.new("show")
13
+ @view = :show
14
14
  end
15
15
 
16
16
  def title
@@ -13,7 +13,7 @@ module Avo
13
13
 
14
14
  def show
15
15
  # Se the view to :new so the default value gets prefilled
16
- @view = Avo::ViewInquirer.new("new")
16
+ @view = :new
17
17
 
18
18
  @resource.hydrate(record: @record, view: @view, user: _current_user, params: params)
19
19
  @record = ActionModel.new @action.get_attributes_for_action
@@ -21,13 +21,23 @@ 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]
24
25
 
25
- performed_action = @action.handle_action(
26
- fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query),
26
+ fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query)
27
+
28
+ args = {
29
+ fields: fields,
27
30
  current_user: _current_user,
28
- resource: resource,
29
- query: decrypted_query || @resource.find_record(resource_ids, params: params)
30
- )
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)
31
41
 
32
42
  respond performed_action.response
33
43
  end
@@ -96,9 +106,10 @@ module Avo
96
106
  end
97
107
 
98
108
  def decrypted_query
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))
109
+ Avo::Services::EncryptionService.decrypt(
110
+ message: @selected_query,
111
+ purpose: :select_all
112
+ )
102
113
  end
103
114
 
104
115
  def decrypted_arguments
@@ -115,7 +115,7 @@ module Avo
115
115
  def set_resource
116
116
  raise ActionController::RoutingError.new "No route matches" if resource.nil?
117
117
 
118
- @resource = resource.new(view: action_name.to_s, user: _current_user, params: params)
118
+ @resource = resource.new(view: action_name.to_sym, user: _current_user, params: params)
119
119
 
120
120
  set_authorization
121
121
  end
@@ -149,12 +149,12 @@ module Avo
149
149
  end
150
150
 
151
151
  def set_view
152
- @view = Avo::ViewInquirer.new(action_name.to_s)
152
+ @view = action_name.to_sym
153
153
  end
154
154
 
155
155
  def set_record_to_fill
156
- @record_to_fill = @resource.model_class.new if @view.create?
157
- @record_to_fill = @record if @view.update?
156
+ @record_to_fill = @resource.model_class.new if @view == :create
157
+ @record_to_fill = @record if @view == :update
158
158
 
159
159
  # If resource.record is nil, most likely the user is creating a new record.
160
160
  # In that case, to access resource.record in visible and readonly blocks we hydrate the resource with a new record.
@@ -167,7 +167,7 @@ module Avo
167
167
  return if is_attach_action?
168
168
 
169
169
  @record = @resource.fill_record(@record_to_fill, cast_nullable(model_params), extra_params: extra_params)
170
- assign_default_value_to_disabled_fields if @view.create?
170
+ assign_default_value_to_disabled_fields if @view == :create
171
171
  end
172
172
 
173
173
  def is_attach_action?
@@ -75,8 +75,6 @@ module Avo
75
75
  @resources = @records.map do |record|
76
76
  @resource.hydrate(record: record, params: params).dup
77
77
  end
78
-
79
- set_component_for __method__
80
78
  end
81
79
 
82
80
  def show
@@ -100,8 +98,6 @@ module Avo
100
98
 
101
99
  add_breadcrumb @resource.record_title
102
100
  add_breadcrumb I18n.t("avo.details").upcase_first
103
-
104
- set_component_for __method__
105
101
  end
106
102
 
107
103
  def new
@@ -123,8 +119,6 @@ module Avo
123
119
 
124
120
  add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
125
121
  add_breadcrumb t("avo.new").humanize
126
-
127
- set_component_for __method__, fallback_view: :edit
128
122
  end
129
123
 
130
124
  def create
@@ -167,8 +161,6 @@ module Avo
167
161
  add_breadcrumb t("avo.new").humanize
168
162
  set_actions
169
163
 
170
- set_component_for :edit
171
-
172
164
  if saved
173
165
  create_success_action
174
166
  else
@@ -178,8 +170,6 @@ module Avo
178
170
 
179
171
  def edit
180
172
  set_actions
181
-
182
- set_component_for __method__
183
173
  end
184
174
 
185
175
  def update
@@ -188,8 +178,6 @@ module Avo
188
178
  @resource = @resource.hydrate(record: @record, view: :edit, user: _current_user)
189
179
  set_actions
190
180
 
191
- set_component_for :edit
192
-
193
181
  if saved
194
182
  update_success_action
195
183
  else
@@ -529,7 +517,7 @@ module Avo
529
517
 
530
518
  if @resource.class.send(action) == :index
531
519
  resources_path(resource: @resource)
532
- elsif @resource.class.send(action) == :edit || Avo.configuration.resource_default_view.edit?
520
+ elsif @resource.class.send(action) == :edit || Avo.configuration.resource_default_view == :edit
533
521
  edit_resource_path(resource: @resource, record: @resource.record)
534
522
  else
535
523
  resource_path(record: @record, resource: @resource)
@@ -552,31 +540,5 @@ module Avo
552
540
  def pagy_query
553
541
  @query
554
542
  end
555
-
556
- # Set the view component for the current view
557
- # It will try to use the custom component if it's set, otherwise it will use the default one
558
- def set_component_for(view, fallback_view: nil)
559
- # Fetch the components from the resource
560
- components = Avo::ExecutionContext.new(
561
- target: @resource.components,
562
- resource: @resource,
563
- record: @record,
564
- view: @view
565
- ).handle
566
-
567
- # If the component is not set, use the default one
568
- if (custom_component = components.dig("resource_#{view}_component".to_sym)).nil?
569
- return @component = "Avo::Views::Resource#{(fallback_view || view).to_s.classify}Component".constantize
570
- end
571
-
572
- # If the component is set, try to use it
573
- @component = custom_component.to_s.safe_constantize
574
-
575
- # If the component is not found, raise an error
576
- if @component.nil?
577
- raise "The component '#{custom_component}' was not found.\n" \
578
- "That component was fetched from 'self.components' option inside '#{@resource.class}' resource."
579
- end
580
- end
581
543
  end
582
544
  end
@@ -9,8 +9,6 @@ module Avo
9
9
 
10
10
  def show
11
11
  render json: search_resources([resource])
12
- rescue => error
13
- render_search_error(error)
14
12
  end
15
13
 
16
14
  private
@@ -42,14 +40,14 @@ module Avo
42
40
  query: resource.query_scope
43
41
  ).handle
44
42
 
45
- query = apply_scope(query) if should_apply_any_scope?
46
-
47
43
  # Get the count
48
44
  results_count = query.reselect(resource.model_class.primary_key).count
49
45
 
50
46
  # Get the results
51
47
  query = query.limit(8)
52
48
 
49
+ query = apply_scope(query) if should_apply_any_scope?
50
+
53
51
  results = apply_search_metadata(query, resource)
54
52
 
55
53
  header = resource.plural_name
@@ -166,20 +164,5 @@ module Avo
166
164
  parent_resource = Avo.resource_manager.get_resource_by_model_class params[:via_reflection_class]
167
165
  parent_resource.find_record params[:via_reflection_id], params: params
168
166
  end
169
-
170
- def render_search_error(error)
171
- raise error unless Rails.env.development?
172
-
173
- render json: {
174
- error: {
175
- header: "🚨 An error occurred while searching. 🚨",
176
- help: "Please see the error and fix it before deploying.",
177
- results: {
178
- _label: error.message
179
- },
180
- count: 1
181
- }
182
- }, status: 500
183
- end
184
167
  end
185
168
  end
@@ -7,7 +7,6 @@ module Avo
7
7
  Avo::Current.view_context = view_context
8
8
  Avo.init
9
9
  Avo::Current.license = Licensing::LicenseManager.new(Licensing::HQ.new(request).response).license
10
- Avo::Current.locale = locale
11
10
  Avo.plugin_manager.init_plugins
12
11
  end
13
12
 
@@ -38,7 +38,7 @@ module Avo
38
38
  end
39
39
 
40
40
  def item_selector_init(resource)
41
- "data-resource-name='#{resource.model_key}' data-resource-id='#{resource.record.to_param}' data-controller='item-selector'"
41
+ "data-resource-name='#{resource.model_key}' data-resource-id='#{resource.record.id}' data-controller='item-selector'"
42
42
  end
43
43
 
44
44
  def item_selector_input(floating: false, size: :md)
@@ -94,7 +94,7 @@ module Avo
94
94
  end
95
95
 
96
96
  def resource_view_path(**args)
97
- if Avo.configuration.resource_default_view.edit?
97
+ if Avo.configuration.resource_default_view == :edit
98
98
  edit_resource_path(**args)
99
99
  else
100
100
  resource_path(**args)
@@ -1 +1 @@
1
- <%= render @component.new(resource: @resource, view: @view, actions: @actions) %>
1
+ <%= render Avo::Views::ResourceEditComponent.new(resource: @resource, view: @view, actions: @actions) %>
@@ -1,5 +1,5 @@
1
1
  <%= render Avo::TurboFrameWrapperComponent.new(params[:turbo_frame]) do %>
2
- <%= render @component.new(
2
+ <%= render Avo::Views::ResourceIndexComponent.new(
3
3
  resource: @resource,
4
4
  resources: @resources,
5
5
  records: @records,
@@ -1,2 +1,2 @@
1
- <%= render @component.new(resource: @resource, record: @record, view: @view, actions: @actions) %>
1
+ <%= render Avo::Views::ResourceEditComponent.new(resource: @resource, record: @record, view: @view, actions: @actions) %>
2
2
 
@@ -1,5 +1,5 @@
1
1
  <%= render Avo::TurboFrameWrapperComponent.new(params[:turbo_frame]) do %>
2
- <%= render @component.new(
2
+ <%= render Avo::Views::ResourceShowComponent.new(
3
3
  resource: @resource,
4
4
  reflection: @reflection,
5
5
  actions: @actions,
@@ -12,18 +12,10 @@
12
12
  <%= render Avo::AssetManager::StylesheetComponent.new asset_manager: Avo.asset_manager %>
13
13
  <% if Avo::PACKED %>
14
14
  <%= javascript_include_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
15
- <% if Rails.root.join("config", "avo", "tailwind.config.js").exist? %>
16
- <%= stylesheet_link_tag "avo.tailwind", "data-turbo-track": "reload", defer: true %>
17
- <% else %>
18
- <%= stylesheet_link_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
19
- <% end %>
15
+ <%= stylesheet_link_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
20
16
  <% else %>
21
17
  <%= javascript_include_tag "avo.base", "data-turbo-track": "reload", defer: true %>
22
- <% if Rails.root.join("config", "avo", "tailwind.config.js").exist? %>
23
- <%= stylesheet_link_tag "avo.tailwind", "data-turbo-track": "reload", defer: true %>
24
- <% else %>
25
- <%= stylesheet_link_tag "avo.base", "data-turbo-track": "reload", defer: true %>
26
- <% end %>
18
+ <%= stylesheet_link_tag "avo.base", "data-turbo-track": "reload", defer: true %>
27
19
  <% if Rails.env.development? %>
28
20
  <%= javascript_include_tag "hotwire-livereload", defer: true %>
29
21
  <% end %>
data/bin/dev CHANGED
@@ -3,8 +3,6 @@
3
3
  PORT="${PORT:-3030}"
4
4
  export PORT
5
5
 
6
- bundle exec rake avo:sym_link
7
-
8
6
  if command -v overmind &> /dev/null; then
9
7
  overmind start -f Procfile.dev "$@"
10
8
  else
data/config/master.key ADDED
@@ -0,0 +1 @@
1
+ 2aeb23d82b909d9c6b5abb62f7058c2a
data/config/routes.rb CHANGED
@@ -4,10 +4,9 @@ Avo::Engine.routes.draw do
4
4
  get "resources", to: redirect(Avo.configuration.root_path)
5
5
  get "dashboards", to: redirect(Avo.configuration.root_path)
6
6
 
7
- # Mount Avo engines routes by default but leave it configurable in case the user wants to nest these under a scope.
8
- if Avo.configuration.mount_avo_engines
9
- instance_exec(&Avo.mount_engines)
10
- end
7
+ mount Avo::DynamicFilters::Engine, at: "/avo-dynamic_filters" if defined?(Avo::DynamicFilters::Engine)
8
+ mount Avo::Dashboards::Engine, at: "/dashboards" if defined?(Avo::Dashboards::Engine)
9
+ mount Avo::Pro::Engine, at: "/avo/avo-pro" if defined?(Avo::Pro::Engine)
11
10
 
12
11
  post "/rails/active_storage/direct_uploads", to: "/active_storage/direct_uploads#create"
13
12
 
data/db/factories.rb CHANGED
@@ -38,7 +38,7 @@ FactoryBot.define do
38
38
  factory :project do
39
39
  name { Faker::App.name }
40
40
  status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample }
41
- stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample }
41
+ stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled"].sample }
42
42
  budget { Faker::Number.decimal(l_digits: 4) }
43
43
  country { Faker::Address.country_code }
44
44
  description { Faker::Markdown.sandwich(sentences: 5) }
@@ -25,7 +25,7 @@ module Avo
25
25
  delegate :view, to: :class
26
26
  # TODO: find a differnet way to delegate this to the uninitialized Current variable
27
27
  delegate :context, to: Avo::Current
28
- def current_user
28
+ def curent_user
29
29
  Avo::Current.user
30
30
  end
31
31
  delegate :params, to: Avo::Current
@@ -65,7 +65,7 @@ module Avo
65
65
  self.class.record = record
66
66
  self.class.resource = resource
67
67
  self.class.user = user
68
- self.class.view = Avo::ViewInquirer.new(view)
68
+ self.class.view = view
69
69
  @arguments = arguments
70
70
 
71
71
  self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
@@ -101,34 +101,39 @@ module Avo
101
101
  end
102
102
 
103
103
  def handle_action(**args)
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
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
113
113
 
114
- args[:fields].to_unsafe_h.map do |name, value|
114
+ if fields.present?
115
+ processed_fields = fields.to_unsafe_h.map do |name, value|
115
116
  field = action_fields_by_database_id[name.to_sym]
116
117
 
117
118
  next if field.blank?
118
119
 
119
120
  [name, field.resolve_attribute(value)]
120
- end.reject(&:blank?).to_h
121
+ end
122
+
123
+ processed_fields = processed_fields.reject(&:blank?).to_h
121
124
  else
122
- {}
125
+ processed_fields = {}
123
126
  end
124
127
 
125
- handle(
128
+ args = {
126
129
  fields: processed_fields.with_indifferent_access,
127
- current_user: args[:current_user],
128
- resource: args[:resource],
129
- records: args[:query],
130
- query: args[:query]
131
- )
130
+ current_user: current_user,
131
+ resource: resource
132
+ }
133
+
134
+ args[:records] = records
135
+
136
+ handle(**args)
132
137
 
133
138
  self
134
139
  end
@@ -136,7 +141,7 @@ module Avo
136
141
  def visible_in_view(parent_resource: nil)
137
142
  if visible.blank?
138
143
  # Hide on the :new view by default
139
- return false if view.new?
144
+ return false if view == :new
140
145
 
141
146
  # Show on all other views
142
147
  return true
@@ -9,11 +9,10 @@ module Avo
9
9
  include Avo::Concerns::HasStimulusControllers
10
10
  include Avo::Concerns::ModelClassConstantized
11
11
  include Avo::Concerns::HasDescription
12
- include Avo::Concerns::HasHelpers
13
12
 
14
13
  # Avo::Current methods
15
14
  delegate :context, to: Avo::Current
16
- def current_user
15
+ def curent_user
17
16
  Avo::Current.user
18
17
  end
19
18
  delegate :params, to: Avo::Current
@@ -66,7 +65,6 @@ module Avo
66
65
  class_attribute :extra_params
67
66
  class_attribute :link_to_child_resource, default: false
68
67
  class_attribute :map_view
69
- class_attribute :components, default: {}
70
68
 
71
69
  # EXTRACT:
72
70
  class_attribute :ordering
@@ -234,14 +232,14 @@ module Avo
234
232
  delegate :model_key, to: :class
235
233
 
236
234
  def initialize(record: nil, view: nil, user: nil, params: nil)
237
- @view = Avo::ViewInquirer.new(view) if view.present?
235
+ @view = view if view.present?
238
236
  @user = user if user.present?
239
237
  @params = params if params.present?
240
238
 
241
239
  if record.present?
242
240
  @record = record
243
241
 
244
- hydrate_model_with_default_values if @view&.new?
242
+ hydrate_model_with_default_values if @view == :new
245
243
  end
246
244
 
247
245
  detect_fields
@@ -295,23 +293,19 @@ module Avo
295
293
 
296
294
  # def get_action_arguments / def get_filter_arguments / def get_scope_arguments
297
295
  define_method "get_#{entity}_arguments" do |entity_class|
298
- klass = send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }
299
-
300
- raise "Couldn't find '#{entity_class}' in the 'def #{plural_entity}' method on your '#{self.class}' resource." if klass.nil?
301
-
302
- klass[:arguments]
296
+ send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }[:arguments]
303
297
  end
304
298
  end
305
299
 
306
300
  def hydrate(record: nil, view: nil, user: nil, params: nil)
307
- @view = Avo::ViewInquirer.new(view) if view.present?
301
+ @view = view if view.present?
308
302
  @user = user if user.present?
309
303
  @params = params if params.present?
310
304
 
311
305
  if record.present?
312
306
  @record = record
313
307
 
314
- hydrate_model_with_default_values if @view&.new?
308
+ hydrate_model_with_default_values if @view == :new
315
309
  end
316
310
 
317
311
  self
@@ -446,7 +440,7 @@ module Avo
446
440
  def hydrate_model_with_default_values
447
441
  default_values = get_fields
448
442
  .select do |field|
449
- !field.computed && !field.is_a?(Avo::Fields::HeadingField)
443
+ !field.computed
450
444
  end
451
445
  .map do |field|
452
446
  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