active_scaffold_batch 3.8.0 → 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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/active_scaffold_overrides/_batch_create_form.html.erb +5 -5
  3. data/app/views/active_scaffold_overrides/_batch_create_form_body.html.erb +1 -1
  4. data/app/views/active_scaffold_overrides/_batch_create_form_footer.html.erb +6 -1
  5. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal.html.erb +21 -2
  6. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal_record.html.erb +12 -1
  7. data/app/views/active_scaffold_overrides/_batch_create_form_vertical.html.erb +11 -2
  8. data/app/views/active_scaffold_overrides/_batch_update_form.html.erb +5 -5
  9. data/app/views/active_scaffold_overrides/_form_messages.html.erb +15 -3
  10. data/app/views/active_scaffold_overrides/batch_add.js.erb +16 -3
  11. data/app/views/active_scaffold_overrides/on_batch_base.js.erb +13 -3
  12. data/app/views/active_scaffold_overrides/on_batch_create.js.erb +8 -3
  13. data/app/views/active_scaffold_overrides/on_batch_update.js.erb +4 -2
  14. data/config/locales/de.yml +2 -1
  15. data/config/locales/en.yml +2 -1
  16. data/config/locales/es.yml +2 -1
  17. data/lib/active_scaffold/actions/batch_base.rb +19 -16
  18. data/lib/active_scaffold/actions/batch_create.rb +70 -36
  19. data/lib/active_scaffold/actions/batch_destroy.rb +14 -13
  20. data/lib/active_scaffold/actions/batch_update.rb +120 -95
  21. data/lib/active_scaffold/config/batch_create.rb +15 -17
  22. data/lib/active_scaffold/config/batch_destroy.rb +24 -14
  23. data/lib/active_scaffold/config/batch_update.rb +19 -18
  24. data/lib/active_scaffold/helpers/batch_create_column_helpers.rb +14 -5
  25. data/lib/active_scaffold/helpers/datepicker_update_column_helpers.rb +30 -22
  26. data/lib/active_scaffold/helpers/update_column_helpers.rb +62 -38
  27. data/lib/active_scaffold_batch/engine.rb +10 -12
  28. data/lib/active_scaffold_batch/extensions.rb +16 -0
  29. data/lib/active_scaffold_batch/version.rb +3 -1
  30. data/lib/active_scaffold_batch.rb +4 -15
  31. metadata +7 -5
@@ -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
@@ -12,19 +14,24 @@ module ActiveScaffold
12
14
  if (method = override_update_field(column))
13
15
  send(method, options[:object], options)
14
16
  # second, check if the dev has specified a valid form_ui for this column, using specific ui for searches
15
- elsif column.form_ui and (method = override_update(column.form_ui))
16
- send(method, column, options)
17
- elsif column.column and column.form_ui.nil? and (method = override_update(column.column.type))
17
+ elsif (update_ui = column.form_ui || column.column&.type) && (method = override_update(update_ui))
18
18
  send(method, column, options)
19
19
  else
20
20
  show_field = batch_update_values.dig(column.name, :value, :operator) == 'REPLACE'
21
- active_scaffold_update_generic_operators_select(column, options) << ' ' <<
22
- active_scaffold_render_input(column, options.merge(name: "record[#{column.name}][value]", style: ('display: none;' unless show_field)))
21
+ input_options = options.merge(
22
+ name: "record[#{column.name}][value]",
23
+ style: ('display: none;' unless show_field)
24
+ )
25
+ html = [
26
+ active_scaffold_update_generic_operators_select(column, options),
27
+ active_scaffold_render_input(column, input_options)
28
+ ]
29
+ safe_join html, ' '
23
30
  end
24
31
  end
25
32
 
26
33
  def active_scaffold_update_generic_operators(column)
27
- operators = ActiveScaffold::Actions::BatchUpdate::GenericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
34
+ operators = active_scaffold_update_options_for(ActiveScaffold::Actions::BatchUpdate::GENERIC_OPERATORS)
28
35
  if column.column.nil? || column.column.null
29
36
  operators << [as_(:null), 'NULL']
30
37
  end
@@ -32,12 +39,9 @@ module ActiveScaffold
32
39
  end
33
40
 
34
41
  def active_scaffold_update_generic_operators_select(column, options)
35
- current = {operator: 'NO_UPDATE'}
36
- current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values.dig(column.name, :value)
37
- attributes = active_scaffold_batch_control_attributes(
38
- column, :select, :batch_update_operator,
39
- id: "#{options[:id]}_operator",
40
- class: 'as_batch_update_operator text-input'
42
+ current = active_scaffold_update_values(column, operator: 'NO_UPDATE')
43
+ attributes = active_scaffold_update_operator_attributes(
44
+ column, options, 'as_batch_update_operator text-input'
41
45
  )
42
46
  select_tag("record[#{column.name}][operator]",
43
47
  options_for_select(active_scaffold_update_generic_operators(column), current[:operator]),
@@ -45,48 +49,68 @@ module ActiveScaffold
45
49
  end
46
50
 
47
51
  def active_scaffold_update_numeric(column, options)
48
- current = {value: nil, opt: 'ABSOLUTE', operator: 'NO_UPDATE'}
49
- current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values[column.name] && batch_update_values[column.name][:value]
50
- operator_options = active_scaffold_update_generic_operators(column) + ActiveScaffold::Actions::BatchUpdate::NumericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
51
- select_options = ActiveScaffold::Actions::BatchUpdate::NumericOptions.collect {|comp| [as_(comp.downcase.to_sym), comp]}
52
+ current = active_scaffold_update_values(column, value: nil, opt: 'ABSOLUTE', operator: 'NO_UPDATE')
53
+ operator_options = active_scaffold_update_generic_operators(column) +
54
+ active_scaffold_update_options_for(ActiveScaffold::Actions::BatchUpdate::NUMERIC_OPERATORS)
55
+ numeric_options = active_scaffold_update_options_for(ActiveScaffold::Actions::BatchUpdate::NUMERIC_OPTIONS)
52
56
  style = current[:operator] == 'NO_UPDATE' ? 'display: none;' : nil
53
- operator_attributes = active_scaffold_batch_control_attributes(
54
- column, :select, :batch_update_operator,
55
- id: "#{options[:id]}_operator",
56
- class: 'as_update_numeric_option'
57
- )
58
- value_attributes = active_scaffold_batch_control_attributes(
57
+ operator_attributes, value_attributes, option_attributes =
58
+ active_scaffold_update_numeric_attributes(column, options, style)
59
+
60
+ name = "record[#{column.name}]"
61
+ controls = [
62
+ select_tag(
63
+ "#{name}[operator]", options_for_select(operator_options, current[:operator]), operator_attributes
64
+ ),
65
+ text_field_tag("#{name}[value]", current[:value], value_attributes),
66
+ select_tag("#{name}[opt]", options_for_select(numeric_options, current[:opt]), option_attributes)
67
+ ]
68
+ safe_join(controls, ' ')
69
+ end
70
+
71
+ def active_scaffold_update_numeric_attributes(column, options, style)
72
+ operator = active_scaffold_update_operator_attributes(column, options, 'as_update_numeric_option')
73
+ value = active_scaffold_batch_control_attributes(
59
74
  column, column.form_ui || column.column&.type, :batch_update_value,
60
75
  id: "#{options[:id]}_value",
61
76
  style: style
62
77
  )
63
- value_attributes = active_scaffold_input_text_options(value_attributes)
64
- option_attributes = active_scaffold_batch_control_attributes(
78
+ numeric_option = active_scaffold_batch_control_attributes(
65
79
  column, :select, :batch_update_numeric_option,
66
80
  id: "#{options[:id]}_opt",
67
81
  class: 'as_update_numeric_option',
68
82
  style: style
69
83
  )
70
- html = select_tag("record[#{column.name}][operator]",
71
- options_for_select(operator_options, current[:operator]),
72
- operator_attributes)
73
- html << ' ' << text_field_tag("record[#{column.name}][value]", current[:value], value_attributes)
74
- html << ' ' << select_tag("record[#{column.name}][opt]",
75
- options_for_select(select_options, current[:opt]),
76
- option_attributes)
77
- html
84
+ [operator, active_scaffold_input_text_options(value), numeric_option]
85
+ end
86
+
87
+ def active_scaffold_update_values(column, defaults)
88
+ values = batch_update_values.dig(column.name, :value)
89
+ values ? defaults.merge(values.symbolize_keys) : defaults
90
+ end
91
+
92
+ def active_scaffold_update_options_for(values)
93
+ values.map { |value| [as_(value.downcase.to_sym), value] }
94
+ end
95
+
96
+ def active_scaffold_update_operator_attributes(column, options, css_class)
97
+ active_scaffold_batch_control_attributes(
98
+ column, :select, :batch_update_operator,
99
+ id: "#{options[:id]}_operator",
100
+ class: css_class
101
+ )
78
102
  end
79
- alias_method :active_scaffold_update_integer, :active_scaffold_update_numeric
80
- alias_method :active_scaffold_update_decimal, :active_scaffold_update_numeric
81
- alias_method :active_scaffold_update_float, :active_scaffold_update_numeric
82
- alias_method :active_scaffold_update_number, :active_scaffold_update_numeric
103
+ alias active_scaffold_update_integer active_scaffold_update_numeric
104
+ alias active_scaffold_update_decimal active_scaffold_update_numeric
105
+ alias active_scaffold_update_float active_scaffold_update_numeric
106
+ alias active_scaffold_update_number active_scaffold_update_numeric
83
107
 
84
108
  def active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options)
85
109
  if active_scaffold_update_scope_select_hidden?(select_options)
86
- hidden_field_tag("batch_scope", select_options.first[1]) unless select_options.empty?
110
+ hidden_field_tag('batch_scope', select_options.first[1]) unless select_options.empty?
87
111
  else
88
112
  attributes = active_scaffold_batch_control_attributes(nil, :select, :batch_scope, class: 'text-input')
89
- select_tag("batch_scope",
113
+ select_tag('batch_scope',
90
114
  options_for_select(select_options, batch_scope || select_options.last[1]),
91
115
  attributes)
92
116
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffoldBatch
2
4
  class Engine < ::Rails::Engine
3
5
  initializer 'active_scaffold_batch.routes' do
@@ -7,23 +9,19 @@ module ActiveScaffoldBatch
7
9
  self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_new] = :get
8
10
  self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_create] = :post
9
11
  self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_add] = :get
10
- #not working because routing picks show route instead
11
- #self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_destroy] = :get
12
- #you may define a route for your controller before resource routes
13
- #match 'players/batch_destroy' => 'players#batch_destroy', via: [:get]
12
+ # not working because routing picks show route instead
13
+ # self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_destroy] = :get
14
+ # you may define a route for your controller before resource routes
15
+ # match 'players/batch_destroy' => 'players#batch_destroy', via: [:get]
14
16
  self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_destroy] = :delete
15
17
  end
16
18
  end
17
19
 
18
- initializer("active_scaffold_batch.view") do
20
+ initializer 'active_scaffold_batch.view' do
19
21
  ActiveSupport.on_load(:action_view) do
20
- begin
21
- include ActiveScaffold::Helpers::UpdateColumnHelpers
22
- include ActiveScaffold::Helpers::DatepickerUpdateColumnHelpers
23
- include ActiveScaffold::Helpers::BatchCreateColumnHelpers
24
- rescue
25
- raise $! unless Rails.env == 'production'
26
- end
22
+ include ActiveScaffold::Helpers::UpdateColumnHelpers
23
+ include ActiveScaffold::Helpers::DatepickerUpdateColumnHelpers
24
+ include ActiveScaffold::Helpers::BatchCreateColumnHelpers
27
25
  end
28
26
  end
29
27
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ActiveScaffold extension namespaces provided by the batch plugin.
4
+ module ActiveScaffold
5
+ module Actions
6
+ ActiveScaffold.autoload_subdir('actions', self, File.expand_path('..', __dir__))
7
+ end
8
+
9
+ module Config
10
+ ActiveScaffold.autoload_subdir('config', self, File.expand_path('..', __dir__))
11
+ end
12
+
13
+ module Helpers
14
+ ActiveScaffold.autoload_subdir('helpers', self, File.expand_path('..', __dir__))
15
+ end
16
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffoldBatch
2
4
  module Version
3
5
  MAJOR = 3
4
- MINOR = 8
6
+ MINOR = 9
5
7
  PATCH = 0
6
8
 
7
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -1,23 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_scaffold_batch/engine'
4
+ require 'active_scaffold_batch/extensions'
2
5
  require 'active_scaffold_batch/version'
3
6
 
4
7
  module ActiveScaffoldBatch
5
8
  def self.root
6
- File.dirname(__FILE__) + "/.."
7
- end
8
- end
9
-
10
- module ActiveScaffold
11
- module Actions
12
- ActiveScaffold.autoload_subdir('actions', self, File.dirname(__FILE__))
13
- end
14
-
15
- module Config
16
- ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
17
- end
18
-
19
- module Helpers
20
- ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
9
+ "#{File.dirname(__FILE__)}/.."
21
10
  end
22
11
  end
23
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.4.0
19
+ version: 4.4.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.4.0
26
+ version: 4.4.6
27
27
  description: You want to destroy/update many records at once with activescaffold?
28
28
  email: activescaffold@googlegroups.com
29
29
  executables: []
@@ -71,11 +71,13 @@ files:
71
71
  - lib/active_scaffold/helpers/update_column_helpers.rb
72
72
  - lib/active_scaffold_batch.rb
73
73
  - lib/active_scaffold_batch/engine.rb
74
+ - lib/active_scaffold_batch/extensions.rb
74
75
  - lib/active_scaffold_batch/version.rb
75
76
  homepage: http://github.com/scambra/active_scaffold_batch
76
77
  licenses:
77
78
  - MIT
78
- metadata: {}
79
+ metadata:
80
+ rubygems_mfa_required: 'true'
79
81
  rdoc_options: []
80
82
  require_paths:
81
83
  - lib
@@ -83,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
85
  requirements:
84
86
  - - ">="
85
87
  - !ruby/object:Gem::Version
86
- version: '0'
88
+ version: '3.2'
87
89
  required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  requirements:
89
91
  - - ">="