cm-admin 2.4.2 → 2.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78f89e2eccee1468634aeeb827a6316ad2aab8b6159e1be81fedad7dcf4af917
4
- data.tar.gz: ce2f0dfc441128af6fac25e51eb64131b3e5aea68398b41af8f585d1529022c8
3
+ metadata.gz: d0637794147d28cbeb2b09c9162104aabb3c5b7f52e3fb9e42c6a291e89b8e5e
4
+ data.tar.gz: 7971b87140570d9a486c65522fa762a960b5d5bc1e2cb392abcb36beec867003
5
5
  SHA512:
6
- metadata.gz: '09855ccdcdec4dde56de8242614948af82513b56c38383e89149416b0e6e39ac0c0f58284410e9b536eb7dd89ccdcaa2f40b6933ecd76e506f7b478f02fc5ad3'
7
- data.tar.gz: 259d5867d373e63750f9af64ab874f1402f2a6dfe7b3cc839ac6a9cb7bb6f29f729d48f24b9537146fafe0951cfff6b1184fbd8a94cce441639ee17ddebceec6
6
+ metadata.gz: 5e61028998a91e7279541570fd4e881cdc9263f3bd89f03db97e0b057c6667e32f69481164cf294bd6c517a55ec34de5c744b50e98340192c56861325eb9a7bb
7
+ data.tar.gz: 2cacfa59737f253733fe9b362464515f944e876e4e67b5e21f0895bd5691c6888c7a9d4013432d80b0ad24b04b4e9f52712786e445826ab539aef4d490a6a1cc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (2.4.2)
4
+ cm-admin (2.4.4)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -23,14 +23,16 @@ function setBulkActionParams() {
23
23
  $('[data-behaviour="bulk-action-checkbox"]:checked').each(function(){ selected_ids.push($(this).data('ar-object-id')) })
24
24
  var bulk_action_form = '[data-section="bulk-action"] form'
25
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
- }
26
+ $(bulk_action_form).each(function( i ) {
27
+ if ($(this).find('[name="selected_ids"]').length == 0) {
28
+ $('<input>').attr({
29
+ type: 'hidden',
30
+ name: 'selected_ids'
31
+ }).appendTo(this);
32
+ }
33
+ })
32
34
  }
33
35
  $('[data-section="bulk-action"] [name="selected_ids"]').each(function( i ) {
34
36
  $(this).val(selected_ids)
35
37
  })
36
- }
38
+ }
@@ -47,7 +47,8 @@ $(document).on("click", '[data-behaviour="form_submit"]', function (e) {
47
47
  });
48
48
  if (submit.length === 0) {
49
49
  $("." + form_class).submit();
50
- return $('[data-behaviour="form_submit"]').button("loading");
50
+ $('[data-behaviour="form_submit_spinner"]').removeClass("visually-hidden");
51
+ return $('[data-behaviour="form_submit"]').addClass("visually-hidden");
51
52
  }
52
53
  });
53
54
 
@@ -118,3 +118,37 @@
118
118
  .discard-form {
119
119
  margin-left: 16px;
120
120
  }
121
+
122
+ // Bulk Actions Dropdown
123
+ .bulk-action-item {
124
+
125
+ form {
126
+ width: 100%;
127
+ }
128
+
129
+ .bulk-action-icon {
130
+ width: 20px;
131
+ height: 20px;
132
+
133
+ svg {
134
+ width: 100%;
135
+ height: 100%;
136
+ object-fit: contain;
137
+ }
138
+ }
139
+
140
+ .bulk-action-button {
141
+ @extend .d-flex, .align-items-center, .gap-2;
142
+
143
+ &:hover {
144
+ color: inherit;
145
+ text-decoration: none;
146
+ }
147
+ }
148
+
149
+ a {
150
+ display: flex;
151
+ gap: 8px;
152
+ }
153
+ }
154
+
@@ -36,6 +36,10 @@
36
36
  text-decoration: underline;
37
37
  }
38
38
 
39
+ .cm-admin .btn-loading {
40
+ @extend .btn, .btn-primary, .btn-sm, .btn-icon-spacing, .disabled;
41
+ }
42
+
39
43
  // button mixin - We can use if needed
40
44
  // @include button-variant($background: #6554e0, $border: #6554e0);
41
45
 
@@ -20,8 +20,7 @@
20
20
  - bulk_actions = actions_filter(@model, @ar_object, :bulk_action)
21
21
  - if bulk_actions.present?
22
22
  .table-top.hidden data-section="bulk-action"
23
- - bulk_actions.each do |action|
24
- = custom_action_items(action, 'index')
23
+ = bulk_action_items(bulk_actions, 'index')
25
24
  .table-wrapper
26
25
  table.index-table data-bulk-actions=(bulk_actions.present? && "present")
27
26
  thead
@@ -7,11 +7,7 @@ module CmAdmin
7
7
 
8
8
  def initialize(attributes = {}, &block)
9
9
  super
10
- override_default_values
11
- end
12
-
13
- def override_default_values
14
- self.icon_name = 'fa fa-layer-group'
10
+ self.icon_name ||= 'fa fa-layer-group'
15
11
  self.verb = :post
16
12
  end
17
13
  end
@@ -282,7 +282,7 @@ module CmAdmin
282
282
  # @param redirection_url [String] the redirection url of action
283
283
  # @param icon_name [String] the icon name of action, follow font-awesome icon name
284
284
  # @param verb [String] the verb of action, +get+, +post+, +put+, +patch+ or +delete+
285
- # @param display_type [Symbol] the display type of action, +:page+, +:modal+
285
+ # @param display_type [Symbol] the display type of action, +:page+, +:modal+, +:button+, +:icon_only+[deprecated]
286
286
  # @param modal_configuration [Hash] the configuration of modal
287
287
  # @param route_type [String] the route type of action, +member+, +collection+
288
288
  # @param partial [String] the partial path of action
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '2.4.2'
2
+ VERSION = '2.4.4'
3
3
  end
@@ -185,7 +185,11 @@ module CmAdmin
185
185
 
186
186
  concat split_form_into_section(resource, form_obj, entities)
187
187
  concat tag.br
188
- concat form_obj.submit 'Save', class: 'btn-cta', data: { behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form" }
188
+ concat form_obj.submit 'Save', class: 'btn-cta', data: { behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form", turbo_submits_with: 'Submitting...' }
189
+ concat (button_tag(type: 'button', class: 'btn-loading visually-hidden', data: { behaviour: 'form_submit_spinner' }) do
190
+ concat content_tag(:span, '', class: 'spinner-border spinner-border-sm', role: 'status')
191
+ concat ' Submitting...'
192
+ end)
189
193
  concat button_tag 'Discard', class: 'btn-secondary discard-form', data: { behaviour: 'discard_form' } unless @is_drawer_form
190
194
  end
191
195
  end
@@ -86,6 +86,76 @@ module CmAdmin
86
86
  end
87
87
  end
88
88
 
89
+ def bulk_action_items(bulk_items, current_action_name)
90
+ content_tag :div, class: 'dropdown' do
91
+ concat(link_to('Bulk Actions', '#', class: 'dropdown-toggle', role: 'button', id: 'dropdownMenuLink', data: { bs_toggle: 'dropdown' }, aria: { expanded: false }))
92
+
93
+ concat(
94
+ content_tag(:ul, class: 'dropdown-menu', aria: { labelledby: 'dropdownMenuLink' }) do
95
+ bulk_action_dropdown_items(bulk_items, current_action_name)
96
+ end
97
+ )
98
+ end
99
+ end
100
+
101
+ def bulk_action_dropdown_items(bulk_items, current_action_name)
102
+ bulk_items.each do |bulk_action|
103
+ next unless bulk_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{bulk_action.name}?")
104
+
105
+ scoped_model = bulk_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{bulk_action.name}?")
106
+
107
+ has_scoped_record = if current_action_name == 'index'
108
+ scoped_model.present?
109
+ else
110
+ scoped_model.find_by(id: ar_object.id).present?
111
+ end
112
+
113
+ next unless bulk_action.display_if.call(@ar_object) && has_scoped_record
114
+
115
+ case bulk_action.display_type
116
+ when :button
117
+ bulk_action_button(bulk_action)
118
+ when :modal
119
+ bulk_action_modal(bulk_action)
120
+ when :page
121
+ bulk_action_page(bulk_action)
122
+ end
123
+ end
124
+ end
125
+
126
+ def bulk_action_button(bulk_action)
127
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
128
+ button_to cm_admin.send("#{@model.name.underscore}_#{bulk_action.name}_path"), method: :post, params: { selected_ids: '' }, class: 'bulk-action-button dropdown-item' do
129
+ concat(content_tag(:div, class: 'bulk-action-icon') do
130
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
131
+ end)
132
+ concat(content_tag(:span, custom_action_title(bulk_action)))
133
+ end
134
+ end)
135
+ end
136
+
137
+ def bulk_action_modal(bulk_action)
138
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
139
+ link_to '#', data: { bs_toggle: 'modal', bs_target: "##{bulk_action.name.classify}Modal-#{@ar_object.id}" }, class: 'dropdown-item' do
140
+ concat(content_tag(:div, class: 'bulk-action-icon') do
141
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
142
+ end)
143
+ concat(content_tag(:span, bulk_action.display_name))
144
+ end
145
+ end)
146
+ end
147
+
148
+ def bulk_action_page(bulk_action)
149
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
150
+ link_to cm_admin.send("#{@model.name.underscore}_#{bulk_action.name}_path", @ar_object, bulk_action.url_params), class: 'dropdown-item' do
151
+ concat(content_tag(:div, class: 'bulk-action-icon') do
152
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
153
+ end)
154
+ concat(content_tag(:span, bulk_action.display_name))
155
+ end
156
+ end)
157
+ end
158
+
89
159
  def custom_action_title(custom_action)
90
160
  custom_action.display_name.to_s.presence || custom_action.name.to_s.titleize
91
161
  end
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: 2.4.2
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -11,10 +11,10 @@ authors:
11
11
  - Pranav
12
12
  - Mahaveer
13
13
  - Austin
14
- autorequire:
14
+ autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2024-10-16 00:00:00.000000000 Z
17
+ date: 2024-10-18 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails
@@ -507,7 +507,7 @@ licenses:
507
507
  metadata:
508
508
  homepage_uri: https://github.com/commutatus/cm-admin
509
509
  source_code_uri: https://github.com/commutatus/cm-admin
510
- post_install_message:
510
+ post_install_message:
511
511
  rdoc_options: []
512
512
  require_paths:
513
513
  - lib
@@ -523,7 +523,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
523
523
  version: '0'
524
524
  requirements: []
525
525
  rubygems_version: 3.5.16
526
- signing_key:
526
+ signing_key:
527
527
  specification_version: 4
528
528
  summary: CmAdmin is a robust gem designed to assist in creating admin panels for Rails
529
529
  applications