cm-admin 1.5.40 → 1.5.42
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 +4 -4
- data/Gemfile.lock +1 -3
- data/README.md +8 -2
- data/app/assets/javascripts/cm_admin/application.js +11 -11
- data/app/assets/javascripts/cm_admin/custom_action.js +30 -0
- data/app/assets/javascripts/cm_admin/filters.js +2 -3
- data/app/assets/javascripts/cm_admin/form_validation.js +0 -10
- data/app/controllers/cm_admin/resource_controller.rb +11 -0
- data/app/javascript/packs/cm_admin/application.js +25 -28
- data/app/views/cm_admin/main/_actions_dropdown.html.slim +2 -2
- data/app/views/layouts/_custom_action_modal.html.slim +1 -1
- data/app/views/layouts/_custom_action_modals.html.slim +8 -7
- data/cm_admin.gemspec +0 -1
- data/config/routes.rb +1 -1
- data/lib/cm_admin/constants.rb +4 -0
- data/lib/cm_admin/models/dsl_method.rb +68 -22
- data/lib/cm_admin/models/form_field.rb +1 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/field_display_helper.rb +1 -0
- data/lib/cm_admin/view_helpers/form_field_helper.rb +53 -89
- data/lib/cm_admin/view_helpers/form_helper.rb +1 -1
- metadata +7 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d1608feb2a0f90e9e8e8202d8898e511a1e1bbb4bc463e0a327190eeedb27a
|
4
|
+
data.tar.gz: 7a2ccc290b1545db664634cb915f81a8dca27630c024e38cbbb9fbf1898cee72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15783cf2216b6390a976eeacc314f5a89b0b696ee777648c2e8bcd9e58fff27e625b1b5f29336d0ac31327833e148b5fb8c563b984df79e1e8d5c321ba27b23a
|
7
|
+
data.tar.gz: 2d3672c631061c354c3e2b72589ceb8b4e5d42f81b3efd9eed9f8b55a743336d434c4ea826bd3a66c3befb11bc770a8c647ddf879c9b86fa1c10296f4c2d265f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cm-admin (1.5.
|
4
|
+
cm-admin (1.5.42)
|
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`.
|
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
|
2
|
-
import
|
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
|
+
});
|
@@ -42,9 +42,8 @@ var getFilteredData = function(filterType, filterValue, filterColumn=null) {
|
|
42
42
|
// Generate the queryString by concatenating the filterParams and
|
43
43
|
// searchParams that are already applied, if searchParams are present.
|
44
44
|
var searchParams = window.location.search
|
45
|
-
var
|
46
|
-
|
47
|
-
if (tempsearchParamshash.length > 0) {
|
45
|
+
var searchParamsHash = getParamsAsObject(searchParams)
|
46
|
+
if (Object.keys(searchParamsHash).length > 0) {
|
48
47
|
// Delete the previous applied value for multi_select filter from the
|
49
48
|
// searchParams as altering the array with new and old value will create
|
50
49
|
// more complicated logic. The new value is passed and structured in
|
@@ -41,13 +41,3 @@ $(document).on("click", '[data-behaviour="form_submit"]', function (e) {
|
|
41
41
|
return $('[data-behaviour="form_submit"]').button("loading");
|
42
42
|
}
|
43
43
|
});
|
44
|
-
|
45
|
-
$(document).on("change", '[data-behaviour="multiple-checkbox"]', function (e) {
|
46
|
-
const inputField = e.target.previousElementSibling;
|
47
|
-
|
48
|
-
if (e.target.checked) {
|
49
|
-
inputField.setAttribute("disabled", "disabled");
|
50
|
-
} else {
|
51
|
-
inputField.removeAttribute("disabled");
|
52
|
-
}
|
53
|
-
});
|
@@ -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(
|
9
|
-
require("jgrowl")
|
10
|
-
require("trix")
|
11
|
-
require(
|
12
|
-
require(
|
13
|
-
require(
|
14
|
-
require(
|
15
|
-
require(
|
16
|
-
require(
|
17
|
-
require(
|
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
|
-
|
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
|
-
=
|
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
|
-
|
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
|
data/lib/cm_admin/constants.rb
CHANGED
@@ -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
|
11
|
+
# @param view_type [Symbol] view type of page +:table+, +:card+ or +:kanban+
|
12
12
|
# @example Index page
|
13
|
-
# cm_index
|
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
|
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
|
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: "
|
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: "
|
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,
|
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
|
-
#
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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
|
-
#
|
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
|
-
#
|
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,
|
244
|
-
# @param display_type [Symbol] the display type of action,
|
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,
|
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
|
-
#
|
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,
|
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,
|
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)
|
@@ -9,7 +9,7 @@ module CmAdmin
|
|
9
9
|
:placeholder, :display_if, :html_attrs, :target, :col_size, :ajax_url, :helper_text
|
10
10
|
|
11
11
|
VALID_INPUT_TYPES = %i[
|
12
|
-
integer decimal string single_select multi_select date date_time text switch custom_single_select
|
12
|
+
integer decimal string single_select multi_select date date_time text switch custom_single_select checkbox_group
|
13
13
|
single_file_upload multi_file_upload hidden rich_text check_box radio_button custom_string custom_date
|
14
14
|
].freeze
|
15
15
|
|
data/lib/cm_admin/version.rb
CHANGED
@@ -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
|
@@ -57,15 +57,15 @@ module CmAdmin
|
|
57
57
|
def cm_switch_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)\
|
58
58
|
content_tag :div, class: 'form-check form-switch' do
|
59
59
|
concat form_obj.check_box cm_field.field_name,
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
merge_wrapper_options(
|
61
|
+
{
|
62
|
+
class: "field-control form-check-input #{required_class}",
|
63
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
64
|
+
value:,
|
65
|
+
role: 'switch'
|
66
|
+
}, cm_field.html_attrs
|
67
|
+
)
|
68
|
+
concat content_tag(:div, cm_field.label, class: 'cm-switch-label')
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -239,12 +239,42 @@ module CmAdmin
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
def cm_check_box_field(form_obj, cm_field,
|
243
|
-
|
242
|
+
def cm_check_box_field(form_obj, cm_field, _value, required_class, target_action, _ajax_url)
|
243
|
+
content_tag :div, class: 'form-check' do
|
244
|
+
concat form_obj.check_box cm_field.field_name,
|
245
|
+
merge_wrapper_options(
|
246
|
+
{
|
247
|
+
class: "form-check-input #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
248
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
249
|
+
data: {
|
250
|
+
field_name: cm_field.field_name,
|
251
|
+
target_action: target_action&.name,
|
252
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
|
253
|
+
}
|
254
|
+
}, cm_field.html_attrs
|
255
|
+
)
|
256
|
+
concat content_tag(:div, cm_field.label, class: 'cm-checkbox-label')
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def cm_checkbox_group_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
261
|
+
original_value = form_obj.object.send(cm_field.field_name)
|
262
|
+
content_tag :div do
|
263
|
+
concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
|
264
|
+
value: nil, hidden: true
|
265
|
+
value.each do |key, val|
|
266
|
+
is_checked = original_value.include?(val)
|
267
|
+
concat format_check_box(val || key, key, form_obj, cm_field, required_class, is_checked)
|
268
|
+
end
|
269
|
+
end
|
244
270
|
end
|
245
271
|
|
246
|
-
def cm_radio_button_field(form_obj,
|
247
|
-
|
272
|
+
def cm_radio_button_field(form_obj, cm_field, value, _required_class, _target_action, _ajax_url)
|
273
|
+
content_tag :div do
|
274
|
+
value.each do |key, val|
|
275
|
+
concat format_radio_option(val || key, key, cm_field, form_obj)
|
276
|
+
end
|
277
|
+
end
|
248
278
|
end
|
249
279
|
|
250
280
|
def cm_hidden_field(form_obj, cm_field, value, _required_class, _target_action, _ajax_url)
|
@@ -269,89 +299,23 @@ module CmAdmin
|
|
269
299
|
end
|
270
300
|
end
|
271
301
|
|
272
|
-
def
|
273
|
-
|
274
|
-
|
275
|
-
else
|
276
|
-
content_tag :div, class: 'cm-checkbox-section' do
|
277
|
-
concat single_checkbox_tag(value, form_obj, cm_field, required_class, target_action)
|
278
|
-
concat content_tag(:div, cm_field.field_name.to_s.titleize, class: 'cm-checkbox-label')
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
def format_check_box_array(options, form_obj, cm_field, required_class, target_action)
|
284
|
-
content_tag :div do
|
285
|
-
options.each do |key, val|
|
286
|
-
concat format_check_box(val, key, form_obj, cm_field, required_class, target_action)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def format_check_box(val, key, form_obj, cm_field, required_class, target_action)
|
292
|
-
content_tag :div, class: 'cm-checkbox-section' do
|
293
|
-
concat format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
|
294
|
-
concat content_tag(:div, key, class: 'cm-checkbox-label')
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def single_checkbox_tag(value, form_obj, cm_field, required_class, target_action)
|
299
|
-
content_tag :div, class: 'cm-checkbox-tag' do
|
300
|
-
concat form_obj.check_box cm_field.field_name,
|
301
|
-
merge_wrapper_options(
|
302
|
-
{
|
303
|
-
class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
304
|
-
disabled: cm_field.disabled.call(form_obj.object),
|
305
|
-
data: {
|
306
|
-
field_name: cm_field.field_name,
|
307
|
-
target_action: target_action&.name,
|
308
|
-
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
|
309
|
-
}
|
310
|
-
}, cm_field.html_attrs
|
311
|
-
)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
def format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
|
316
|
-
content_tag :div, class: 'cm-checkbox-tag' do
|
317
|
-
if val.present?
|
318
|
-
concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]", value: '0', hidden: true, disabled: 'disabled'
|
319
|
-
else
|
320
|
-
concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]", value: '0', hidden: true
|
321
|
-
end
|
322
|
-
concat check_box_tag "#{@model.name.underscore}[#{cm_field.field_name}][]", '1', val,
|
302
|
+
def format_check_box(val, key, form_obj, cm_field, required_class, is_checked)
|
303
|
+
content_tag :div, class: 'form-check' do
|
304
|
+
concat check_box_tag "#{@model.name.underscore}[#{cm_field.field_name}][]", val, is_checked,
|
323
305
|
merge_wrapper_options(
|
324
306
|
{
|
325
|
-
class: "
|
326
|
-
disabled: cm_field.disabled.call(form_obj.object)
|
327
|
-
data: {
|
328
|
-
behaviour: 'multiple-checkbox',
|
329
|
-
target_action: target_action&.name,
|
330
|
-
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path", ':param_1') : ''
|
331
|
-
}
|
307
|
+
class: "form-check-input #{required_class}",
|
308
|
+
disabled: cm_field.disabled.call(form_obj.object)
|
332
309
|
}, cm_field.html_attrs
|
333
310
|
)
|
311
|
+
concat content_tag(:div, key, class: 'cm-checkbox-label')
|
334
312
|
end
|
335
313
|
end
|
336
314
|
|
337
|
-
def
|
338
|
-
content_tag :div do
|
339
|
-
|
340
|
-
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def format_radio_option(val, key, form_obj)
|
346
|
-
content_tag :div, class: 'cm-radio-section' do
|
347
|
-
concat format_radio_button(val, form_obj)
|
348
|
-
concat content_tag(:div, key, class: 'cm-radio-label')
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
def format_radio_button(val, form_obj)
|
353
|
-
content_tag :div, class: 'cm-radio-tag' do
|
354
|
-
concat form_obj.radio_button :level, val, class: 'field-control cm-radio'
|
315
|
+
def format_radio_option(val, key, cm_field, form_obj)
|
316
|
+
content_tag :div, class: 'form-check' do
|
317
|
+
concat form_obj.radio_button cm_field.field_name, val, merge_wrapper_options({ class: 'form-check-input' }, cm_field.html_attrs)
|
318
|
+
concat content_tag(:div, key, class: 'form-check-label')
|
355
319
|
end
|
356
320
|
end
|
357
321
|
|
@@ -112,7 +112,7 @@ module CmAdmin
|
|
112
112
|
concat input_field_for_column(form_obj, field)
|
113
113
|
else
|
114
114
|
concat(content_tag(:div, class: "form-field #{field.disabled ? 'disabled' : ''}") do
|
115
|
-
if field.label
|
115
|
+
if field.label && %i[check_box switch].exclude?(field.input_type)
|
116
116
|
concat form_obj.label field.label, field.label, class: 'field-label'
|
117
117
|
concat tag.br
|
118
118
|
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.
|
4
|
+
version: 1.5.42
|
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-
|
17
|
+
date: 2024-08-05 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.
|
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
|