avo 0.5.0.beta9 → 0.5.0.beta14
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 +46 -50
- data/Gemfile.lock +1 -6
- 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/images/logo.png +0 -0
- 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 +30 -31
- data/config/initializers/pagy.rb +1 -1
- data/config/routes.rb +12 -12
- data/config/spring.rb +5 -5
- data/config/webpack/base.js +2 -2
- data/config/webpacker.yml +32 -0
- 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 +25 -26
- 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/generators/avo/templates/action.tt +0 -4
- data/lib/generators/avo/templates/resource/resource.tt +3 -13
- data/lib/tasks/avo_tasks.rake +0 -60
- data/public/avo-packs/css/{application-38e7e91b.css → application-9d115b7e.css} +44 -147
- data/public/avo-packs/css/application-9d115b7e.css.br +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.gz +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.map +1 -0
- data/public/avo-packs/css/application-9d115b7e.css.map.br +0 -0
- data/public/avo-packs/css/application-9d115b7e.css.map.gz +0 -0
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js → application-4751feac1bb0404b9c47.js} +4 -4
- data/public/avo-packs/js/{application-2b90fe889f7d6df1ad92.js.LICENSE.txt → application-4751feac1bb0404b9c47.js.LICENSE.txt} +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.br +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.gz +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map +1 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map.br +0 -0
- data/public/avo-packs/js/application-4751feac1bb0404b9c47.js.map.gz +0 -0
- data/public/avo-packs/manifest.json +16 -16
- data/public/avo-packs/media/images/dadf2db36589607d107d.png +0 -0
- metadata +16 -31
- data/config/initializers/inline_svg.rb +0 -33
- data/public/avo-packs/css/application-38e7e91b.css.br +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.gz +0 -0
- data/public/avo-packs/css/application-38e7e91b.css.map +0 -1
- 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
- data/public/avo-packs/media/images/f1b4befac91a3336db9a.png +0 -0
data/lib/avo/base_action.rb
CHANGED
@@ -25,13 +25,13 @@ module Avo
|
|
25
25
|
self.class.resource = resource if resource.present?
|
26
26
|
self.class.user = user if user.present?
|
27
27
|
|
28
|
-
self.class.message ||= I18n.t(
|
29
|
-
self.class.confirm_button_label ||= I18n.t(
|
30
|
-
self.class.cancel_button_label ||= I18n.t(
|
28
|
+
self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
|
29
|
+
self.class.confirm_button_label ||= I18n.t("avo.run")
|
30
|
+
self.class.cancel_button_label ||= I18n.t("avo.cancel")
|
31
31
|
|
32
32
|
@response ||= {}
|
33
33
|
@response[:message_type] ||= :notice
|
34
|
-
@response[:message] ||= I18n.t(
|
34
|
+
@response[:message] ||= I18n.t("avo.action_ran_successfully")
|
35
35
|
end
|
36
36
|
|
37
37
|
def context
|
@@ -50,7 +50,7 @@ module Avo
|
|
50
50
|
get_field_definitions.map do |field|
|
51
51
|
field.hydrate(action: self, model: @model)
|
52
52
|
end
|
53
|
-
|
53
|
+
.select do |field|
|
54
54
|
field.visible?
|
55
55
|
end
|
56
56
|
end
|
@@ -59,7 +59,7 @@ module Avo
|
|
59
59
|
get_fields.map do |field|
|
60
60
|
[field.id, field.value]
|
61
61
|
end
|
62
|
-
|
62
|
+
.to_h
|
63
63
|
end
|
64
64
|
|
65
65
|
def handle_action(models:, fields:)
|
@@ -75,50 +75,50 @@ module Avo
|
|
75
75
|
processed_fields = {}
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
handle models: models, fields: processed_fields
|
79
79
|
|
80
80
|
self
|
81
81
|
end
|
82
82
|
|
83
83
|
def param_id
|
84
|
-
self.class.to_s.demodulize.underscore.
|
84
|
+
self.class.to_s.demodulize.underscore.tr "/", "_"
|
85
85
|
end
|
86
86
|
|
87
87
|
def succeed(text)
|
88
|
-
|
89
|
-
|
88
|
+
response[:message_type] = :notice
|
89
|
+
response[:message] = text
|
90
90
|
|
91
91
|
self
|
92
92
|
end
|
93
93
|
|
94
94
|
def fail(text)
|
95
|
-
|
96
|
-
|
95
|
+
response[:message_type] = :alert
|
96
|
+
response[:message] = text
|
97
97
|
|
98
98
|
self
|
99
99
|
end
|
100
100
|
|
101
101
|
def redirect_to(path = nil, &block)
|
102
|
-
|
103
|
-
if block.present?
|
104
|
-
|
102
|
+
response[:type] = :redirect
|
103
|
+
response[:path] = if block.present?
|
104
|
+
block
|
105
105
|
else
|
106
|
-
|
106
|
+
path
|
107
107
|
end
|
108
108
|
|
109
109
|
self
|
110
110
|
end
|
111
111
|
|
112
112
|
def reload
|
113
|
-
|
113
|
+
response[:type] = :reload
|
114
114
|
|
115
115
|
self
|
116
116
|
end
|
117
117
|
|
118
118
|
def download(path, filename)
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
response[:type] = :download
|
120
|
+
response[:path] = path
|
121
|
+
response[:filename] = filename
|
122
122
|
|
123
123
|
self
|
124
124
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -67,16 +67,16 @@ module Avo
|
|
67
67
|
|
68
68
|
def get_fields(panel: nil, reflection: nil)
|
69
69
|
fields = get_field_definitions.select do |field|
|
70
|
-
field.send("show_on_#{@view
|
70
|
+
field.send("show_on_#{@view}")
|
71
71
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
.select do |field|
|
73
|
+
field.visible?
|
74
|
+
end
|
75
|
+
.select do |field|
|
76
76
|
unless field.respond_to?(:foreign_key) &&
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
reflection.present? &&
|
78
|
+
reflection.respond_to?(:foreign_key) &&
|
79
|
+
reflection.foreign_key == field.foreign_key
|
80
80
|
true
|
81
81
|
end
|
82
82
|
end
|
@@ -87,11 +87,9 @@ module Avo
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
fields
|
90
|
+
fields.map do |field|
|
91
91
|
field.hydrate(model: @model, view: @view, resource: self)
|
92
92
|
end
|
93
|
-
|
94
|
-
fields
|
95
93
|
end
|
96
94
|
|
97
95
|
def get_grid_fields
|
@@ -117,24 +115,22 @@ module Avo
|
|
117
115
|
|
118
116
|
case @view
|
119
117
|
when :show
|
120
|
-
I18n.t(
|
118
|
+
I18n.t("avo.resource_details", item: name.downcase, title: model_title).upcase_first
|
121
119
|
when :edit
|
122
|
-
I18n.t(
|
120
|
+
I18n.t("avo.update_item", item: name.downcase, title: model_title).upcase_first
|
123
121
|
when :new
|
124
|
-
I18n.t(
|
122
|
+
I18n.t("avo.create_new_item", item: name.downcase).upcase_first
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
128
126
|
def panels
|
129
|
-
|
127
|
+
[
|
130
128
|
{
|
131
129
|
name: default_panel_name,
|
132
130
|
type: :fields,
|
133
|
-
in_panel: true
|
131
|
+
in_panel: true
|
134
132
|
}
|
135
133
|
]
|
136
|
-
|
137
|
-
panels
|
138
134
|
end
|
139
135
|
|
140
136
|
def model_class
|
@@ -142,7 +138,7 @@ module Avo
|
|
142
138
|
|
143
139
|
return @model.class if @model.present?
|
144
140
|
|
145
|
-
self.class.name.demodulize.chomp(
|
141
|
+
self.class.name.demodulize.chomp("Resource").safe_constantize
|
146
142
|
end
|
147
143
|
|
148
144
|
def model_title
|
@@ -156,7 +152,7 @@ module Avo
|
|
156
152
|
|
157
153
|
return I18n.t(@translation_key, count: 1).capitalize if @translation_key
|
158
154
|
|
159
|
-
self.class.name.demodulize.chomp(
|
155
|
+
self.class.name.demodulize.chomp("Resource").titlecase
|
160
156
|
end
|
161
157
|
|
162
158
|
def singular_name
|
@@ -191,7 +187,7 @@ module Avo
|
|
191
187
|
self.class.context
|
192
188
|
end
|
193
189
|
|
194
|
-
def query_search(
|
190
|
+
def query_search(via_resource_name:, via_resource_id:, user:, query: "")
|
195
191
|
# model_class = self.model
|
196
192
|
|
197
193
|
db_query = AuthorizationService.apply_policy(user, model_class)
|
@@ -199,18 +195,18 @@ module Avo
|
|
199
195
|
if via_resource_name.present?
|
200
196
|
related_model = App.get_resource_by_name(via_resource_name).model
|
201
197
|
|
202
|
-
db_query = related_model.find(via_resource_id).public_send(
|
198
|
+
db_query = related_model.find(via_resource_id).public_send(plural_name.downcase)
|
203
199
|
end
|
204
200
|
|
205
201
|
new_query = []
|
206
202
|
|
207
|
-
[
|
208
|
-
new_query.push
|
203
|
+
[search].flatten.each_with_index do |search_by, index|
|
204
|
+
new_query.push "or" if index != 0
|
209
205
|
|
210
206
|
new_query.push "text(#{search_by}) ILIKE '%#{query}%'"
|
211
207
|
end
|
212
208
|
|
213
|
-
db_query.where(new_query.join(
|
209
|
+
db_query.where(new_query.join(" "))
|
214
210
|
end
|
215
211
|
|
216
212
|
def attached_file_fields
|
@@ -221,7 +217,7 @@ module Avo
|
|
221
217
|
|
222
218
|
def fill_model(model, params)
|
223
219
|
# Map the received params to their actual fields
|
224
|
-
fields_by_database_id =
|
220
|
+
fields_by_database_id = get_field_definitions.map { |field| [field.database_id(model).to_s, field] }.to_h
|
225
221
|
|
226
222
|
params.each do |key, value|
|
227
223
|
field = fields_by_database_id[key]
|
@@ -239,16 +235,16 @@ module Avo
|
|
239
235
|
end
|
240
236
|
|
241
237
|
def file_hash
|
242
|
-
content_to_be_hashed =
|
238
|
+
content_to_be_hashed = ""
|
243
239
|
|
244
240
|
# resource file hash
|
245
|
-
resource_path = Rails.root.join(
|
241
|
+
resource_path = Rails.root.join("app", "avo", "resources", "#{self.class.name.underscore}.rb").to_s
|
246
242
|
if File.file? resource_path
|
247
243
|
content_to_be_hashed += File.read(resource_path)
|
248
244
|
end
|
249
245
|
|
250
246
|
# policy file hash
|
251
|
-
policy_path = Rails.root.join(
|
247
|
+
policy_path = Rails.root.join("app", "policies", "#{self.class.name.underscore.gsub("_resource", "")}_policy.rb").to_s
|
252
248
|
if File.file? policy_path
|
253
249
|
content_to_be_hashed += File.read(policy_path)
|
254
250
|
end
|
@@ -258,9 +254,9 @@ module Avo
|
|
258
254
|
|
259
255
|
def cache_hash(parent_model)
|
260
256
|
if parent_model.present?
|
261
|
-
[
|
257
|
+
[model, file_hash, parent_model]
|
262
258
|
else
|
263
|
-
[
|
259
|
+
[model, file_hash]
|
264
260
|
end
|
265
261
|
end
|
266
262
|
|
@@ -270,24 +266,24 @@ module Avo
|
|
270
266
|
default_values = get_fields.select do |field|
|
271
267
|
!field.computed
|
272
268
|
end
|
273
|
-
|
274
|
-
|
275
|
-
|
269
|
+
.map do |field|
|
270
|
+
id = field.id
|
271
|
+
value = field.value
|
276
272
|
|
277
|
-
|
278
|
-
|
273
|
+
if field.respond_to? :foreign_key
|
274
|
+
id = field.foreign_key.to_sym
|
279
275
|
|
280
|
-
|
276
|
+
reflection = @model._reflections[@params[:via_relation]]
|
281
277
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
278
|
+
if reflection.present? && reflection.foreign_key.present?
|
279
|
+
value = @params[:via_resource_id]
|
280
|
+
end
|
281
|
+
end
|
286
282
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
283
|
+
[id, value]
|
284
|
+
end
|
285
|
+
.to_h
|
286
|
+
.select do |id, value|
|
291
287
|
value.present?
|
292
288
|
end
|
293
289
|
|
data/lib/avo/configuration.rb
CHANGED
@@ -21,27 +21,27 @@ module Avo
|
|
21
21
|
attr_accessor :context
|
22
22
|
|
23
23
|
def initialize
|
24
|
-
@root_path =
|
25
|
-
@app_name = Rails.application.class.to_s.split(
|
26
|
-
@timezone =
|
24
|
+
@root_path = "/avo"
|
25
|
+
@app_name = Rails.application.class.to_s.split("::").first.underscore.humanize(keep_id_suffix: true)
|
26
|
+
@timezone = "UTC"
|
27
27
|
@per_page = 24
|
28
28
|
@per_page_steps = [12, 24, 48, 72]
|
29
29
|
@via_per_page = 8
|
30
|
-
@locale =
|
31
|
-
@currency =
|
30
|
+
@locale = "en-US"
|
31
|
+
@currency = "USD"
|
32
32
|
@default_view_type = :table
|
33
|
-
@license =
|
33
|
+
@license = "community"
|
34
34
|
@license_key = nil
|
35
35
|
@current_user = proc {}
|
36
36
|
@authenticate = proc {}
|
37
37
|
@authorization_methods = {
|
38
|
-
index:
|
39
|
-
show:
|
40
|
-
edit:
|
41
|
-
new:
|
42
|
-
update:
|
43
|
-
create:
|
44
|
-
destroy:
|
38
|
+
index: "index?",
|
39
|
+
show: "show?",
|
40
|
+
edit: "edit?",
|
41
|
+
new: "new?",
|
42
|
+
update: "update?",
|
43
|
+
create: "create?",
|
44
|
+
destroy: "destroy?"
|
45
45
|
}
|
46
46
|
@id_links_to_resource = false
|
47
47
|
@full_width_container = false
|
@@ -55,11 +55,9 @@ module Avo
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def language_code
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
'en'
|
62
|
-
end
|
58
|
+
locale_tag.language.code
|
59
|
+
rescue
|
60
|
+
"en"
|
63
61
|
end
|
64
62
|
|
65
63
|
def current_user_method(&block)
|
data/lib/avo/engine.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# requires all dependencies
|
2
|
-
Gem.loaded_specs[
|
2
|
+
Gem.loaded_specs["avo"].dependencies.each do |d|
|
3
3
|
require d.name
|
4
4
|
end
|
5
|
-
require
|
5
|
+
require "view_component/engine"
|
6
6
|
|
7
7
|
module Avo
|
8
8
|
class Engine < ::Rails::Engine
|
@@ -13,42 +13,42 @@ module Avo
|
|
13
13
|
::Avo::App.boot
|
14
14
|
end
|
15
15
|
|
16
|
-
initializer
|
17
|
-
Rails.autoloaders.main.push_dir(Rails.root.join(
|
18
|
-
Rails.autoloaders.main.push_dir(Rails.root.join(
|
19
|
-
Rails.autoloaders.main.push_dir(Rails.root.join(
|
16
|
+
initializer "avo.autoload", before: :set_autoload_paths do |app|
|
17
|
+
Rails.autoloaders.main.push_dir(Rails.root.join("app", "avo", "filters"))
|
18
|
+
Rails.autoloaders.main.push_dir(Rails.root.join("app", "avo", "actions"))
|
19
|
+
Rails.autoloaders.main.push_dir(Rails.root.join("app", "avo", "resources"))
|
20
20
|
end
|
21
21
|
|
22
|
-
initializer
|
22
|
+
initializer "avo.init_fields" do |app|
|
23
23
|
# Init the fields
|
24
24
|
::Avo::App.init_fields
|
25
25
|
end
|
26
26
|
|
27
|
-
initializer
|
28
|
-
if Avo::IN_DEVELOPMENT && ENV[
|
27
|
+
initializer "avo.reload_avo_files" do |app|
|
28
|
+
if Avo::IN_DEVELOPMENT && ENV["RELOAD_AVO_FILES"]
|
29
29
|
avo_root_path = Avo::Engine.root.to_s
|
30
30
|
# Register reloader
|
31
31
|
app.reloaders << app.config.file_watcher.new([], {
|
32
|
-
Avo::Engine.root.join(
|
32
|
+
Avo::Engine.root.join("lib", "avo").to_s => ["rb"]
|
33
33
|
}) {}
|
34
34
|
|
35
35
|
# What to do on file change
|
36
36
|
config.to_prepare do
|
37
|
-
Dir.glob(avo_root_path +
|
37
|
+
Dir.glob(avo_root_path + "/lib/avo/**/*.rb".to_s).each { |c| load c }
|
38
38
|
Avo::App.boot
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
initializer
|
43
|
+
initializer "webpacker.proxy" do |app|
|
44
44
|
app.config.debug_exception_response_format = :api
|
45
45
|
# app.config.logger = ::Logger.new(STDOUT)
|
46
46
|
|
47
47
|
insert_middleware = begin
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
Avo.webpacker.config.dev_server.present?
|
49
|
+
rescue
|
50
|
+
nil
|
51
|
+
end
|
52
52
|
|
53
53
|
if insert_middleware
|
54
54
|
app.middleware.insert_before(
|
@@ -61,8 +61,8 @@ module Avo
|
|
61
61
|
|
62
62
|
config.app_middleware.use(
|
63
63
|
Rack::Static,
|
64
|
-
urls: [
|
65
|
-
root: Avo::Engine.root.join(
|
64
|
+
urls: ["/avo-packs"],
|
65
|
+
root: Avo::Engine.root.join("public")
|
66
66
|
)
|
67
67
|
|
68
68
|
config.generators do |g|
|
@@ -3,14 +3,14 @@ module Avo
|
|
3
3
|
class BadgeField < BaseField
|
4
4
|
def initialize(name, **args, &block)
|
5
5
|
@defaults = {
|
6
|
-
partial_name:
|
6
|
+
partial_name: "badge-field"
|
7
7
|
}
|
8
8
|
|
9
9
|
super(name, **args, &block)
|
10
10
|
|
11
11
|
hide_on [:edit, :new]
|
12
12
|
|
13
|
-
default_options = {
|
13
|
+
default_options = {info: :info, success: :success, danger: :danger, warning: :warning}
|
14
14
|
@meta[:options] = args[:options].present? ? default_options.merge(args[:options]) : default_options
|
15
15
|
end
|
16
16
|
end
|
@@ -44,14 +44,14 @@ module Avo
|
|
44
44
|
|
45
45
|
args = @defaults.merge(args).symbolize_keys
|
46
46
|
|
47
|
-
null_values = [nil,
|
47
|
+
null_values = [nil, "", *args[:null_values]]
|
48
48
|
# The field properties as a hash {property: default_value}
|
49
49
|
@field_properties = {
|
50
50
|
id: id,
|
51
51
|
name: id.to_s.humanize(keep_id_suffix: true),
|
52
52
|
translation_key: nil,
|
53
53
|
block: block,
|
54
|
-
partial_name:
|
54
|
+
partial_name: "field",
|
55
55
|
required: false,
|
56
56
|
readonly: false,
|
57
57
|
updatable: true,
|
@@ -67,7 +67,7 @@ module Avo
|
|
67
67
|
default: nil,
|
68
68
|
visible: true,
|
69
69
|
meta: {},
|
70
|
-
panel_name: nil
|
70
|
+
panel_name: nil
|
71
71
|
}
|
72
72
|
|
73
73
|
# Set the values in the following order
|
@@ -76,7 +76,7 @@ module Avo
|
|
76
76
|
# - field option
|
77
77
|
@field_properties.each do |name, default_value|
|
78
78
|
final_value = args[name.to_sym]
|
79
|
-
|
79
|
+
send("#{name}=", name != "null_values" && (final_value.nil? || !defined?(final_value)) ? default_value : final_value)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Set the visibility
|
@@ -102,8 +102,8 @@ module Avo
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def visible?
|
105
|
-
if visible.present?
|
106
|
-
visible.call
|
105
|
+
if visible.present? && visible.respond_to?(:call)
|
106
|
+
visible.call resource: resource
|
107
107
|
else
|
108
108
|
visible
|
109
109
|
end
|
@@ -111,18 +111,18 @@ module Avo
|
|
111
111
|
|
112
112
|
def value
|
113
113
|
# Get model value
|
114
|
-
final_value = @model.send(id) if model_or_class(@model) ==
|
114
|
+
final_value = @model.send(id) if (model_or_class(@model) == "model") && @model.respond_to?(id)
|
115
115
|
|
116
|
-
if @view === :new
|
117
|
-
if default.present?
|
118
|
-
|
116
|
+
if (@view === :new) || @action.present?
|
117
|
+
final_value = if default.present? && default.respond_to?(:call)
|
118
|
+
default.call
|
119
119
|
else
|
120
|
-
|
120
|
+
default
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
# Run callback block if present
|
125
|
-
if computable
|
125
|
+
if computable && block.present?
|
126
126
|
final_value = block.call @model, @resource, @view, self
|
127
127
|
end
|
128
128
|
|
@@ -141,18 +141,16 @@ module Avo
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def partial_path_for(view)
|
144
|
-
return @custom_partials[view] if @custom_partials.present?
|
144
|
+
return @custom_partials[view] if @custom_partials.present? && @custom_partials[view].present?
|
145
145
|
|
146
146
|
"avo/fields/#{view}/#{partial_name}"
|
147
147
|
end
|
148
148
|
|
149
149
|
# Try to see if the field has a different database ID than it's name
|
150
150
|
def database_id(model)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
id
|
155
|
-
end
|
151
|
+
foreign_key
|
152
|
+
rescue
|
153
|
+
id
|
156
154
|
end
|
157
155
|
|
158
156
|
def has_own_panel?
|
@@ -168,7 +166,7 @@ module Avo
|
|
168
166
|
end
|
169
167
|
|
170
168
|
def component_name(view = :index)
|
171
|
-
"Avo::#{view.to_s.classify}::Fields::#{partial_name.gsub(
|
169
|
+
"Avo::#{view.to_s.classify}::Fields::#{partial_name.gsub("-field", "").underscore.camelize}FieldComponent"
|
172
170
|
end
|
173
171
|
|
174
172
|
def model_errors
|
@@ -178,17 +176,18 @@ module Avo
|
|
178
176
|
end
|
179
177
|
|
180
178
|
def type
|
181
|
-
self.class.name.demodulize.to_s.underscore.gsub(
|
179
|
+
self.class.name.demodulize.to_s.underscore.gsub("_field", "")
|
182
180
|
end
|
183
181
|
|
184
182
|
private
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
183
|
+
|
184
|
+
def model_or_class(model)
|
185
|
+
if model.instance_of?(String)
|
186
|
+
"class"
|
187
|
+
else
|
188
|
+
"model"
|
191
189
|
end
|
190
|
+
end
|
192
191
|
end
|
193
192
|
end
|
194
193
|
end
|