active_scaffold 3.6.20 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +47 -0
- data/README.md +29 -16
- data/app/assets/javascripts/jquery/active_scaffold.js +106 -68
- data/app/assets/javascripts/jquery/active_scaffold_chosen.js +6 -5
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +18 -4
- data/app/assets/stylesheets/active_scaffold_layout.css +13 -2
- data/app/views/active_scaffold_overrides/_base_form.html.erb +5 -1
- data/app/views/active_scaffold_overrides/_field_search.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_render_field.js.erb +24 -13
- data/config/locales/de.yml +6 -3
- data/config/locales/en.yml +3 -0
- data/config/locales/es.yml +3 -0
- data/config/locales/fr.yml +9 -6
- data/config/locales/hu.yml +20 -17
- data/config/locales/ja.yml +83 -80
- data/config/locales/ru.yml +17 -14
- data/lib/active_scaffold/actions/common_search.rb +2 -2
- data/lib/active_scaffold/actions/core.rb +30 -10
- data/lib/active_scaffold/actions/field_search.rb +9 -6
- data/lib/active_scaffold/actions/nested.rb +7 -7
- data/lib/active_scaffold/actions/update.rb +3 -3
- data/lib/active_scaffold/attribute_params.rb +22 -70
- data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +0 -3
- data/lib/active_scaffold/bridges/active_storage/form_ui.rb +6 -6
- data/lib/active_scaffold/bridges/active_storage/list_ui.rb +7 -7
- data/lib/active_scaffold/bridges/active_storage.rb +3 -0
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +2 -2
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +2 -2
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +12 -14
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +2 -2
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +10 -10
- data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +7 -7
- data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -9
- data/lib/active_scaffold/bridges/date_picker/helper.rb +9 -9
- data/lib/active_scaffold/bridges/date_picker.rb +2 -0
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +3 -3
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +5 -5
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +1 -1
- data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -1
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +3 -3
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/record_select/helpers.rb +17 -17
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +6 -6
- data/lib/active_scaffold/bridges/tiny_mce.rb +1 -1
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +6 -11
- data/lib/active_scaffold/bridges.rb +0 -3
- data/lib/active_scaffold/config/core.rb +1 -1
- data/lib/active_scaffold/config/field_search.rb +9 -1
- data/lib/active_scaffold/config/form.rb +9 -1
- data/lib/active_scaffold/constraints.rb +22 -7
- data/lib/active_scaffold/core.rb +6 -10
- data/lib/active_scaffold/data_structures/action_columns.rb +0 -25
- data/lib/active_scaffold/data_structures/action_links.rb +1 -1
- data/lib/active_scaffold/data_structures/association/abstract.rb +8 -0
- data/lib/active_scaffold/data_structures/association/active_mongoid.rb +8 -0
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -13
- data/lib/active_scaffold/data_structures/association/mongoid.rb +21 -8
- data/lib/active_scaffold/data_structures/column.rb +139 -28
- data/lib/active_scaffold/data_structures/columns.rb +12 -12
- data/lib/active_scaffold/data_structures/nested_info.rb +12 -0
- data/lib/active_scaffold/data_structures/sorting.rb +1 -1
- data/lib/active_scaffold/engine.rb +15 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +13 -5
- data/lib/active_scaffold/extensions/cow_proxy.rb +1 -1
- data/lib/active_scaffold/extensions/routing_mapper.rb +1 -0
- data/lib/active_scaffold/extensions/unsaved_record.rb +9 -3
- data/lib/active_scaffold/finder.rb +147 -28
- data/lib/active_scaffold/helpers/action_link_helpers.rb +1 -1
- data/lib/active_scaffold/helpers/controller_helpers.rb +9 -4
- data/lib/active_scaffold/helpers/form_column_helpers.rb +153 -107
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +48 -14
- data/lib/active_scaffold/helpers/list_column_helpers.rb +37 -20
- data/lib/active_scaffold/helpers/search_column_helpers.rb +137 -55
- data/lib/active_scaffold/helpers/show_column_helpers.rb +6 -6
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/orm_checks.rb +21 -1
- data/lib/active_scaffold/registry.rb +10 -15
- data/lib/active_scaffold/tableless.rb +10 -79
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/active_scaffold.rb +3 -9
- data/lib/generators/active_scaffold/install_generator.rb +2 -2
- data/test/bridges/bridge_test.rb +1 -1
- data/test/bridges/date_picker_test.rb +3 -2
- data/test/bridges/paperclip_test.rb +18 -14
- data/test/bridges/tiny_mce_test.rb +5 -3
- data/test/config/base_test.rb +1 -1
- data/test/config/core_test.rb +1 -1
- data/test/config/create_test.rb +1 -1
- data/test/config/delete_test.rb +1 -1
- data/test/config/field_search_test.rb +1 -1
- data/test/config/list_test.rb +1 -1
- data/test/config/nested_test.rb +1 -1
- data/test/config/search_test.rb +1 -1
- data/test/config/show_test.rb +1 -1
- data/test/config/subform_test.rb +1 -1
- data/test/config/update_test.rb +1 -1
- data/test/data_structures/action_columns_test.rb +1 -1
- data/test/data_structures/action_link_test.rb +1 -1
- data/test/data_structures/action_links_test.rb +1 -1
- data/test/data_structures/actions_test.rb +1 -1
- data/test/data_structures/association_column_test.rb +1 -1
- data/test/data_structures/column_test.rb +1 -1
- data/test/data_structures/columns_test.rb +1 -1
- data/test/data_structures/set_test.rb +1 -1
- data/test/data_structures/sorting_test.rb +1 -1
- data/test/data_structures/standard_column_test.rb +1 -1
- data/test/data_structures/validation_reflection_test.rb +1 -1
- data/test/data_structures/virtual_column_test.rb +1 -1
- data/test/extensions/active_record_test.rb +1 -1
- data/test/helpers/form_column_helpers_test.rb +7 -5
- data/test/helpers/pagination_helpers_test.rb +1 -1
- data/test/helpers/search_column_helpers_test.rb +2 -1
- data/test/misc/active_record_permissions_test.rb +1 -1
- data/test/misc/attribute_params_test.rb +1 -1
- data/test/misc/calculation_test.rb +1 -1
- data/test/misc/configurable_test.rb +1 -1
- data/test/misc/constraints_test.rb +2 -1
- data/test/misc/convert_numbers_format_test.rb +1 -1
- data/test/misc/finder_test.rb +39 -1
- data/test/misc/lang_test.rb +1 -1
- data/test/misc/parse_datetime_test.rb +1 -1
- data/test/misc/tableless_test.rb +1 -1
- data/test/test_helper.rb +4 -4
- metadata +5 -17
- data/config/brakeman.ignore +0 -26
- data/config/brakeman.yml +0 -3
- data/config/i18n-tasks.yml +0 -121
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +0 -221
- data/lib/active_scaffold/delayed_setup.rb +0 -41
- data/lib/active_scaffold/extensions/left_outer_joins.rb +0 -43
|
@@ -33,41 +33,10 @@ module ActiveScaffold
|
|
|
33
33
|
module AttributeParams
|
|
34
34
|
protected
|
|
35
35
|
|
|
36
|
-
# workaround to update counters when polymorphic has_many changes on persisted record
|
|
37
|
-
# TODO: remove when rails4 support is removed or counter cache for polymorphic has_many association works on rails4
|
|
38
|
-
def hack_for_has_many_counter_cache(parent_record, column, value)
|
|
39
|
-
association = parent_record.association(column.name)
|
|
40
|
-
counter_attr = association.send(:cached_counter_attribute_name)
|
|
41
|
-
difference = value.select(&:persisted?).size - parent_record.send(counter_attr)
|
|
42
|
-
|
|
43
|
-
if parent_record.new_record?
|
|
44
|
-
parent_record.send "#{column.name}=", value
|
|
45
|
-
parent_record.send "#{counter_attr}_will_change!"
|
|
46
|
-
else
|
|
47
|
-
# don't decrement counter for deleted records, on destroy they will update counter
|
|
48
|
-
difference += (parent_record.send(column.name) - value).size
|
|
49
|
-
association.send :update_counter, difference unless difference.zero?
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# update counters on old parents if belongs_to is changed
|
|
53
|
-
value.select(&:persisted?).each do |record|
|
|
54
|
-
key = record.send(column.association.foreign_key)
|
|
55
|
-
parent_record.class.decrement_counter counter_attr, key if key && key != parent_record.id # rubocop:disable Rails/SkipsModelValidations
|
|
56
|
-
end
|
|
57
|
-
parent_record.send "#{column.name}=", value if parent_record.persisted?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# rails 4 needs this hack for polymorphic has_many
|
|
61
|
-
# TODO: remove when hack_for_has_many_counter_cache is not needed
|
|
62
|
-
def hack_for_has_many_counter_cache?(parent_record, column)
|
|
63
|
-
column.association.counter_cache_hack? && parent_record.association(column.name).send(:has_cached_counter?)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
36
|
# workaround for updating counters twice bug on rails4 (https://github.com/rails/rails/pull/14849)
|
|
67
|
-
# rails 4 needs this hack for non-polymorphic belongs_to, when selecting record, not creating new one (value is Hash)
|
|
68
37
|
# rails 5 needs this hack for belongs_to, when selecting record, not creating new one (value is Hash)
|
|
69
|
-
# TODO: remove when
|
|
70
|
-
def
|
|
38
|
+
# TODO: remove when rails5 support is removed
|
|
39
|
+
def belongs_to_counter_cache_hack?(association, value)
|
|
71
40
|
!params_hash?(value) && association.belongs_to? && association.counter_cache_hack?
|
|
72
41
|
end
|
|
73
42
|
|
|
@@ -92,21 +61,19 @@ module ActiveScaffold
|
|
|
92
61
|
multi_parameter_attrs = multi_parameter_attributes(attributes)
|
|
93
62
|
|
|
94
63
|
columns.each_column(for: parent_record, crud_type: crud_type, flatten: true) do |column|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
column.params.select { |p| attributes.key? p }.each { |p| parent_record.send("#{p}=", attributes[p]) }
|
|
64
|
+
# Set any passthrough parameters that may be associated with this column (ie, file column "keep" and "temp" attributes)
|
|
65
|
+
column.params.select { |p| attributes.key? p }.each { |p| parent_record.send("#{p}=", attributes[p]) }
|
|
98
66
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
end
|
|
104
|
-
rescue StandardError => e
|
|
105
|
-
message = "on the ActiveScaffold column = :#{column.name} for #{parent_record.inspect} "\
|
|
106
|
-
"(value from params #{attributes[column.name].inspect})"
|
|
107
|
-
Rails.logger.error "#{e.class.name}: #{e.message} -- #{message}"
|
|
108
|
-
raise
|
|
67
|
+
if multi_parameter_attrs.key? column.name.to_s
|
|
68
|
+
parent_record.send(:assign_multiparameter_attributes, multi_parameter_attrs[column.name.to_s])
|
|
69
|
+
elsif attributes.key? column.name
|
|
70
|
+
update_column_from_params(parent_record, column, attributes[column.name], avoid_changes)
|
|
109
71
|
end
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
message = "on the ActiveScaffold column = :#{column.name} for #{parent_record.inspect} "\
|
|
74
|
+
"(value from params #{attributes[column.name].inspect})"
|
|
75
|
+
Rails.logger.error "#{e.class.name}: #{e.message} -- #{message}"
|
|
76
|
+
raise
|
|
110
77
|
end
|
|
111
78
|
|
|
112
79
|
parent_record
|
|
@@ -132,7 +99,7 @@ module ActiveScaffold
|
|
|
132
99
|
end
|
|
133
100
|
|
|
134
101
|
def update_column_association(parent_record, column, attribute, value)
|
|
135
|
-
if
|
|
102
|
+
if belongs_to_counter_cache_hack?(column.association, attribute)
|
|
136
103
|
parent_record.send "#{column.association.foreign_key}=", value&.id
|
|
137
104
|
parent_record.association(column.name).target = value
|
|
138
105
|
elsif column.association.collection? && column.association.through_singular?
|
|
@@ -140,8 +107,6 @@ module ActiveScaffold
|
|
|
140
107
|
through_record = parent_record.send(through)
|
|
141
108
|
through_record ||= parent_record.send "build_#{through}"
|
|
142
109
|
through_record.send "#{column.association.source_reflection.name}=", value
|
|
143
|
-
elsif hack_for_has_many_counter_cache?(parent_record, column)
|
|
144
|
-
hack_for_has_many_counter_cache(parent_record, column, value)
|
|
145
110
|
else
|
|
146
111
|
parent_record.send "#{column.name}=", value
|
|
147
112
|
end
|
|
@@ -164,7 +129,7 @@ module ActiveScaffold
|
|
|
164
129
|
|
|
165
130
|
def datetime_conversion_for_value(column)
|
|
166
131
|
if column.column
|
|
167
|
-
column.
|
|
132
|
+
column.column_type == :date ? :to_date : :to_time
|
|
168
133
|
else
|
|
169
134
|
:to_time
|
|
170
135
|
end
|
|
@@ -184,7 +149,11 @@ module ActiveScaffold
|
|
|
184
149
|
|
|
185
150
|
def association_value_from_param_simple_value(parent_record, column, value)
|
|
186
151
|
if column.association.singular?
|
|
187
|
-
|
|
152
|
+
# value may be Array if using update_columns in field_search with multi-select
|
|
153
|
+
klass = column.association.klass(parent_record)
|
|
154
|
+
# find_by needed when using update_columns in type foreign type key of polymorphic association,
|
|
155
|
+
# and foreign key had value, it will try to find record with id of previous type
|
|
156
|
+
klass&.find_by(klass&.primary_key => value) if value.present? && !value.is_a?(Array)
|
|
188
157
|
else # column.association.collection?
|
|
189
158
|
column_plural_assocation_value_from_value(column, Array(value))
|
|
190
159
|
end
|
|
@@ -315,26 +284,9 @@ module ActiveScaffold
|
|
|
315
284
|
end
|
|
316
285
|
|
|
317
286
|
def default_value?(column_name, klass, value)
|
|
318
|
-
|
|
319
|
-
default_value =
|
|
320
|
-
casted_value = ActiveScaffold::Core.column_type_cast(value, column)
|
|
287
|
+
casted_value = ActiveScaffold::OrmChecks.cast(klass, column_name, value)
|
|
288
|
+
default_value = ActiveScaffold::OrmChecks.default_value(klass, column_name)
|
|
321
289
|
casted_value == default_value
|
|
322
290
|
end
|
|
323
|
-
|
|
324
|
-
def column_default_value(column_name, klass)
|
|
325
|
-
column = ActiveScaffold::OrmChecks.columns_hash(klass)[column_name]
|
|
326
|
-
return unless column
|
|
327
|
-
if ActiveScaffold::OrmChecks.mongoid? klass
|
|
328
|
-
column.default_val
|
|
329
|
-
elsif ActiveScaffold::OrmChecks.active_record? klass
|
|
330
|
-
if Rails.version < '5.0'
|
|
331
|
-
column.type_cast_from_database(column.default)
|
|
332
|
-
else
|
|
333
|
-
column_type = ActiveScaffold::OrmChecks.column_type(klass, column_name)
|
|
334
|
-
cast_type = ActiveRecord::Type.lookup column_type
|
|
335
|
-
cast_type ? cast_type.deserialize(column.default) : column.default
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
end
|
|
339
291
|
end
|
|
340
292
|
end
|
|
@@ -2,9 +2,6 @@ module ActiveScaffold
|
|
|
2
2
|
module Bridges
|
|
3
3
|
class ActiveStorage
|
|
4
4
|
module ActiveStorageBridgeHelpers
|
|
5
|
-
mattr_accessor :thumbnail_variant
|
|
6
|
-
self.thumbnail_variant = {resize_to_limit: [nil, 30]}
|
|
7
|
-
|
|
8
5
|
class << self
|
|
9
6
|
# has_one :"#{name}_attachment", -> { where(name: name) }, class_name: "ActiveStorage::Attachment", as: :record, inverse_of: :record, dependent: false
|
|
10
7
|
def active_storage_has_one_fields(klass)
|
|
@@ -2,20 +2,20 @@ module ActiveScaffold
|
|
|
2
2
|
module Helpers
|
|
3
3
|
# Helpers that assist with the rendering of a Form Column
|
|
4
4
|
module FormColumnHelpers
|
|
5
|
-
def active_scaffold_input_active_storage_has_one(column, options)
|
|
5
|
+
def active_scaffold_input_active_storage_has_one(column, options, ui_options: column.options)
|
|
6
6
|
record = options[:object]
|
|
7
7
|
active_storage = record.send(column.name.to_s)
|
|
8
|
-
content = active_scaffold_column_active_storage_has_one(record, column) if active_storage.attached?
|
|
9
|
-
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
|
|
8
|
+
content = active_scaffold_column_active_storage_has_one(record, column, ui_options: ui_options) if active_storage.attached?
|
|
9
|
+
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def active_scaffold_input_active_storage_has_many(column, options)
|
|
12
|
+
def active_scaffold_input_active_storage_has_many(column, options, ui_options: column.options)
|
|
13
13
|
record = options[:object]
|
|
14
14
|
options[:multiple] = 'multiple'
|
|
15
15
|
options[:name] += '[]'
|
|
16
16
|
active_storage = record.send(column.name.to_s)
|
|
17
|
-
content = active_scaffold_column_active_storage_has_many(record, column) if active_storage.attached?
|
|
18
|
-
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls')
|
|
17
|
+
content = active_scaffold_column_active_storage_has_many(record, column, ui_options: ui_options) if active_storage.attached?
|
|
18
|
+
active_scaffold_file_with_remove_link(column, options, content, 'delete_', 'active_storage_controls', ui_options: ui_options)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
module ActiveScaffold
|
|
2
2
|
module Helpers
|
|
3
3
|
module ListColumnHelpers
|
|
4
|
-
def active_scaffold_column_active_storage_has_one(record, column)
|
|
4
|
+
def active_scaffold_column_active_storage_has_one(record, column, ui_options: column.options)
|
|
5
5
|
attachment = record.send(column.name.to_s)
|
|
6
|
-
attachment.attached? ? link_for_attachment(attachment, column) : nil
|
|
6
|
+
attachment.attached? ? link_for_attachment(attachment, column, ui_options: ui_options) : nil
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def active_scaffold_column_active_storage_has_many(record, column)
|
|
9
|
+
def active_scaffold_column_active_storage_has_many(record, column, ui_options: column.options)
|
|
10
10
|
active_storage_files = record.send(column.name.to_s)
|
|
11
11
|
return nil unless active_storage_files.attached?
|
|
12
12
|
|
|
13
13
|
attachments = active_storage_files.attachments
|
|
14
14
|
if attachments.size <= 3 # Lets display up to three links, otherwise just show the count.
|
|
15
|
-
links = attachments.map { |attachment| link_for_attachment(attachment, column) }
|
|
15
|
+
links = attachments.map { |attachment| link_for_attachment(attachment, column, ui_options: ui_options) }
|
|
16
16
|
safe_join links, association_join_text(column)
|
|
17
17
|
else
|
|
18
18
|
pluralize attachments.size, column.name.to_s
|
|
@@ -21,10 +21,10 @@ module ActiveScaffold
|
|
|
21
21
|
|
|
22
22
|
private
|
|
23
23
|
|
|
24
|
-
def link_for_attachment(attachment, column)
|
|
25
|
-
variant =
|
|
24
|
+
def link_for_attachment(attachment, column, ui_options: column.options)
|
|
25
|
+
variant = ui_options[:thumb] || ActiveScaffold::Bridges::ActiveStorage.thumbnail_variant
|
|
26
26
|
content =
|
|
27
|
-
if variant && attachment.variable? &&
|
|
27
|
+
if variant && attachment.variable? && ui_options[:thumb] != false
|
|
28
28
|
image_tag(attachment.variant(variant))
|
|
29
29
|
else
|
|
30
30
|
attachment.filename
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
class ActiveScaffold::Bridges::ActiveStorage < ActiveScaffold::DataStructures::Bridge
|
|
2
|
+
cattr_accessor :thumbnail_variant
|
|
3
|
+
self.thumbnail_variant = {resize_to_limit: [nil, 30]}
|
|
4
|
+
|
|
2
5
|
def self.install
|
|
3
6
|
Dir[File.join(__dir__, 'active_storage', '*.rb')].each { |file| require file }
|
|
4
7
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::ActiveStorage::ActiveStorageBridge
|
|
@@ -15,12 +15,12 @@ module ActiveScaffold::Bridges
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
module FormColumnHelpers
|
|
18
|
-
def active_scaffold_input_ancestry(column, options)
|
|
18
|
+
def active_scaffold_input_ancestry(column, options, ui_options: column.options)
|
|
19
19
|
record = options[:object]
|
|
20
20
|
select_options = []
|
|
21
21
|
select_control_options = {:selected => record.parent_id}
|
|
22
22
|
select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
|
|
23
|
-
method =
|
|
23
|
+
method = ui_options[:label_method] || :to_label
|
|
24
24
|
traverse_ancestry = proc do |key, value|
|
|
25
25
|
unless key == record
|
|
26
26
|
select_options << ["#{'__' * key.depth}#{key.send(method)}", key.id]
|
|
@@ -8,9 +8,9 @@ module ActiveScaffold
|
|
|
8
8
|
|
|
9
9
|
model.bitfields.each_value do |options|
|
|
10
10
|
columns << options.keys
|
|
11
|
-
options.
|
|
11
|
+
options.each_key.with_index(1) do |column, i|
|
|
12
12
|
columns[column].form_ui = :checkbox
|
|
13
|
-
columns[column].weight = 1000 +
|
|
13
|
+
columns[column].weight = 1000 + i
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -16,19 +16,20 @@ module ActiveScaffold
|
|
|
16
16
|
|
|
17
17
|
# Helpers that assist with the rendering of a Form Column
|
|
18
18
|
module FormColumnHelpers
|
|
19
|
-
def active_scaffold_input_calendar_date_select(column, options)
|
|
19
|
+
def active_scaffold_input_calendar_date_select(column, options, ui_options: column.options)
|
|
20
20
|
options[:class] = "#{options[:class]} text-input".strip
|
|
21
|
-
calendar_date_select('record', column.name, options.merge(
|
|
21
|
+
calendar_date_select('record', column.name, options.merge(ui_options))
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
module SearchColumnHelpers
|
|
26
|
-
def
|
|
27
|
-
value =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
def active_scaffold_search_calendar_date_select_field(column, options, current_search, name, ui_options: column.options)
|
|
27
|
+
value =
|
|
28
|
+
if current_search.is_a? Hash
|
|
29
|
+
controller.class.condition_value_for_datetime(column, current_search[name], column.column_type == :date ? :to_date : :to_time)
|
|
30
|
+
else
|
|
31
|
+
current_search
|
|
32
|
+
end
|
|
32
33
|
calendar_date_select(
|
|
33
34
|
'record', column.name,
|
|
34
35
|
:name => "#{options[:name]}[#{name}]",
|
|
@@ -46,15 +47,12 @@ end
|
|
|
46
47
|
|
|
47
48
|
ActionView::Base.class_eval do
|
|
48
49
|
include ActiveScaffold::Bridges::CalendarDateSelect::FormColumnHelpers
|
|
49
|
-
|
|
50
|
-
alias_method :
|
|
51
|
-
include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers
|
|
52
|
-
alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_date_bridge
|
|
50
|
+
alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_datetime
|
|
51
|
+
alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_datetime
|
|
53
52
|
include ActiveScaffold::Bridges::CalendarDateSelect::SearchColumnHelpers
|
|
54
53
|
end
|
|
55
54
|
|
|
56
55
|
ActiveScaffold::Finder::ClassMethods.module_eval do
|
|
57
|
-
|
|
58
|
-
alias_method :condition_for_calendar_date_select_type, :condition_for_date_bridge_type
|
|
56
|
+
alias_method :condition_for_calendar_date_select_type, :condition_for_datetime
|
|
59
57
|
end
|
|
60
58
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::CalendarDateSelect::CalendarDateSelectBridge
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module ActiveScaffold
|
|
2
2
|
module Helpers
|
|
3
3
|
module FormColumnHelpers
|
|
4
|
-
def active_scaffold_input_carrierwave(column, options)
|
|
4
|
+
def active_scaffold_input_carrierwave(column, options, ui_options: column.options)
|
|
5
5
|
record = options[:object]
|
|
6
6
|
carrierwave = record.send(column.name.to_s)
|
|
7
7
|
content = get_column_value(record, column) if carrierwave.file.present?
|
|
8
|
-
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls') do
|
|
8
|
+
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'carrierwave_controls', ui_options: ui_options) do
|
|
9
9
|
cache_field_options = {
|
|
10
10
|
name: options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"),
|
|
11
11
|
id: options[:id] + '_cache'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ActiveScaffold
|
|
2
2
|
module Helpers
|
|
3
3
|
module ListColumnHelpers
|
|
4
|
-
def active_scaffold_column_carrierwave(record, column)
|
|
4
|
+
def active_scaffold_column_carrierwave(record, column, ui_options: column.options)
|
|
5
5
|
carrierwave = record.send(column.name.to_s)
|
|
6
6
|
return nil if carrierwave.file.blank?
|
|
7
7
|
thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style
|
|
@@ -10,39 +10,39 @@ class ActiveScaffold::Bridges::Chosen
|
|
|
10
10
|
|
|
11
11
|
module FormColumnHelpers
|
|
12
12
|
# requires RecordSelect plugin to be installed and configured.
|
|
13
|
-
def active_scaffold_input_chosen(column, html_options)
|
|
13
|
+
def active_scaffold_input_chosen(column, html_options, ui_options: column.options)
|
|
14
14
|
html_options[:class] << ' chosen'
|
|
15
15
|
if column.association&.collection?
|
|
16
16
|
record = html_options.delete(:object)
|
|
17
17
|
associated_options, select_options = active_scaffold_plural_association_options(column, record)
|
|
18
18
|
options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}
|
|
19
19
|
|
|
20
|
-
html_options.update(multiple: true).update(
|
|
21
|
-
options.update(
|
|
20
|
+
html_options.update(multiple: true).update(ui_options[:html_options] || {})
|
|
21
|
+
options.update(ui_options)
|
|
22
22
|
active_scaffold_select_name_with_multiple html_options
|
|
23
23
|
|
|
24
24
|
if (optgroup = options.delete(:optgroup))
|
|
25
25
|
select(:record, column.name, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options)
|
|
26
26
|
else
|
|
27
|
-
collection_select(:record, column.name, select_options, :id,
|
|
27
|
+
collection_select(:record, column.name, select_options, :id, ui_options[:label_method] || :to_label, options, html_options)
|
|
28
28
|
end
|
|
29
29
|
else
|
|
30
|
-
active_scaffold_input_select(column, html_options)
|
|
30
|
+
active_scaffold_input_select(column, html_options, ui_options: ui_options)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
module SearchColumnHelpers
|
|
36
|
-
def active_scaffold_search_chosen(column, options)
|
|
36
|
+
def active_scaffold_search_chosen(column, options, ui_options: column.options)
|
|
37
37
|
options[:class] << ' chosen'
|
|
38
|
-
active_scaffold_search_select(column, options)
|
|
38
|
+
active_scaffold_search_select(column, options, ui_options: ui_options)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def active_scaffold_search_multi_chosen(column, options)
|
|
41
|
+
def active_scaffold_search_multi_chosen(column, options, ui_options: column.options)
|
|
42
42
|
options[:class] << ' chosen'
|
|
43
43
|
options[:multiple] = true
|
|
44
|
-
options[:'data-placeholder'] =
|
|
45
|
-
active_scaffold_search_select(column, options)
|
|
44
|
+
options[:'data-placeholder'] = ui_options[:placeholder] || as_(:_select_)
|
|
45
|
+
active_scaffold_search_select(column, options, ui_options: ui_options)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
module ActiveScaffold::Bridges
|
|
2
2
|
class CountrySelect
|
|
3
3
|
module FormColumnHelpers
|
|
4
|
-
def active_scaffold_input_country(column, options)
|
|
5
|
-
select_options = {:prompt => as_(:_select_), :priority_countries =>
|
|
6
|
-
select_options[:format] =
|
|
4
|
+
def active_scaffold_input_country(column, options, ui_options: column.options)
|
|
5
|
+
select_options = {:prompt => as_(:_select_), :priority_countries => ui_options[:priority] || [:us]}
|
|
6
|
+
select_options[:format] = ui_options[:format] if ui_options[:format]
|
|
7
7
|
select_options.merge!(options)
|
|
8
|
-
options.reverse_merge!(
|
|
8
|
+
options.reverse_merge!(ui_options).except!(:prompt, :priority, :format)
|
|
9
9
|
active_scaffold_select_name_with_multiple options
|
|
10
10
|
country_select(:record, column.name, select_options, options.except(:object))
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
module ListColumnHelpers
|
|
15
|
-
def active_scaffold_column_country(record, column)
|
|
15
|
+
def active_scaffold_column_country(record, column, ui_options: column.options)
|
|
16
16
|
country_code = record.send(column.name)
|
|
17
17
|
return if country_code.blank?
|
|
18
18
|
country = ISO3166::Country[country_code]
|
|
@@ -22,8 +22,8 @@ module ActiveScaffold::Bridges
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
module SearchColumnHelpers
|
|
25
|
-
def active_scaffold_search_country(column, options)
|
|
26
|
-
active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)))
|
|
25
|
+
def active_scaffold_search_country(column, options, ui_options: column.options)
|
|
26
|
+
active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)), ui_options: ui_options)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -10,6 +10,7 @@ class ActiveScaffold::Bridges::DatePicker
|
|
|
10
10
|
module DatePickerBridge
|
|
11
11
|
def initialize(model_id)
|
|
12
12
|
super
|
|
13
|
+
return unless ActiveScaffold::Bridges::DatePicker.default_ui
|
|
13
14
|
|
|
14
15
|
date_picker_fields = _columns.collect { |c| {:name => c.name.to_sym, :type => c.type} if %i[date datetime].include?(c.type) }.compact
|
|
15
16
|
# check to see if file column was used on the model
|
|
@@ -31,6 +32,18 @@ class ActiveScaffold::Bridges::DatePicker
|
|
|
31
32
|
super
|
|
32
33
|
end
|
|
33
34
|
end
|
|
35
|
+
|
|
36
|
+
def datetime_column_date?(column)
|
|
37
|
+
if %i[date_picker datetime_picker].include? column.search_ui
|
|
38
|
+
column.search_ui == :date_picker
|
|
39
|
+
else
|
|
40
|
+
super
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def format_for_date(column, value, format_name = column.options[:format])
|
|
45
|
+
super column, value, format_name || (:default if column.search_ui == :date_picker)
|
|
46
|
+
end
|
|
34
47
|
end
|
|
35
48
|
|
|
36
49
|
module AttributeParams
|
|
@@ -46,22 +59,20 @@ end
|
|
|
46
59
|
|
|
47
60
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::DatePicker::DatePickerBridge
|
|
48
61
|
ActionView::Base.class_eval do
|
|
49
|
-
|
|
50
|
-
alias_method :
|
|
51
|
-
alias_method :
|
|
52
|
-
|
|
53
|
-
alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_date_bridge
|
|
54
|
-
alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_date_bridge
|
|
62
|
+
alias_method :active_scaffold_search_date_picker, :active_scaffold_search_datetime
|
|
63
|
+
alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_datetime
|
|
64
|
+
alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_datetime
|
|
65
|
+
alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_datetime
|
|
55
66
|
include ActiveScaffold::Bridges::DatePicker::Helper::SearchColumnHelpers
|
|
67
|
+
alias_method :active_scaffold_search_datetime_picker_field, :active_scaffold_search_date_picker_field
|
|
56
68
|
include ActiveScaffold::Bridges::DatePicker::Helper::FormColumnHelpers
|
|
57
69
|
alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker
|
|
58
70
|
include ActiveScaffold::Bridges::DatePicker::Helper::DatepickerColumnHelpers
|
|
59
71
|
end
|
|
60
72
|
ActiveScaffold::Finder::ClassMethods.module_eval do
|
|
61
73
|
prepend ActiveScaffold::Bridges::DatePicker::Finder
|
|
62
|
-
|
|
63
|
-
alias_method :
|
|
64
|
-
alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type
|
|
74
|
+
alias_method :condition_for_date_picker_type, :condition_for_datetime
|
|
75
|
+
alias_method :condition_for_datetime_picker_type, :condition_for_datetime
|
|
65
76
|
end
|
|
66
77
|
ActiveScaffold::AttributeParams.module_eval do
|
|
67
78
|
prepend ActiveScaffold::Bridges::DatePicker::AttributeParams
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module ActiveScaffold::Bridges
|
|
2
2
|
class DatePicker
|
|
3
3
|
module Helper
|
|
4
|
+
UNSUPPORTED_FORMAT_OPTIONS = /%[cUWwxXZ]/
|
|
4
5
|
DATE_FORMAT_CONVERSION = {
|
|
5
6
|
/%a/ => 'D',
|
|
6
7
|
/%A/ => 'DD',
|
|
@@ -19,7 +20,7 @@ module ActiveScaffold::Bridges
|
|
|
19
20
|
/%p/ => 'tt',
|
|
20
21
|
/%S/ => 'ss',
|
|
21
22
|
/%z/ => 'z',
|
|
22
|
-
|
|
23
|
+
UNSUPPORTED_FORMAT_OPTIONS => ''
|
|
23
24
|
}.freeze
|
|
24
25
|
|
|
25
26
|
def self.date_options_for_locales
|
|
@@ -83,9 +84,8 @@ module ActiveScaffold::Bridges
|
|
|
83
84
|
|
|
84
85
|
def self.to_datepicker_format(rails_format)
|
|
85
86
|
return nil if rails_format.nil?
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
options = unsupported.to_s.scan(/\[(.*)\]/).dig(0, 0)&.each_char&.map { |c| "%#{c}" }
|
|
87
|
+
if rails_format.match?(UNSUPPORTED_FORMAT_OPTIONS)
|
|
88
|
+
options = UNSUPPORTED_FORMAT_OPTIONS.to_s.scan(/\[(.*)\]/).dig(0, 0)&.each_char&.map { |c| "%#{c}" }
|
|
89
89
|
Rails.logger.warn(
|
|
90
90
|
"AS DatePicker::Helper: rails date format #{rails_format} includes options "\
|
|
91
91
|
"which can't be converted to jquery datepicker format. "\
|
|
@@ -148,15 +148,15 @@ module ActiveScaffold::Bridges
|
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
module SearchColumnHelpers
|
|
151
|
-
def
|
|
151
|
+
def active_scaffold_search_date_picker_field(column, options, current_search, name, ui_options: column.options)
|
|
152
152
|
value =
|
|
153
153
|
if current_search.is_a? Hash
|
|
154
154
|
controller.class.condition_value_for_datetime(column, current_search[name], column.search_ui == :date_picker ? :to_date : :to_time)
|
|
155
155
|
else
|
|
156
156
|
current_search
|
|
157
157
|
end
|
|
158
|
-
options =
|
|
159
|
-
options = active_scaffold_input_text_options(options
|
|
158
|
+
options = ui_options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value)
|
|
159
|
+
options = active_scaffold_input_text_options(options)
|
|
160
160
|
format = datepicker_format(options, column.search_ui)
|
|
161
161
|
options[:class] << " #{column.search_ui}"
|
|
162
162
|
options[:style] = 'display: none' if options[:show] == false # hide only if asked to hide
|
|
@@ -168,9 +168,9 @@ module ActiveScaffold::Bridges
|
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
module FormColumnHelpers
|
|
171
|
-
def active_scaffold_input_date_picker(column, options)
|
|
171
|
+
def active_scaffold_input_date_picker(column, options, ui_options: column.options)
|
|
172
172
|
record = options[:object]
|
|
173
|
-
options = active_scaffold_input_text_options(options.merge(
|
|
173
|
+
options = active_scaffold_input_text_options(options.merge(ui_options))
|
|
174
174
|
options[:class] << " #{column.form_ui}"
|
|
175
175
|
|
|
176
176
|
format = datepicker_format(options, column.form_ui)
|
|
@@ -12,6 +12,8 @@ module ActiveScaffold::Bridges
|
|
|
12
12
|
def self.jquery_ui_included?
|
|
13
13
|
Jquery::Rails.const_defined?('JQUERY_UI_VERSION') || Jquery.const_defined?('Ui') if Object.const_defined?('Jquery')
|
|
14
14
|
end
|
|
15
|
+
mattr_accessor :default_ui
|
|
16
|
+
@@default_ui = true
|
|
15
17
|
|
|
16
18
|
def self.stylesheets
|
|
17
19
|
'jquery-ui-timepicker-addon'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module ActiveScaffold
|
|
2
2
|
module Helpers
|
|
3
3
|
module FormColumnHelpers
|
|
4
|
-
def active_scaffold_input_dragonfly(column, options)
|
|
4
|
+
def active_scaffold_input_dragonfly(column, options, ui_options: column.options)
|
|
5
5
|
record = options[:object]
|
|
6
6
|
dragonfly = record.send(column.name.to_s)
|
|
7
|
-
content = active_scaffold_column_dragonfly(record, column) if dragonfly.present?
|
|
8
|
-
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'dragonfly_controls')
|
|
7
|
+
content = active_scaffold_column_dragonfly(record, column, ui_options: ui_options) if dragonfly.present?
|
|
8
|
+
active_scaffold_file_with_remove_link(column, options, content, 'remove_', 'dragonfly_controls', ui_options: ui_options)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
module ActiveScaffold
|
|
2
2
|
module Helpers
|
|
3
3
|
module ListColumnHelpers
|
|
4
|
-
def active_scaffold_column_dragonfly(record, column)
|
|
4
|
+
def active_scaffold_column_dragonfly(record, column, ui_options: column.options)
|
|
5
5
|
attachment = record.send(column.name.to_s)
|
|
6
6
|
return nil if attachment.blank?
|
|
7
7
|
content =
|
|
8
8
|
if attachment.image?
|
|
9
|
-
image_tag(attachment.thumb(
|
|
9
|
+
image_tag(attachment.thumb(ui_options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0)
|
|
10
10
|
else
|
|
11
11
|
attachment.name
|
|
12
12
|
end
|
|
13
|
-
link_to(content, dragonfly_url_for_attachment(attachment, record, column), :target => '_blank', rel: 'noopener noreferrer')
|
|
13
|
+
link_to(content, dragonfly_url_for_attachment(attachment, record, column, ui_options: ui_options), :target => '_blank', rel: 'noopener noreferrer')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def dragonfly_url_for_attachment(attachment, record, column)
|
|
17
|
-
url_method =
|
|
16
|
+
def dragonfly_url_for_attachment(attachment, record, column, ui_options: column.options)
|
|
17
|
+
url_method = ui_options[:private_store] ? :url : :remote_url
|
|
18
18
|
attachment.send(url_method)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -2,7 +2,7 @@ module ActiveScaffold
|
|
|
2
2
|
module Helpers
|
|
3
3
|
# Helpers that assist with the rendering of a Form Column
|
|
4
4
|
module FormColumnHelpers
|
|
5
|
-
def active_scaffold_input_file_column(column, options)
|
|
5
|
+
def active_scaffold_input_file_column(column, options, ui_options: column.options)
|
|
6
6
|
record = options[:object]
|
|
7
7
|
if record.send(column.name)
|
|
8
8
|
# we already have a value? display the form for deletion.
|
|
@@ -2,18 +2,18 @@ module ActiveScaffold
|
|
|
2
2
|
module Helpers
|
|
3
3
|
# Helpers that assist with the rendering of a List Column
|
|
4
4
|
module ListColumnHelpers
|
|
5
|
-
def active_scaffold_column_download_link_with_filename(record, column)
|
|
5
|
+
def active_scaffold_column_download_link_with_filename(record, column, ui_options: column.options)
|
|
6
6
|
return nil if record.send(column.name).nil?
|
|
7
7
|
active_scaffold_column_download_link(record, column, File.basename(record.send(column.name)))
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def active_scaffold_column_download_link(record, column, label = nil)
|
|
10
|
+
def active_scaffold_column_download_link(record, column, label = nil, ui_options: column.options)
|
|
11
11
|
return nil if record.send(column.name).nil?
|
|
12
12
|
label ||= as_(:download)
|
|
13
13
|
link_to(label, url_for_file_column(record, column.name.to_s), :popup => true)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def active_scaffold_column_thumbnail(record, column)
|
|
16
|
+
def active_scaffold_column_thumbnail(record, column, ui_options: column.options)
|
|
17
17
|
return nil if record.send(column.name).nil?
|
|
18
18
|
link_to(
|
|
19
19
|
image_tag(url_for_file_column(record, column.name.to_s, 'thumb'), :border => 0),
|
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
|
2
2
|
require File.expand_path('../mock_model.rb', __dir__)
|
|
3
3
|
require File.expand_path('../../file_column_helpers.rb', __dir__)
|
|
4
4
|
|
|
5
|
-
class DeleteFileColumnTest <
|
|
5
|
+
class DeleteFileColumnTest < Minitest::Test
|
|
6
6
|
def setup
|
|
7
7
|
MockModel.extend ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
|
|
8
8
|
ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.generate_delete_helpers(MockModel)
|