cm-admin 1.5.40 → 1.5.41

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: f475032d34987ece76840fc174951e055960b8dfbd98ee71b8b57616eddc501d
4
- data.tar.gz: e745cc4fafd087fcbc19edcb14d66a11c15ec04d072d6e0a8512a34f3438a91a
3
+ metadata.gz: c64d865b82c2abfd0975930a349a1ba2f63ee85d5ecbf0a4e627d3cbc1629bb1
4
+ data.tar.gz: 5ce41edd98628d3b20315a5ca44c5be95daf578bbdd53c97192f114f58110545
5
5
  SHA512:
6
- metadata.gz: 804bebee2f580d8ad4b63c389bc5f5af3c84de8ebc3aa71ead30392baf104a25b106983138d3ac12cbdabce6ebdb7987ddc864ed9cdf26174c7bc0fdc7cbbddf
7
- data.tar.gz: bb9ef705565cafdd1229281da4ad28dedf126557943779390db4c1c53f8d5d88f9b0bd4220c3d609e5cf19070a9a8c502c6c0f7cfbd9413d8502783aa327c932
6
+ metadata.gz: 7327d73ee5028535163d62e4f3dbc7197389132178331c9bf76e4e0bb463166a06fb74186c4c32c0a50871c37ead0895e7f4b43157646bb3a5ff59b3e5e7e207
7
+ data.tar.gz: fefcc76ae24e4cc066c9dc70831fa5f1974bfe03563c49863e319180adec9577eb0dcb6acae9a4d35d4b587a7a2b602d3a09e0cab4c4b03ae8eac1e12eddd286
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.5.39)
4
+ cm-admin (1.5.41)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -12,7 +12,6 @@ PATH
12
12
  rails (>= 6.0)
13
13
  slim (~> 4.1.0)
14
14
  webpacker (~> 5.4.3)
15
- yard
16
15
 
17
16
  GEM
18
17
  remote: https://rubygems.org/
@@ -258,7 +257,6 @@ GEM
258
257
  websocket-driver (0.7.6)
259
258
  websocket-extensions (>= 0.1.0)
260
259
  websocket-extensions (0.1.5)
261
- yard (0.9.36)
262
260
  zeitwerk (2.6.15)
263
261
 
264
262
  PLATFORMS
data/README.md CHANGED
@@ -37,13 +37,19 @@ For demo repo check [here](https://github.com/commutatus/cm-admin-panel-demo)
37
37
 
38
38
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
39
 
40
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+ To install this gem onto your local machine, run `bundle exec rake install`.
41
+
42
+ ## Deployment
43
+
44
+ To release a new version of the Gem you can use Github Actions.
45
+
46
+ Go to Actions tab in your repository and click on `Bump Gem` workflow.
47
+ You will see `Run workflow` button click on it and choose `Bump Type`, then click `Run Workflow` and it will bump the version of the gem and push the changes to the repository.
41
48
 
42
49
  ## Contributing
43
50
 
44
51
  Bug reports and pull requests are welcome on [GitHub](https://github.com/commutatus/cm-admin).
45
52
 
46
-
47
53
  ## License
48
54
 
49
55
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,12 +1,12 @@
1
- import './scaffolds.js';
2
- import './shared_scaffolds.js';
3
-
4
- import './bulk_actions.js'
5
- import './cocoon.js'
6
- import './exports.js'
7
- import './filters.js'
8
- import './form_validation.js'
9
- import './quick_search.js'
10
- import './custom.js'
11
- import './kanban.js'
1
+ import "./scaffolds.js";
2
+ import "./shared_scaffolds.js";
12
3
 
4
+ import "./bulk_actions.js";
5
+ import "./cocoon.js";
6
+ import "./exports.js";
7
+ import "./filters.js";
8
+ import "./form_validation.js";
9
+ import "./quick_search.js";
10
+ import "./custom.js";
11
+ import "./kanban.js";
12
+ import "./custom_action";
@@ -0,0 +1,30 @@
1
+ import * as bootstrap from "bootstrap";
2
+ window.bootstrap = bootstrap;
3
+
4
+ document.addEventListener("turbo:load", function () {
5
+ $('[data-action="fetch-modal"]').on("click", function (e) {
6
+ const actionName = $(this).attr("data-action_name");
7
+ const modelName = $(this).attr("data-model_name");
8
+ const recordId = $(this).attr("data-record_id");
9
+ const modalContainer = $(
10
+ "[data-behaviour='custom-action-modal-container']"
11
+ );
12
+ const routeMount = document.location.href.split("/")[3];
13
+
14
+ if (!actionName || !modelName || !recordId || !modalContainer) return;
15
+ $.ajax({
16
+ url: `/${routeMount}/${modelName}/${recordId}/custom_action_modal/${actionName}`,
17
+ method: "GET",
18
+ success: function (response) {
19
+ modalContainer.html(response);
20
+ const actionModal = new bootstrap.Modal(
21
+ modalContainer.children().first()
22
+ );
23
+ actionModal.show();
24
+ },
25
+ error: function (error) {
26
+ console.error("Error:", error);
27
+ },
28
+ });
29
+ });
30
+ });
@@ -172,6 +172,17 @@ module CmAdmin
172
172
  end
173
173
  end
174
174
 
175
+ def cm_custom_action_modal(params)
176
+ scoped_model = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve
177
+ @ar_object = fetch_ar_object(scoped_model, params[:id])
178
+ if params[:action_name] == 'destroy'
179
+ render partial: '/layouts/destroy_action_modal', locals: { ar_object: @ar_object }
180
+ else
181
+ custom_action = @model.available_actions.select { |x| x.name == params[:action_name].to_s }.first
182
+ render partial: '/layouts/custom_action_modal', locals: { custom_action:, ar_object: @ar_object }
183
+ end
184
+ end
185
+
175
186
  def get_nested_table_fields(fields)
176
187
  nested_table_fields = []
177
188
  fields.each do |field|
@@ -1,30 +1,27 @@
1
- require("@rails/ujs").start()
2
- require("turbolinks").start()
3
- require("@rails/activestorage").start()
4
- require("stylesheets/cm_admin/application")
5
- require("jquery")
6
- require("moment")
7
- require("bootstrap")
8
- require('flatpickr')
9
- require("jgrowl")
10
- require("trix")
11
- require('./scaffolds.js')
12
- require('/app/assets/javascripts/cm_admin/shared_scaffolds.js')
13
- require('/app/assets/javascripts/cm_admin/form_validation.js')
14
- require('/app/assets/javascripts/cm_admin/quick_search.js')
15
- require('/app/assets/javascripts/cm_admin/filters.js')
16
- require('/app/assets/javascripts/cm_admin/exports.js')
17
- require('/app/assets/javascripts/cm_admin/bulk_actions.js')
18
-
19
- import jQuery from 'jquery'
20
- import LocalTime from "local-time"
21
- window.$ = jQuery
22
- window.jQuery = jQuery
23
-
24
- LocalTime.start()
25
- require("@nathanvda/cocoon")
26
- import "@fortawesome/fontawesome-free/css/all"
27
- import "daterangepicker"
28
-
1
+ require("@rails/ujs").start();
2
+ require("turbolinks").start();
3
+ require("@rails/activestorage").start();
4
+ require("stylesheets/cm_admin/application");
5
+ require("jquery");
6
+ require("moment");
7
+ require("bootstrap");
8
+ require("flatpickr");
9
+ require("jgrowl");
10
+ require("trix");
11
+ require("./scaffolds.js");
12
+ require("/app/assets/javascripts/cm_admin/shared_scaffolds.js");
13
+ require("/app/assets/javascripts/cm_admin/form_validation.js");
14
+ require("/app/assets/javascripts/cm_admin/quick_search.js");
15
+ require("/app/assets/javascripts/cm_admin/filters.js");
16
+ require("/app/assets/javascripts/cm_admin/exports.js");
17
+ require("/app/assets/javascripts/cm_admin/bulk_actions.js");
29
18
 
19
+ import jQuery from "jquery";
20
+ import LocalTime from "local-time";
21
+ window.$ = jQuery;
22
+ window.jQuery = jQuery;
30
23
 
24
+ LocalTime.start();
25
+ require("@nathanvda/cocoon");
26
+ import "@fortawesome/fontawesome-free/css/all";
27
+ import "daterangepicker";
@@ -27,7 +27,7 @@
27
27
  i.fa.fa-trash
28
28
  | Destroy
29
29
  - else
30
- = link_to '', data: { bs_toggle: 'modal', bs_target: "##{@model.name.classify}DestroyModal-#{ar_object.id.to_s}" } do
30
+ div data={action: 'fetch-modal', model_name: "#{cm_model.name.underscore.pluralize}", action_name: "destroy", record_id: "#{ar_object.id.to_s}"}
31
31
  .popup-option
32
32
  span
33
33
  i.fa.fa-trash
@@ -42,7 +42,7 @@
42
42
  i class="#{custom_action.icon_name}"
43
43
  = custom_action_title(custom_action)
44
44
  - when :modal
45
- = link_to '', data: { bs_toggle: 'modal', bs_target: "##{custom_action.name.classify}Modal-#{ar_object.id.to_s}" } do
45
+ div data={action: 'fetch-modal', model_name: "#{cm_model.name.underscore.pluralize}", action_name: "#{custom_action.name}", record_id: "#{ar_object.id.to_s}"}
46
46
  .popup-option
47
47
  span
48
48
  i class="#{custom_action.icon_name}"
@@ -8,4 +8,4 @@
8
8
  - if custom_action.partial
9
9
  = render partial: custom_action.partial, locals: { custom_action: custom_action, ar_object: ar_object }
10
10
  - else
11
- = render partial: 'cm_admin/main/custom_action_modal_form', locals: { custom_action: custom_action, ar_object: ar_object }
11
+ = render partial: 'cm_admin/main/custom_action_modal_form', locals: { custom_action: custom_action, ar_object: ar_object }
@@ -1,24 +1,25 @@
1
1
  - custom_action_with_modals = @model.available_actions.select{ |act| act if act.display_type == :modal && act.action_type == :custom }
2
2
  - bulk_action_with_modals = @model.available_actions.select{ |act| act if act.display_type == :modal && act.action_type == :bulk_action }
3
3
  - destroy_action = @ar_object ? available_actions(@model, @ar_object, 'destroy') : nil
4
+
5
+ div[data-behaviour="custom-action-modal-container"]
6
+
4
7
  - if @associated_model
5
8
  - custom_action_with_modals += @associated_model.available_actions.select{ |act| act if act.display_type == :modal }
9
+
6
10
  - if @current_action&.name == 'index'
7
11
  - bulk_action_with_modals.each do |bulk_action|
8
12
  = render partial: '/layouts/custom_action_modal', locals: { custom_action: bulk_action, ar_object: nil }
9
- - @ar_object.data.each do |ar_object|
10
- - custom_action_with_modals.each do |custom_action|
11
- = render partial: '/layouts/custom_action_modal', locals: { custom_action: custom_action, ar_object: ar_object }
12
- - if destroy_action
13
- = render partial: '/layouts/destroy_action_modal', locals: { ar_object: ar_object }
13
+
14
14
  - elsif @current_action&.name == 'show'
15
15
  - custom_action_with_modals.each do |custom_action|
16
- = render partial: '/layouts/custom_action_modal', locals: { custom_action: custom_action, ar_object: @ar_object }
16
+ = render partial: '/layouts/custom_action_modal', locals: { custom_action: custom_action, ar_object: @ar_object }
17
17
  - if destroy_action
18
18
  = render partial: '/layouts/destroy_action_modal', locals: { ar_object: @ar_object }
19
+
19
20
  - elsif @current_action&.action_type == :custom && @associated_ar_object&.data.present?
20
21
  - @associated_ar_object.data.each do |ar_object|
21
22
  - custom_action_with_modals.select{|custom_action| custom_action.model_name == @current_action.child_records.to_s.classify}.each do |custom_action|
22
23
  = render partial: '/layouts/custom_action_modal', locals: { custom_action: custom_action, ar_object: ar_object }
23
24
  - if destroy_action
24
- = render partial: '/layouts/destroy_action_modal', locals: { ar_object: ar_object }
25
+ = render partial: '/layouts/destroy_action_modal', locals: { ar_object: ar_object }
data/cm_admin.gemspec CHANGED
@@ -37,6 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_runtime_dependency('rails', '>= 6.0')
38
38
  spec.add_runtime_dependency 'slim', '~> 4.1.0'
39
39
  spec.add_runtime_dependency 'webpacker', '~> 5.4.3'
40
- spec.add_runtime_dependency 'yard'
41
40
  spec.add_dependency 'importmap-rails'
42
41
  end
data/config/routes.rb CHANGED
@@ -16,7 +16,7 @@ CmAdmin::Engine.routes.draw do
16
16
  send(:post, 'import', to: "#{model.name.underscore}#import", as: "#{model.name.underscore}_import")
17
17
  end
18
18
  end
19
-
19
+
20
20
  model.available_actions.sort_by {|act| act.name}.each do |act|
21
21
  scope model.name.tableize do
22
22
  # Define route only when action trail related field is present
@@ -34,6 +34,10 @@ module CmAdmin
34
34
  },
35
35
  custom_action: {
36
36
  verb: :post
37
+ },
38
+ custom_action_modal: {
39
+ verb: :get,
40
+ path: ':id/custom_action_modal/:action_name'
37
41
  }
38
42
  }
39
43
  REJECTABLE_FIELDS = %w(id created_at updated_at)
@@ -8,9 +8,15 @@ module CmAdmin
8
8
  # @param page_title [String] the title of page
9
9
  # @param page_description [String] the description of page
10
10
  # @param partial [String] the partial path of page
11
- # @param view_type [Symbol] view type of page, `:table`, `:card` or `:kanban
11
+ # @param view_type [Symbol] view type of page +:table+, +:card+ or +:kanban+
12
12
  # @example Index page
13
- # cm_index(page_title: "Home", page_description: 'Home page', partial: 'pages/home', view_type: :table)
13
+ # cm_index do
14
+ # page_title 'Post'
15
+ # column :title
16
+ # column :created_at, field_type: :date, format: '%d %b, %Y'
17
+ # column :updated_at, field_type: :date, format: '%d %b, %Y', header: 'Last Updated At'
18
+ # end
19
+ # rdoc-image:/public/examples/cm_index.png
14
20
  def cm_index(page_title: nil, page_description: nil, partial: nil, view_type: :table)
15
21
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'index')
16
22
  @current_action.set_values(page_title, page_description, partial, view_type)
@@ -19,12 +25,21 @@ module CmAdmin
19
25
 
20
26
  # Create a view for show page
21
27
  #
22
- # @param page_title [String] or [Symbol] the title of page, if symbol passed, it will be a method name on model
28
+ # @param page_title [String | Symbol] the title of page, if symbol passed, it will be a method name on model
23
29
  # @param page_description [String] the description of page
24
30
  # @param partial [String] the partial path of page
25
31
  #
26
32
  # @example Showing page
27
- # cm_show(page_title: "Home", page_description: 'Home page', partial: 'pages/home')
33
+ # cm_show page_title: :title do
34
+ # tab :profile, '' do
35
+ # cm_section 'Post Details' do
36
+ # field :title
37
+ # field :body, field_type: :rich_text
38
+ # field :is_featured
39
+ # field :status, field_type: :tag, tag_class: STATUS_TAG_COLOR
40
+ # end
41
+ # end
42
+ # end
28
43
  def cm_show(page_title: nil, page_description: nil, partial: nil)
29
44
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
30
45
  @current_action.set_values(page_title, page_description, partial)
@@ -39,7 +54,12 @@ module CmAdmin
39
54
  # @param redirect_to [Proc, nil] A lambda that takes the current object and redirect to path after update
40
55
  #
41
56
  # @example Editing page with a redirect
42
- # cm_edit(page_title: "Home", redirect_to: ->(current_object) { "/pages/#{current_object.id}" })
57
+ # cm_edit(page_title: "Edit Post", page_description: 'Enter all details to edit Post', redirect_to: ->(current_object) { "/pages/#{current_object.id}" }) do
58
+ # cm_section 'Details' do
59
+ # form_field :title, input_type: :string
60
+ # form_field :body, input_type: :rich_text
61
+ # end
62
+ # end
43
63
  def cm_edit(page_title: nil, page_description: nil, partial: nil, redirect_to: nil)
44
64
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'edit')
45
65
  @current_action.set_values(page_title, page_description, partial, redirect_to)
@@ -54,7 +74,12 @@ module CmAdmin
54
74
  # @param redirect_to [Proc, nil] A lambda that takes the current object and redirect to path after create
55
75
  #
56
76
  # @example Creating a new page with a redirect
57
- # cm_new(page_title: "Home", redirect_to: ->(current_object) { "/pages/#{current_object.id}" })
77
+ # cm_new(page_title: "Add Post", page_description: 'Enter all details to add Post', redirect_to: ->(current_object) { "/pages/#{current_object.id}" }) do
78
+ # cm_section 'Details' do
79
+ # form_field :title, input_type: :string
80
+ # form_field :body, input_type: :rich_text
81
+ # end
82
+ # end
58
83
  def cm_new(page_title: nil, page_description: nil, partial: nil, redirect_to: nil)
59
84
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'new')
60
85
  @current_action.set_values(page_title, page_description, partial, redirect_to)
@@ -102,13 +127,15 @@ module CmAdmin
102
127
  # @param tab_name [String] or [Symbol] the name of tab
103
128
  # @param custom_action [String] the name of custom action
104
129
  # @param associated_model [String] the name of associated model
105
- # @param layout_type [String] the layout type of tab, `'cm_association_index'`, `'cm_association_show'`
130
+ # @param layout_type [String] the layout type of tab, +cm_association_index+, +cm_association_show+
106
131
  # @param layout [String] the layout of tab
107
132
  # @param partial [String] the partial path of tab
108
133
  # @param display_if [Proc] A lambda that takes the current object and return true or false
109
134
  #
110
135
  # @example Creating a tab
111
- # tab(:comments, 'comment', associated_model: 'comments', layout_type: 'cm_association_index')
136
+ # tab :comments, 'comment', associated_model: 'comments', layout_type: 'cm_association_index' do
137
+ # column :message
138
+ # end
112
139
  def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, display_if: nil, &block)
113
140
  if custom_action.to_s == ''
114
141
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
@@ -129,6 +156,10 @@ module CmAdmin
129
156
  # @param html_attrs [Hash] A hash that contains html attributes
130
157
  # @example Creating a row
131
158
  # row(display_if: ->(current_object) { current_object.name == 'John' }, html_attrs: { class: 'row-class' }) do
159
+ # cm_section 'Details' do
160
+ # form_field :title, input_type: :string
161
+ # end
162
+ # end
132
163
  def row(display_if: nil, html_attrs: nil, &block)
133
164
  @available_fields[@current_action.name.to_sym] ||= []
134
165
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Row.new(@current_action, @model, display_if, html_attrs, &block)
@@ -142,6 +173,8 @@ module CmAdmin
142
173
 
143
174
  # @example Creating a section
144
175
  # cm_section('Basic Information', display_if: ->(current_object) { current_object.name == 'John' }, col_size: 6, html_attrs: { class: 'section-class' }) do
176
+ # field :title, input_type: :string
177
+ # end
145
178
  def cm_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
146
179
  @available_fields[@current_action.name.to_sym] ||= []
147
180
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
@@ -154,10 +187,10 @@ module CmAdmin
154
187
 
155
188
  # Create a new column on index layout.
156
189
  # @param field_name [String] the name of field
157
- # @param field_type [Symbol] the type of field, :string, :text, :image, :date, :rich_text, :time, :integer, :decimal, :custom, :datetime, :money, :money_with_symbol, :link, :association, :enum, :tag, :attachment, :drawer
190
+ # @param field_type [Symbol] the type of field, +:string+, +:text+, +:image+, +:date+, +:rich_text+, +:time+, +:integer+, +:decimal+, +:custom+, +:datetime+, +:money+, +:money_with_symbol+, +:link+, +:association+, +:enum+, +:tag+, +:attachment+, +:drawer+
158
191
  # @param header [String] the header of field
159
192
  # @param format [String] the format of field for date field
160
- # @param helper_method [Symbol] the helper method for field, should be defined in custom_helper.rb file, will take two arguments, `record` and `field_name`
193
+ # @param helper_method [Symbol] the helper method for field, should be defined in custom_helper.rb file, will take two arguments, +record+ and +field_name+
161
194
  # @param height [Integer] the height of field for image field
162
195
  # @param width [Integer] the width of field for image field
163
196
  # @params custom_link [String] the custom link for field
@@ -207,21 +240,29 @@ module CmAdmin
207
240
  # @param page_title [String] the title of page
208
241
  # @param page_description [String] the description of page
209
242
  # @param display_name [String] the display name of action
210
- # @param verb [String] the verb of action, `get`, `post`, `put`, `patch` or `delete`
243
+ # @param verb [String] the verb of action, +get+, +post+, +put+, +patch+ or +delete+
211
244
  # @param layout [String] the layout of action
212
- # @param layout_type [String] the layout type of action, `'cm_association_index'`, `'cm_association_show'`
245
+ # @param layout_type [String] the layout type of action, +cm_association_index+, +cm_association_show+
213
246
  # @param partial [String] the partial path of action
214
247
  # @param path [String] the path of action
215
- # @param display_type [Symbol] the display type of action, `:button`, `:modal`
248
+ # @param display_type [Symbol] the display type of action, +:button+, +:modal+
216
249
  # @param modal_configuration [Hash] the configuration of modal
217
250
  # @param url_params [Hash] the url params of action
218
251
  # @param display_if [Proc] A lambda that takes the current object and return true or false
219
- # @param route_type [String] the route type of action, `member`, `collection`
252
+ # @param route_type [String] the route type of action, +member+, +collection+
220
253
  # @param icon_name [String] the icon name of action, follow font-awesome icon name
221
254
  # @example Creating a custom action with modal
222
- # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :modal, display_if: lambda(&:draft?), modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' }
255
+ # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :modal, display_if: lambda(&:draft?), modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' } do
256
+ # post = ::Post.find(params[:id])
257
+ # post.approved!
258
+ # post
259
+ # end
223
260
  # @example Creating a custom action with button
224
- # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :button, display_if: lambda(&:draft?)
261
+ # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :button, display_if: lambda(&:draft?) do
262
+ # post = ::Post.find(params[:id])
263
+ # post.approved!
264
+ # post
265
+ # end
225
266
  def custom_action(name: nil, page_title: nil, page_description: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, modal_configuration: {}, url_params: {}, display_if: ->(_arg) { true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
226
267
  action = CmAdmin::Models::CustomAction.new(
227
268
  page_title:, page_description:,
@@ -240,13 +281,17 @@ module CmAdmin
240
281
  # @param display_if [Proc] A lambda that takes the current object and return true or false
241
282
  # @param redirection_url [String] the redirection url of action
242
283
  # @param icon_name [String] the icon name of action, follow font-awesome icon name
243
- # @param verb [String] the verb of action, `get`, `post`, `put`, `patch` or `delete`
244
- # @param display_type [Symbol] the display type of action, `:page`, `:modal`
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+
245
286
  # @param modal_configuration [Hash] the configuration of modal
246
- # @param route_type [String] the route type of action, `member`, `collection`
287
+ # @param route_type [String] the route type of action, +member+, +collection+
247
288
  # @param partial [String] the partial path of action
248
289
  # @example Creating a bulk action
249
- # bulk_action name: 'approve', display_name: 'Approve', display_if: lambda { |arg| arg.draft? }, redirection_url: '/posts', icon_name: 'fa-regular fa-circle-check', verb: :patch, display_type: :modal, modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' }
290
+ # bulk_action name: 'approve', display_name: 'Approve', display_if: lambda { |arg| arg.draft? }, redirection_url: '/posts', icon_name: 'fa-regular fa-circle-check', verb: :patch, display_type: :modal, modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' } do
291
+ # posts = ::Post.where(id: params[:ids])
292
+ # posts.each(&:approved!)
293
+ # posts
294
+ # end
250
295
  def bulk_action(name: nil, display_name: nil, display_if: ->(_arg) { true }, redirection_url: nil, icon_name: nil, verb: nil, display_type: nil, modal_configuration: {}, route_type: nil, partial: nil, &block)
251
296
  bulk_action = CmAdmin::Models::BulkAction.new(
252
297
  name:, display_name:, display_if:, modal_configuration:,
@@ -258,7 +303,7 @@ module CmAdmin
258
303
 
259
304
  # Create a new filter for model
260
305
  # @param db_column_name [String] the name of column
261
- # @param filter_type [String] the type of filter, :date, :multi_select, :range, :search, :single_select
306
+ # @param filter_type [String] the type of filter, +:date+, +:multi_select+, +:range+, +:search+, +:single_select+
262
307
  # @param placeholder [String] the placeholder of filter
263
308
  # @param helper_method [String] the helper method for filter, should be defined in custom_helper.rb file
264
309
  # @param filter_with [Symbol] filter with scope name on model
@@ -268,12 +313,13 @@ module CmAdmin
268
313
  # filter('created_at', :date)
269
314
  # filter('status', :single_select, collection: ['draft', 'published'])
270
315
  # filter('status', :multi_select, helper_method: 'status_collection')
316
+ # filter('age', :range)
271
317
  def filter(db_column_name, filter_type, options = {})
272
318
  @filters << CmAdmin::Models::Filter.new(db_column_name:, filter_type:, options:)
273
319
  end
274
320
 
275
321
  # Set sort direction for filters
276
- # @param direction [Symbol] the direction of sort, `:asc`, `:desc`
322
+ # @param direction [Symbol] the direction of sort, +:asc+, +:desc+
277
323
  # @example Setting sort direction
278
324
  # sort_direction(:asc)
279
325
  def sort_direction(direction = :desc)
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.5.40'
2
+ VERSION = '1.5.41'
3
3
  end
@@ -87,6 +87,7 @@ module CmAdmin
87
87
  ar_object.send(field.field_name).to_s.titleize
88
88
  when :tag
89
89
  tag_class = field.tag_class.dig("#{ar_object.send(field.field_name.to_s)}".to_sym).to_s
90
+ tag_class = 'neutral' if tag_class.blank?
90
91
  content_tag :span, class: "status-tag #{tag_class}" do
91
92
  ar_object.send(field.field_name).to_s.titleize.upcase
92
93
  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: 1.5.40
4
+ version: 1.5.41
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-07-25 00:00:00.000000000 Z
17
+ date: 2024-08-01 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails
@@ -142,20 +142,6 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: 5.4.3
145
- - !ruby/object:Gem::Dependency
146
- name: yard
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - ">="
150
- - !ruby/object:Gem::Version
151
- version: '0'
152
- type: :runtime
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- version: '0'
159
145
  - !ruby/object:Gem::Dependency
160
146
  name: importmap-rails
161
147
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +207,7 @@ files:
221
207
  - app/assets/javascripts/cm_admin/bulk_actions.js
222
208
  - app/assets/javascripts/cm_admin/cocoon.js
223
209
  - app/assets/javascripts/cm_admin/custom.js
210
+ - app/assets/javascripts/cm_admin/custom_action.js
224
211
  - app/assets/javascripts/cm_admin/exports.js
225
212
  - app/assets/javascripts/cm_admin/filters.js
226
213
  - app/assets/javascripts/cm_admin/form_validation.js
@@ -506,7 +493,7 @@ licenses:
506
493
  metadata:
507
494
  homepage_uri: https://github.com/commutatus/cm-admin
508
495
  source_code_uri: https://github.com/commutatus/cm-admin
509
- post_install_message:
496
+ post_install_message:
510
497
  rdoc_options: []
511
498
  require_paths:
512
499
  - lib
@@ -521,8 +508,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
521
508
  - !ruby/object:Gem::Version
522
509
  version: '0'
523
510
  requirements: []
524
- rubygems_version: 3.0.9
525
- signing_key:
511
+ rubygems_version: 3.5.11
512
+ signing_key:
526
513
  specification_version: 4
527
514
  summary: CmAdmin is a robust gem designed to assist in creating admin panels for Rails
528
515
  applications