active_scaffold 3.5.5 → 3.6.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +18 -2
- data/README.md +17 -7
- data/app/assets/javascripts/jquery/active_scaffold.js +28 -2
- data/app/views/active_scaffold_overrides/_base_form.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_form.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +3 -2
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_list.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_list_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_messages.html.erb +1 -0
- data/app/views/active_scaffold_overrides/_render_field.js.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +2 -1
- data/app/views/active_scaffold_overrides/_show_columns.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +4 -4
- data/app/views/active_scaffold_overrides/_update_calculations.js.erb +1 -1
- data/app/views/active_scaffold_overrides/_update_column.js.erb +2 -2
- data/app/views/active_scaffold_overrides/action_confirmation.html.erb +2 -2
- data/app/views/active_scaffold_overrides/delete.html.erb +2 -2
- data/app/views/active_scaffold_overrides/on_action_update.js.erb +16 -6
- data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
- data/app/views/active_scaffold_overrides/row.js.erb +1 -1
- data/app/views/active_scaffold_overrides/update_column.js.erb +1 -1
- data/lib/active_scaffold.rb +11 -13
- data/lib/active_scaffold/actions/core.rb +25 -35
- data/lib/active_scaffold/actions/create.rb +1 -1
- data/lib/active_scaffold/actions/delete.rb +2 -2
- data/lib/active_scaffold/actions/field_search.rb +2 -2
- data/lib/active_scaffold/actions/list.rb +8 -7
- data/lib/active_scaffold/actions/nested.rb +9 -9
- data/lib/active_scaffold/actions/search.rb +1 -1
- data/lib/active_scaffold/actions/show.rb +1 -1
- data/lib/active_scaffold/actions/subform.rb +3 -1
- data/lib/active_scaffold/actions/update.rb +5 -4
- data/lib/active_scaffold/active_record_permissions.rb +2 -11
- data/lib/active_scaffold/attribute_params.rb +16 -23
- data/lib/active_scaffold/bridges.rb +8 -8
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +3 -18
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/chosen/helpers.rb +7 -6
- data/lib/active_scaffold/bridges/date_picker/ext.rb +0 -13
- data/lib/active_scaffold/bridges/date_picker/helper.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +3 -3
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +8 -7
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -4
- data/lib/active_scaffold/bridges/paper_trail.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +2 -2
- data/lib/active_scaffold/bridges/record_select/helpers.rb +9 -9
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +3 -3
- data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +1 -1
- data/lib/active_scaffold/config/base.rb +89 -21
- data/lib/active_scaffold/config/core.rb +127 -18
- data/lib/active_scaffold/config/delete.rb +2 -0
- data/lib/active_scaffold/config/field_search.rb +7 -1
- data/lib/active_scaffold/config/form.rb +10 -1
- data/lib/active_scaffold/config/list.rb +27 -11
- data/lib/active_scaffold/config/mark.rb +3 -1
- data/lib/active_scaffold/config/nested.rb +16 -17
- data/lib/active_scaffold/config/search.rb +9 -0
- data/lib/active_scaffold/config/show.rb +4 -0
- data/lib/active_scaffold/config/update.rb +4 -0
- data/lib/active_scaffold/configurable.rb +11 -6
- data/lib/active_scaffold/constraints.rb +1 -1
- data/lib/active_scaffold/core.rb +46 -16
- data/lib/active_scaffold/data_structures/action_columns.rb +50 -59
- data/lib/active_scaffold/data_structures/action_link.rb +20 -8
- data/lib/active_scaffold/data_structures/action_links.rb +6 -2
- data/lib/active_scaffold/data_structures/association/abstract.rb +9 -5
- data/lib/active_scaffold/data_structures/association/active_record.rb +1 -1
- data/lib/active_scaffold/data_structures/column.rb +51 -33
- data/lib/active_scaffold/data_structures/nested_info.rb +1 -1
- data/lib/active_scaffold/data_structures/set.rb +8 -0
- data/lib/active_scaffold/data_structures/sorting.rb +5 -2
- data/lib/active_scaffold/delayed_setup.rb +2 -1
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +2 -1
- data/lib/active_scaffold/extensions/action_view_rendering.rb +1 -1
- data/lib/active_scaffold/extensions/cow_proxy.rb +43 -0
- data/lib/active_scaffold/extensions/ice_nine.rb +36 -0
- data/lib/active_scaffold/extensions/left_outer_joins.rb +8 -33
- data/lib/active_scaffold/extensions/routing_mapper.rb +4 -43
- data/lib/active_scaffold/extensions/unsaved_record.rb +2 -4
- data/lib/active_scaffold/finder.rb +26 -30
- data/lib/active_scaffold/helpers/action_link_helpers.rb +16 -16
- data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
- data/lib/active_scaffold/helpers/controller_helpers.rb +11 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +25 -24
- data/lib/active_scaffold/helpers/id_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/list_column_helpers.rb +8 -6
- data/lib/active_scaffold/helpers/search_column_helpers.rb +4 -4
- data/lib/active_scaffold/helpers/view_helpers.rb +7 -13
- data/lib/active_scaffold/marked_model.rb +2 -2
- data/lib/active_scaffold/orm_checks.rb +1 -5
- data/lib/active_scaffold/paginator.rb +6 -4
- data/lib/active_scaffold/registry.rb +22 -0
- data/lib/active_scaffold/responds_to_parent.rb +2 -6
- data/lib/active_scaffold/tableless.rb +63 -59
- data/lib/active_scaffold/version.rb +2 -2
- data/lib/generators/active_scaffold/controller_generator.rb +2 -2
- data/lib/generators/active_scaffold/install_generator.rb +1 -1
- data/lib/generators/active_scaffold/resource_generator.rb +2 -2
- data/test/bridges/date_picker_test.rb +1 -2
- data/test/bridges/paperclip_test.rb +5 -5
- data/test/class_with_finder.rb +2 -2
- data/test/company.rb +2 -2
- data/test/config/create_test.rb +4 -2
- data/test/config/nested_test.rb +1 -1
- data/test/config/show_test.rb +1 -1
- data/test/config/update_test.rb +7 -6
- data/test/data_structures/action_links_test.rb +1 -1
- data/test/data_structures/sorting_test.rb +7 -0
- data/test/misc/active_record_permissions_test.rb +1 -9
- data/test/misc/attribute_params_test.rb +8 -8
- data/test/misc/calculation_test.rb +1 -1
- data/test/misc/constraints_test.rb +2 -2
- data/test/misc/convert_numbers_format_test.rb +3 -3
- data/test/misc/lang_test.rb +1 -1
- data/test/misc/parse_datetime_test.rb +3 -4
- data/test/misc/tableless_test.rb +6 -0
- data/test/mock_app/Rakefile +1 -1
- data/test/mock_app/config/application.rb +1 -1
- data/test/mock_app/config/boot.rb +1 -1
- data/test/mock_app/config/environment.rb +2 -2
- data/test/test_helper.rb +8 -1
- metadata +38 -13
@@ -37,7 +37,7 @@ module ActiveScaffold
|
|
37
37
|
# because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the
|
38
38
|
# current_user_method on this ApplicationController.
|
39
39
|
def assign_current_user_to_models
|
40
|
-
|
40
|
+
ActiveScaffold::Registry.current_user_proc = proc { send(ActiveRecordPermissions.current_user_method) }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -48,18 +48,9 @@ module ActiveScaffold
|
|
48
48
|
end
|
49
49
|
|
50
50
|
module ClassMethods
|
51
|
-
# The proc to call that retrieves the current_user from the ApplicationController.
|
52
|
-
def current_user_proc
|
53
|
-
Thread.current[:current_user_proc]
|
54
|
-
end
|
55
|
-
|
56
|
-
def current_user_proc=(proc_value)
|
57
|
-
Thread.current[:current_user_proc] = proc_value
|
58
|
-
end
|
59
|
-
|
60
51
|
# Class-level access to the current user
|
61
52
|
def current_user
|
62
|
-
|
53
|
+
ActiveScaffold::Registry.current_user_proc&.call
|
63
54
|
end
|
64
55
|
end
|
65
56
|
|
@@ -41,13 +41,8 @@ module ActiveScaffold
|
|
41
41
|
difference = value.select(&:persisted?).size - parent_record.send(counter_attr)
|
42
42
|
|
43
43
|
if parent_record.new_record?
|
44
|
-
|
45
|
-
|
46
|
-
parent_record.send "#{counter_attr}_will_change!"
|
47
|
-
else # < 4.2
|
48
|
-
parent_record.send "#{counter_attr}=", difference
|
49
|
-
parent_record.send "#{column.name}=", value
|
50
|
-
end
|
44
|
+
parent_record.send "#{column.name}=", value
|
45
|
+
parent_record.send "#{counter_attr}_will_change!"
|
51
46
|
else
|
52
47
|
# don't decrement counter for deleted records, on destroy they will update counter
|
53
48
|
difference += (parent_record.send(column.name) - value).size
|
@@ -57,7 +52,7 @@ module ActiveScaffold
|
|
57
52
|
# update counters on old parents if belongs_to is changed
|
58
53
|
value.select(&:persisted?).each do |record|
|
59
54
|
key = record.send(column.association.foreign_key)
|
60
|
-
parent_record.class.decrement_counter counter_attr, key if key && key != parent_record.id
|
55
|
+
parent_record.class.decrement_counter counter_attr, key if key && key != parent_record.id # rubocop:disable Rails/SkipsModelValidations
|
61
56
|
end
|
62
57
|
parent_record.send "#{column.name}=", value if parent_record.persisted?
|
63
58
|
end
|
@@ -93,7 +88,7 @@ module ActiveScaffold
|
|
93
88
|
multi_parameter_attributes[column_name] << [k, v]
|
94
89
|
end
|
95
90
|
|
96
|
-
columns.
|
91
|
+
columns.each_column(for: parent_record, crud_type: crud_type, flatten: true) do |column|
|
97
92
|
begin
|
98
93
|
# Set any passthrough parameters that may be associated with this column (ie, file column "keep" and "temp" attributes)
|
99
94
|
unless column.params.empty?
|
@@ -105,7 +100,7 @@ module ActiveScaffold
|
|
105
100
|
elsif attributes.key? column.name
|
106
101
|
value = update_column_from_params(parent_record, column, attributes[column.name], avoid_changes)
|
107
102
|
end
|
108
|
-
rescue => e
|
103
|
+
rescue StandardError => e
|
109
104
|
Rails.logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} for #{parent_record.inspect}#{" with value #{value}" if value}"
|
110
105
|
raise
|
111
106
|
end
|
@@ -118,11 +113,11 @@ module ActiveScaffold
|
|
118
113
|
value = column_value_from_param_value(parent_record, column, attribute, avoid_changes)
|
119
114
|
if avoid_changes && column.association
|
120
115
|
parent_record.association(column.name).target = value
|
121
|
-
parent_record.send("#{column.association.foreign_key}=", value
|
116
|
+
parent_record.send("#{column.association.foreign_key}=", value&.id) if column.association.belongs_to?
|
122
117
|
elsif column.association && counter_cache_hack?(column.association, attribute)
|
123
|
-
parent_record.send "#{column.association.foreign_key}=", value
|
118
|
+
parent_record.send "#{column.association.foreign_key}=", value&.id
|
124
119
|
parent_record.association(column.name).target = value
|
125
|
-
elsif column.association
|
120
|
+
elsif column.association&.collection? && column.association.through? && !column.association.through_reflection.collection?
|
126
121
|
through = column.association.through_reflection.name
|
127
122
|
through_record = parent_record.send(through)
|
128
123
|
through_record ||= parent_record.send "build_#{through}"
|
@@ -139,7 +134,7 @@ module ActiveScaffold
|
|
139
134
|
parent_record.association(column.name).target = value if column.association
|
140
135
|
end
|
141
136
|
end
|
142
|
-
if column.association
|
137
|
+
if column.association&.reverse_association&.belongs_to?
|
143
138
|
Array(value).each { |v| v.send("#{column.association.reverse}=", parent_record) if v.new_record? }
|
144
139
|
end
|
145
140
|
value
|
@@ -147,7 +142,7 @@ module ActiveScaffold
|
|
147
142
|
|
148
143
|
def column_value_from_param_value(parent_record, column, value, avoid_changes = false)
|
149
144
|
# convert the value, possibly by instantiating associated objects
|
150
|
-
form_ui = column.form_ui || column.column
|
145
|
+
form_ui = column.form_ui || column.column&.type
|
151
146
|
if form_ui && respond_to?("column_value_for_#{form_ui}_type", true)
|
152
147
|
send("column_value_for_#{form_ui}_type", parent_record, column, value)
|
153
148
|
elsif params_hash? value
|
@@ -178,7 +173,7 @@ module ActiveScaffold
|
|
178
173
|
end
|
179
174
|
|
180
175
|
def column_value_from_param_simple_value(parent_record, column, value)
|
181
|
-
if column.association
|
176
|
+
if column.association&.singular?
|
182
177
|
if value.present?
|
183
178
|
if column.association.polymorphic?
|
184
179
|
class_name = parent_record.send(column.association.foreign_type)
|
@@ -188,7 +183,7 @@ module ActiveScaffold
|
|
188
183
|
column.association.klass.find(value)
|
189
184
|
end
|
190
185
|
end
|
191
|
-
elsif column.association
|
186
|
+
elsif column.association&.collection?
|
192
187
|
column_plural_assocation_value_from_value(column, Array(value))
|
193
188
|
elsif column.number? && column.options[:format] && column.form_ui != :number
|
194
189
|
column.number_to_native(value)
|
@@ -213,9 +208,9 @@ module ActiveScaffold
|
|
213
208
|
end
|
214
209
|
|
215
210
|
def column_value_from_param_hash_value(parent_record, column, value, avoid_changes = false)
|
216
|
-
if column.association
|
211
|
+
if column.association&.singular?
|
217
212
|
manage_nested_record_from_params(parent_record, column, value, avoid_changes)
|
218
|
-
elsif column.association
|
213
|
+
elsif column.association&.collection?
|
219
214
|
# HACK: to be able to delete all associated records, hash will include "0" => ""
|
220
215
|
values = value.values.reject(&:blank?)
|
221
216
|
values.collect { |val| manage_nested_record_from_params(parent_record, column, val, avoid_changes) }.compact
|
@@ -272,7 +267,7 @@ module ActiveScaffold
|
|
272
267
|
end
|
273
268
|
|
274
269
|
def save_record_to_association(record, association, value)
|
275
|
-
if association
|
270
|
+
if association&.collection?
|
276
271
|
record.send(association.name) << value
|
277
272
|
elsif association
|
278
273
|
record.send("#{association.name}=", value)
|
@@ -317,9 +312,7 @@ module ActiveScaffold
|
|
317
312
|
if ActiveScaffold::OrmChecks.mongoid? klass
|
318
313
|
column.default_val
|
319
314
|
elsif ActiveScaffold::OrmChecks.active_record? klass
|
320
|
-
if Rails.version < '
|
321
|
-
column.default
|
322
|
-
elsif Rails.version < '5.0'
|
315
|
+
if Rails.version < '5.0'
|
323
316
|
column.type_cast_from_database(column.default)
|
324
317
|
else
|
325
318
|
column_type = ActiveScaffold::OrmChecks.column_type(klass, column_name)
|
@@ -11,7 +11,7 @@ module ActiveScaffold
|
|
11
11
|
self.bridges = {}
|
12
12
|
|
13
13
|
def self.register(file)
|
14
|
-
match = file.match(
|
14
|
+
match = file.match(%r{(active_scaffold/bridges/(.*))\.rb\Z})
|
15
15
|
bridges[match[2].to_sym] = match[1] if match
|
16
16
|
end
|
17
17
|
|
@@ -34,18 +34,18 @@ module ActiveScaffold
|
|
34
34
|
|
35
35
|
def self.run_all
|
36
36
|
return false if bridges_run
|
37
|
-
bridges.
|
38
|
-
|
39
|
-
bridge.run if bridge
|
37
|
+
bridges.each_key do |bridge_name|
|
38
|
+
self[bridge_name]&.run
|
40
39
|
end
|
40
|
+
ActiveScaffold::Config::Core.freeze if ActiveScaffold.threadsafe
|
41
41
|
self.bridges_run = true
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.prepare_all
|
45
45
|
return false if bridges_prepared
|
46
|
-
bridges.
|
46
|
+
bridges.each_key do |bridge_name|
|
47
47
|
bridge = self[bridge_name]
|
48
|
-
bridge.prepare if bridge
|
48
|
+
bridge.prepare if bridge&.install?
|
49
49
|
end
|
50
50
|
self.bridges_prepared = true
|
51
51
|
end
|
@@ -53,14 +53,14 @@ module ActiveScaffold
|
|
53
53
|
def self.all_stylesheets
|
54
54
|
bridges.keys.collect do |bridge_name|
|
55
55
|
bridge = self[bridge_name]
|
56
|
-
bridge.stylesheets if bridge
|
56
|
+
bridge.stylesheets if bridge&.install?
|
57
57
|
end.compact.flatten
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.all_javascripts
|
61
61
|
bridges.keys.collect do |bridge_name|
|
62
62
|
bridge = self[bridge_name]
|
63
|
-
bridge.javascripts if bridge
|
63
|
+
bridge.javascripts if bridge&.install?
|
64
64
|
end.compact.flatten
|
65
65
|
end
|
66
66
|
end
|
@@ -6,7 +6,7 @@ module ActiveScaffold
|
|
6
6
|
super
|
7
7
|
return unless model.respond_to?(:bitfields) && model.bitfields.present?
|
8
8
|
|
9
|
-
model.bitfields.
|
9
|
+
model.bitfields.each_value do |_, options|
|
10
10
|
columns << options.keys
|
11
11
|
options.each do |column, value|
|
12
12
|
columns[column].form_ui = :checkbox
|
@@ -36,7 +36,7 @@ module ActiveScaffold
|
|
36
36
|
:class => 'text-input',
|
37
37
|
:id => "#{options[:id]}_#{name}",
|
38
38
|
:time => column_datetime?(column) ? true : false,
|
39
|
-
:style => (
|
39
|
+
:style => ('display: none' if options[:show] == false) # hide only if asked to hide
|
40
40
|
)
|
41
41
|
end
|
42
42
|
end
|
@@ -45,12 +45,6 @@ module ActiveScaffold::Bridges
|
|
45
45
|
def beginning_of_chain
|
46
46
|
super.accessible_by(current_ability)
|
47
47
|
end
|
48
|
-
|
49
|
-
# fix when ability allow access base on id
|
50
|
-
# can [:manage], Client, id: Client.of_employee(user).pluck(:id)
|
51
|
-
def new_model
|
52
|
-
super.tap { |record| record.id = nil }
|
53
|
-
end
|
54
48
|
end
|
55
49
|
end
|
56
50
|
|
@@ -66,7 +60,7 @@ module ActiveScaffold::Bridges
|
|
66
60
|
# because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the
|
67
61
|
# current_ability_method on this ApplicationController.
|
68
62
|
def assign_current_ability_to_models
|
69
|
-
::
|
63
|
+
::ActiveScaffold::Registry.current_ability_proc = proc { send(:current_ability) }
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
@@ -74,18 +68,9 @@ module ActiveScaffold::Bridges
|
|
74
68
|
extend ActiveSupport::Concern
|
75
69
|
|
76
70
|
module ClassMethods
|
77
|
-
# The proc to call that retrieves the current_ability from the ApplicationController.
|
78
|
-
def current_ability_proc
|
79
|
-
Thread.current[:current_ability_proc]
|
80
|
-
end
|
81
|
-
|
82
|
-
def current_ability_proc=(value)
|
83
|
-
Thread.current[:current_ability_proc] = value
|
84
|
-
end
|
85
|
-
|
86
71
|
# Class-level access to the current ability
|
87
72
|
def current_ability
|
88
|
-
::
|
73
|
+
::ActiveScaffold::Registry.current_ability_proc&.call
|
89
74
|
end
|
90
75
|
end
|
91
76
|
|
@@ -120,7 +105,7 @@ module ActiveScaffold::Bridges
|
|
120
105
|
crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self)
|
121
106
|
action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self)
|
122
107
|
else
|
123
|
-
crud_type_result
|
108
|
+
crud_type_result = action_result = false
|
124
109
|
end
|
125
110
|
result = (crud_type_result && action_result) || super(options.merge(:reason => nil))
|
126
111
|
# return array with nil reason if requested with options[:reason], we don't have reason but caller expects array
|
@@ -1,17 +1,18 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
1
3
|
class ActiveScaffold::Bridges::Chosen
|
2
4
|
module Helpers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
include FormColumnHelpers
|
8
|
+
include SearchColumnHelpers
|
8
9
|
end
|
9
10
|
|
10
11
|
module FormColumnHelpers
|
11
12
|
# requires RecordSelect plugin to be installed and configured.
|
12
13
|
def active_scaffold_input_chosen(column, html_options)
|
13
14
|
html_options[:class] << ' chosen'
|
14
|
-
if column.association
|
15
|
+
if column.association&.collection?
|
15
16
|
record = html_options.delete(:object)
|
16
17
|
associated_options, select_options = active_scaffold_plural_association_options(column, record)
|
17
18
|
options = {selected: associated_options.collect(&:id), include_blank: as_(:_select_), object: record}
|
@@ -42,19 +42,6 @@ class ActiveScaffold::Bridges::DatePicker
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
module CastExtension
|
47
|
-
def fallback_string_to_date(string)
|
48
|
-
Date.strptime(string, I18n.t('date.formats.default')) rescue super
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
if defined?(ActiveRecord::ConnectionAdapters::Type) # rails >= 4.2
|
53
|
-
ActiveRecord::ConnectionAdapters::Type::Date.send(:prepend, ActiveScaffold::Bridges::DatePicker::CastExtension)
|
54
|
-
else
|
55
|
-
class << ActiveRecord::ConnectionAdapters::Column
|
56
|
-
prepend ActiveScaffold::Bridges::DatePicker::CastExtension
|
57
|
-
end
|
58
45
|
end
|
59
46
|
|
60
47
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::DatePicker::DatePickerBridge
|
@@ -52,7 +52,7 @@ module ActiveScaffold::Bridges
|
|
52
52
|
js_format = to_datepicker_format(I18n.translate!('date.formats.default', :locale => locale, :default => ''))
|
53
53
|
date_picker_options[:dateFormat] = js_format if js_format.present?
|
54
54
|
date_picker_options
|
55
|
-
rescue
|
55
|
+
rescue StandardError
|
56
56
|
raise if locale == I18n.locale
|
57
57
|
end
|
58
58
|
|
@@ -85,7 +85,7 @@ module ActiveScaffold::Bridges
|
|
85
85
|
datetime_picker_options[:ampm] = true if rails_time_format.include?('%I')
|
86
86
|
end
|
87
87
|
datetime_picker_options
|
88
|
-
rescue
|
88
|
+
rescue StandardError
|
89
89
|
raise if locale == I18n.locale
|
90
90
|
end
|
91
91
|
|
@@ -155,7 +155,7 @@ module ActiveScaffold::Bridges
|
|
155
155
|
options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value)
|
156
156
|
options = active_scaffold_input_text_options(options.merge(column.options))
|
157
157
|
options[:class] << " #{column.search_ui}"
|
158
|
-
options[:style] =
|
158
|
+
options[:style] = 'display: none' if options[:show] == false # hide only if asked to hide
|
159
159
|
format = options.delete(:format) || (column.search_ui == :date_picker ? :default : :picker)
|
160
160
|
datepicker_format_options(column, format, options)
|
161
161
|
text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]", :object => nil))
|
@@ -33,7 +33,7 @@ class ActiveScaffold::Bridges::FileColumn
|
|
33
33
|
# set null to false so active_scaffold wont set it to null
|
34
34
|
# delete_file_column will take care of deleting a file or not.
|
35
35
|
_columns_hash[field.to_s].instance_variable_set('@null', false)
|
36
|
-
rescue
|
36
|
+
rescue StandardError
|
37
37
|
false
|
38
38
|
end
|
39
39
|
end
|
@@ -9,7 +9,7 @@ module ActiveScaffold
|
|
9
9
|
|
10
10
|
def generate_delete_helpers(klass)
|
11
11
|
file_column_fields(klass).each do |field|
|
12
|
-
klass.send :class_eval, <<-
|
12
|
+
klass.send :class_eval, <<-END, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=")
|
13
13
|
attr_reader :delete_#{field}
|
14
14
|
|
15
15
|
def delete_#{field}=(value)
|
@@ -19,7 +19,7 @@ module ActiveScaffold
|
|
19
19
|
# passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
|
20
20
|
self.#{field} = nil unless self.#{field}_just_uploaded?
|
21
21
|
end
|
22
|
-
|
22
|
+
END
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -41,7 +41,7 @@ module ActiveScaffold
|
|
41
41
|
versions = options[:magick][:versions]
|
42
42
|
raise unless versions.stringify_keys[version]
|
43
43
|
true
|
44
|
-
rescue
|
44
|
+
rescue StandardError
|
45
45
|
false
|
46
46
|
end
|
47
47
|
|
@@ -1,14 +1,15 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../test_helper.rb', __dir__)
|
2
2
|
|
3
|
-
class DeleteFileColumnTest < Test
|
3
|
+
class DeleteFileColumnTest < MiniTest::Test
|
4
4
|
def setup
|
5
|
-
|
5
|
+
MockModel.extend ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
|
6
|
+
ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.generate_delete_helpers(MockModel)
|
6
7
|
@model = MockModel.new
|
7
8
|
@model.band_image = 'coolio.jpg'
|
8
9
|
end
|
9
10
|
|
10
11
|
def test__file_column_fields
|
11
|
-
assert_equal(1, @model.file_column_fields.length)
|
12
|
+
assert_equal(1, @model.class.file_column_fields.length)
|
12
13
|
end
|
13
14
|
|
14
15
|
def test__delete_band_image__boolean__should_delete
|
@@ -23,17 +24,17 @@ class DeleteFileColumnTest < Test::Unit::TestCase
|
|
23
24
|
|
24
25
|
def test__delete_band_image__boolean_false__shouldnt_delete
|
25
26
|
@model.delete_band_image = false
|
26
|
-
|
27
|
+
refute_nil @model.band_image
|
27
28
|
end
|
28
29
|
|
29
30
|
def test__delete_band_image__string_false__shouldnt_delete
|
30
31
|
@model.delete_band_image = 'false'
|
31
|
-
|
32
|
+
refute_nil @model.band_image
|
32
33
|
end
|
33
34
|
|
34
35
|
def test__just_uploaded__shouldnt_delete
|
35
36
|
@model.band_image_just_uploaded = true
|
36
37
|
@model.delete_band_image = 'true'
|
37
|
-
|
38
|
+
refute_nil(@model.band_image)
|
38
39
|
end
|
39
40
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'rubygems'
|
3
|
-
require 'active_support'
|
1
|
+
require 'minitest/autorun'
|
4
2
|
|
5
|
-
%w[../
|
3
|
+
%w[../file_column_helpers.rb mock_model.rb].each do |file|
|
6
4
|
require File.expand_path(File.join(File.dirname(__FILE__), file))
|
7
5
|
end
|
@@ -7,6 +7,6 @@ class ActiveScaffold::Bridges::PaperTrail < ActiveScaffold::DataStructures::Brid
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.prepare
|
10
|
-
|
10
|
+
ActiveScaffold::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:deleted] = :get
|
11
11
|
end
|
12
12
|
end
|