cm-admin 1.1.5 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop-https---raw-githubusercontent-com-commutatus-cm-linters-main-rubocop-yml +20 -0
- data/Gemfile.lock +60 -60
- data/app/assets/config/cm_admin_manifest.js +2 -1
- data/app/assets/fonts/fa-brands-400.ttf +0 -0
- data/app/assets/fonts/fa-brands-400.woff2 +0 -0
- data/app/assets/fonts/fa-regular-400.ttf +0 -0
- data/app/assets/fonts/fa-regular-400.woff2 +0 -0
- data/app/assets/fonts/fa-solid-900.ttf +0 -0
- data/app/assets/fonts/fa-solid-900.woff2 +0 -0
- data/app/assets/fonts/fa-v4compatibility.ttf +0 -0
- data/app/assets/fonts/fa-v4compatibility.woff2 +0 -0
- data/app/assets/javascripts/cm_admin/application.js +8 -3
- data/app/assets/javascripts/cm_admin/bulk_actions.js +36 -0
- data/app/assets/javascripts/cm_admin/custom.js +0 -0
- data/app/assets/stylesheets/cm_admin/cm_admin.css.scss +2 -2
- data/app/assets/stylesheets/cm_admin/dependency/fontawesome.all.css +7831 -0
- data/app/controllers/cm_admin/resource_controller.rb +16 -1
- data/app/helpers/cm_admin/application_helper.rb +4 -0
- data/app/javascript/packs/cm_admin/application.js +1 -0
- data/app/models/concerns/cm_admin/bulk_action_processor.rb +29 -0
- data/app/views/cm_admin/main/_associated_table.html.slim +19 -9
- data/app/views/cm_admin/main/_table.html.slim +27 -14
- data/app/views/cm_admin/main/index.html.slim +1 -1
- data/app/views/layouts/_custom_action_modals.html.slim +4 -1
- data/lib/cm_admin/model.rb +3 -1
- data/lib/cm_admin/models/action.rb +10 -4
- data/lib/cm_admin/models/bulk_action.rb +18 -0
- data/lib/cm_admin/models/dsl_method.rb +9 -0
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/page_info_helper.rb +10 -0
- metadata +16 -2
@@ -93,7 +93,22 @@ module CmAdmin
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
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}
|
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
|
data/lib/cm_admin/model.rb
CHANGED
@@ -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
|
52
|
+
if action_type == :custom
|
49
53
|
'cm_custom_method'
|
50
|
-
elsif
|
51
|
-
'
|
54
|
+
elsif action_type == :bulk_action
|
55
|
+
'cm_bulk_action'
|
56
|
+
elsif parent
|
57
|
+
"cm_#{parent}"
|
52
58
|
else
|
53
|
-
|
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
|
data/lib/cm_admin/version.rb
CHANGED
@@ -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.
|
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-
|
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"
|
@@ -178,10 +179,20 @@ files:
|
|
178
179
|
- README.md
|
179
180
|
- Rakefile
|
180
181
|
- app/assets/config/cm_admin_manifest.js
|
182
|
+
- app/assets/fonts/fa-brands-400.ttf
|
183
|
+
- app/assets/fonts/fa-brands-400.woff2
|
184
|
+
- app/assets/fonts/fa-regular-400.ttf
|
185
|
+
- app/assets/fonts/fa-regular-400.woff2
|
186
|
+
- app/assets/fonts/fa-solid-900.ttf
|
187
|
+
- app/assets/fonts/fa-solid-900.woff2
|
188
|
+
- app/assets/fonts/fa-v4compatibility.ttf
|
189
|
+
- app/assets/fonts/fa-v4compatibility.woff2
|
181
190
|
- app/assets/images/image_not_available.png
|
182
191
|
- app/assets/images/logo.png
|
183
192
|
- app/assets/javascripts/cm_admin/application.js
|
193
|
+
- app/assets/javascripts/cm_admin/bulk_actions.js
|
184
194
|
- app/assets/javascripts/cm_admin/cocoon.js
|
195
|
+
- app/assets/javascripts/cm_admin/custom.js
|
185
196
|
- app/assets/javascripts/cm_admin/exports.js
|
186
197
|
- app/assets/javascripts/cm_admin/filters.js
|
187
198
|
- app/assets/javascripts/cm_admin/form_validation.js
|
@@ -212,6 +223,7 @@ files:
|
|
212
223
|
- app/assets/stylesheets/cm_admin/components/index.scss
|
213
224
|
- app/assets/stylesheets/cm_admin/dependency/bootstrap.min.css
|
214
225
|
- app/assets/stylesheets/cm_admin/dependency/flatpickr.min.css
|
226
|
+
- app/assets/stylesheets/cm_admin/dependency/fontawesome.all.css
|
215
227
|
- app/assets/stylesheets/cm_admin/helpers/_mixins.scss
|
216
228
|
- app/assets/stylesheets/cm_admin/helpers/_variable.scss
|
217
229
|
- app/assets/stylesheets/cm_admin/helpers/index.scss
|
@@ -228,6 +240,7 @@ files:
|
|
228
240
|
- app/javascript/packs/cm_admin/scaffolds.js
|
229
241
|
- app/javascript/stylesheets/cm_admin/application.scss
|
230
242
|
- app/jobs/file_import_processor_job.rb
|
243
|
+
- app/models/concerns/cm_admin/bulk_action_processor.rb
|
231
244
|
- app/models/concerns/cm_admin/file_import.rb
|
232
245
|
- app/models/file_import.rb
|
233
246
|
- app/policies/cm_admin/file_import_policy.rb
|
@@ -285,6 +298,7 @@ files:
|
|
285
298
|
- lib/cm_admin/models/action.rb
|
286
299
|
- lib/cm_admin/models/actions/blocks.rb
|
287
300
|
- lib/cm_admin/models/blocks.rb
|
301
|
+
- lib/cm_admin/models/bulk_action.rb
|
288
302
|
- lib/cm_admin/models/column.rb
|
289
303
|
- lib/cm_admin/models/custom_action.rb
|
290
304
|
- lib/cm_admin/models/dsl_method.rb
|