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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README +101 -5
  3. data/app/assets/javascripts/active_scaffold_batch.js +10 -10
  4. data/app/assets/stylesshets/active_scaffold_batch.scss +4 -13
  5. data/app/views/active_scaffold_overrides/_batch_create_form.html.erb +8 -8
  6. data/app/views/active_scaffold_overrides/_batch_create_form_attribute.html.erb +7 -19
  7. data/app/views/active_scaffold_overrides/_batch_create_form_body.html.erb +24 -23
  8. data/app/views/active_scaffold_overrides/_batch_create_form_footer.html.erb +11 -2
  9. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal.html.erb +24 -9
  10. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal_record.html.erb +11 -26
  11. data/app/views/active_scaffold_overrides/_batch_create_form_multiple.html.erb +1 -1
  12. data/app/views/active_scaffold_overrides/_batch_create_form_vertical.html.erb +12 -3
  13. data/app/views/active_scaffold_overrides/_batch_create_form_vertical_record.html.erb +5 -5
  14. data/app/views/active_scaffold_overrides/_batch_update_form.html.erb +6 -6
  15. data/app/views/active_scaffold_overrides/_batch_update_form_attribute.html.erb +1 -11
  16. data/app/views/active_scaffold_overrides/_batch_update_form_attribute_scope.html.erb +7 -12
  17. data/app/views/active_scaffold_overrides/_batch_update_form_body.html.erb +24 -23
  18. data/app/views/active_scaffold_overrides/_form_messages.html.erb +16 -4
  19. data/app/views/active_scaffold_overrides/batch_add.js.erb +16 -3
  20. data/app/views/active_scaffold_overrides/batch_create.html.erb +1 -1
  21. data/app/views/active_scaffold_overrides/batch_update.html.erb +1 -1
  22. data/app/views/active_scaffold_overrides/on_batch_base.js.erb +14 -4
  23. data/app/views/active_scaffold_overrides/on_batch_create.js.erb +10 -5
  24. data/app/views/active_scaffold_overrides/on_batch_update.js.erb +6 -4
  25. data/config/locales/de.yml +2 -1
  26. data/config/locales/en.yml +2 -1
  27. data/config/locales/es.yml +2 -1
  28. data/lib/active_scaffold/actions/batch_base.rb +23 -28
  29. data/lib/active_scaffold/actions/batch_create.rb +78 -44
  30. data/lib/active_scaffold/actions/batch_destroy.rb +16 -15
  31. data/lib/active_scaffold/actions/batch_update.rb +129 -104
  32. data/lib/active_scaffold/config/batch_create.rb +17 -19
  33. data/lib/active_scaffold/config/batch_destroy.rb +24 -14
  34. data/lib/active_scaffold/config/batch_update.rb +21 -20
  35. data/lib/active_scaffold/helpers/batch_create_column_helpers.rb +17 -18
  36. data/lib/active_scaffold/helpers/datepicker_update_column_helpers.rb +48 -17
  37. data/lib/active_scaffold/helpers/update_column_helpers.rb +91 -33
  38. data/lib/active_scaffold_batch/engine.rb +10 -12
  39. data/lib/active_scaffold_batch/extensions.rb +16 -0
  40. data/lib/active_scaffold_batch/version.rb +4 -2
  41. data/lib/active_scaffold_batch.rb +5 -15
  42. metadata +7 -5
@@ -1,27 +1,58 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffold
2
4
  module Helpers
3
5
  module DatepickerUpdateColumnHelpers
4
6
  def active_scaffold_update_date_picker(column, options)
5
- current_params = {:value => nil, :number => nil, :unit => nil, :operator => 'NO_UPDATE'}
6
- current_params.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values.dig(column.name, :value)
7
- operator_options = active_scaffold_update_generic_operators(column)
8
- operator_options.concat(ActiveScaffold::Actions::BatchUpdate::DateOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}) if active_scaffold_config.batch_update.process_mode == :update
9
- options = options.merge(:show => ['PLUS', 'MINUS'].exclude?(current_params[:operator]))
10
- tags = []
11
- tags << select_tag("#{options[:name]}[operator]",
12
- options_for_select(operator_options, current_params[:operator]),
13
- :id => "#{options[:id]}_operator",
14
- :class => "text-input as_update_date_operator")
15
- tags << active_scaffold_search_date_picker_field(column, options.merge(show: current_params[:operator] == 'REPLACE'), current_params[:value], 'value')
16
- tags << active_scaffold_update_date_bridge_trend_tag(column, current_params, options)
17
- tags.join("&nbsp;").html_safe
7
+ defaults = {value: nil, number: nil, unit: nil, operator: 'NO_UPDATE'}
8
+ current_params = active_scaffold_update_values(column, defaults)
9
+ operator_options = active_scaffold_update_date_operator_options(column)
10
+ options = options.merge(show: %w[PLUS MINUS].exclude?(current_params[:operator]))
11
+ operator_attributes = active_scaffold_update_operator_attributes(
12
+ column, options, 'text-input as_update_date_operator'
13
+ )
14
+ controls = [
15
+ select_tag(
16
+ "#{options[:name]}[operator]",
17
+ options_for_select(operator_options, current_params[:operator]),
18
+ operator_attributes
19
+ ),
20
+ active_scaffold_search_date_picker_field(
21
+ column, options.merge(show: current_params[:operator] == 'REPLACE'), current_params[:value], 'value'
22
+ ),
23
+ active_scaffold_update_date_bridge_trend_tag(column, current_params, options)
24
+ ]
25
+ safe_join(controls, ' ')
26
+ end
27
+
28
+ def active_scaffold_update_date_operator_options(column)
29
+ operators = active_scaffold_update_generic_operators(column)
30
+ return operators unless active_scaffold_config.batch_update.process_mode == :update
31
+
32
+ operators + active_scaffold_update_options_for(ActiveScaffold::Actions::BatchUpdate::DATE_OPERATORS)
18
33
  end
19
34
 
20
35
  def active_scaffold_update_date_bridge_trend_tag(column, current_params, options)
21
- active_scaffold_search_datetime_trend_tag(column, options,
22
- {'number' => current_params[:number],
23
- 'unit' => current_params[:unit],
24
- show: ['PLUS','MINUS'].include?(current_params[:operator])})
36
+ number_attributes = active_scaffold_batch_control_attributes(
37
+ column, :text, :batch_update_date_amount,
38
+ class: 'text-input', size: 10, autocomplete: 'off'
39
+ )
40
+ unit_attributes = active_scaffold_batch_control_attributes(
41
+ column, :select, :batch_update_date_unit,
42
+ class: 'text-input'
43
+ )
44
+ unit_options = options_for_select(active_scaffold_search_datetime_trend_units(column), current_params[:unit])
45
+ controls = [
46
+ text_field_tag("#{options[:name]}[number]", current_params[:number], number_attributes),
47
+ select_tag("#{options[:name]}[unit]", unit_options, unit_attributes)
48
+ ]
49
+ content_tag(
50
+ :span,
51
+ safe_join(controls, ' '),
52
+ id: "#{options[:id]}_trend",
53
+ class: 'search-date-trend',
54
+ style: ('display: none' unless %w[PLUS MINUS].include?(current_params[:operator]))
55
+ )
25
56
  end
26
57
  end
27
58
  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
@@ -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,44 +39,95 @@ 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)
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'
45
+ )
37
46
  select_tag("record[#{column.name}][operator]",
38
- options_for_select(active_scaffold_update_generic_operators(column), current[:operator]),
39
- :id => "#{options[:id]}_operator",
40
- :class => "as_batch_update_operator text_input")
47
+ options_for_select(active_scaffold_update_generic_operators(column), current[:operator]),
48
+ attributes)
41
49
  end
42
50
 
43
51
  def active_scaffold_update_numeric(column, options)
44
- current = {:value => nil, :opt => 'ABSOLUTE', :operator => 'NO_UPDATE'}
45
- current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values[column.name] && batch_update_values[column.name][:value]
46
- operator_options = active_scaffold_update_generic_operators(column) + ActiveScaffold::Actions::BatchUpdate::NumericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
47
- select_options = ActiveScaffold::Actions::BatchUpdate::NumericOptions.collect {|comp| [as_(comp.downcase.to_sym), comp]}
48
- html = select_tag("record[#{column.name}][operator]",
49
- options_for_select(operator_options, current[:operator]),
50
- :id => "#{options[:id]}_operator",
51
- :class => "as_update_numeric_option")
52
- html << ' ' << text_field_tag("record[#{column.name}][value]", current[:value], active_scaffold_input_text_options)
53
- html << ' ' << select_tag("record[#{column.name}][opt]",
54
- options_for_select(select_options, current[:opt]),
55
- :id => "#{options[:id]}_opt",
56
- :class => "as_update_numeric_option")
57
- html
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)
56
+ style = current[:operator] == 'NO_UPDATE' ? 'display: none;' : nil
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(
74
+ column, column.form_ui || column.column&.type, :batch_update_value,
75
+ id: "#{options[:id]}_value",
76
+ style: style
77
+ )
78
+ numeric_option = active_scaffold_batch_control_attributes(
79
+ column, :select, :batch_update_numeric_option,
80
+ id: "#{options[:id]}_opt",
81
+ class: 'as_update_numeric_option',
82
+ style: style
83
+ )
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] }
58
94
  end
59
- alias_method :active_scaffold_update_integer, :active_scaffold_update_numeric
60
- alias_method :active_scaffold_update_decimal, :active_scaffold_update_numeric
61
- alias_method :active_scaffold_update_float, :active_scaffold_update_numeric
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
+ )
102
+ end
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
62
107
 
63
108
  def active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options)
64
- if select_options.length > 1
65
- select_tag("batch_scope",
66
- options_for_select(select_options, batch_scope || select_options.last[1]),
67
- :class => "text_input")
109
+ if active_scaffold_update_scope_select_hidden?(select_options)
110
+ hidden_field_tag('batch_scope', select_options.first[1]) unless select_options.empty?
68
111
  else
69
- hidden_field_tag("batch_scope", select_options.first[1]) unless select_options.empty?
112
+ attributes = active_scaffold_batch_control_attributes(nil, :select, :batch_scope, class: 'text-input')
113
+ select_tag('batch_scope',
114
+ options_for_select(select_options, batch_scope || select_options.last[1]),
115
+ attributes)
70
116
  end
71
117
  end
72
118
 
119
+ def active_scaffold_batch_control_attributes(column, form_ui, batch_role, **attributes)
120
+ as_element_attributes(
121
+ :form_control,
122
+ proc_options: {column: column, form_ui: form_ui, batch_role: batch_role},
123
+ **attributes
124
+ )
125
+ end
126
+
127
+ def active_scaffold_update_scope_select_hidden?(select_options = active_scaffold_update_scope_select_options)
128
+ select_options.length < 2
129
+ end
130
+
73
131
  def active_scaffold_update_scope_select_options
74
132
  select_options = []
75
133
  select_options << [as_(:listed), 'LISTED'] if active_scaffold_config.batch_update.list_mode_enabled
@@ -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,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveScaffoldBatch
2
4
  module Version
3
5
  MAJOR = 3
4
- MINOR = 7
5
- PATCH = 3
6
+ MINOR = 9
7
+ PATCH = 0
6
8
 
7
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
10
  end
@@ -1,25 +1,15 @@
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
 
24
13
  ActiveScaffold.stylesheets << 'active_scaffold_batch'
25
14
  ActiveScaffold.javascripts << 'active_scaffold_batch'
15
+ ActiveScaffold.set_element :batch_create_add_rows, attributes: {}
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.7.3
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.1.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.1.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
  - - ">="