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,15 +1,20 @@
|
|
|
1
|
-
<% form_selector =
|
|
1
|
+
<% form_selector = element_form_id(action: :batch_create).to_s %>
|
|
2
2
|
|
|
3
3
|
<% if controller.send :batch_successful? %>
|
|
4
4
|
<% called_by_controller = params.delete(:batch_create_by) %>
|
|
5
5
|
<% if called_by_controller.nil? %>
|
|
6
|
-
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>','<%= escape_javascript(render(
|
|
6
|
+
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>');
|
|
7
7
|
<% else %>
|
|
8
|
-
ActiveScaffold.mark_records(
|
|
8
|
+
ActiveScaffold.mark_records(
|
|
9
|
+
'<%= "#{controller_id(called_by_controller)}-tbody" %>',
|
|
10
|
+
{checked: false, include_checkboxes: true}
|
|
11
|
+
);
|
|
9
12
|
<% end %>
|
|
10
13
|
ActiveScaffold.find_action_link('<%= form_selector %>').close();
|
|
11
14
|
<% else %>
|
|
12
|
-
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages(
|
|
13
|
-
|
|
15
|
+
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages(
|
|
16
|
+
'<%= escape_javascript(render('messages')) %>'
|
|
17
|
+
);
|
|
18
|
+
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render('batch_create_form', {xhr: true})) %>');
|
|
14
19
|
ActiveScaffold.scroll_to('<%= form_selector %>', true);
|
|
15
20
|
<% end %>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
<% form_selector =
|
|
1
|
+
<% form_selector = element_form_id(action: :batch_update).to_s %>
|
|
2
2
|
|
|
3
3
|
<% if controller.send :batch_successful? %>
|
|
4
|
-
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>','<%= escape_javascript(render(
|
|
4
|
+
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>');
|
|
5
5
|
ActiveScaffold.find_action_link('<%= form_selector %>').close();
|
|
6
6
|
<% else %>
|
|
7
|
-
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages(
|
|
8
|
-
|
|
7
|
+
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages(
|
|
8
|
+
'<%= escape_javascript(render('messages')) %>'
|
|
9
|
+
);
|
|
10
|
+
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render('batch_update_form', {xhr: true})) %>');
|
|
9
11
|
ActiveScaffold.scroll_to('<%= form_selector %>', true);
|
|
10
12
|
<% end %>
|
data/config/locales/de.yml
CHANGED
|
@@ -9,7 +9,8 @@ de:
|
|
|
9
9
|
absolute: abs
|
|
10
10
|
percent: '%'
|
|
11
11
|
batch_update: 'Speichern'
|
|
12
|
-
add_some_records:
|
|
12
|
+
add_some_records:
|
|
13
|
+
html: 'Add %{number_input} %{model}'
|
|
13
14
|
records: 'Records'
|
|
14
15
|
batch_processing_successful: "Batch processing successful"
|
|
15
16
|
batch: Batch
|
data/config/locales/en.yml
CHANGED
|
@@ -9,7 +9,8 @@ en:
|
|
|
9
9
|
absolute: abs
|
|
10
10
|
percent: '%'
|
|
11
11
|
batch_update: 'Batch Update'
|
|
12
|
-
add_some_records:
|
|
12
|
+
add_some_records:
|
|
13
|
+
html: 'Add %{number_input} %{model}'
|
|
13
14
|
records: 'Records'
|
|
14
15
|
batch_processing_successful: "Batch processing successful"
|
|
15
16
|
batch: Batch
|
data/config/locales/es.yml
CHANGED
|
@@ -9,7 +9,8 @@ es:
|
|
|
9
9
|
absolute: abs
|
|
10
10
|
percent: '%'
|
|
11
11
|
batch_update: 'Actualizar Lote'
|
|
12
|
-
add_some_records:
|
|
12
|
+
add_some_records:
|
|
13
|
+
html: 'Añadir %{number_input} %{model}'
|
|
13
14
|
records: 'Registros'
|
|
14
15
|
batch_processing_successful: "Proceso en lote realizado correctamente"
|
|
15
16
|
batch: Lote
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module BatchBase
|
|
3
|
-
|
|
4
5
|
def self.included(base)
|
|
5
6
|
base.helper_method :batch_scope
|
|
6
7
|
end
|
|
@@ -15,7 +16,7 @@ module ActiveScaffold::Actions
|
|
|
15
16
|
|
|
16
17
|
def batch_scope
|
|
17
18
|
if @batch_scope.nil? && params[:batch_scope]
|
|
18
|
-
@batch_scope = params[:batch_scope] if [
|
|
19
|
+
@batch_scope = params[:batch_scope] if %w[LISTED MARKED].include?(params[:batch_scope])
|
|
19
20
|
params.delete :batch_scope
|
|
20
21
|
end
|
|
21
22
|
@batch_scope
|
|
@@ -47,7 +48,9 @@ module ActiveScaffold::Actions
|
|
|
47
48
|
do_new
|
|
48
49
|
send("#{action_name}_values").each do |attribute, value|
|
|
49
50
|
form_ui = column_form_ui(value[:column])
|
|
50
|
-
|
|
51
|
+
unless form_ui && send("override_#{action_name}_value", form_ui)
|
|
52
|
+
set_record_attribute(value[:column], attribute, value[:value])
|
|
53
|
+
end
|
|
51
54
|
end
|
|
52
55
|
end
|
|
53
56
|
|
|
@@ -57,46 +60,46 @@ module ActiveScaffold::Actions
|
|
|
57
60
|
|
|
58
61
|
def process_batch
|
|
59
62
|
send("before_do_#{action_name}")
|
|
60
|
-
|
|
63
|
+
if batch_scope.present? && respond_to?("#{action_name}_#{batch_scope.downcase}", true)
|
|
64
|
+
send("#{action_name}_#{batch_scope.downcase}")
|
|
65
|
+
end
|
|
61
66
|
prepare_error_record unless batch_successful?
|
|
62
67
|
end
|
|
63
68
|
|
|
64
69
|
def authorized_for_job?(record)
|
|
65
|
-
if record.authorized_for?(:
|
|
70
|
+
if record.authorized_for?(crud_type: active_scaffold_config.send(action_name).crud_type)
|
|
66
71
|
true
|
|
67
72
|
else
|
|
68
|
-
record.errors.add(:base, as_(:no_authorization_for_action, :
|
|
73
|
+
record.errors.add(:base, as_(:no_authorization_for_action, action: action_name))
|
|
69
74
|
error_records << record
|
|
70
75
|
false
|
|
71
76
|
end
|
|
72
77
|
end
|
|
73
78
|
|
|
74
79
|
def temporary_id
|
|
75
|
-
(Time.now.to_f*1000).to_i.to_s
|
|
80
|
+
(Time.now.to_f * 1000).to_i.to_s
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
def batch_base_respond_to_html
|
|
79
84
|
if respond_to? "#{action_name}_respond_to_html", true
|
|
80
85
|
send("#{action_name}_respond_to_html")
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
render :action => 'on_batch_base.js', :layout => false
|
|
86
|
-
end
|
|
87
|
-
else # just a regular post
|
|
88
|
-
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
89
|
-
return_to_main
|
|
86
|
+
elsif params[:iframe] == 'true'
|
|
87
|
+
do_refresh_list
|
|
88
|
+
responds_to_parent do
|
|
89
|
+
render action: 'on_batch_base.js', layout: false
|
|
90
90
|
end
|
|
91
|
+
else # just a regular post
|
|
92
|
+
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
93
|
+
return_to_main
|
|
91
94
|
end
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
def batch_base_respond_to_js
|
|
95
98
|
if respond_to? "#{action_name}_respond_to_js", true
|
|
96
99
|
send("#{action_name}_respond_to_js")
|
|
97
|
-
else
|
|
100
|
+
else
|
|
98
101
|
do_refresh_list
|
|
99
|
-
render :
|
|
102
|
+
render action: 'on_batch_base'
|
|
100
103
|
end
|
|
101
104
|
end
|
|
102
105
|
|
|
@@ -104,7 +107,7 @@ module ActiveScaffold::Actions
|
|
|
104
107
|
if respond_to? "#{action_name}_respond_to_xml", true
|
|
105
108
|
send("#{action_name}_respond_to_xml")
|
|
106
109
|
else
|
|
107
|
-
|
|
110
|
+
response_to_api(:xml, active_scaffold_config.send(action_name).columns.visible_columns_names)
|
|
108
111
|
end
|
|
109
112
|
end
|
|
110
113
|
|
|
@@ -112,15 +115,7 @@ module ActiveScaffold::Actions
|
|
|
112
115
|
if respond_to? "#{action_name}_respond_to_json", true
|
|
113
116
|
send("#{action_name}_respond_to_json")
|
|
114
117
|
else
|
|
115
|
-
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def batch_base_respond_to_yaml
|
|
120
|
-
if respond_to? "#{action_name}_respond_to_yaml", true
|
|
121
|
-
send("#{action_name}_respond_to_yaml")
|
|
122
|
-
else
|
|
123
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.send(action_name).columns.visible_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
118
|
+
response_to_api(:json, active_scaffold_config.send(action_name).columns.visible_columns_names)
|
|
124
119
|
end
|
|
125
120
|
end
|
|
126
121
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module BatchCreate
|
|
3
|
-
|
|
4
5
|
def self.included(base)
|
|
5
6
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
6
|
-
base.before_action :batch_create_authorized_filter, :
|
|
7
|
+
base.before_action :batch_create_authorized_filter, only: %i[batch_new batch_create]
|
|
7
8
|
base.helper_method :batch_create_values
|
|
8
9
|
base.helper_method :batch_create_by_column
|
|
9
10
|
base.helper_method :batch_create_by_records
|
|
@@ -23,18 +24,18 @@ module ActiveScaffold::Actions
|
|
|
23
24
|
batch_action
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
|
|
27
27
|
protected
|
|
28
|
+
|
|
28
29
|
def batch_new_respond_to_html
|
|
29
30
|
if batch_successful?
|
|
30
|
-
render(:
|
|
31
|
+
render(action: 'batch_create')
|
|
31
32
|
else
|
|
32
33
|
return_to_main
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def batch_new_respond_to_js
|
|
37
|
-
render(:
|
|
38
|
+
render(partial: 'batch_create_form')
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def batch_add_respond_to_js
|
|
@@ -46,37 +47,36 @@ module ActiveScaffold::Actions
|
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def batch_create_by_records
|
|
49
|
-
if @batch_create_by_records.nil?
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if @batch_create_by_records.nil? && marked_records_parent
|
|
51
|
+
column = active_scaffold_config.columns[batch_create_by_column.to_sym]
|
|
52
|
+
@batch_create_by_records =
|
|
53
|
+
if column.association.polymorphic?
|
|
53
54
|
active_scaffold_config_for(params[:batch_create_by].singularize).model.find(marked_records_parent.keys)
|
|
54
55
|
else
|
|
55
56
|
column_plural_assocation_value_from_value(column, marked_records_parent.keys)
|
|
56
57
|
end
|
|
57
|
-
end
|
|
58
58
|
end
|
|
59
59
|
@batch_create_by_records || []
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def batch_create_respond_to_html
|
|
63
|
-
if params[:iframe]=='true' # was this an iframe post ?
|
|
63
|
+
if params[:iframe] == 'true' # was this an iframe post ?
|
|
64
64
|
do_refresh_list
|
|
65
65
|
responds_to_parent do
|
|
66
|
-
render :
|
|
66
|
+
render action: 'on_batch_create.js', layout: false
|
|
67
67
|
end
|
|
68
68
|
else # just a regular post
|
|
69
69
|
if batch_successful?
|
|
70
70
|
return_to_main
|
|
71
71
|
else
|
|
72
|
-
render(:
|
|
72
|
+
render(action: 'batch_create')
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def batch_create_respond_to_js
|
|
78
78
|
do_refresh_list
|
|
79
|
-
render :
|
|
79
|
+
render action: 'on_batch_create'
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def do_batch_new
|
|
@@ -99,12 +99,13 @@ module ActiveScaffold::Actions
|
|
|
99
99
|
|
|
100
100
|
def marked_records_parent
|
|
101
101
|
if @marked_records_parent.nil?
|
|
102
|
-
@marked_records_parent =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
@marked_records_parent =
|
|
103
|
+
if params[:batch_create_by]
|
|
104
|
+
session_parent = active_scaffold_session_storage(params[:batch_create_by])
|
|
105
|
+
session_parent['marked_records'] || {}
|
|
106
|
+
else
|
|
107
|
+
false
|
|
108
|
+
end
|
|
108
109
|
end
|
|
109
110
|
@marked_records_parent
|
|
110
111
|
end
|
|
@@ -142,33 +143,40 @@ module ActiveScaffold::Actions
|
|
|
142
143
|
else
|
|
143
144
|
processed_records, created_records = yield
|
|
144
145
|
end
|
|
145
|
-
|
|
146
|
+
return unless batch_successful? || created_records.positive?
|
|
147
|
+
|
|
148
|
+
flash[:info] = as_(
|
|
149
|
+
:some_records_created,
|
|
150
|
+
count: created_records,
|
|
151
|
+
model: active_scaffold_config.label(count: created_records)
|
|
152
|
+
)
|
|
146
153
|
end
|
|
147
154
|
|
|
148
155
|
def batch_create_listed
|
|
149
156
|
run_in_transaction_if_enabled do
|
|
150
157
|
processed_records = created_records = 0
|
|
151
158
|
case active_scaffold_config.batch_create.process_mode
|
|
152
|
-
when :create
|
|
159
|
+
when :create
|
|
153
160
|
batch_create_by_records.each do |batch_record|
|
|
154
161
|
create_record_in_batch(batch_record)
|
|
155
162
|
created_records += 1 if successful?
|
|
156
163
|
processed_records += 1
|
|
157
164
|
end
|
|
158
165
|
else
|
|
159
|
-
Rails.logger.error
|
|
166
|
+
Rails.logger.error "Unknown process_mode: #{active_scaffold_config.batch_create.process_mode} for " \
|
|
167
|
+
'action batch_create'
|
|
160
168
|
end
|
|
161
169
|
[processed_records, created_records]
|
|
162
170
|
end
|
|
163
171
|
end
|
|
164
|
-
|
|
172
|
+
alias batch_create_marked batch_create_listed
|
|
165
173
|
|
|
166
174
|
def batch_create_multiple
|
|
167
175
|
run_in_transaction_if_enabled do
|
|
168
176
|
@error_records = {}
|
|
169
177
|
processed_records = created_records = 0
|
|
170
178
|
params[:record].each do |scope, record_hash|
|
|
171
|
-
do_create(:
|
|
179
|
+
do_create(attributes: record_hash, skip_save: validate_first?)
|
|
172
180
|
error_records[scope] = @record unless successful? && !run_in_transaction?
|
|
173
181
|
created_records += 1 if successful?
|
|
174
182
|
processed_records += 1
|
|
@@ -182,29 +190,53 @@ module ActiveScaffold::Actions
|
|
|
182
190
|
end
|
|
183
191
|
|
|
184
192
|
def create_record_in_batch(created_by)
|
|
193
|
+
prepare_batch_create_record(created_by)
|
|
194
|
+
return unless authorized_for_job?(@record)
|
|
195
|
+
|
|
196
|
+
validate_or_save_batch_create_record
|
|
197
|
+
finalize_batch_create_record(created_by)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def prepare_batch_create_record(created_by)
|
|
185
201
|
@successful = nil
|
|
186
202
|
@record = new_batch_create_record(created_by)
|
|
187
203
|
@record.send("#{batch_create_by_column}=", created_by)
|
|
188
204
|
batch_create_values.each do |attribute, value|
|
|
189
205
|
set_record_attribute(value[:column], attribute, value[:value])
|
|
190
206
|
end
|
|
207
|
+
end
|
|
191
208
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
209
|
+
def validate_or_save_batch_create_record
|
|
210
|
+
if validate_first?
|
|
211
|
+
self.successful = [@record.valid?, @record.associated_valid?].all?
|
|
212
|
+
else
|
|
213
|
+
save_batch_create_record
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def save_batch_create_record
|
|
218
|
+
create_save(@record)
|
|
219
|
+
self.successful = @record.persisted?
|
|
220
|
+
rescue ActiveRecord::ActiveRecordError => e
|
|
221
|
+
@record.errors.add(:base, e.message) if @record.errors.empty?
|
|
222
|
+
self.successful = false
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def finalize_batch_create_record(created_by)
|
|
226
|
+
if successful?
|
|
227
|
+
marked_records_parent.delete(created_by.id.to_s) if batch_scope == 'MARKED' && marked_records_parent
|
|
228
|
+
else
|
|
229
|
+
normalize_batch_create_errors
|
|
207
230
|
end
|
|
231
|
+
error_records << @record unless successful? && !run_in_transaction?
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def normalize_batch_create_errors
|
|
235
|
+
new_errors = @record.errors.messages[batch_create_by_column].map do |error|
|
|
236
|
+
"#{@record.send(batch_create_by_column)} #{error}"
|
|
237
|
+
end
|
|
238
|
+
@record.errors.delete(batch_create_by_column)
|
|
239
|
+
new_errors.each { |error| @record.errors.add batch_create_by_column, error }
|
|
208
240
|
end
|
|
209
241
|
|
|
210
242
|
def batch_create_by_column
|
|
@@ -215,12 +247,13 @@ module ActiveScaffold::Actions
|
|
|
215
247
|
values = {}
|
|
216
248
|
parent_record = active_scaffold_config.model.new
|
|
217
249
|
columns.each_column(for: active_scaffold_config.model, crud_type: :create, flatten: true) do |column|
|
|
218
|
-
next unless attributes.
|
|
250
|
+
next unless attributes.key?(column.name)
|
|
251
|
+
|
|
219
252
|
if column == batch_create_by_column.to_sym
|
|
220
253
|
@batch_create_by_records = batch_values_for_column(column, attributes[column.name])
|
|
221
254
|
else
|
|
222
255
|
value = column_value_from_param_value(parent_record, column, attributes[column.name])
|
|
223
|
-
values[column.name] = {:
|
|
256
|
+
values[column.name] = {column: column, value: value}
|
|
224
257
|
end
|
|
225
258
|
end
|
|
226
259
|
values
|
|
@@ -237,7 +270,7 @@ module ActiveScaffold::Actions
|
|
|
237
270
|
# The default security delegates to ActiveRecordPermissions.
|
|
238
271
|
# You may override the method to customize.
|
|
239
272
|
def batch_create_authorized?(record = nil)
|
|
240
|
-
authorized_for?(:
|
|
273
|
+
authorized_for?(crud_type: :create)
|
|
241
274
|
end
|
|
242
275
|
|
|
243
276
|
def batch_create_ignore?(record = nil)
|
|
@@ -257,8 +290,9 @@ module ActiveScaffold::Actions
|
|
|
257
290
|
|
|
258
291
|
def batch_create_authorized_filter
|
|
259
292
|
link = active_scaffold_config.batch_create.link || active_scaffold_config.batch_create.class.link
|
|
260
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
293
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.security_method)
|
|
261
294
|
end
|
|
295
|
+
|
|
262
296
|
def batch_new_formats
|
|
263
297
|
(default_formats + active_scaffold_config.formats).uniq
|
|
264
298
|
end
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module BatchDestroy
|
|
3
|
-
|
|
4
5
|
def self.included(base)
|
|
5
6
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
6
|
-
base.before_action :batch_destroy_authorized_filter, :
|
|
7
|
+
base.before_action :batch_destroy_authorized_filter, only: [:batch_destroy]
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def batch_destroy
|
|
10
11
|
batch_action
|
|
11
12
|
end
|
|
12
|
-
|
|
13
|
+
|
|
13
14
|
protected
|
|
14
15
|
|
|
15
|
-
def before_do_batch_destroy
|
|
16
|
-
end
|
|
16
|
+
def before_do_batch_destroy; end
|
|
17
17
|
|
|
18
18
|
def batch_destroy_listed
|
|
19
19
|
case active_scaffold_config.batch_destroy.process_mode
|
|
20
|
-
when :delete
|
|
20
|
+
when :delete
|
|
21
21
|
each_record_in_scope do |record|
|
|
22
22
|
destroy_record(record) if authorized_for_job?(record)
|
|
23
23
|
end
|
|
24
|
-
when :delete_all
|
|
24
|
+
when :delete_all
|
|
25
25
|
do_search if respond_to? :do_search, true
|
|
26
26
|
# dummy condition cause we have to call delete_all on relation not on association
|
|
27
27
|
filtered_query.where('1=1').delete_all(all_conditions)
|
|
28
28
|
else
|
|
29
|
-
Rails.logger.error
|
|
29
|
+
Rails.logger.error "Unknown process_mode: #{active_scaffold_config.batch_destroy.process_mode} " \
|
|
30
|
+
'for action batch_destroy'
|
|
30
31
|
end
|
|
31
|
-
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def batch_destroy_marked
|
|
35
35
|
case active_scaffold_config.batch_destroy.process_mode
|
|
36
|
-
when :delete
|
|
36
|
+
when :delete
|
|
37
37
|
each_marked_record do |record|
|
|
38
38
|
destroy_record(record) if authorized_for_job?(record)
|
|
39
39
|
end
|
|
40
|
-
when :delete_all
|
|
40
|
+
when :delete_all
|
|
41
41
|
active_scaffold_config.model.where(active_scaffold_config.model.primary_key => marked_records.to_a).delete_all
|
|
42
42
|
do_demark_all
|
|
43
43
|
else
|
|
44
|
-
Rails.logger.error
|
|
44
|
+
Rails.logger.error "Unknown process_mode: #{active_scaffold_config.batch_destroy.process_mode} " \
|
|
45
|
+
'for action batch_destroy'
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
|
|
@@ -60,18 +61,18 @@ module ActiveScaffold::Actions
|
|
|
60
61
|
# The default security delegates to ActiveRecordPermissions.
|
|
61
62
|
# You may override the method to customize.
|
|
62
63
|
def batch_destroy_authorized?(record = nil)
|
|
63
|
-
authorized_for?(:
|
|
64
|
+
authorized_for?(crud_type: :delete)
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def batch_destroy_marked_ignore?(record = nil)
|
|
67
|
-
|
|
68
|
+
active_scaffold_config.actions.exclude?(:mark)
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
private
|
|
71
72
|
|
|
72
73
|
def batch_destroy_authorized_filter
|
|
73
74
|
link = active_scaffold_config.batch_destroy.link || active_scaffold_config.batch_destroy.class.link
|
|
74
|
-
raise ActiveScaffold::ActionNotAllowed unless
|
|
75
|
+
raise ActiveScaffold::ActionNotAllowed unless send(link.first.security_method)
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
end
|