active_scaffold_batch 3.7.3 → 3.9.0
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/README +101 -5
- data/app/assets/javascripts/active_scaffold_batch.js +10 -10
- data/app/assets/stylesshets/active_scaffold_batch.scss +4 -13
- data/app/views/active_scaffold_overrides/_batch_create_form.html.erb +8 -8
- data/app/views/active_scaffold_overrides/_batch_create_form_attribute.html.erb +7 -19
- data/app/views/active_scaffold_overrides/_batch_create_form_body.html.erb +24 -23
- data/app/views/active_scaffold_overrides/_batch_create_form_footer.html.erb +11 -2
- data/app/views/active_scaffold_overrides/_batch_create_form_horizontal.html.erb +24 -9
- data/app/views/active_scaffold_overrides/_batch_create_form_horizontal_record.html.erb +11 -26
- data/app/views/active_scaffold_overrides/_batch_create_form_multiple.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_batch_create_form_vertical.html.erb +12 -3
- data/app/views/active_scaffold_overrides/_batch_create_form_vertical_record.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_batch_update_form.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_batch_update_form_attribute.html.erb +1 -11
- data/app/views/active_scaffold_overrides/_batch_update_form_attribute_scope.html.erb +7 -12
- data/app/views/active_scaffold_overrides/_batch_update_form_body.html.erb +24 -23
- data/app/views/active_scaffold_overrides/_form_messages.html.erb +16 -4
- data/app/views/active_scaffold_overrides/batch_add.js.erb +16 -3
- data/app/views/active_scaffold_overrides/batch_create.html.erb +1 -1
- data/app/views/active_scaffold_overrides/batch_update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/on_batch_base.js.erb +14 -4
- data/app/views/active_scaffold_overrides/on_batch_create.js.erb +10 -5
- data/app/views/active_scaffold_overrides/on_batch_update.js.erb +6 -4
- data/config/locales/de.yml +2 -1
- data/config/locales/en.yml +2 -1
- data/config/locales/es.yml +2 -1
- data/lib/active_scaffold/actions/batch_base.rb +23 -28
- data/lib/active_scaffold/actions/batch_create.rb +78 -44
- data/lib/active_scaffold/actions/batch_destroy.rb +16 -15
- data/lib/active_scaffold/actions/batch_update.rb +129 -104
- data/lib/active_scaffold/config/batch_create.rb +17 -19
- data/lib/active_scaffold/config/batch_destroy.rb +24 -14
- data/lib/active_scaffold/config/batch_update.rb +21 -20
- data/lib/active_scaffold/helpers/batch_create_column_helpers.rb +17 -18
- data/lib/active_scaffold/helpers/datepicker_update_column_helpers.rb +48 -17
- data/lib/active_scaffold/helpers/update_column_helpers.rb +91 -33
- data/lib/active_scaffold_batch/engine.rb +10 -12
- data/lib/active_scaffold_batch/extensions.rb +16 -0
- data/lib/active_scaffold_batch/version.rb +4 -2
- data/lib/active_scaffold_batch.rb +5 -15
- metadata +7 -5
|
@@ -1,29 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module BatchUpdate
|
|
5
|
+
GENERIC_OPERATORS = %w[
|
|
6
|
+
NO_UPDATE
|
|
7
|
+
REPLACE
|
|
8
|
+
].freeze
|
|
9
|
+
NUMERIC_OPERATORS = %w[
|
|
10
|
+
PLUS
|
|
11
|
+
MINUS
|
|
12
|
+
TIMES
|
|
13
|
+
DIVISION
|
|
14
|
+
].freeze
|
|
15
|
+
NUMERIC_OPTIONS = %w[
|
|
16
|
+
ABSOLUTE
|
|
17
|
+
PERCENT
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
DATE_OPERATORS = %w[
|
|
21
|
+
PLUS
|
|
22
|
+
MINUS
|
|
23
|
+
].freeze
|
|
3
24
|
|
|
4
|
-
GenericOperators = [
|
|
5
|
-
'NO_UPDATE',
|
|
6
|
-
'REPLACE'
|
|
7
|
-
]
|
|
8
|
-
NumericOperators = [
|
|
9
|
-
'PLUS',
|
|
10
|
-
'MINUS',
|
|
11
|
-
'TIMES',
|
|
12
|
-
'DIVISION'
|
|
13
|
-
]
|
|
14
|
-
NumericOptions = [
|
|
15
|
-
'ABSOLUTE',
|
|
16
|
-
'PERCENT'
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
DateOperators = [
|
|
20
|
-
'PLUS',
|
|
21
|
-
'MINUS'
|
|
22
|
-
]
|
|
23
|
-
|
|
24
25
|
def self.included(base)
|
|
25
26
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
26
|
-
base.before_action :batch_update_authorized_filter, :
|
|
27
|
+
base.before_action :batch_update_authorized_filter, only: %i[batch_edit batch_update]
|
|
27
28
|
base.helper_method :batch_update_values
|
|
28
29
|
end
|
|
29
30
|
|
|
@@ -36,18 +37,18 @@ module ActiveScaffold::Actions
|
|
|
36
37
|
batch_action
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
|
|
40
40
|
protected
|
|
41
|
+
|
|
41
42
|
def batch_edit_respond_to_html
|
|
42
43
|
if batch_successful?
|
|
43
|
-
render(:
|
|
44
|
+
render(action: 'batch_update')
|
|
44
45
|
else
|
|
45
46
|
return_to_main
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
def batch_edit_respond_to_js
|
|
50
|
-
render(:
|
|
51
|
+
render(partial: 'batch_update_form')
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
def batch_update_values
|
|
@@ -55,18 +56,18 @@ module ActiveScaffold::Actions
|
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def batch_update_respond_to_html
|
|
58
|
-
if params[:iframe]=='true' # was this an iframe post ?
|
|
59
|
+
if params[:iframe] == 'true' # was this an iframe post ?
|
|
59
60
|
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
60
61
|
do_refresh_list
|
|
61
62
|
responds_to_parent do
|
|
62
|
-
render :
|
|
63
|
+
render action: 'on_batch_update.js', layout: false
|
|
63
64
|
end
|
|
64
65
|
else # just a regular post
|
|
65
66
|
if batch_successful?
|
|
66
|
-
flash[:info] = as_(:updated_model, :
|
|
67
|
+
flash[:info] = as_(:updated_model, model: @record.to_label)
|
|
67
68
|
return_to_main
|
|
68
69
|
else
|
|
69
|
-
render(:
|
|
70
|
+
render(action: 'batch_update')
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
73
|
end
|
|
@@ -74,7 +75,7 @@ module ActiveScaffold::Actions
|
|
|
74
75
|
def batch_update_respond_to_js
|
|
75
76
|
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
76
77
|
do_refresh_list
|
|
77
|
-
render :
|
|
78
|
+
render action: 'on_batch_update'
|
|
78
79
|
end
|
|
79
80
|
|
|
80
81
|
def do_batch_edit
|
|
@@ -83,42 +84,49 @@ module ActiveScaffold::Actions
|
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def before_do_batch_update
|
|
86
|
-
@batch_update_values = update_attribute_values_from_params(
|
|
87
|
+
@batch_update_values = update_attribute_values_from_params(
|
|
88
|
+
active_scaffold_config.batch_update.columns,
|
|
89
|
+
params[:record]
|
|
90
|
+
)
|
|
87
91
|
end
|
|
88
92
|
|
|
89
93
|
def batch_update_listed
|
|
90
94
|
case active_scaffold_config.batch_update.process_mode
|
|
91
|
-
when :update
|
|
92
|
-
each_record_in_scope {|record| update_record_in_batch(record) if authorized_for_job?(record)}
|
|
93
|
-
when :update_all
|
|
95
|
+
when :update
|
|
96
|
+
each_record_in_scope { |record| update_record_in_batch(record) if authorized_for_job?(record) }
|
|
97
|
+
when :update_all
|
|
94
98
|
updates = updates_for_update_all
|
|
95
99
|
unless updates.first.empty?
|
|
96
100
|
do_search if respond_to? :do_search, true
|
|
97
101
|
# all_conditions might fail cause joins are not working in update_all
|
|
98
|
-
|
|
102
|
+
# update_all is the explicitly configured batch processing mode.
|
|
103
|
+
active_scaffold_config.model.update_all(updates, all_conditions) # rubocop:disable Rails/SkipsModelValidations
|
|
99
104
|
end
|
|
100
105
|
else
|
|
101
|
-
Rails.logger.error
|
|
106
|
+
Rails.logger.error "Unknown process_mode: #{active_scaffold_config.batch_update.process_mode} " \
|
|
107
|
+
'for action batch_update'
|
|
102
108
|
end
|
|
103
|
-
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
def batch_update_marked
|
|
107
112
|
case active_scaffold_config.batch_update.process_mode
|
|
108
|
-
when :update
|
|
109
|
-
each_marked_record {|record| update_record_in_batch(record) if authorized_for_job?(record)}
|
|
110
|
-
when :update_all
|
|
113
|
+
when :update
|
|
114
|
+
each_marked_record { |record| update_record_in_batch(record) if authorized_for_job?(record) }
|
|
115
|
+
when :update_all
|
|
111
116
|
updates = updates_for_update_all
|
|
112
117
|
unless updates.first.empty?
|
|
113
|
-
|
|
118
|
+
model = active_scaffold_config.model
|
|
119
|
+
# update_all is the explicitly configured batch processing mode.
|
|
120
|
+
model.where(model.primary_key => marked_records.to_a).update_all(updates) # rubocop:disable Rails/SkipsModelValidations
|
|
114
121
|
do_demark_all
|
|
115
122
|
end
|
|
116
123
|
else
|
|
117
|
-
Rails.logger.error
|
|
124
|
+
Rails.logger.error "Unknown process_mode: #{active_scaffold_config.batch_update.process_mode} " \
|
|
125
|
+
'for action batch_update'
|
|
118
126
|
end
|
|
119
127
|
end
|
|
120
128
|
|
|
121
|
-
def updates_for_update_all
|
|
129
|
+
def updates_for_update_all
|
|
122
130
|
update_all = [[]]
|
|
123
131
|
batch_update_values.each do |attribute, value|
|
|
124
132
|
sql_set, value = get_update_all_attribute(value[:column], attribute, value[:value])
|
|
@@ -127,10 +135,24 @@ module ActiveScaffold::Actions
|
|
|
127
135
|
update_all << value if value.present?
|
|
128
136
|
end
|
|
129
137
|
end
|
|
138
|
+
add_timestamps_to_update_all(update_all) if update_all.first.any?
|
|
130
139
|
update_all[0] = update_all.first.join(',')
|
|
131
140
|
update_all
|
|
132
141
|
end
|
|
133
142
|
|
|
143
|
+
def add_timestamps_to_update_all(update_all)
|
|
144
|
+
return unless active_scaffold_config.batch_update.update_timestamps
|
|
145
|
+
|
|
146
|
+
model = active_scaffold_config.model
|
|
147
|
+
model.touch_attributes_with_time.each do |attribute, time|
|
|
148
|
+
next if batch_update_values.key?(attribute) || batch_update_values.key?(attribute.to_sym)
|
|
149
|
+
|
|
150
|
+
quoted_attribute = model.connection.quote_column_name(attribute)
|
|
151
|
+
update_all.first << "#{quoted_attribute} = ?"
|
|
152
|
+
update_all << time
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
134
156
|
def update_record_in_batch(record)
|
|
135
157
|
@successful = nil
|
|
136
158
|
@record = record
|
|
@@ -138,8 +160,8 @@ module ActiveScaffold::Actions
|
|
|
138
160
|
batch_update_values.each do |attribute, value|
|
|
139
161
|
set_record_attribute(value[:column], attribute, value[:value])
|
|
140
162
|
end
|
|
141
|
-
|
|
142
|
-
update_save(:
|
|
163
|
+
|
|
164
|
+
update_save(no_record_param_update: true)
|
|
143
165
|
if successful?
|
|
144
166
|
@record.as_marked = false if batch_scope == 'MARKED'
|
|
145
167
|
else
|
|
@@ -149,7 +171,7 @@ module ActiveScaffold::Actions
|
|
|
149
171
|
|
|
150
172
|
def get_update_all_attribute(column, attribute, value)
|
|
151
173
|
form_ui = column_form_ui(column)
|
|
152
|
-
|
|
174
|
+
|
|
153
175
|
if form_ui && (method = override_batch_update_all_value(form_ui))
|
|
154
176
|
update_value = send(method, column, value)
|
|
155
177
|
if update_value.nil?
|
|
@@ -162,8 +184,8 @@ module ActiveScaffold::Actions
|
|
|
162
184
|
sql_set = "#{attribute} = ?"
|
|
163
185
|
update_value = value[:value]
|
|
164
186
|
end
|
|
165
|
-
|
|
166
|
-
|
|
187
|
+
|
|
188
|
+
[sql_set, update_value]
|
|
167
189
|
end
|
|
168
190
|
|
|
169
191
|
# TODO: delete when ActiveScaffold 3.5 is released and required
|
|
@@ -174,19 +196,21 @@ module ActiveScaffold::Actions
|
|
|
174
196
|
def update_attribute_values_from_params(columns, attributes)
|
|
175
197
|
values = {}
|
|
176
198
|
return values unless params_hash? attributes
|
|
199
|
+
|
|
177
200
|
columns.each_column(for: new_model, crud_type: :update, flatten: true) do |column|
|
|
178
201
|
next unless params_hash?(attributes[column.name]) && attributes[column.name][:operator] != 'NO_UPDATE'
|
|
202
|
+
|
|
179
203
|
value = attributes[column.name]
|
|
180
204
|
value[:value] = value[:operator] == 'NULL' ? nil : column_value_from_param_value(nil, column, value[:value])
|
|
181
|
-
values[column.name] = {:
|
|
205
|
+
values[column.name] = {column: column, value: value}
|
|
182
206
|
end
|
|
183
207
|
values
|
|
184
208
|
end
|
|
185
|
-
|
|
209
|
+
|
|
186
210
|
# The default security delegates to ActiveRecordPermissions.
|
|
187
211
|
# You may override the method to customize.
|
|
188
212
|
def batch_update_authorized?(record = nil)
|
|
189
|
-
authorized_for?(:
|
|
213
|
+
authorized_for?(crud_type: :update)
|
|
190
214
|
end
|
|
191
215
|
|
|
192
216
|
def batch_update_ignore?(record = nil)
|
|
@@ -195,72 +219,72 @@ module ActiveScaffold::Actions
|
|
|
195
219
|
|
|
196
220
|
def batch_update_value_for_numeric(column, record, calculation_info)
|
|
197
221
|
current_value = record.send(column.name)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
222
|
+
operator = calculation_info[:operator]
|
|
223
|
+
return current_value unless batch_update_operator?(operator, NUMERIC_OPERATORS)
|
|
224
|
+
|
|
225
|
+
operand = self.class.condition_value_for_numeric(column, calculation_info[:value])
|
|
226
|
+
operand = current_value / 100 * operand if calculation_info[:opt] == 'PERCENT'
|
|
227
|
+
return operand if operator == 'REPLACE'
|
|
228
|
+
return if operator == 'NULL' || current_value.blank?
|
|
229
|
+
|
|
230
|
+
apply_numeric_operator(operator, current_value, operand)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def apply_numeric_operator(operator, current_value, operand)
|
|
234
|
+
case operator
|
|
235
|
+
when 'PLUS' then current_value + operand
|
|
236
|
+
when 'MINUS' then current_value - operand
|
|
237
|
+
when 'TIMES' then current_value * operand
|
|
238
|
+
when 'DIVISION' then current_value / operand
|
|
211
239
|
else
|
|
212
240
|
current_value
|
|
213
241
|
end
|
|
214
242
|
end
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
243
|
+
alias batch_update_value_for_integer batch_update_value_for_numeric
|
|
244
|
+
alias batch_update_value_for_decimal batch_update_value_for_numeric
|
|
245
|
+
alias batch_update_value_for_float batch_update_value_for_numeric
|
|
218
246
|
|
|
219
247
|
def batch_update_all_value_for_numeric(column, calculation_info)
|
|
220
248
|
operator = calculation_info[:operator]
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else
|
|
237
|
-
nil
|
|
249
|
+
return unless batch_update_operator?(operator, NUMERIC_OPERATORS)
|
|
250
|
+
|
|
251
|
+
model = active_scaffold_config.model
|
|
252
|
+
connection = model.connection
|
|
253
|
+
operand = model.quote_value(self.class.condition_value_for_numeric(column, calculation_info[:value]))
|
|
254
|
+
if calculation_info[:opt] == 'PERCENT'
|
|
255
|
+
operand = "#{connection.quote_column_name(column.name)} / 100.0 * #{operand}"
|
|
256
|
+
end
|
|
257
|
+
case calculation_info[:operator]
|
|
258
|
+
when 'REPLACE' then operand
|
|
259
|
+
when 'NULL' then model.quote_value(nil)
|
|
260
|
+
when 'PLUS' then "#{connection.quote_column_name(column.name)} + #{operand}"
|
|
261
|
+
when 'MINUS' then "#{connection.quote_column_name(column.name)} - #{operand}"
|
|
262
|
+
when 'TIMES' then "#{connection.quote_column_name(column.name)} * #{operand}"
|
|
263
|
+
when 'DIVISION' then "#{connection.quote_column_name(column.name)} / #{operand}"
|
|
238
264
|
end
|
|
239
265
|
end
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
266
|
+
alias batch_update_all_value_for_integer batch_update_all_value_for_numeric
|
|
267
|
+
alias batch_update_all_value_for_decimal batch_update_all_value_for_numeric
|
|
268
|
+
alias batch_update_all_value_for_float batch_update_all_value_for_numeric
|
|
243
269
|
|
|
244
270
|
def batch_update_value_for_date_picker(column, record, calculation_info)
|
|
245
271
|
current_value = record.send(column.name)
|
|
246
272
|
operator = calculation_info[:operator]
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
current_value
|
|
263
|
-
end
|
|
273
|
+
return current_value unless batch_update_operator?(operator, DATE_OPERATORS)
|
|
274
|
+
|
|
275
|
+
conversion = column.column.type == :date ? :to_date : :to_time
|
|
276
|
+
operand = self.class.condition_value_for_datetime(column, calculation_info[:value], conversion)
|
|
277
|
+
return operand if operator == 'REPLACE'
|
|
278
|
+
return if operator == 'NULL'
|
|
279
|
+
return current_value unless DATE_OPERATORS.include?(operator)
|
|
280
|
+
|
|
281
|
+
trend_number = [calculation_info['number'].to_i, 1].max
|
|
282
|
+
duration = trend_number.send(calculation_info['unit'].downcase.singularize.to_sym)
|
|
283
|
+
operator == 'PLUS' ? current_value&.in(duration) : current_value&.ago(duration)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def batch_update_operator?(operator, type_operators)
|
|
287
|
+
operator == 'NULL' || GENERIC_OPERATORS.include?(operator) || type_operators.include?(operator)
|
|
264
288
|
end
|
|
265
289
|
|
|
266
290
|
def override_batch_update_value(form_ui)
|
|
@@ -277,8 +301,9 @@ module ActiveScaffold::Actions
|
|
|
277
301
|
|
|
278
302
|
def batch_update_authorized_filter
|
|
279
303
|
link = active_scaffold_config.batch_update.link || active_scaffold_config.batch_update.class.link
|
|
280
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
304
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
|
|
281
305
|
end
|
|
306
|
+
|
|
282
307
|
def batch_edit_formats
|
|
283
308
|
(default_formats + active_scaffold_config.formats).uniq
|
|
284
309
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Config
|
|
2
4
|
class BatchCreate < ActiveScaffold::Config::Form
|
|
3
5
|
self.crud_type = :create
|
|
@@ -13,37 +15,33 @@ module ActiveScaffold::Config
|
|
|
13
15
|
# global level configuration
|
|
14
16
|
# --------------------------
|
|
15
17
|
# the ActionLink for this action
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_new', :label => :create, :type => :collection, :security_method => :batch_create_authorized?, :ignore_method => :batch_create_ignore?)
|
|
18
|
+
cattr_accessor :link,
|
|
19
|
+
instance_accessor: false,
|
|
20
|
+
default: ActiveScaffold::DataStructures::ActionLink.new(
|
|
21
|
+
'batch_new', label: :create, type: :collection,
|
|
22
|
+
security_method: :batch_create_authorized?, ignore_method: :batch_create_ignore?
|
|
23
|
+
)
|
|
23
24
|
|
|
24
25
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
25
|
-
cattr_accessor :plugin_directory
|
|
26
|
-
|
|
26
|
+
cattr_accessor :plugin_directory,
|
|
27
|
+
instance_accessor: false,
|
|
28
|
+
default: File.expand_path(__FILE__).match(%r{(^.*)/lib/active_scaffold/config/batch_create.rb})[1]
|
|
27
29
|
|
|
28
30
|
# configures how batch create should be processed
|
|
29
31
|
# :create => standard activerecord create including validations
|
|
30
|
-
cattr_accessor :process_mode
|
|
31
|
-
@@process_mode = :create
|
|
32
|
+
cattr_accessor :process_mode, instance_accessor: false, default: :create
|
|
32
33
|
|
|
33
34
|
# you may update all records in list view or all marked records
|
|
34
35
|
# you might disable list mode with this switch if you think it is
|
|
35
36
|
# too "dangerous"
|
|
36
|
-
cattr_accessor :list_mode_enabled
|
|
37
|
-
@@list_mode_enabled = true
|
|
37
|
+
cattr_accessor :list_mode_enabled, instance_accessor: false, default: true
|
|
38
38
|
|
|
39
39
|
# run all create statements in a transaction, so no record is created
|
|
40
40
|
# if someone fails
|
|
41
|
-
cattr_accessor :run_in_transaction
|
|
42
|
-
@@run_in_transaction = true
|
|
41
|
+
cattr_accessor :run_in_transaction, instance_accessor: false, default: true
|
|
43
42
|
|
|
44
43
|
# layout for create multiple records
|
|
45
|
-
cattr_accessor :layout
|
|
46
|
-
@@layout = :vertical
|
|
44
|
+
cattr_accessor :layout, instance_accessor: false, default: :vertical
|
|
47
45
|
|
|
48
46
|
# instance-level configuration
|
|
49
47
|
# ----------------------------
|
|
@@ -72,8 +70,8 @@ module ActiveScaffold::Config
|
|
|
72
70
|
|
|
73
71
|
# the label= method already exists in the Form base class
|
|
74
72
|
def label(model = nil, core: @core)
|
|
75
|
-
model ||= core.label(:
|
|
76
|
-
@label ? as_(@label) : as_(:create_model, :
|
|
73
|
+
model ||= core.label(count: 2)
|
|
74
|
+
@label ? as_(@label) : as_(:create_model, model: model)
|
|
77
75
|
end
|
|
78
76
|
end
|
|
79
77
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Config
|
|
2
4
|
class BatchDestroy < ActiveScaffold::Config::Base
|
|
3
5
|
self.crud_type = :delete
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
def initialize(core_config)
|
|
6
8
|
super
|
|
7
9
|
@action_group ||= 'collection.batch.destroy'
|
|
@@ -11,25 +13,33 @@ module ActiveScaffold::Config
|
|
|
11
13
|
# global level configuration
|
|
12
14
|
# --------------------------
|
|
13
15
|
# the ActionLink for this action
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
cattr_accessor :link,
|
|
17
|
+
instance_accessor: false,
|
|
18
|
+
default: [
|
|
19
|
+
ActiveScaffold::DataStructures::ActionLink.new(
|
|
20
|
+
'batch_destroy', label: :listed, type: :collection, method: :delete, position: false,
|
|
21
|
+
crud_type: :delete, confirm: :are_you_sure_to_delete,
|
|
22
|
+
parameters: {batch_scope: 'LISTED'},
|
|
23
|
+
security_method: :batch_destroy_authorized?
|
|
24
|
+
),
|
|
25
|
+
ActiveScaffold::DataStructures::ActionLink.new(
|
|
26
|
+
'batch_destroy', label: :marked, type: :collection, method: :delete, position: false,
|
|
27
|
+
crud_type: :delete, confirm: :are_you_sure_to_delete,
|
|
28
|
+
parameters: {batch_scope: 'MARKED'},
|
|
29
|
+
security_method: :batch_destroy_authorized?,
|
|
30
|
+
ignore_method: :batch_destroy_marked_ignore?
|
|
31
|
+
)
|
|
32
|
+
]
|
|
22
33
|
|
|
23
34
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
24
|
-
cattr_accessor :plugin_directory
|
|
25
|
-
|
|
35
|
+
cattr_accessor :plugin_directory,
|
|
36
|
+
instance_accessor: false,
|
|
37
|
+
default: File.expand_path(__FILE__).match(%r{(^.*)/lib/active_scaffold/config/batch_destroy.rb})[1]
|
|
26
38
|
|
|
27
39
|
# configures how batch updates should be processed
|
|
28
40
|
# :delete => standard activerecord delete including validations
|
|
29
41
|
# :delete_all => updating in one sql call without activerecord instantiation and validation
|
|
30
|
-
cattr_accessor :process_mode
|
|
31
|
-
@@process_mode = :delete
|
|
32
|
-
|
|
42
|
+
cattr_accessor :process_mode, instance_accessor: false, default: :delete
|
|
33
43
|
|
|
34
44
|
# instance-level configuration
|
|
35
45
|
# ----------------------------
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Config
|
|
2
4
|
class BatchUpdate < ActiveScaffold::Config::Form
|
|
3
5
|
self.crud_type = :update
|
|
@@ -6,47 +8,46 @@ module ActiveScaffold::Config
|
|
|
6
8
|
@process_mode = self.class.process_mode
|
|
7
9
|
@action_group ||= 'collection.batch'
|
|
8
10
|
@list_mode_enabled = self.class.list_mode_enabled
|
|
11
|
+
@update_timestamps = self.class.update_timestamps
|
|
9
12
|
end
|
|
10
13
|
|
|
11
14
|
# global level configuration
|
|
12
15
|
# --------------------------
|
|
13
16
|
# the ActionLink for this action
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_edit', :label => :edit, :type => :collection, :security_method => :batch_update_authorized?, :ignore_method => :batch_update_ignore?)
|
|
17
|
+
cattr_accessor :link,
|
|
18
|
+
instance_accessor: false,
|
|
19
|
+
default: ActiveScaffold::DataStructures::ActionLink.new(
|
|
20
|
+
'batch_edit', label: :edit, type: :collection,
|
|
21
|
+
security_method: :batch_update_authorized?, ignore_method: :batch_update_ignore?
|
|
22
|
+
)
|
|
21
23
|
|
|
22
24
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
23
|
-
cattr_accessor :plugin_directory
|
|
24
|
-
|
|
25
|
+
cattr_accessor :plugin_directory,
|
|
26
|
+
instance_accessor: false,
|
|
27
|
+
default: File.expand_path(__FILE__).match(%r{(^.*)/lib/active_scaffold/config/batch_update.rb})[1]
|
|
25
28
|
|
|
26
29
|
# configures how batch updates should be processed
|
|
27
30
|
# :update => standard activerecord update including validations
|
|
28
31
|
# :update_all => updating in one sql call without activerecord instantiation and validation
|
|
29
|
-
cattr_accessor :process_mode
|
|
30
|
-
@@process_mode = :update
|
|
32
|
+
cattr_accessor :process_mode, instance_accessor: false, default: :update
|
|
31
33
|
|
|
32
34
|
# you may update all records in list view or all marked records
|
|
33
35
|
# you might disable list mode with this switch if you think it is
|
|
34
36
|
# too "dangerous"
|
|
35
|
-
cattr_accessor :list_mode_enabled
|
|
36
|
-
|
|
37
|
+
cattr_accessor :list_mode_enabled, instance_accessor: false, default: true
|
|
38
|
+
|
|
39
|
+
# update the model's update timestamp when process_mode is :update_all
|
|
40
|
+
cattr_accessor :update_timestamps, instance_accessor: false, default: true
|
|
37
41
|
# instance-level configuration
|
|
38
42
|
# ----------------------------
|
|
39
43
|
|
|
40
|
-
# see class
|
|
41
|
-
attr_accessor :process_mode
|
|
42
|
-
|
|
43
|
-
attr_accessor :list_mode_enabled
|
|
44
|
-
|
|
44
|
+
# see class accessors
|
|
45
|
+
attr_accessor :process_mode, :list_mode_enabled, :update_timestamps
|
|
45
46
|
|
|
46
47
|
# the label= method already exists in the Form base class
|
|
47
48
|
def label(model = nil, core: @core)
|
|
48
|
-
model ||= core.label(:
|
|
49
|
-
@label ? as_(@label) : as_(:update_model, :
|
|
49
|
+
model ||= core.label(count: 2)
|
|
50
|
+
@label ? as_(@label) : as_(:update_model, model: model)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold
|
|
2
4
|
module Helpers
|
|
3
5
|
# Helpers that assist with the rendering of a Form Column
|
|
@@ -7,30 +9,26 @@ module ActiveScaffold
|
|
|
7
9
|
def active_scaffold_batch_create_by_column(column, scope = nil, options = {})
|
|
8
10
|
options = active_scaffold_input_options(column, scope, options)
|
|
9
11
|
|
|
12
|
+
ui_options = column.form_ui_options || column.options
|
|
10
13
|
if column.form_ui == :record_select
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
active_scaffold_record_select(options[:object], column, options, batch_create_by_records, true,
|
|
15
|
+
ui_options: ui_options)
|
|
13
16
|
elsif column.association
|
|
14
|
-
active_scaffold_batch_create_singular_association(column, options)
|
|
17
|
+
active_scaffold_batch_create_singular_association(column, options, ui_options: ui_options)
|
|
15
18
|
else
|
|
16
|
-
text_area_tag(column.name, params[:record] ? params[:record][column.name] : '',
|
|
19
|
+
text_area_tag(column.name, params[:record] ? params[:record][column.name] : '',
|
|
20
|
+
options.merge(column.options[:html_options] || {}))
|
|
17
21
|
end
|
|
18
|
-
|
|
19
22
|
end
|
|
20
23
|
|
|
21
|
-
def active_scaffold_batch_create_singular_association(column, html_options)
|
|
22
|
-
associated_options = batch_create_by_records.collect
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
select_tag(column.name, options_from_collection_for_select(select_options.uniq, :id, column.options[:label_method] || :to_label, associated_options), html_options)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def batch_create_multiple_remove_link
|
|
33
|
-
link_to as_(:remove), '#', :class => 'remove'
|
|
24
|
+
def active_scaffold_batch_create_singular_association(column, html_options, ui_options: column.options)
|
|
25
|
+
associated_options = batch_create_by_records.collect(&:id)
|
|
26
|
+
active_scaffold_input_singular_association(
|
|
27
|
+
column,
|
|
28
|
+
html_options.merge(multiple: true, associated: associated_options),
|
|
29
|
+
{include_blank: false},
|
|
30
|
+
ui_options: ui_options
|
|
31
|
+
)
|
|
34
32
|
end
|
|
35
33
|
|
|
36
34
|
def batch_create_multiple_layout
|
|
@@ -40,6 +38,7 @@ module ActiveScaffold
|
|
|
40
38
|
def current_form_columns(record, scope, subform_controller = nil)
|
|
41
39
|
columns = super
|
|
42
40
|
return columns if columns
|
|
41
|
+
|
|
43
42
|
if %i[batch_new batch_create].include? action_name.to_sym
|
|
44
43
|
active_scaffold_config.batch_create.columns.visible_columns_names
|
|
45
44
|
elsif %i[batch_edit batch_update].include? action_name.to_sym
|