avo 0.5.0.beta9 → 0.5.0.beta10

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 +47 -48
  3. data/Gemfile.lock +1 -1
  4. data/Rakefile +14 -14
  5. data/app/components/avo/common/multiple_file_viewer_component.rb +1 -1
  6. data/app/components/avo/common/single_file_viewer_component.rb +1 -1
  7. data/app/components/avo/edit/field_wrapper_component.rb +3 -3
  8. data/app/components/avo/index/field_wrapper_component.rb +1 -1
  9. data/app/components/avo/index/grid_item_component.rb +10 -9
  10. data/app/components/avo/index/resource_controls_component.rb +2 -2
  11. data/app/components/avo/panel_component.rb +7 -6
  12. data/app/components/avo/resource_component.rb +4 -3
  13. data/app/components/avo/show/field_wrapper_component.rb +3 -3
  14. data/app/components/avo/views/resource_edit_component.rb +4 -3
  15. data/app/components/avo/views/resource_index_component.rb +8 -7
  16. data/app/components/avo/views/resource_new_component.rb +4 -3
  17. data/app/components/avo/views/resource_show_component.rb +21 -21
  18. data/app/controllers/avo/actions_controller.rb +30 -29
  19. data/app/controllers/avo/application_controller.rb +113 -126
  20. data/app/controllers/avo/attachments_controller.rb +3 -3
  21. data/app/controllers/avo/base_controller.rb +81 -80
  22. data/app/controllers/avo/home_controller.rb +2 -2
  23. data/app/controllers/avo/relations_controller.rb +29 -28
  24. data/app/controllers/avo/resources_controller.rb +1 -1
  25. data/app/controllers/avo/search_controller.rb +20 -19
  26. data/app/helpers/avo/application_helper.rb +48 -42
  27. data/app/helpers/avo/resources_helper.rb +11 -11
  28. data/app/mailers/avo/application_mailer.rb +2 -2
  29. data/app/packs/entrypoints/application.js +9 -7
  30. data/app/packs/js/controllers/fields/code_field_controller.js +14 -14
  31. data/app/packs/js/controllers/filter_controller.js +9 -8
  32. data/app/packs/js/toastr.js +1 -0
  33. data/avo.gemspec +31 -31
  34. data/config/initializers/inline_svg.rb +1 -1
  35. data/config/initializers/pagy.rb +1 -1
  36. data/config/routes.rb +12 -12
  37. data/config/spring.rb +5 -5
  38. data/db/factories.rb +3 -5
  39. data/lib/avo.rb +6 -6
  40. data/lib/avo/app.rb +18 -18
  41. data/lib/avo/base_action.rb +20 -20
  42. data/lib/avo/base_resource.rb +41 -45
  43. data/lib/avo/configuration.rb +16 -18
  44. data/lib/avo/engine.rb +18 -18
  45. data/lib/avo/fields/badge_field.rb +2 -2
  46. data/lib/avo/fields/base_field.rb +24 -25
  47. data/lib/avo/fields/belongs_to_field.rb +13 -12
  48. data/lib/avo/fields/boolean_field.rb +4 -4
  49. data/lib/avo/fields/boolean_group_field.rb +3 -3
  50. data/lib/avo/fields/code_field.rb +4 -4
  51. data/lib/avo/fields/country_field.rb +2 -2
  52. data/lib/avo/fields/currency_field.rb +3 -3
  53. data/lib/avo/fields/date_field.rb +3 -3
  54. data/lib/avo/fields/date_time_field.rb +2 -2
  55. data/lib/avo/fields/external_image_field.rb +2 -2
  56. data/lib/avo/fields/field_extensions/has_field_name.rb +2 -2
  57. data/lib/avo/fields/field_extensions/visible_in_different_views.rb +34 -33
  58. data/lib/avo/fields/file_field.rb +1 -1
  59. data/lib/avo/fields/files_field.rb +2 -2
  60. data/lib/avo/fields/gravatar_field.rb +9 -9
  61. data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -1
  62. data/lib/avo/fields/has_many_field.rb +1 -1
  63. data/lib/avo/fields/has_one_field.rb +2 -2
  64. data/lib/avo/fields/heading_field.rb +2 -2
  65. data/lib/avo/fields/hidden_field.rb +1 -1
  66. data/lib/avo/fields/id_field.rb +3 -3
  67. data/lib/avo/fields/key_value_field.rb +12 -12
  68. data/lib/avo/fields/markdown_field.rb +2 -2
  69. data/lib/avo/fields/number_field.rb +3 -3
  70. data/lib/avo/fields/password_field.rb +1 -1
  71. data/lib/avo/fields/select_field.rb +8 -12
  72. data/lib/avo/fields/status_field.rb +4 -4
  73. data/lib/avo/fields/text_field.rb +2 -2
  74. data/lib/avo/fields/textarea_field.rb +2 -2
  75. data/lib/avo/fields/trix_field.rb +1 -1
  76. data/lib/avo/fields_collector.rb +4 -5
  77. data/lib/avo/filters/base_filter.rb +6 -6
  78. data/lib/avo/filters/boolean_filter.rb +1 -1
  79. data/lib/avo/filters/select_filter.rb +1 -1
  80. data/lib/avo/licensing/h_q.rb +56 -55
  81. data/lib/avo/licensing/license.rb +5 -5
  82. data/lib/avo/licensing/license_manager.rb +4 -4
  83. data/lib/avo/licensing/null_license.rb +2 -2
  84. data/lib/avo/licensing/pro_license.rb +1 -1
  85. data/lib/avo/loaders/fields_loader.rb +4 -4
  86. data/lib/avo/services/authorization_service.rb +2 -2
  87. data/lib/avo/services/panel_service.rb +4 -4
  88. data/lib/avo/version.rb +1 -1
  89. data/lib/generators/avo/action_generator.rb +4 -4
  90. data/lib/generators/avo/controller_generator.rb +4 -4
  91. data/lib/generators/avo/filter_generator.rb +5 -5
  92. data/lib/generators/avo/install_generator.rb +8 -8
  93. data/lib/generators/avo/locales_generator.rb +5 -5
  94. data/lib/generators/avo/partials_generator.rb +4 -4
  95. data/lib/generators/avo/resource_generator.rb +5 -5
  96. data/lib/tasks/avo_tasks.rake +52 -53
  97. data/public/avo-packs/css/{application-38e7e91b.css → application-4e16d6a6.css} +4 -4
  98. data/public/avo-packs/css/application-4e16d6a6.css.br +0 -0
  99. data/public/avo-packs/css/{application-38e7e91b.css.gz → application-4e16d6a6.css.gz} +0 -0
  100. data/public/avo-packs/css/{application-38e7e91b.css.map → application-4e16d6a6.css.map} +1 -1
  101. data/public/avo-packs/css/application-4e16d6a6.css.map.br +0 -0
  102. data/public/avo-packs/css/application-4e16d6a6.css.map.gz +0 -0
  103. data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js → application-8eb130a4688f2c667703.js} +4 -4
  104. data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js.LICENSE.txt → application-8eb130a4688f2c667703.js.LICENSE.txt} +0 -0
  105. data/public/avo-packs/js/application-8eb130a4688f2c667703.js.br +0 -0
  106. data/public/avo-packs/js/application-8eb130a4688f2c667703.js.gz +0 -0
  107. data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map +1 -0
  108. data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.br +0 -0
  109. data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.gz +0 -0
  110. data/public/avo-packs/manifest.json +15 -15
  111. metadata +15 -15
  112. data/public/avo-packs/css/application-38e7e91b.css.br +0 -0
  113. data/public/avo-packs/css/application-38e7e91b.css.map.br +0 -0
  114. data/public/avo-packs/css/application-38e7e91b.css.map.gz +0 -0
  115. data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.br +0 -0
  116. data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.gz +0 -0
  117. data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map +0 -1
  118. data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.br +0 -0
  119. data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.gz +0 -0
@@ -1,4 +1,4 @@
1
- require_dependency 'avo/application_controller'
1
+ require_dependency "avo/application_controller"
2
2
 
3
3
  module Avo
4
4
  class ActionsController < ApplicationController
@@ -11,11 +11,11 @@ module Avo
11
11
  end
12
12
 
13
13
  def handle
14
- resource_ids = action_params[:fields][:resource_ids].split(',').map(&:to_i)
14
+ resource_ids = action_params[:fields][:resource_ids].split(",").map(&:to_i)
15
15
  models = @resource.model_class.find resource_ids
16
16
 
17
17
  fields = action_params[:fields].select do |key, value|
18
- key != 'resource_ids'
18
+ key != "resource_ids"
19
19
  end
20
20
 
21
21
  performed_action = @action.handle_action(models: models, fields: fields)
@@ -24,44 +24,45 @@ module Avo
24
24
  end
25
25
 
26
26
  private
27
- def action_params
28
- params.permit(:resource_name, :action_id, fields: {})
29
- end
30
27
 
31
- def set_action
32
- action_class = params[:action_id].gsub('avo_actions_', '').classify.safe_constantize
28
+ def action_params
29
+ params.permit(:resource_name, :action_id, fields: {})
30
+ end
33
31
 
34
- if params[:id].present?
35
- model = @resource.model_class.find params[:id]
36
- end
32
+ def set_action
33
+ action_class = params[:action_id].gsub("avo_actions_", "").classify.safe_constantize
37
34
 
38
- @action = action_class.new(model: model, resource: resource, user: _current_user)
35
+ if params[:id].present?
36
+ model = @resource.model_class.find params[:id]
39
37
  end
40
38
 
41
- def respond(response)
42
- response[:type] ||= :reload
43
- response[:message_type] ||= :notice
44
- response[:message] ||= I18n.t('avo.action_ran_successfully')
39
+ @action = action_class.new(model: model, resource: resource, user: _current_user)
40
+ end
45
41
 
46
- if response[:type] == :download
47
- return send_data response[:path], filename: response[:filename]
48
- end
42
+ def respond(response)
43
+ response[:type] ||= :reload
44
+ response[:message_type] ||= :notice
45
+ response[:message] ||= I18n.t("avo.action_ran_successfully")
49
46
 
50
- respond_to do |format|
51
- format.html do
52
- if response[:type] == :redirect
53
- path = response[:path]
47
+ if response[:type] == :download
48
+ return send_data response[:path], filename: response[:filename]
49
+ end
54
50
 
55
- if path.respond_to? :call
56
- path = instance_eval &path
57
- end
51
+ respond_to do |format|
52
+ format.html do
53
+ if response[:type] == :redirect
54
+ path = response[:path]
58
55
 
59
- redirect_to path, "#{response[:message_type]}": response[:message]
60
- elsif response[:type] == :reload
61
- redirect_back fallback_location: resources_path(@resource.model_class), "#{response[:message_type]}": response[:message]
56
+ if path.respond_to? :call
57
+ path = instance_eval(&path)
62
58
  end
59
+
60
+ redirect_to path, "#{response[:message_type]}": response[:message]
61
+ elsif response[:type] == :reload
62
+ redirect_back fallback_location: resources_path(@resource.model_class), "#{response[:message_type]}": response[:message]
63
63
  end
64
64
  end
65
65
  end
66
+ end
66
67
  end
67
68
  end
@@ -23,11 +23,13 @@ module Avo
23
23
  def exception_logger(exception)
24
24
  respond_to do |format|
25
25
  format.html { raise exception }
26
- format.json { render json: {
27
- errors: exception.respond_to?(:record) && exception.record.present? ? exception.record.errors : [],
28
- message: exception.message,
29
- traces: exception.backtrace,
30
- }, status: ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name) }
26
+ format.json {
27
+ render json: {
28
+ errors: exception.respond_to?(:record) && exception.record.present? ? exception.record.errors : [],
29
+ message: exception.message,
30
+ traces: exception.backtrace
31
+ }, status: ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name)
32
+ }
31
33
  end
32
34
  end
33
35
 
@@ -48,8 +50,7 @@ module Avo
48
50
  if keep_query_params
49
51
  existing_params = Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
50
52
  end
51
- rescue;end
52
-
53
+ rescue; end
53
54
  send :"resources_#{model.model_name.route_key}_path", **existing_params, **args
54
55
  end
55
56
 
@@ -62,22 +63,13 @@ module Avo
62
63
  if keep_query_params
63
64
  existing_params = Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
64
65
  end
65
- rescue;end
66
-
66
+ rescue; end
67
67
  Addressable::Template.new("#{Avo.configuration.root_path}/resources/#{@parent_resource.model.model_name.route_key}/#{@parent_resource.model.id}/#{@resource.route_key}{?query*}")
68
68
  .expand({query: {**existing_params, **args}})
69
69
  .to_str
70
70
  end
71
71
 
72
72
  def resource_path(model = nil, resource_id: nil, keep_query_params: false, **args)
73
- existing_params = {}
74
-
75
- begin
76
- if keep_query_params
77
- existing_params = Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
78
- end
79
- rescue;end
80
-
81
73
  return send :"resources_#{model.model_name.route_key.singularize}_path", resource_id, **args if resource_id.present?
82
74
 
83
75
  send :"resources_#{model.model_name.route_key.singularize}_path", model, **args
@@ -108,151 +100,146 @@ module Avo
108
100
  end
109
101
 
110
102
  private
111
- def set_resource_name
112
- @resource_name = resource_name
113
- end
114
103
 
115
- def set_related_resource_name
116
- @related_resource_name = related_resource_name
117
- end
104
+ def set_resource_name
105
+ @resource_name = resource_name
106
+ end
118
107
 
119
- def set_resource
120
- @resource = resource.hydrate(params: params)
121
- end
108
+ def set_related_resource_name
109
+ @related_resource_name = related_resource_name
110
+ end
122
111
 
123
- def set_related_resource
124
- @related_resource = related_resource.hydrate(params: params)
125
- end
112
+ def set_resource
113
+ @resource = resource.hydrate(params: params)
114
+ end
126
115
 
127
- def set_model
128
- @model = eager_load_files(@resource, @resource.model_class).find params[:id]
129
- end
116
+ def set_related_resource
117
+ @related_resource = related_resource.hydrate(params: params)
118
+ end
130
119
 
131
- def set_related_model
132
- @related_model = eager_load_files(@related_resource, @related_resource.model_class).find params[:related_id]
133
- end
120
+ def set_model
121
+ @model = eager_load_files(@resource, @resource.model_class).find params[:id]
122
+ end
134
123
 
135
- def hydrate_resource
136
- @resource.hydrate(view: action_name.to_sym, user: _current_user)
137
- end
124
+ def set_related_model
125
+ @related_model = eager_load_files(@related_resource, @related_resource.model_class).find params[:related_id]
126
+ end
138
127
 
139
- def hydrate_related_resource
140
- @related_resource.hydrate(view: action_name.to_sym, user: _current_user)
141
- end
128
+ def hydrate_resource
129
+ @resource.hydrate(view: action_name.to_sym, user: _current_user)
130
+ end
142
131
 
143
- def authorize_action
144
- if @model.present?
145
- @authorization.set_record(@model).authorize_action :index
146
- else
147
- @authorization.set_record(@resource.model_class).authorize_action :index
148
- end
149
- end
132
+ def hydrate_related_resource
133
+ @related_resource.hydrate(view: action_name.to_sym, user: _current_user)
134
+ end
150
135
 
151
- # Get the pluralized resource name for this request
152
- # Ex: projects, teams, users
153
- def resource_name
154
- return params[:resource_name] if params[:resource_name].present?
136
+ def authorize_action
137
+ if @model.present?
138
+ @authorization.set_record(@model).authorize_action :index
139
+ else
140
+ @authorization.set_record(@resource.model_class).authorize_action :index
141
+ end
142
+ end
155
143
 
156
- return controller_name if controller_name.present?
144
+ # Get the pluralized resource name for this request
145
+ # Ex: projects, teams, users
146
+ def resource_name
147
+ return params[:resource_name] if params[:resource_name].present?
157
148
 
158
- begin
159
- request.path
160
- .match(/\/?#{Avo.configuration.root_path.gsub('/', '')}\/resources\/([a-z1-9\-_]*)\/?/mi)
161
- .captures
162
- .first
163
- rescue => exception
164
- end
165
- end
149
+ return controller_name if controller_name.present?
166
150
 
167
- def related_resource_name
168
- params[:related_name]
151
+ begin
152
+ request.path
153
+ .match(/\/?#{Avo.configuration.root_path.delete('/')}\/resources\/([a-z1-9\-_]*)\/?/mi)
154
+ .captures
155
+ .first
156
+ rescue
169
157
  end
158
+ end
170
159
 
171
- # Gets the Avo resource for this request based on the request from the `resource_name` "param"
172
- # Ex: Avo::Resources::Project, Avo::Resources::Team, Avo::Resources::User
173
- def resource
160
+ def related_resource_name
161
+ params[:related_name]
162
+ end
174
163
 
175
- resource = App.get_resource @resource_name.to_s.camelize.singularize
164
+ # Gets the Avo resource for this request based on the request from the `resource_name` "param"
165
+ # Ex: Avo::Resources::Project, Avo::Resources::Team, Avo::Resources::User
166
+ def resource
167
+ resource = App.get_resource @resource_name.to_s.camelize.singularize
176
168
 
177
- return resource if resource.present?
169
+ return resource if resource.present?
178
170
 
179
- App.get_resource_by_controller_name @resource_name
180
- end
171
+ App.get_resource_by_controller_name @resource_name
172
+ end
181
173
 
182
- def related_resource
183
- reflection = @model._reflections[params[:related_name]]
174
+ def related_resource
175
+ reflection = @model._reflections[params[:related_name]]
184
176
 
185
- if reflection.is_a? ::ActiveRecord::Reflection::HasOneReflection
186
- reflected_model = reflection.klass
187
- else
188
- reflected_model = reflection.klass
189
- end
177
+ reflected_model = reflection.klass
190
178
 
191
- App.get_resource_by_model_name reflected_model
192
- end
179
+ App.get_resource_by_model_name reflected_model
180
+ end
193
181
 
194
- def eager_load_files(resource, query)
195
- if resource.attached_file_fields.present?
196
- resource.attached_file_fields.map do |field|
197
- # abort "#{field.pluralize}".inspect
198
- # abort field.class.inspect
199
- attachment = case field.class.to_s
200
- when 'Avo::Fields::FileField'
201
- 'attachment'
202
- when 'Avo::Fields::FilesField'
203
- 'attachments'
204
- else
205
- 'attachment'
206
- end
207
-
208
- return query.eager_load "#{field.id}_#{attachment}": :blob
209
- # return query.send :"with_attached_#{field}"
182
+ def eager_load_files(resource, query)
183
+ if resource.attached_file_fields.present?
184
+ resource.attached_file_fields.map do |field|
185
+ # abort "#{field.pluralize}".inspect
186
+ # abort field.class.inspect
187
+ attachment = case field.class.to_s
188
+ when "Avo::Fields::FileField"
189
+ "attachment"
190
+ when "Avo::Fields::FilesField"
191
+ "attachments"
192
+ else
193
+ "attachment"
210
194
  end
211
- end
212
195
 
213
- query
196
+ return query.eager_load "#{field.id}_#{attachment}": :blob
197
+ # return query.send :"with_attached_#{field}"
198
+ end
214
199
  end
215
200
 
201
+ query
202
+ end
216
203
 
217
- # def authorize_user
218
- # return if params[:controller] == 'avo/search'
219
-
220
- # model = record = resource.model
204
+ # def authorize_user
205
+ # return if params[:controller] == 'avo/search'
221
206
 
222
- # if ['show', 'edit', 'update'].include?(params[:action]) && params[:controller] == 'avo/resources'
223
- # record = resource
224
- # end
207
+ # model = record = resource.model
225
208
 
226
- # # AuthorizationService::authorize_action _current_user, record, params[:action] return render_unauthorized unless
227
- # end
209
+ # if ['show', 'edit', 'update'].include?(params[:action]) && params[:controller] == 'avo/resources'
210
+ # record = resource
211
+ # end
228
212
 
229
- def _authenticate!
230
- instance_eval(&Avo.configuration.authenticate)
231
- end
213
+ # # AuthorizationService::authorize_action _current_user, record, params[:action] return render_unauthorized unless
214
+ # end
232
215
 
233
- def render_unauthorized(exception)
234
- if !exception.is_a? Pundit::NotDefinedError
235
- flash[:notice] = t 'avo.not_authorized'
216
+ def _authenticate!
217
+ instance_eval(&Avo.configuration.authenticate)
218
+ end
236
219
 
237
- redirect_url = if request.referrer.blank? or request.referrer == request.url
238
- root_url
239
- else
240
- request.referrer
241
- end
220
+ def render_unauthorized(exception)
221
+ if !exception.is_a? Pundit::NotDefinedError
222
+ flash[:notice] = t "avo.not_authorized"
242
223
 
243
- redirect_to(redirect_url)
224
+ redirect_url = if request.referrer.blank? || (request.referrer == request.url)
225
+ root_url
226
+ else
227
+ request.referrer
244
228
  end
245
- end
246
229
 
247
- def set_authorization
248
- @authorization = Services::AuthorizationService.new _current_user
230
+ redirect_to(redirect_url)
249
231
  end
232
+ end
250
233
 
251
- def set_container_classes
252
- contain = !Avo.configuration.full_width_container
253
- contain = false if Avo.configuration.full_width_index_view && action_name.to_sym == :index && self.class.superclass.to_s == 'Avo::ResourcesController'
234
+ def set_authorization
235
+ @authorization = Services::AuthorizationService.new _current_user
236
+ end
254
237
 
255
- @container_classes = contain ? '2xl:container 2xl:mx-auto' : ''
256
- end
238
+ def set_container_classes
239
+ contain = !Avo.configuration.full_width_container
240
+ contain = false if Avo.configuration.full_width_index_view && action_name.to_sym == :index && self.class.superclass.to_s == "Avo::ResourcesController"
241
+
242
+ @container_classes = contain ? "2xl:container 2xl:mx-auto" : ""
243
+ end
257
244
  end
258
245
  end
@@ -1,4 +1,4 @@
1
- require_dependency 'avo/application_controller'
1
+ require_dependency "avo/application_controller"
2
2
 
3
3
  module Avo
4
4
  class AttachmentsController < ApplicationController
@@ -16,9 +16,9 @@ module Avo
16
16
  if attachment.present?
17
17
  attachment.destroy
18
18
 
19
- redirect_to params[:referrer] || resource_path(@model), notice: t('avo.attachment_destroyed')
19
+ redirect_to params[:referrer] || resource_path(@model), notice: t("avo.attachment_destroyed")
20
20
  else
21
- redirect_back fallback_location: resource_path(@model), notice: t('avo.failed_to_find_attachment')
21
+ redirect_back fallback_location: resource_path(@model), notice: t("avo.failed_to_find_attachment")
22
22
  end
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require_dependency 'avo/application_controller'
1
+ require_dependency "avo/application_controller"
2
2
 
3
3
  module Avo
4
4
  class BaseController < ApplicationController
@@ -66,16 +66,16 @@ module Avo
66
66
 
67
67
  respond_to do |format|
68
68
  if saved
69
- if params[:via_relation_class].present? && params[:via_resource_id].present?
70
- redirect_path = resource_path(params[:via_relation_class].safe_constantize, resource_id: params[:via_resource_id])
69
+ redirect_path = if params[:via_relation_class].present? && params[:via_resource_id].present?
70
+ resource_path(params[:via_relation_class].safe_constantize, resource_id: params[:via_resource_id])
71
71
  else
72
- redirect_path = resource_path(@model)
72
+ resource_path(@model)
73
73
  end
74
74
 
75
75
  format.html { redirect_to redirect_path, notice: "#{@model.class.name} was successfully created." }
76
76
  format.json { render :show, status: :created, location: @model }
77
77
  else
78
- flash[:error] = t 'avo.you_missed_something_check_form'
78
+ flash[:error] = t "avo.you_missed_something_check_form"
79
79
  format.html { render :new, status: :unprocessable_entity }
80
80
  format.json { render json: @model.errors, status: :unprocessable_entity }
81
81
  end
@@ -92,7 +92,7 @@ module Avo
92
92
  format.html { redirect_to params[:referrer] || resource_path(@model), notice: "#{@model.class.name} was successfully updated." }
93
93
  format.json { render :show, status: :ok, location: @model }
94
94
  else
95
- flash[:error] = t 'avo.you_missed_something_check_form'
95
+ flash[:error] = t "avo.you_missed_something_check_form"
96
96
  format.html { render :edit, status: :unprocessable_entity }
97
97
  format.json { render json: @model.errors, status: :unprocessable_entity }
98
98
  end
@@ -103,116 +103,117 @@ module Avo
103
103
  @model.destroy!
104
104
 
105
105
  respond_to do |format|
106
- format.html { redirect_to params[:referrer] || resources_path(@model, turbo_frame: params[:turbo_frame], view_type: params[:view_type]), notice: t('avo.resource_destroyed', attachment_class: @attachment_class) }
106
+ format.html { redirect_to params[:referrer] || resources_path(@model, turbo_frame: params[:turbo_frame], view_type: params[:view_type]), notice: t("avo.resource_destroyed", attachment_class: @attachment_class) }
107
107
  format.json { head :no_content }
108
108
  end
109
109
  end
110
110
 
111
111
  private
112
- def model_route_key
113
- @resource.model_class.model_name.route_key.singularize
114
- end
115
112
 
116
- def model_params
117
- request_params = params.require(model_route_key).permit(permitted_params)
113
+ def model_route_key
114
+ @resource.model_class.model_name.route_key.singularize
115
+ end
118
116
 
119
- if @resource.devise_password_optional and request_params[:password].blank? and request_params[:password_confirmation].blank?
120
- request_params.delete(:password_confirmation)
121
- request_params.delete(:password)
122
- end
117
+ def model_params
118
+ request_params = params.require(model_route_key).permit(permitted_params)
123
119
 
124
- request_params
120
+ if @resource.devise_password_optional && request_params[:password].blank? && request_params[:password_confirmation].blank?
121
+ request_params.delete(:password_confirmation)
122
+ request_params.delete(:password)
125
123
  end
126
124
 
127
- def permitted_params
128
- @resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param)
129
- end
125
+ request_params
126
+ end
130
127
 
131
- def cast_nullable(params)
132
- fields = @resource.get_field_definitions
128
+ def permitted_params
129
+ @resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param)
130
+ end
133
131
 
134
- nullable_fields = fields.filter do |field|
135
- field.nullable
136
- end
132
+ def cast_nullable(params)
133
+ fields = @resource.get_field_definitions
134
+
135
+ nullable_fields = fields.filter do |field|
136
+ field.nullable
137
+ end
137
138
  .map do |field|
138
- [field.id, field.null_values]
139
- end
139
+ [field.id, field.null_values]
140
+ end
140
141
  .to_h
141
142
 
142
- params.each do |key, value|
143
- nullable = nullable_fields[key.to_sym]
143
+ params.each do |key, value|
144
+ nullable = nullable_fields[key.to_sym]
144
145
 
145
- if nullable.present? && value.in?(nullable)
146
- params[key] = nil
147
- end
146
+ if nullable.present? && value.in?(nullable)
147
+ params[key] = nil
148
148
  end
149
-
150
- params
151
149
  end
152
150
 
153
- def set_index_params
154
- @index_params = {}
155
-
156
- # Pagination
157
- @index_params[:page] = params[:page] || 1
158
- @index_params[:per_page] = Avo.configuration.per_page
151
+ params
152
+ end
159
153
 
160
- if cookies[:per_page].present?
161
- @index_params[:per_page] = cookies[:per_page]
162
- end
154
+ def set_index_params
155
+ @index_params = {}
163
156
 
164
- if @parent_model.present?
165
- @index_params[:per_page] = Avo.configuration.via_per_page
166
- end
157
+ # Pagination
158
+ @index_params[:page] = params[:page] || 1
159
+ @index_params[:per_page] = Avo.configuration.per_page
167
160
 
168
- if params[:per_page].present?
169
- @index_params[:per_page] = params[:per_page]
170
- cookies[:per_page] = params[:per_page]
171
- end
161
+ if cookies[:per_page].present?
162
+ @index_params[:per_page] = cookies[:per_page]
163
+ end
172
164
 
173
- # Sorting
174
- @index_params[:sort_by] = params[:sort_by] || :created_at
175
- @index_params[:sort_direction] = params[:sort_direction] || :desc
165
+ if @parent_model.present?
166
+ @index_params[:per_page] = Avo.configuration.via_per_page
167
+ end
176
168
 
177
- # View types
178
- @index_params[:view_type] = params[:view_type] || @resource.default_view_type || Avo.configuration.default_view_type
179
- @index_params[:available_view_types] = @resource.available_view_types
169
+ if params[:per_page].present?
170
+ @index_params[:per_page] = params[:per_page]
171
+ cookies[:per_page] = params[:per_page]
180
172
  end
181
173
 
182
- def set_filters
183
- @filters = @resource.get_filters.map do |filter_class|
184
- filter = filter_class.new
174
+ # Sorting
175
+ @index_params[:sort_by] = params[:sort_by] || :created_at
176
+ @index_params[:sort_direction] = params[:sort_direction] || :desc
185
177
 
186
- filter
187
- end
178
+ # View types
179
+ @index_params[:view_type] = params[:view_type] || @resource.default_view_type || Avo.configuration.default_view_type
180
+ @index_params[:available_view_types] = @resource.available_view_types
181
+ end
182
+
183
+ def set_filters
184
+ @filters = @resource.get_filters.map do |filter_class|
185
+ filter = filter_class.new
186
+
187
+ filter
188
188
  end
189
+ end
189
190
 
190
- def set_actions
191
- if params[:resource_id].present?
192
- model = @resource.model_class.find params[:resource_id]
193
- end
191
+ def set_actions
192
+ if params[:resource_id].present?
193
+ model = @resource.model_class.find params[:resource_id]
194
+ end
194
195
 
195
- @actions = @resource.get_actions.map do |action|
196
- action.new(model: model, resource: @resource)
197
- end
196
+ @actions = @resource.get_actions.map do |action|
197
+ action.new(model: model, resource: @resource)
198
198
  end
199
+ end
199
200
 
200
- def applied_filters
201
- if params[:filters].present?
202
- return JSON.parse(Base64.decode64(params[:filters]))
203
- end
201
+ def applied_filters
202
+ if params[:filters].present?
203
+ return JSON.parse(Base64.decode64(params[:filters]))
204
+ end
204
205
 
205
- filter_defaults = {}
206
+ filter_defaults = {}
206
207
 
207
- @resource.get_filters.each do |filter_class|
208
- filter = filter_class.new
208
+ @resource.get_filters.each do |filter_class|
209
+ filter = filter_class.new
209
210
 
210
- if filter.default.present?
211
- filter_defaults[filter_class.to_s] = filter.default
212
- end
211
+ if filter.default.present?
212
+ filter_defaults[filter_class.to_s] = filter.default
213
213
  end
214
-
215
- filter_defaults
216
214
  end
215
+
216
+ filter_defaults
217
+ end
217
218
  end
218
219
  end