cm-admin 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01cfdef16d888507aaaa1969921502f28a3f5f7af5c80f29ef4cde88975805f9
4
- data.tar.gz: 6d257af43f68b2d5ab7b57162724a91b1494946d02e2fe1536531d5d0363bb6b
3
+ metadata.gz: 5aba23127b4e8223782b919d0c5c767b156262e55198835fb738c72fd9c5fa68
4
+ data.tar.gz: 89a3df2239cc6a56eb3360afe1502654c2ad83b1921c5f8f7dedcc1d8eaf3407
5
5
  SHA512:
6
- metadata.gz: 3cb0fb31de297ecf1bb914e891188a72f6c2fd95d4b0ef05adaa99c36a9c15d3b8f2ad167e35c6ba65e5bd515951ee0474f2027df64aa95a31a4d7dd03fd29d9
7
- data.tar.gz: 97119da3716c2be594af5cf3207eb830e13b32d79c15e3286a3abda3616c863a1a5439b94553ac9bfe1c56452d76cd9c9993893d6d1359541c9f366cf02ca8b2
6
+ metadata.gz: 66c416a85d9e84c5d9122adc0a14d8728ce51934711839db9a261ddba9aeae8d13d3033f3e06f3c359b5a3c7a62ed74c2d253aa1c038865ba77486f7ddc6fbf7
7
+ data.tar.gz: 5d91df86bb2cb64be4158688473c316c8e3c16b77bb11ed7a0a1e683f7e2af67e84b7240a45262ab79384cf1fdc238880f2da02525686ba73d43f9c5c98253c2
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ DisabledByDefault: false
3
+
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Layout/IndentationStyle:
11
+ Enabled: false
12
+
13
+ Layout/LineLength:
14
+ Enabled: false
15
+
16
+ Metrics/MethodLength:
17
+ Enabled: false
18
+
19
+ Metrics/AbcSize:
20
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.1.6)
4
+ cm-admin (1.1.7)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -16,67 +16,67 @@ PATH
16
16
  GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
- actioncable (7.0.3.1)
20
- actionpack (= 7.0.3.1)
21
- activesupport (= 7.0.3.1)
19
+ actioncable (7.0.5.1)
20
+ actionpack (= 7.0.5.1)
21
+ activesupport (= 7.0.5.1)
22
22
  nio4r (~> 2.0)
23
23
  websocket-driver (>= 0.6.1)
24
- actionmailbox (7.0.3.1)
25
- actionpack (= 7.0.3.1)
26
- activejob (= 7.0.3.1)
27
- activerecord (= 7.0.3.1)
28
- activestorage (= 7.0.3.1)
29
- activesupport (= 7.0.3.1)
24
+ actionmailbox (7.0.5.1)
25
+ actionpack (= 7.0.5.1)
26
+ activejob (= 7.0.5.1)
27
+ activerecord (= 7.0.5.1)
28
+ activestorage (= 7.0.5.1)
29
+ activesupport (= 7.0.5.1)
30
30
  mail (>= 2.7.1)
31
31
  net-imap
32
32
  net-pop
33
33
  net-smtp
34
- actionmailer (7.0.3.1)
35
- actionpack (= 7.0.3.1)
36
- actionview (= 7.0.3.1)
37
- activejob (= 7.0.3.1)
38
- activesupport (= 7.0.3.1)
34
+ actionmailer (7.0.5.1)
35
+ actionpack (= 7.0.5.1)
36
+ actionview (= 7.0.5.1)
37
+ activejob (= 7.0.5.1)
38
+ activesupport (= 7.0.5.1)
39
39
  mail (~> 2.5, >= 2.5.4)
40
40
  net-imap
41
41
  net-pop
42
42
  net-smtp
43
43
  rails-dom-testing (~> 2.0)
44
- actionpack (7.0.3.1)
45
- actionview (= 7.0.3.1)
46
- activesupport (= 7.0.3.1)
47
- rack (~> 2.0, >= 2.2.0)
44
+ actionpack (7.0.5.1)
45
+ actionview (= 7.0.5.1)
46
+ activesupport (= 7.0.5.1)
47
+ rack (~> 2.0, >= 2.2.4)
48
48
  rack-test (>= 0.6.3)
49
49
  rails-dom-testing (~> 2.0)
50
50
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
51
- actiontext (7.0.3.1)
52
- actionpack (= 7.0.3.1)
53
- activerecord (= 7.0.3.1)
54
- activestorage (= 7.0.3.1)
55
- activesupport (= 7.0.3.1)
51
+ actiontext (7.0.5.1)
52
+ actionpack (= 7.0.5.1)
53
+ activerecord (= 7.0.5.1)
54
+ activestorage (= 7.0.5.1)
55
+ activesupport (= 7.0.5.1)
56
56
  globalid (>= 0.6.0)
57
57
  nokogiri (>= 1.8.5)
58
- actionview (7.0.3.1)
59
- activesupport (= 7.0.3.1)
58
+ actionview (7.0.5.1)
59
+ activesupport (= 7.0.5.1)
60
60
  builder (~> 3.1)
61
61
  erubi (~> 1.4)
62
62
  rails-dom-testing (~> 2.0)
63
63
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
64
- activejob (7.0.3.1)
65
- activesupport (= 7.0.3.1)
64
+ activejob (7.0.5.1)
65
+ activesupport (= 7.0.5.1)
66
66
  globalid (>= 0.3.6)
67
- activemodel (7.0.3.1)
68
- activesupport (= 7.0.3.1)
69
- activerecord (7.0.3.1)
70
- activemodel (= 7.0.3.1)
71
- activesupport (= 7.0.3.1)
72
- activestorage (7.0.3.1)
73
- actionpack (= 7.0.3.1)
74
- activejob (= 7.0.3.1)
75
- activerecord (= 7.0.3.1)
76
- activesupport (= 7.0.3.1)
67
+ activemodel (7.0.5.1)
68
+ activesupport (= 7.0.5.1)
69
+ activerecord (7.0.5.1)
70
+ activemodel (= 7.0.5.1)
71
+ activesupport (= 7.0.5.1)
72
+ activestorage (7.0.5.1)
73
+ actionpack (= 7.0.5.1)
74
+ activejob (= 7.0.5.1)
75
+ activerecord (= 7.0.5.1)
76
+ activesupport (= 7.0.5.1)
77
77
  marcel (~> 1.0)
78
78
  mini_mime (>= 1.1.0)
79
- activesupport (7.0.3.1)
79
+ activesupport (7.0.5.1)
80
80
  concurrent-ruby (~> 1.0, >= 1.0.2)
81
81
  i18n (>= 1.6, < 2)
82
82
  minitest (>= 5.1)
@@ -98,7 +98,7 @@ GEM
98
98
  cocoon (1.2.15)
99
99
  coercible (1.0.0)
100
100
  descendants_tracker (~> 0.0.1)
101
- concurrent-ruby (1.1.10)
101
+ concurrent-ruby (1.2.2)
102
102
  crass (1.0.6)
103
103
  csv-importer (0.8.2)
104
104
  virtus
@@ -110,7 +110,7 @@ GEM
110
110
  globalid (1.1.0)
111
111
  activesupport (>= 5.0)
112
112
  htmlentities (4.3.4)
113
- i18n (1.11.0)
113
+ i18n (1.14.1)
114
114
  concurrent-ruby (~> 1.0)
115
115
  ice_nine (0.11.2)
116
116
  importmap-rails (1.2.1)
@@ -129,7 +129,7 @@ GEM
129
129
  marcel (1.0.2)
130
130
  method_source (1.0.0)
131
131
  mini_mime (1.1.2)
132
- minitest (5.16.2)
132
+ minitest (5.18.1)
133
133
  net-imap (0.3.6)
134
134
  date
135
135
  net-protocol
@@ -149,25 +149,25 @@ GEM
149
149
  pundit (2.2.0)
150
150
  activesupport (>= 3.0.0)
151
151
  racc (1.7.1)
152
- rack (2.2.6.4)
152
+ rack (2.2.7)
153
153
  rack-proxy (0.7.6)
154
154
  rack
155
155
  rack-test (2.1.0)
156
156
  rack (>= 1.3)
157
- rails (7.0.3.1)
158
- actioncable (= 7.0.3.1)
159
- actionmailbox (= 7.0.3.1)
160
- actionmailer (= 7.0.3.1)
161
- actionpack (= 7.0.3.1)
162
- actiontext (= 7.0.3.1)
163
- actionview (= 7.0.3.1)
164
- activejob (= 7.0.3.1)
165
- activemodel (= 7.0.3.1)
166
- activerecord (= 7.0.3.1)
167
- activestorage (= 7.0.3.1)
168
- activesupport (= 7.0.3.1)
157
+ rails (7.0.5.1)
158
+ actioncable (= 7.0.5.1)
159
+ actionmailbox (= 7.0.5.1)
160
+ actionmailer (= 7.0.5.1)
161
+ actionpack (= 7.0.5.1)
162
+ actiontext (= 7.0.5.1)
163
+ actionview (= 7.0.5.1)
164
+ activejob (= 7.0.5.1)
165
+ activemodel (= 7.0.5.1)
166
+ activerecord (= 7.0.5.1)
167
+ activestorage (= 7.0.5.1)
168
+ activesupport (= 7.0.5.1)
169
169
  bundler (>= 1.15.0)
170
- railties (= 7.0.3.1)
170
+ railties (= 7.0.5.1)
171
171
  rails-dom-testing (2.1.1)
172
172
  activesupport (>= 5.0.0)
173
173
  minitest
@@ -175,9 +175,9 @@ GEM
175
175
  rails-html-sanitizer (1.6.0)
176
176
  loofah (~> 2.21)
177
177
  nokogiri (~> 1.14)
178
- railties (7.0.3.1)
179
- actionpack (= 7.0.3.1)
180
- activesupport (= 7.0.3.1)
178
+ railties (7.0.5.1)
179
+ actionpack (= 7.0.5.1)
180
+ activesupport (= 7.0.5.1)
181
181
  method_source
182
182
  rake (>= 12.2)
183
183
  thor (~> 1.0)
@@ -229,7 +229,7 @@ GEM
229
229
  thread_safe (0.3.6)
230
230
  tilt (2.0.10)
231
231
  timeout (0.4.0)
232
- tzinfo (2.0.4)
232
+ tzinfo (2.0.6)
233
233
  concurrent-ruby (~> 1.0)
234
234
  unicode-display_width (2.3.0)
235
235
  virtus (2.0.0)
@@ -1,7 +1,12 @@
1
1
  import './scaffolds.js';
2
- import './cocoon.js'
3
2
  import './shared_scaffolds.js';
3
+
4
+ import './bulk_actions.js'
5
+ import './cocoon.js'
6
+ import './exports.js'
7
+ import './filters.js'
4
8
  import './form_validation.js'
5
9
  import './quick_search.js'
6
- import './filters.js'
7
- import './exports.js'
10
+ import './custom.js'
11
+
12
+
@@ -0,0 +1,36 @@
1
+ $(document).on('click', '[data-behaviour="bulk-action-checkbox"]', function(e) {
2
+ if ($('[data-behaviour="bulk-action-checkbox"]').is(':checked')) {
3
+ $('[data-section="bulk-action"]').removeClass('hidden')
4
+ setBulkActionParams()
5
+ } else {
6
+ $('[data-section="bulk-action"]').addClass('hidden')
7
+ }
8
+ });
9
+
10
+ $(document).on('click', '[data-behaviour="bulk-action-select-all"]', function(e) {
11
+ if ($(this).is(':checked')) {
12
+ $('[data-behaviour="bulk-action-checkbox"]').prop('checked', true)
13
+ $('[data-section="bulk-action"]').removeClass('hidden')
14
+ setBulkActionParams()
15
+ } else {
16
+ $('[data-behaviour="bulk-action-checkbox"]').prop('checked', false)
17
+ $('[data-section="bulk-action"]').addClass('hidden')
18
+ }
19
+ });
20
+
21
+ function setBulkActionParams() {
22
+ var selected_ids = []
23
+ $('[data-behaviour="bulk-action-checkbox"]:checked').each(function(){ selected_ids.push($(this).data('ar-object-id')) })
24
+ var bulk_action_form = '[data-section="bulk-action"] form'
25
+ if ($(bulk_action_form)) {
26
+ if ($(bulk_action_form + ' [name="selected_ids"]').length == 0) {
27
+ $('<input>').attr({
28
+ type: 'hidden',
29
+ name: 'selected_ids'
30
+ }).appendTo(bulk_action_form);
31
+ }
32
+ }
33
+ $('[data-section="bulk-action"] [name="selected_ids"]').each(function( i ) {
34
+ $(this).val(selected_ids)
35
+ })
36
+ }
File without changes
@@ -93,7 +93,22 @@ module CmAdmin
93
93
  end
94
94
  end
95
95
 
96
- def cm_history(params)
96
+ def cm_bulk_action(params)
97
+ @model = Model.find_by({ name: controller_name.classify })
98
+ @bulk_action_processor = CmAdmin::BulkActionProcessor.new(@action, @model, params).perform_bulk_action
99
+ respond_to do |format|
100
+ if @bulk_action_processor.invalid_records.empty?
101
+ format.html { redirect_to request.referrer, notice: "#{@action.name.humanize} is successful" }
102
+ else
103
+ error_messages = @bulk_action_processor.invalid_records.map { |invalid_record|
104
+ "<li>#{invalid_record.error_message}</li>"
105
+ }.join
106
+ format.html { redirect_to request.referrer, alert: "<b>#{@action.name.humanize} is unsuccessful</b><br /><ul>#{error_messages}</ul>" }
107
+ end
108
+ end
109
+ end
110
+
111
+ def cm_history(_params)
97
112
  @current_action = CmAdmin::Models::Action.find_by(@model, name: 'history')
98
113
  resource_identifier
99
114
  respond_to do |format|
@@ -68,5 +68,9 @@ module CmAdmin
68
68
  model.available_actions.map(&:name).include?('show') &&
69
69
  has_valid_policy(model.name, 'show')
70
70
  end
71
+
72
+ def actions_filter(model, action_type)
73
+ model.available_actions.select { |action| action.action_type == action_type && has_valid_policy(model.name, action.name) }
74
+ end
71
75
  end
72
76
  end
@@ -14,6 +14,7 @@ require('/app/assets/javascripts/cm_admin/form_validation.js')
14
14
  require('/app/assets/javascripts/cm_admin/quick_search.js')
15
15
  require('/app/assets/javascripts/cm_admin/filters.js')
16
16
  require('/app/assets/javascripts/cm_admin/exports.js')
17
+ require('/app/assets/javascripts/cm_admin/bulk_actions.js')
17
18
 
18
19
  import jQuery from 'jquery'
19
20
  import LocalTime from "local-time"
@@ -0,0 +1,29 @@
1
+ class CmAdmin::BulkActionProcessor
2
+ extend ActiveSupport::Concern
3
+ attr_accessor :invalid_records
4
+
5
+ def initialize(current_action, model, params)
6
+ @invalid_records = []
7
+ @current_action = current_action
8
+ @model = model
9
+ @params = params
10
+ end
11
+
12
+ def perform_bulk_action
13
+ @params[:selected_ids].split(',').each do |id|
14
+ ar_object = @model.ar_model.find(id)
15
+ column_name = @model.available_fields[:index].first.field_name
16
+ begin
17
+ @current_action.code_block.call(id)
18
+ rescue NoMethodError, NameError => e
19
+ @error_message = "#{e.message.slice(0..(e.message.index(' for')))} at #{ar_object.send(column_name)}"
20
+ rescue ActiveRecord::RecordInvalid => e
21
+ @error_message = "#{e.message} at #{ar_object.send(column_name)}"
22
+ rescue StandardError => e
23
+ @error_message = e.message
24
+ end
25
+ @invalid_records << OpenStruct.new({ row_identifier: ar_object.send(column_name), error_message: @error_message }) if @error_message
26
+ end
27
+ self
28
+ end
29
+ end
@@ -14,25 +14,35 @@
14
14
  / i.fa.fa-columns.bolder
15
15
  / span
16
16
  / i.fa.fa-angle-down
17
-
17
+ - if flash[:alert].present?
18
+ .alert.alert-danger role="alert"
19
+ = flash[:alert].html_safe
20
+ - elsif flash[:notice].present?
21
+ .alert.alert-success
22
+ = flash[:notice].html_safe
23
+ - bulk_actions = actions_filter(@associated_model, :bulk_action)
24
+ - if bulk_actions.present?
25
+ .table-top.hidden data-section="bulk-action"
26
+ - bulk_actions.each do |action|
27
+ = custom_action_items(action, 'index')
18
28
  .new-admin-table.scrollable
19
29
  table.cm-table
20
30
  thead.cm-table__header
21
31
  tr.header-row
22
- // To be added once bulk-select is finalized
23
- / th.check-box-space
24
- / span
25
- / input.cm-checkbox type="checkbox"
32
+ - if bulk_actions.present?
33
+ th.check-box-space
34
+ span
35
+ input.cm-checkbox type="checkbox" data-behaviour="bulk-action-select-all"
26
36
  - @model.available_fields[@action.name.to_sym].each do |column|
27
37
  - if column.display_if.call(Current.user) && column.viewable
28
38
  th = column.header
29
39
  tbody.cm-table__body
30
40
  - @associated_ar_object.data.each do |ar_object|
31
41
  tr.body-row
32
- // To be added once bulk-select is finalized
33
- / td.check-box-space
34
- / span
35
- / input.cm-checkbox type="checkbox"
42
+ - if bulk_actions.present?
43
+ td.check-box-space
44
+ span
45
+ input.cm-checkbox type="checkbox" data-behaviour="bulk-action-checkbox" data-ar-object-id="#{ar_object.id}"
36
46
  - @model.available_fields[@action.name.to_sym].each_with_index do |column, index|
37
47
  - if column.display_if.call(Current.user) && column.viewable
38
48
  td class="text-ellipsis"
@@ -1,28 +1,41 @@
1
1
  .table-top
2
2
  p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.ar_model.table_name)}"
3
- // .table-top__column-action
4
- // button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
5
- // span
6
- // i.fa.fa-columns.bolder
7
- // span
8
- // i.fa.fa-angle-down
3
+ / .table-top__column-action
4
+ / button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
5
+ / span
6
+ / i.fa.fa-columns.bolder
7
+ / span
8
+ / i.fa.fa-angle-down
9
+ - if flash[:alert].present?
10
+ .alert.alert-danger role="alert"
11
+ = flash[:alert].html_safe
12
+ - elsif flash[:notice].present?
13
+ .alert.alert-success
14
+ = flash[:notice].html_safe
15
+
16
+ - bulk_actions = actions_filter(@model, :bulk_action)
17
+ - if bulk_actions.present?
18
+ .table-top.hidden data-section="bulk-action"
19
+ - bulk_actions.each do |action|
20
+ = custom_action_items(action, 'index')
9
21
  .new-admin-table
10
22
  table.cm-table
11
23
  thead.cm-table__header
12
24
  tr.header-row
13
- // Select all checkbox feature to be added later
14
- / th.check-box-space
15
- / span
16
- / input.cm-checkbox type="checkbox"
25
+ - if bulk_actions.present?
26
+ th.check-box-space
27
+ span
28
+ input.cm-checkbox type="checkbox" data-behaviour="bulk-action-select-all"
17
29
  - @model.available_fields[:index].each do |column|
18
30
  - if column.display_if.call(Current.user) && column.viewable
19
31
  th = column.header
20
32
  tbody.cm-table__body
21
33
  - @ar_object.data.each do |ar_object|
22
34
  tr.body-row
23
- / td.check-box-space
24
- / span
25
- / input.cm-checkbox type="checkbox"
35
+ - if bulk_actions.present?
36
+ td.check-box-space
37
+ span
38
+ input.cm-checkbox type="checkbox" data-behaviour="bulk-action-checkbox" data-ar-object-id="#{ar_object.id}"
26
39
  - @model.available_fields[:index].each_with_index do |column, index|
27
40
  - if column.display_if.call(Current.user) && column.viewable
28
41
  td.text-ellipsis
@@ -41,4 +54,4 @@
41
54
  .cm-pagination__rhs
42
55
  == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @ar_object.pagy }
43
56
 
44
- = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
57
+ / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @model, ar_collection: @ar_object }
@@ -1,3 +1,4 @@
1
+
1
2
  .cm-index-page.cm-page-container
2
3
  .sticky-container.page-top-bar
3
4
  == render 'cm_admin/main/top_navbar'
@@ -9,7 +10,6 @@
9
10
  == render @action.partial
10
11
  - else
11
12
  == render 'cm_admin/main/table'
12
-
13
13
  = column_pop_up(@model)
14
14
  = manage_column_pop_up(@model)
15
15
 
@@ -1,4 +1,7 @@
1
- - @model.available_actions.select{|act| act if act.display_type == :modal}.each do |custom_action|
1
+ - custom_action_with_modals = @model.available_actions.select{ |act| act if act.display_type == :modal }
2
+ - if @associated_model
3
+ - custom_action_with_modals += @associated_model.available_actions.select{ |act| act if act.display_type == :modal }
4
+ - custom_action_with_modals.each do |custom_action|
2
5
  .modal.fade id="#{custom_action.name.classify}Modal" aria-hidden="true" aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex="1"
3
6
  .modal-dialog
4
7
  .modal-content
@@ -2,6 +2,7 @@ require_relative 'constants'
2
2
  require_relative 'models/action'
3
3
  require_relative 'models/importer'
4
4
  require_relative 'models/custom_action'
5
+ require_relative 'models/bulk_action'
5
6
  require_relative 'models/field'
6
7
  require_relative 'models/form_field'
7
8
  require_relative 'models/blocks'
@@ -24,7 +25,7 @@ module CmAdmin
24
25
  include Models::Blocks
25
26
  include Models::DslMethod
26
27
  attr_accessor :available_actions, :actions_set, :available_fields, :additional_permitted_fields,
27
- :current_action, :params, :filters, :available_tabs, :icon_name
28
+ :current_action, :params, :filters, :available_tabs, :icon_name, :bulk_actions
28
29
  attr_reader :name, :ar_model, :is_visible_on_sidebar, :importer
29
30
 
30
31
  def initialize(entity, &block)
@@ -33,6 +34,7 @@ module CmAdmin
33
34
  @is_visible_on_sidebar = true
34
35
  @icon_name = 'fa fa-th-large'
35
36
  @available_actions ||= []
37
+ @bulk_actions ||= []
36
38
  @additional_permitted_fields ||= []
37
39
  @current_action = nil
38
40
  @available_tabs ||= []
@@ -36,6 +36,10 @@ module CmAdmin
36
36
  self.sort_direction = :desc
37
37
  self.scopes ||= []
38
38
  self.icon_name = 'fa fa-th-large'
39
+ self.verb = :get
40
+ self.route_type = nil
41
+ self.display_type = nil
42
+
39
43
  end
40
44
 
41
45
  def set_values(page_title, page_description, partial)
@@ -45,12 +49,14 @@ module CmAdmin
45
49
  end
46
50
 
47
51
  def controller_action_name
48
- if self.action_type == :custom
52
+ if action_type == :custom
49
53
  'cm_custom_method'
50
- elsif self.parent
51
- 'cm_' + self.parent
54
+ elsif action_type == :bulk_action
55
+ 'cm_bulk_action'
56
+ elsif parent
57
+ "cm_#{parent}"
52
58
  else
53
- 'cm_' + name
59
+ "cm_#{name}"
54
60
  end
55
61
  end
56
62
 
@@ -0,0 +1,18 @@
1
+ require_relative 'actions/blocks'
2
+
3
+ module CmAdmin
4
+ module Models
5
+ class BulkAction < Action
6
+
7
+ def initialize(attributes = {}, &block)
8
+ super
9
+ override_default_values
10
+ end
11
+
12
+ def override_default_values
13
+ self.icon_name = 'fa fa-layer-group'
14
+ self.verb = :post
15
+ end
16
+ end
17
+ end
18
+ end
@@ -127,6 +127,15 @@ module CmAdmin
127
127
  # self.class.class_eval(&block)
128
128
  end
129
129
 
130
+ def bulk_action(name: nil, display_name: nil, display_if: lambda { |arg| return true }, redirection_url: nil, icon_name: nil, verb: nil, display_type: nil, route_type: nil, partial: nil, &block)
131
+ bulk_action = CmAdmin::Models::BulkAction.new(
132
+ name: name, display_name: display_name, display_if: display_if,
133
+ redirection_url: redirection_url, icon_name: icon_name, action_type: :bulk_action,
134
+ verb: verb, display_type: display_type, route_type: route_type, partial: partial, &block
135
+ )
136
+ @available_actions << bulk_action
137
+ end
138
+
130
139
  def filter(db_column_name, filter_type, options={})
131
140
  @filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
132
141
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.1.6'
2
+ VERSION = '1.1.7'
3
3
  end
@@ -60,6 +60,8 @@ module CmAdmin
60
60
  if custom_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{custom_action.name}?")
61
61
  if custom_action.display_if.call(@ar_object)
62
62
  case custom_action.display_type
63
+ when :icon_only
64
+ custom_action_icon(custom_action, current_action_name)
63
65
  when :button
64
66
  custom_action_button(custom_action, current_action_name)
65
67
  when :modal
@@ -71,6 +73,14 @@ module CmAdmin
71
73
  end
72
74
  end
73
75
 
76
+ def custom_action_icon(custom_action, current_action_name)
77
+ button_to cm_admin.send("#{@model.name.underscore}_#{custom_action.name}_path"), method: :post, params: {selected_ids: ''} do
78
+ content_tag(:span) do
79
+ content_tag(:i, '', class: custom_action.icon_name)
80
+ end
81
+ end
82
+ end
83
+
74
84
  def custom_action_button(custom_action, current_action_name)
75
85
  if current_action_name == "index"
76
86
  button_to custom_action_title(custom_action), @model.ar_model.table_name + '/' + custom_action.path, class: 'secondary-btn ml-2', method: custom_action.verb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - sajinmp
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-07-27 00:00:00.000000000 Z
13
+ date: 2023-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -168,6 +168,7 @@ files:
168
168
  - ".gitignore"
169
169
  - ".reek.yml"
170
170
  - ".rspec"
171
+ - ".rubocop-https---raw-githubusercontent-com-commutatus-cm-linters-main-rubocop-yml"
171
172
  - ".rubocop.yml"
172
173
  - ".stylelintrc.json"
173
174
  - ".travis.yml"
@@ -189,7 +190,9 @@ files:
189
190
  - app/assets/images/image_not_available.png
190
191
  - app/assets/images/logo.png
191
192
  - app/assets/javascripts/cm_admin/application.js
193
+ - app/assets/javascripts/cm_admin/bulk_actions.js
192
194
  - app/assets/javascripts/cm_admin/cocoon.js
195
+ - app/assets/javascripts/cm_admin/custom.js
193
196
  - app/assets/javascripts/cm_admin/exports.js
194
197
  - app/assets/javascripts/cm_admin/filters.js
195
198
  - app/assets/javascripts/cm_admin/form_validation.js
@@ -237,6 +240,7 @@ files:
237
240
  - app/javascript/packs/cm_admin/scaffolds.js
238
241
  - app/javascript/stylesheets/cm_admin/application.scss
239
242
  - app/jobs/file_import_processor_job.rb
243
+ - app/models/concerns/cm_admin/bulk_action_processor.rb
240
244
  - app/models/concerns/cm_admin/file_import.rb
241
245
  - app/models/file_import.rb
242
246
  - app/policies/cm_admin/file_import_policy.rb
@@ -294,6 +298,7 @@ files:
294
298
  - lib/cm_admin/models/action.rb
295
299
  - lib/cm_admin/models/actions/blocks.rb
296
300
  - lib/cm_admin/models/blocks.rb
301
+ - lib/cm_admin/models/bulk_action.rb
297
302
  - lib/cm_admin/models/column.rb
298
303
  - lib/cm_admin/models/custom_action.rb
299
304
  - lib/cm_admin/models/dsl_method.rb