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.
- checksums.yaml +4 -4
- data/Gemfile +47 -48
- data/Gemfile.lock +1 -1
- data/Rakefile +14 -14
- data/app/components/avo/common/multiple_file_viewer_component.rb +1 -1
- data/app/components/avo/common/single_file_viewer_component.rb +1 -1
- data/app/components/avo/edit/field_wrapper_component.rb +3 -3
- data/app/components/avo/index/field_wrapper_component.rb +1 -1
- data/app/components/avo/index/grid_item_component.rb +10 -9
- data/app/components/avo/index/resource_controls_component.rb +2 -2
- data/app/components/avo/panel_component.rb +7 -6
- data/app/components/avo/resource_component.rb +4 -3
- data/app/components/avo/show/field_wrapper_component.rb +3 -3
- data/app/components/avo/views/resource_edit_component.rb +4 -3
- data/app/components/avo/views/resource_index_component.rb +8 -7
- data/app/components/avo/views/resource_new_component.rb +4 -3
- data/app/components/avo/views/resource_show_component.rb +21 -21
- data/app/controllers/avo/actions_controller.rb +30 -29
- data/app/controllers/avo/application_controller.rb +113 -126
- data/app/controllers/avo/attachments_controller.rb +3 -3
- data/app/controllers/avo/base_controller.rb +81 -80
- data/app/controllers/avo/home_controller.rb +2 -2
- data/app/controllers/avo/relations_controller.rb +29 -28
- data/app/controllers/avo/resources_controller.rb +1 -1
- data/app/controllers/avo/search_controller.rb +20 -19
- data/app/helpers/avo/application_helper.rb +48 -42
- data/app/helpers/avo/resources_helper.rb +11 -11
- data/app/mailers/avo/application_mailer.rb +2 -2
- data/app/packs/entrypoints/application.js +9 -7
- data/app/packs/js/controllers/fields/code_field_controller.js +14 -14
- data/app/packs/js/controllers/filter_controller.js +9 -8
- data/app/packs/js/toastr.js +1 -0
- data/avo.gemspec +31 -31
- data/config/initializers/inline_svg.rb +1 -1
- data/config/initializers/pagy.rb +1 -1
- data/config/routes.rb +12 -12
- data/config/spring.rb +5 -5
- data/db/factories.rb +3 -5
- data/lib/avo.rb +6 -6
- data/lib/avo/app.rb +18 -18
- data/lib/avo/base_action.rb +20 -20
- data/lib/avo/base_resource.rb +41 -45
- data/lib/avo/configuration.rb +16 -18
- data/lib/avo/engine.rb +18 -18
- data/lib/avo/fields/badge_field.rb +2 -2
- data/lib/avo/fields/base_field.rb +24 -25
- data/lib/avo/fields/belongs_to_field.rb +13 -12
- data/lib/avo/fields/boolean_field.rb +4 -4
- data/lib/avo/fields/boolean_group_field.rb +3 -3
- data/lib/avo/fields/code_field.rb +4 -4
- data/lib/avo/fields/country_field.rb +2 -2
- data/lib/avo/fields/currency_field.rb +3 -3
- data/lib/avo/fields/date_field.rb +3 -3
- data/lib/avo/fields/date_time_field.rb +2 -2
- data/lib/avo/fields/external_image_field.rb +2 -2
- data/lib/avo/fields/field_extensions/has_field_name.rb +2 -2
- data/lib/avo/fields/field_extensions/visible_in_different_views.rb +34 -33
- data/lib/avo/fields/file_field.rb +1 -1
- data/lib/avo/fields/files_field.rb +2 -2
- data/lib/avo/fields/gravatar_field.rb +9 -9
- data/lib/avo/fields/has_and_belongs_to_many_field.rb +1 -1
- data/lib/avo/fields/has_many_field.rb +1 -1
- data/lib/avo/fields/has_one_field.rb +2 -2
- data/lib/avo/fields/heading_field.rb +2 -2
- data/lib/avo/fields/hidden_field.rb +1 -1
- data/lib/avo/fields/id_field.rb +3 -3
- data/lib/avo/fields/key_value_field.rb +12 -12
- data/lib/avo/fields/markdown_field.rb +2 -2
- data/lib/avo/fields/number_field.rb +3 -3
- data/lib/avo/fields/password_field.rb +1 -1
- data/lib/avo/fields/select_field.rb +8 -12
- data/lib/avo/fields/status_field.rb +4 -4
- data/lib/avo/fields/text_field.rb +2 -2
- data/lib/avo/fields/textarea_field.rb +2 -2
- data/lib/avo/fields/trix_field.rb +1 -1
- data/lib/avo/fields_collector.rb +4 -5
- data/lib/avo/filters/base_filter.rb +6 -6
- data/lib/avo/filters/boolean_filter.rb +1 -1
- data/lib/avo/filters/select_filter.rb +1 -1
- data/lib/avo/licensing/h_q.rb +56 -55
- data/lib/avo/licensing/license.rb +5 -5
- data/lib/avo/licensing/license_manager.rb +4 -4
- data/lib/avo/licensing/null_license.rb +2 -2
- data/lib/avo/licensing/pro_license.rb +1 -1
- data/lib/avo/loaders/fields_loader.rb +4 -4
- data/lib/avo/services/authorization_service.rb +2 -2
- data/lib/avo/services/panel_service.rb +4 -4
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/action_generator.rb +4 -4
- data/lib/generators/avo/controller_generator.rb +4 -4
- data/lib/generators/avo/filter_generator.rb +5 -5
- data/lib/generators/avo/install_generator.rb +8 -8
- data/lib/generators/avo/locales_generator.rb +5 -5
- data/lib/generators/avo/partials_generator.rb +4 -4
- data/lib/generators/avo/resource_generator.rb +5 -5
- data/lib/tasks/avo_tasks.rake +52 -53
- data/public/avo-packs/css/{application-38e7e91b.css → application-4e16d6a6.css} +4 -4
- data/public/avo-packs/css/application-4e16d6a6.css.br +0 -0
- data/public/avo-packs/css/{application-38e7e91b.css.gz → application-4e16d6a6.css.gz} +0 -0
- data/public/avo-packs/css/{application-38e7e91b.css.map → application-4e16d6a6.css.map} +1 -1
- data/public/avo-packs/css/application-4e16d6a6.css.map.br +0 -0
- data/public/avo-packs/css/application-4e16d6a6.css.map.gz +0 -0
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js → application-8eb130a4688f2c667703.js} +4 -4
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js.LICENSE.txt → application-8eb130a4688f2c667703.js.LICENSE.txt} +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.br +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.gz +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map +1 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.br +0 -0
- data/public/avo-packs/js/application-8eb130a4688f2c667703.js.map.gz +0 -0
- data/public/avo-packs/manifest.json +15 -15
- metadata +15 -15
- data/public/avo-packs/css/application-38e7e91b.css.br +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.map.br +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.map.gz +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.br +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.gz +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map +0 -1
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.br +0 -0
- data/public/avo-packs/js/application-2b90fe889f7d6df1ad92.js.map.gz +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
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(
|
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 !=
|
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
|
-
|
32
|
-
|
28
|
+
def action_params
|
29
|
+
params.permit(:resource_name, :action_id, fields: {})
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
32
|
+
def set_action
|
33
|
+
action_class = params[:action_id].gsub("avo_actions_", "").classify.safe_constantize
|
37
34
|
|
38
|
-
|
35
|
+
if params[:id].present?
|
36
|
+
model = @resource.model_class.find params[:id]
|
39
37
|
end
|
40
38
|
|
41
|
-
|
42
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
path = response[:path]
|
47
|
+
if response[:type] == :download
|
48
|
+
return send_data response[:path], filename: response[:filename]
|
49
|
+
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
respond_to do |format|
|
52
|
+
format.html do
|
53
|
+
if response[:type] == :redirect
|
54
|
+
path = response[:path]
|
58
55
|
|
59
|
-
|
60
|
-
|
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 {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
104
|
+
def set_resource_name
|
105
|
+
@resource_name = resource_name
|
106
|
+
end
|
118
107
|
|
119
|
-
|
120
|
-
|
121
|
-
|
108
|
+
def set_related_resource_name
|
109
|
+
@related_resource_name = related_resource_name
|
110
|
+
end
|
122
111
|
|
123
|
-
|
124
|
-
|
125
|
-
|
112
|
+
def set_resource
|
113
|
+
@resource = resource.hydrate(params: params)
|
114
|
+
end
|
126
115
|
|
127
|
-
|
128
|
-
|
129
|
-
|
116
|
+
def set_related_resource
|
117
|
+
@related_resource = related_resource.hydrate(params: params)
|
118
|
+
end
|
130
119
|
|
131
|
-
|
132
|
-
|
133
|
-
|
120
|
+
def set_model
|
121
|
+
@model = eager_load_files(@resource, @resource.model_class).find params[:id]
|
122
|
+
end
|
134
123
|
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
128
|
+
def hydrate_resource
|
129
|
+
@resource.hydrate(view: action_name.to_sym, user: _current_user)
|
130
|
+
end
|
142
131
|
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
168
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
160
|
+
def related_resource_name
|
161
|
+
params[:related_name]
|
162
|
+
end
|
174
163
|
|
175
|
-
|
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
|
-
|
169
|
+
return resource if resource.present?
|
178
170
|
|
179
|
-
|
180
|
-
|
171
|
+
App.get_resource_by_controller_name @resource_name
|
172
|
+
end
|
181
173
|
|
182
|
-
|
183
|
-
|
174
|
+
def related_resource
|
175
|
+
reflection = @model._reflections[params[:related_name]]
|
184
176
|
|
185
|
-
|
186
|
-
reflected_model = reflection.klass
|
187
|
-
else
|
188
|
-
reflected_model = reflection.klass
|
189
|
-
end
|
177
|
+
reflected_model = reflection.klass
|
190
178
|
|
191
|
-
|
192
|
-
|
179
|
+
App.get_resource_by_model_name reflected_model
|
180
|
+
end
|
193
181
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
# model = record = resource.model
|
204
|
+
# def authorize_user
|
205
|
+
# return if params[:controller] == 'avo/search'
|
221
206
|
|
222
|
-
|
223
|
-
# record = resource
|
224
|
-
# end
|
207
|
+
# model = record = resource.model
|
225
208
|
|
226
|
-
|
227
|
-
|
209
|
+
# if ['show', 'edit', 'update'].include?(params[:action]) && params[:controller] == 'avo/resources'
|
210
|
+
# record = resource
|
211
|
+
# end
|
228
212
|
|
229
|
-
|
230
|
-
|
231
|
-
end
|
213
|
+
# # AuthorizationService::authorize_action _current_user, record, params[:action] return render_unauthorized unless
|
214
|
+
# end
|
232
215
|
|
233
|
-
|
234
|
-
|
235
|
-
|
216
|
+
def _authenticate!
|
217
|
+
instance_eval(&Avo.configuration.authenticate)
|
218
|
+
end
|
236
219
|
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|
-
|
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
|
-
|
248
|
-
@authorization = Services::AuthorizationService.new _current_user
|
230
|
+
redirect_to(redirect_url)
|
249
231
|
end
|
232
|
+
end
|
250
233
|
|
251
|
-
|
252
|
-
|
253
|
-
|
234
|
+
def set_authorization
|
235
|
+
@authorization = Services::AuthorizationService.new _current_user
|
236
|
+
end
|
254
237
|
|
255
|
-
|
256
|
-
|
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
|
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(
|
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(
|
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
|
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
|
-
|
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
|
-
|
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
|
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
|
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(
|
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
|
-
|
117
|
-
|
113
|
+
def model_route_key
|
114
|
+
@resource.model_class.model_name.route_key.singularize
|
115
|
+
end
|
118
116
|
|
119
|
-
|
120
|
-
|
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
|
-
|
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
|
-
|
128
|
-
|
129
|
-
end
|
125
|
+
request_params
|
126
|
+
end
|
130
127
|
|
131
|
-
|
132
|
-
|
128
|
+
def permitted_params
|
129
|
+
@resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param)
|
130
|
+
end
|
133
131
|
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
139
|
+
[field.id, field.null_values]
|
140
|
+
end
|
140
141
|
.to_h
|
141
142
|
|
142
|
-
|
143
|
-
|
143
|
+
params.each do |key, value|
|
144
|
+
nullable = nullable_fields[key.to_sym]
|
144
145
|
|
145
|
-
|
146
|
-
|
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
|
-
|
154
|
-
|
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
|
-
|
161
|
-
|
162
|
-
end
|
154
|
+
def set_index_params
|
155
|
+
@index_params = {}
|
163
156
|
|
164
|
-
|
165
|
-
|
166
|
-
|
157
|
+
# Pagination
|
158
|
+
@index_params[:page] = params[:page] || 1
|
159
|
+
@index_params[:per_page] = Avo.configuration.per_page
|
167
160
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
end
|
161
|
+
if cookies[:per_page].present?
|
162
|
+
@index_params[:per_page] = cookies[:per_page]
|
163
|
+
end
|
172
164
|
|
173
|
-
|
174
|
-
@index_params[:
|
175
|
-
|
165
|
+
if @parent_model.present?
|
166
|
+
@index_params[:per_page] = Avo.configuration.via_per_page
|
167
|
+
end
|
176
168
|
|
177
|
-
|
178
|
-
@index_params[:
|
179
|
-
|
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
|
-
|
183
|
-
|
184
|
-
|
174
|
+
# Sorting
|
175
|
+
@index_params[:sort_by] = params[:sort_by] || :created_at
|
176
|
+
@index_params[:sort_direction] = params[:sort_direction] || :desc
|
185
177
|
|
186
|
-
|
187
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
def set_actions
|
192
|
+
if params[:resource_id].present?
|
193
|
+
model = @resource.model_class.find params[:resource_id]
|
194
|
+
end
|
194
195
|
|
195
|
-
|
196
|
-
|
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
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
201
|
+
def applied_filters
|
202
|
+
if params[:filters].present?
|
203
|
+
return JSON.parse(Base64.decode64(params[:filters]))
|
204
|
+
end
|
204
205
|
|
205
|
-
|
206
|
+
filter_defaults = {}
|
206
207
|
|
207
|
-
|
208
|
-
|
208
|
+
@resource.get_filters.each do |filter_class|
|
209
|
+
filter = filter_class.new
|
209
210
|
|
210
|
-
|
211
|
-
|
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
|