cm-admin 0.4.2 → 0.5.2
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 +2 -4
- data/README.md +2 -23
- data/app/assets/stylesheets/cm_admin/base/common.scss +1 -1
- data/app/assets/stylesheets/cm_admin/base/form.scss +0 -1
- data/app/assets/stylesheets/cm_admin/base/scaffold.scss +2 -0
- data/app/assets/stylesheets/cm_admin/cm_admin.css.scss +1 -0
- data/app/assets/stylesheets/cm_admin/components/_status-tag.scss +5 -5
- data/app/assets/stylesheets/cm_admin/scaffold.scss +14 -0
- data/app/javascript/packs/cm_admin/application.js +1 -0
- data/app/javascript/stylesheets/cm_admin/application.scss +2 -1
- data/app/views/cm_admin/main/_associated_table.html.slim +2 -2
- data/app/views/cm_admin/main/_table.html.slim +17 -26
- data/app/views/cm_admin/main/_top_navbar.html.slim +13 -2
- data/app/views/cm_admin/main/associated_index.html.slim +2 -2
- data/app/views/cm_admin/main/edit.html.slim +10 -7
- data/app/views/layouts/_custom_action_modals.html.slim +9 -0
- data/app/views/layouts/_flash_message.html.slim +9 -0
- data/app/views/layouts/cm_admin.html.slim +8 -3
- data/cm_admin.gemspec +2 -2
- data/config/routes.rb +2 -2
- data/lib/cm_admin/constants.rb +3 -0
- data/lib/cm_admin/engine.rb +2 -0
- data/lib/cm_admin/model.rb +18 -2
- data/lib/cm_admin/models/action.rb +8 -2
- data/lib/cm_admin/models/controller_method.rb +3 -2
- data/lib/cm_admin/models/custom_action.rb +13 -0
- data/lib/cm_admin/models/dsl_method.rb +17 -4
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/field_display_helper.rb +7 -1
- data/lib/cm_admin/view_helpers/form_helper.rb +2 -2
- data/lib/cm_admin/view_helpers/page_info_helper.rb +7 -2
- data/package.json +1 -0
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- data/yarn.lock +17 -12
- metadata +9 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee189fda2ffbbbebebbf187b269408ae2b95a17e8373133fe5d0a8046abc4375
|
|
4
|
+
data.tar.gz: e6a788a92b95d4492dc86cbdcdc6abd518d3a361f802a88449ed923ebf02cc72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4eff826866357c66a2ff35980f3ef2a66576649b4c9285442f045986ee2a9435fb96dfa7f0761fe6b61df2f26941e62b13385d4aa6c7546808f5736d08437ae3
|
|
7
|
+
data.tar.gz: 281ba123d2514c2f51abe820f7f16eee2448b5efcea11ee06acee96b2ac3851663ff836a05cfe91b704f49e11f4c28c0e3490c1cf5ee4076cc68724b22b6c728
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cm-admin (0.
|
|
4
|
+
cm-admin (0.4.2)
|
|
5
5
|
axlsx_rails (~> 0.6.1)
|
|
6
6
|
cocoon (~> 1.2.15)
|
|
7
7
|
pagy (~> 4.11.0)
|
|
@@ -52,10 +52,8 @@ GEM
|
|
|
52
52
|
nokogiri (>= 1.5.9)
|
|
53
53
|
marcel (1.0.2)
|
|
54
54
|
method_source (1.0.0)
|
|
55
|
-
mini_portile2 (2.6.1)
|
|
56
55
|
minitest (5.14.4)
|
|
57
|
-
nokogiri (1.12.5)
|
|
58
|
-
mini_portile2 (~> 2.6.1)
|
|
56
|
+
nokogiri (1.12.5-x86_64-darwin)
|
|
59
57
|
racc (~> 1.4)
|
|
60
58
|
pagy (4.11.0)
|
|
61
59
|
racc (1.5.2)
|
data/README.md
CHANGED
|
@@ -7,7 +7,7 @@ New CmAdmin gem
|
|
|
7
7
|
Add this line to your application's Gemfile:
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
|
-
gem '
|
|
10
|
+
gem 'cm-admin'
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
And then execute:
|
|
@@ -16,7 +16,7 @@ And then execute:
|
|
|
16
16
|
|
|
17
17
|
Or install it yourself as:
|
|
18
18
|
|
|
19
|
-
$ gem install
|
|
19
|
+
$ gem install cm-admin
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
@@ -24,27 +24,6 @@ Install the gem
|
|
|
24
24
|
|
|
25
25
|
$ rails g cm_admin:install
|
|
26
26
|
|
|
27
|
-
For generating the index page views
|
|
28
|
-
|
|
29
|
-
$ rails g cm_admin:view products index title description
|
|
30
|
-
|
|
31
|
-
For generating the show page views
|
|
32
|
-
|
|
33
|
-
$ rails g cm_admin:view products show title description
|
|
34
|
-
|
|
35
|
-
For generating the form page views
|
|
36
|
-
$ rails g cm_admin:view products form column_name:field_type
|
|
37
|
-
$ rails g cm_admin:view products form title:string description:string
|
|
38
|
-
|
|
39
|
-
Following field types are acceted
|
|
40
|
-
|
|
41
|
-
* input-integer
|
|
42
|
-
* input-string
|
|
43
|
-
* single-select
|
|
44
|
-
* multi-select
|
|
45
|
-
* checkbox
|
|
46
|
-
* radio
|
|
47
|
-
|
|
48
27
|
## Usage
|
|
49
28
|
|
|
50
29
|
For demo check [here](http://cm-admin.labs.commutatus.com/admin/users/)
|
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
font-size: $t4-text;
|
|
5
5
|
line-height: 22px;
|
|
6
6
|
padding: 4px;
|
|
7
|
-
&.default-
|
|
7
|
+
&.default-0 {
|
|
8
8
|
color: $primary-text-clr;
|
|
9
9
|
background: $grey-lighter-clr;
|
|
10
10
|
}
|
|
11
|
-
&.
|
|
11
|
+
&.default-1 {
|
|
12
12
|
color: $green-regular-clr;
|
|
13
13
|
background: $green-lightest-clr;
|
|
14
14
|
}
|
|
15
|
-
&.
|
|
15
|
+
&.default-2 {
|
|
16
16
|
color: $yellow-regular-clr;
|
|
17
17
|
background: $yellow-lightest-clr;
|
|
18
18
|
}
|
|
19
|
-
&.
|
|
19
|
+
&.default-3 {
|
|
20
20
|
color: $red-regular-clr;
|
|
21
21
|
background: $red-lightest-clr;
|
|
22
22
|
}
|
|
23
|
-
&.
|
|
23
|
+
&.default-4 {
|
|
24
24
|
color: $blue-regular-clr;
|
|
25
25
|
background: $blue-lightest-clr;
|
|
26
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.admin-table-index
|
|
2
2
|
.table-top
|
|
3
|
-
p.table-top__total-count = "#{@associated_ar_object.pagy.count} #{@associated_model
|
|
3
|
+
p.table-top__total-count = "#{@associated_ar_object.pagy.count} #{@associated_model&.ar_model&.table_name} found"
|
|
4
4
|
.table-top__column-action
|
|
5
5
|
button.secondary-btn.column-btn data-target="#columnActionModal" data-toggle="modal" type="button"
|
|
6
6
|
span
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
input.cm-checkbox type="checkbox"
|
|
26
26
|
- @model.available_fields[@action.name.to_sym].each do |column|
|
|
27
27
|
td
|
|
28
|
-
span class="#{column.cm_css_class}" = show_field_value(ar_object, column)
|
|
28
|
+
span class="#{column.cm_css_class} text-ellipsis" = show_field_value(ar_object, column)
|
|
29
29
|
td.row-action-cell
|
|
30
30
|
.row-action-tool
|
|
31
31
|
button.secondary-btn.tool-btn type="button"
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
.admin-table-index
|
|
2
2
|
.table-top
|
|
3
3
|
p.table-top__total-count = "#{@ar_object.pagy.count} #{@model.ar_model.table_name} found"
|
|
4
|
-
.table-top__column-action
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
// .table-top__column-action
|
|
5
|
+
// button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
|
|
6
|
+
// span
|
|
7
|
+
// i.fa.fa-columns.bolder
|
|
8
|
+
// span
|
|
9
|
+
// i.fa.fa-angle-down
|
|
11
10
|
.new-admin-table.scrollable
|
|
12
11
|
table.cm-table
|
|
13
12
|
thead.cm-table__header
|
|
@@ -23,9 +22,13 @@
|
|
|
23
22
|
td.check-box-space
|
|
24
23
|
span
|
|
25
24
|
input.cm-checkbox type="checkbox"
|
|
26
|
-
- @model.available_fields[:index].
|
|
27
|
-
td
|
|
28
|
-
span class="#{column.cm_css_class}"
|
|
25
|
+
- @model.available_fields[:index].each_with_index do |column, index|
|
|
26
|
+
td.text-ellipsis
|
|
27
|
+
span class="#{column.cm_css_class}"
|
|
28
|
+
- if index == 0
|
|
29
|
+
= link_to ar_object.send(column.field_name), "/cm_admin/#{ar_object.model_name.collection}/#{ar_object.id}"
|
|
30
|
+
- else
|
|
31
|
+
= show_field_value(ar_object, column)
|
|
29
32
|
td.row-action-cell
|
|
30
33
|
.row-action-tool
|
|
31
34
|
button.secondary-btn.tool-btn type="button"
|
|
@@ -37,22 +40,10 @@
|
|
|
37
40
|
.popup-option
|
|
38
41
|
a href="#{page_url('edit', ar_object)}"
|
|
39
42
|
| Edit
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/ i.fa.fa-angle-double-left.bolder.f14
|
|
45
|
-
/ span.page-move-btn.disabled
|
|
46
|
-
/ i.fa.fa-chevron-left.bolder
|
|
47
|
-
/ span.page-num-btn.active 1
|
|
48
|
-
/ span.page-num-btn 2
|
|
49
|
-
/ span.page-num-btn 3
|
|
50
|
-
/ span.page-num-btn 4
|
|
51
|
-
/ span.page-num-btn 5
|
|
52
|
-
/ span.page-move-btn
|
|
53
|
-
/ i.fa.fa-chevron-right.bolder
|
|
54
|
-
/ span.page-move-btn
|
|
55
|
-
/ i.fa.fa-angle-double-right.bolder.f14
|
|
43
|
+
- @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
|
44
|
+
- if custom_action.display_if.call(ar_object)
|
|
45
|
+
.popup-option
|
|
46
|
+
= link_to custom_action.name, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
|
|
56
47
|
|
|
57
48
|
.cm-pagination
|
|
58
49
|
.cm-pagination__lhs Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
.nav-title-area
|
|
6
6
|
p.title-text = action_title
|
|
7
7
|
p.title-sub-text = action_description
|
|
8
|
-
-
|
|
9
|
-
.
|
|
8
|
+
.cm-navbar__rhs
|
|
9
|
+
- if @model.current_action.name == 'index'
|
|
10
10
|
.export-container
|
|
11
11
|
.dropdown
|
|
12
12
|
button.secondary-btn data-bs-toggle='dropdown'
|
|
@@ -23,3 +23,14 @@
|
|
|
23
23
|
|
|
24
24
|
a.primary-btn.ml-2 href="#{page_url('new')}"
|
|
25
25
|
| Add
|
|
26
|
+
- @model.available_actions.select{|act| act if act.route_type == 'collection'}.each do |custom_action|
|
|
27
|
+
- if custom_action.display_type == :button
|
|
28
|
+
= link_to custom_action.name.titleize, @model.ar_model.table_name + '/' + custom_action.path, class: 'primary-btn ml-2', method: custom_action.verb
|
|
29
|
+
- elsif custom_action.display_type == :modal
|
|
30
|
+
= link_to custom_action.name.titleize, '', class: 'primary-btn ml-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal" }
|
|
31
|
+
- elsif @model.current_action.name == 'show'
|
|
32
|
+
- @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
|
33
|
+
- if custom_action.display_type == :button && custom_action.display_if.call(@ar_object)
|
|
34
|
+
= link_to custom_action.name.titleize, custom_action.path.gsub(':id', params[:id]), class: 'primary-btn ml-2', method: custom_action.verb
|
|
35
|
+
- elsif custom_action.display_type == :modal && custom_action.display_if.call(@ar_object)
|
|
36
|
+
= link_to custom_action.name.titleize, '', class: 'primary-btn ml-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal" }
|
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
.form-page
|
|
3
3
|
.form-page__inner
|
|
4
4
|
.form-wrapper
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- if @ar_object.errors.present?
|
|
6
|
+
.flag-alert.mb-4
|
|
7
|
+
p.alert-header
|
|
7
8
|
span
|
|
8
9
|
i.fa.fa-exclamation-triangle
|
|
9
10
|
| Attention
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
.alert-body
|
|
12
|
+
p.body-title
|
|
13
|
+
| Error heading
|
|
14
|
+
p.body-info
|
|
15
|
+
ul
|
|
16
|
+
- @ar_object.errors.full_messages.each do |error_message|
|
|
17
|
+
li = error_message
|
|
15
18
|
.form-container
|
|
16
19
|
p.form-title
|
|
17
20
|
| Section heading
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
- @model.available_actions.select{|act| act if act.route_type == 'collection' && act.display_type == :modal}.each do |custom_action|
|
|
2
|
+
.modal.fade id="#{custom_action.name.classify}Modal" aria-hidden="true" aria-labelledby="exampleModalLabel" tabindex="1"
|
|
3
|
+
.modal-dialog
|
|
4
|
+
.modal-content
|
|
5
|
+
.modal-header
|
|
6
|
+
h5#exampleModalLabel.modal-title = custom_action.name.classify
|
|
7
|
+
button.btn-close aria-label="Close" data-bs-dismiss="modal" type="button"
|
|
8
|
+
.modal-body
|
|
9
|
+
= render partial: custom_action.partial
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
- if flash[:notice].present?
|
|
2
|
+
javascript:
|
|
3
|
+
$.jGrowl("#{flash[:notice]}", {theme: 'notice'})
|
|
4
|
+
- elsif flash[:success].present?
|
|
5
|
+
javascript:
|
|
6
|
+
$.jGrowl("#{flash[:success]}", {theme: 'success'})
|
|
7
|
+
- elsif flash[:alert].present?
|
|
8
|
+
javascript:
|
|
9
|
+
$.jGrowl("#{flash[:alert]}", {theme: 'error'})
|
|
@@ -10,6 +10,8 @@ html
|
|
|
10
10
|
= stylesheet_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
|
|
11
11
|
link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /
|
|
12
12
|
= javascript_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
|
|
13
|
+
= javascript_include_tag 'cm_admin/custom', 'data-turbolinks-track': 'reload'
|
|
14
|
+
= stylesheet_link_tag 'cm_admin/custom', media: 'all', 'data-turbolinks-track': 'reload'
|
|
13
15
|
script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"
|
|
14
16
|
script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"
|
|
15
17
|
body
|
|
@@ -19,7 +21,7 @@ html
|
|
|
19
21
|
.cm-admin
|
|
20
22
|
= render 'layouts/left_sidebar_nav'
|
|
21
23
|
.panel-area
|
|
22
|
-
- if defined?(@action) && @action&.layout_type.to_s == 'cm_association_show'
|
|
24
|
+
- if defined?(@action) && (@action&.layout_type.to_s == 'cm_association_show' || @action.parent == "show")
|
|
23
25
|
.show-page.page-container
|
|
24
26
|
.show-page__tabs.sticky-container
|
|
25
27
|
.cm-tabs-bar
|
|
@@ -27,15 +29,18 @@ html
|
|
|
27
29
|
== render 'cm_admin/main/tabs'
|
|
28
30
|
.show-page__inner.scrollable
|
|
29
31
|
= yield
|
|
30
|
-
- elsif defined?(@action) && @action&.layout_type.to_s == 'cm_association_index'
|
|
32
|
+
- elsif defined?(@action) && (@action&.layout_type.to_s == 'cm_association_index' || @action.parent == "index")
|
|
31
33
|
.show-page.page-container
|
|
32
34
|
.show-page__tabs.sticky-container
|
|
33
35
|
.cm-tabs-bar
|
|
34
36
|
== render 'cm_admin/main/top_navbar'
|
|
35
37
|
== render 'cm_admin/main/tabs'
|
|
36
|
-
- if @associated_model.filters.present?
|
|
38
|
+
- if @associated_model && @associated_model.filters.present?
|
|
37
39
|
.index-page__filters
|
|
38
40
|
== render partial: 'cm_admin/main/filters', locals: { filters: @associated_model.filters }
|
|
39
41
|
= yield
|
|
40
42
|
- else
|
|
41
43
|
= yield
|
|
44
|
+
= render 'layouts/flash_message'
|
|
45
|
+
= render 'layouts/custom_action_modals'
|
|
46
|
+
|
data/cm_admin.gemspec
CHANGED
|
@@ -3,8 +3,8 @@ require_relative 'lib/cm_admin/version'
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "cm-admin"
|
|
5
5
|
spec.version = CmAdmin::VERSION
|
|
6
|
-
spec.authors = ["sajinmp", "anbublacky", "
|
|
7
|
-
spec.email = ["sajinprasadkm@gmail.com", "anbublacky@gmail.com"]
|
|
6
|
+
spec.authors = ["sajinmp", "anbublacky", "AdityaTiwari2102"]
|
|
7
|
+
spec.email = ["sajinprasadkm@gmail.com", "anbublacky@gmail.com", "taditya.tiwari007@gmail.com"]
|
|
8
8
|
|
|
9
9
|
spec.summary = %q{This is an admin panel gem}
|
|
10
10
|
spec.description = %q{This is an admin panel gem}
|
data/config/routes.rb
CHANGED
|
@@ -10,9 +10,9 @@ CmAdmin::Engine.routes.draw do
|
|
|
10
10
|
|
|
11
11
|
# Defining action routes for each model
|
|
12
12
|
CmAdmin.cm_admin_models.each do |model|
|
|
13
|
-
model.available_actions.each do |act|
|
|
13
|
+
model.available_actions.sort_by {|act| act.class}.each do |act|
|
|
14
14
|
scope model.name.tableize do
|
|
15
|
-
send(act.verb, act.path.present? ? act.path : act.name, to: "#{model.name.underscore}##{act.name}")
|
|
15
|
+
send(act.verb, act.path.present? ? act.path : act.name, to: "#{model.name.underscore}##{act.name}", as: "#{model.name.underscore}_#{act.name}")
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/cm_admin/constants.rb
CHANGED
data/lib/cm_admin/engine.rb
CHANGED
data/lib/cm_admin/model.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative 'constants'
|
|
2
2
|
require_relative 'models/action'
|
|
3
|
+
require_relative 'models/custom_action'
|
|
3
4
|
require_relative 'models/field'
|
|
4
5
|
require_relative 'models/form_field'
|
|
5
6
|
require_relative 'models/blocks'
|
|
@@ -91,7 +92,6 @@ module CmAdmin
|
|
|
91
92
|
# If model is User, controller will be UsersController
|
|
92
93
|
def define_controller
|
|
93
94
|
klass = Class.new(CmAdmin::ApplicationController) do
|
|
94
|
-
|
|
95
95
|
$available_actions.each do |action|
|
|
96
96
|
define_method action.name.to_sym do
|
|
97
97
|
|
|
@@ -99,8 +99,10 @@ module CmAdmin
|
|
|
99
99
|
@model = CmAdmin::Model.find_by(name: controller_name.classify)
|
|
100
100
|
@model.params = params
|
|
101
101
|
@action = CmAdmin::Models::Action.find_by(@model, name: action_name)
|
|
102
|
-
@ar_object = @model.try(action_name, params)
|
|
102
|
+
@ar_object = @model.try(@action.parent || action_name, params)
|
|
103
103
|
@ar_object, @associated_model, @associated_ar_object = @model.custom_controller_action(action_name, params.permit!) if !@ar_object.present? && params[:id].present?
|
|
104
|
+
aar_model = request.url.split('/')[-2].classify.constantize if params[:aar_id]
|
|
105
|
+
@associated_ar_object = aar_model.find(params[:aar_id]) if params[:aar_id]
|
|
104
106
|
nested_tables = @model.available_fields[:new].except(:fields).keys
|
|
105
107
|
nested_tables += @model.available_fields[:edit].except(:fields).keys
|
|
106
108
|
@reflections = @model.ar_model.reflect_on_all_associations
|
|
@@ -125,6 +127,20 @@ module CmAdmin
|
|
|
125
127
|
else
|
|
126
128
|
format.html { render '/cm_admin/main/new' }
|
|
127
129
|
end
|
|
130
|
+
elsif action.action_type == :custom
|
|
131
|
+
if action.child_records
|
|
132
|
+
format.html { render action.layout }
|
|
133
|
+
elsif action.display_type == :page
|
|
134
|
+
data = @action.parent == "index" ? @ar_object.data : @ar_object
|
|
135
|
+
format.html { render action.partial }
|
|
136
|
+
else
|
|
137
|
+
redirect_url = request.referrer || "/cm_admin/#{@model.ar_model.table_name}/#{@ar_object.id}"
|
|
138
|
+
if @action.code_block.call(@ar_object)
|
|
139
|
+
format.html { redirect_to redirect_url }
|
|
140
|
+
else
|
|
141
|
+
format.html { redirect_to redirect_url }
|
|
142
|
+
end
|
|
143
|
+
end
|
|
128
144
|
elsif action.layout.present?
|
|
129
145
|
if request.xhr? && action.partial.present?
|
|
130
146
|
format.html { render partial: action.partial }
|
|
@@ -4,9 +4,11 @@ module CmAdmin
|
|
|
4
4
|
module Models
|
|
5
5
|
class Action
|
|
6
6
|
include Actions::Blocks
|
|
7
|
-
attr_accessor :name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
|
|
7
|
+
attr_accessor :name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
|
|
8
|
+
:child_records, :is_nested_field, :nested_table_name, :parent, :display_if, :route_type, :code_block,
|
|
9
|
+
:display_type, :action_type
|
|
8
10
|
|
|
9
|
-
def initialize(attributes = {})
|
|
11
|
+
def initialize(attributes = {}, &block)
|
|
10
12
|
if attributes[:layout_type].present? && attributes[:layout].nil? && attributes[:partial].nil?
|
|
11
13
|
case attributes[:layout_type]
|
|
12
14
|
when 'cm_association_index'
|
|
@@ -20,10 +22,14 @@ module CmAdmin
|
|
|
20
22
|
attributes.each do |key, value|
|
|
21
23
|
self.send("#{key.to_s}=", value)
|
|
22
24
|
end
|
|
25
|
+
self.send("code_block=", block) if block_given?
|
|
23
26
|
end
|
|
24
27
|
|
|
25
28
|
def set_default_values
|
|
26
29
|
self.is_nested_field = false
|
|
30
|
+
self.display_if = lambda { |arg| return true }
|
|
31
|
+
self.display_type = :button
|
|
32
|
+
self.action_type = :default
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
class << self
|
|
@@ -29,7 +29,8 @@ module CmAdmin
|
|
|
29
29
|
@ar_object.assign_attributes(resource_params(params))
|
|
30
30
|
@ar_object
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
|
|
33
34
|
def create(params)
|
|
34
35
|
@ar_object = @ar_model.new(resource_params(params))
|
|
35
36
|
end
|
|
@@ -64,7 +65,7 @@ module CmAdmin
|
|
|
64
65
|
nested_fields = nested_tables.map {|table|
|
|
65
66
|
Hash[
|
|
66
67
|
table.to_s + '_attributes',
|
|
67
|
-
table.to_s.
|
|
68
|
+
table.to_s.classify.constantize.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym) + [:id, :_destroy]
|
|
68
69
|
]
|
|
69
70
|
}
|
|
70
71
|
permittable_fields += nested_fields
|
|
@@ -3,6 +3,13 @@ module CmAdmin
|
|
|
3
3
|
module DslMethod
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
|
+
def cm_page(name: nil, partial: nil, path: nil, route_type: nil, page_title: nil, display_type: :button, &block)
|
|
7
|
+
action = CmAdmin::Models::CustomAction.new(name: name, verb: :get, partial: partial, path: path, route_type: route_type, display_type: display_type, &block)
|
|
8
|
+
@available_actions << action
|
|
9
|
+
# @available_actions << CmAdmin::Models::CustomAction.new(name: name, verb: 'get', layout: 'cm_admin', partial: partial, path: path, parent: self.current_action.name, route_type: route_type, page_title: page_title, display_type: display_type, &block)
|
|
10
|
+
# @current_action = CmAdmin::Models::CustomAction.find_by(self, name: name)
|
|
11
|
+
end
|
|
12
|
+
|
|
6
13
|
def cm_index(page_title: nil ,page_description: nil, &block)
|
|
7
14
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'index')
|
|
8
15
|
@current_action.page_title = page_title
|
|
@@ -49,7 +56,9 @@ module CmAdmin
|
|
|
49
56
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
|
|
50
57
|
@available_tabs << CmAdmin::Models::Tab.new(tab_name, '', &block)
|
|
51
58
|
else
|
|
52
|
-
action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/'+custom_action,
|
|
59
|
+
action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/'+custom_action,
|
|
60
|
+
layout_type: layout_type, layout: layout, partial: partial, child_records: associated_model,
|
|
61
|
+
action_type: :custom, display_type: :page)
|
|
53
62
|
@available_actions << action
|
|
54
63
|
@current_action = action
|
|
55
64
|
@available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, &block)
|
|
@@ -109,9 +118,13 @@ module CmAdmin
|
|
|
109
118
|
# end
|
|
110
119
|
# end
|
|
111
120
|
# end
|
|
112
|
-
def custom_action(name: nil, verb: nil, layout: nil, partial: nil, path: nil, &block)
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
def custom_action(name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, display_if: lambda { |arg| return true }, route_type: nil, &block)
|
|
122
|
+
action = CmAdmin::Models::CustomAction.new(
|
|
123
|
+
name: name, verb: verb, layout: layout, layout_type: layout_type, partial: partial, path: path,
|
|
124
|
+
parent: self.current_action.name, display_type: display_type, display_if: display_if,
|
|
125
|
+
action_type: :custom, route_type: route_type, &block)
|
|
126
|
+
@available_actions << action
|
|
127
|
+
# self.class.class_eval(&block)
|
|
115
128
|
end
|
|
116
129
|
|
|
117
130
|
def filter(db_column_name, filter_type, options={})
|
data/lib/cm_admin/version.rb
CHANGED
|
@@ -38,7 +38,13 @@ module CmAdmin
|
|
|
38
38
|
end
|
|
39
39
|
content_tag :a, href: link do
|
|
40
40
|
ar_object.send(field.field_name).to_s
|
|
41
|
-
end
|
|
41
|
+
end
|
|
42
|
+
when :enum
|
|
43
|
+
ar_object.send(field.field_name).to_s.titleize
|
|
44
|
+
when :tag
|
|
45
|
+
content_tag :span, class: "status-tag default-#{ar_object.send(field.field_name.to_s + '_before_type_cast')}" do
|
|
46
|
+
ar_object.send(field.field_name).to_s.titleize
|
|
47
|
+
end
|
|
42
48
|
when :attachment
|
|
43
49
|
concat show_attachment_value(ar_object, field)
|
|
44
50
|
end
|
|
@@ -22,7 +22,7 @@ module CmAdmin
|
|
|
22
22
|
|
|
23
23
|
def form_with_all_fields(resource, method)
|
|
24
24
|
columns = resource.class.columns.dup
|
|
25
|
-
table_name = resource.
|
|
25
|
+
table_name = resource.model_name.collection
|
|
26
26
|
columns.reject! { |i| REJECTABLE.include?(i.name) }
|
|
27
27
|
url = CmAdmin::Engine.mount_path + "/#{table_name}/#{resource.id}"
|
|
28
28
|
set_form_for_fields(resource, columns, url, method)
|
|
@@ -30,7 +30,7 @@ module CmAdmin
|
|
|
30
30
|
|
|
31
31
|
def form_with_mentioned_fields(resource, available_fields, method)
|
|
32
32
|
# columns = resource.class.columns.select { |i| available_fields.map(&:field_name).include?(i.name.to_sym) }
|
|
33
|
-
table_name = resource.
|
|
33
|
+
table_name = resource.model_name.collection
|
|
34
34
|
# columns.reject! { |i| REJECTABLE.include?(i.name) }
|
|
35
35
|
url = CmAdmin::Engine.mount_path + "/#{table_name}/#{resource.id}"
|
|
36
36
|
set_form_for_fields(resource, available_fields, url, method)
|
|
@@ -6,8 +6,10 @@ module CmAdmin
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def action_title
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
show_action = CmAdmin::Models::Action.find_by(@model, name: 'show')
|
|
10
|
+
title = @model.current_action.page_title || show_action.page_title
|
|
11
|
+
if title
|
|
12
|
+
title = (title.class == Symbol) ? @ar_object.send(title) : title
|
|
11
13
|
else
|
|
12
14
|
title = "#{@model.name}"
|
|
13
15
|
case action_name
|
|
@@ -24,8 +26,11 @@ module CmAdmin
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def action_description
|
|
29
|
+
show_action = CmAdmin::Models::Action.find_by(@model, name: 'show')
|
|
27
30
|
if @model.current_action.page_description
|
|
28
31
|
title = @model.current_action.page_description
|
|
32
|
+
elsif show_action.page_description
|
|
33
|
+
title = show_action.page_description
|
|
29
34
|
else
|
|
30
35
|
title = "#{@model.name}"
|
|
31
36
|
case action_name
|
data/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
b50f217278de15248bddb0b6f2e6be58edbffa7c
|
data/yarn.lock
CHANGED
|
@@ -3763,6 +3763,11 @@ jest-worker@^26.5.0:
|
|
|
3763
3763
|
merge-stream "^2.0.0"
|
|
3764
3764
|
supports-color "^7.0.0"
|
|
3765
3765
|
|
|
3766
|
+
jgrowl@^1.4.8:
|
|
3767
|
+
version "1.4.8"
|
|
3768
|
+
resolved "https://registry.yarnpkg.com/jgrowl/-/jgrowl-1.4.8.tgz#4ba40ffb93757a7e1d9b262d916be299d03df3a4"
|
|
3769
|
+
integrity sha512-JFi609DhWhD4wbnt1/NvYqt702SncgBk2SFssUi6GEUfnxM5TQ9YAKHP/kODwch7Q6QVhOWYvk1QCxLtujwRog==
|
|
3770
|
+
|
|
3766
3771
|
jquery@>=1.10, jquery@^3.3.1, jquery@^3.6.0:
|
|
3767
3772
|
version "3.6.0"
|
|
3768
3773
|
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
|
|
@@ -5384,9 +5389,9 @@ postcss-values-parser@^2.0.0, postcss-values-parser@^2.0.1:
|
|
|
5384
5389
|
uniq "^1.0.1"
|
|
5385
5390
|
|
|
5386
5391
|
postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0.6:
|
|
5387
|
-
version "7.0.
|
|
5388
|
-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.
|
|
5389
|
-
integrity sha512-
|
|
5392
|
+
version "7.0.36"
|
|
5393
|
+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.36.tgz#056f8cffa939662a8f5905950c07d5285644dfcb"
|
|
5394
|
+
integrity sha512-BebJSIUMwJHRH0HAQoxN4u1CN86glsrwsW0q7T+/m44eXOUAxSNdHRkNZPYz5vVUbg17hFgOQDE7fZk7li3pZw==
|
|
5390
5395
|
dependencies:
|
|
5391
5396
|
chalk "^2.4.2"
|
|
5392
5397
|
source-map "^0.6.1"
|
|
@@ -6322,9 +6327,9 @@ tapable@^1.0.0, tapable@^1.1.3:
|
|
|
6322
6327
|
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==
|
|
6323
6328
|
|
|
6324
6329
|
tar@^6.0.2:
|
|
6325
|
-
version "6.1.
|
|
6326
|
-
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.
|
|
6327
|
-
integrity sha512-
|
|
6330
|
+
version "6.1.11"
|
|
6331
|
+
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621"
|
|
6332
|
+
integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==
|
|
6328
6333
|
dependencies:
|
|
6329
6334
|
chownr "^2.0.0"
|
|
6330
6335
|
fs-minipass "^2.0.0"
|
|
@@ -6584,9 +6589,9 @@ urix@^0.1.0:
|
|
|
6584
6589
|
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
|
|
6585
6590
|
|
|
6586
6591
|
url-parse@^1.4.3, url-parse@^1.5.1:
|
|
6587
|
-
version "1.5.
|
|
6588
|
-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.
|
|
6589
|
-
integrity sha512-
|
|
6592
|
+
version "1.5.3"
|
|
6593
|
+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862"
|
|
6594
|
+
integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==
|
|
6590
6595
|
dependencies:
|
|
6591
6596
|
querystringify "^2.1.1"
|
|
6592
6597
|
requires-port "^1.0.0"
|
|
@@ -6872,9 +6877,9 @@ wrappy@1:
|
|
|
6872
6877
|
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
|
6873
6878
|
|
|
6874
6879
|
ws@^6.2.1:
|
|
6875
|
-
version "6.2.
|
|
6876
|
-
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.
|
|
6877
|
-
integrity sha512-
|
|
6880
|
+
version "6.2.2"
|
|
6881
|
+
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e"
|
|
6882
|
+
integrity sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==
|
|
6878
6883
|
dependencies:
|
|
6879
6884
|
async-limiter "~1.0.0"
|
|
6880
6885
|
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cm-admin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sajinmp
|
|
8
8
|
- anbublacky
|
|
9
|
-
-
|
|
9
|
+
- AdityaTiwari2102
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: exe
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: pagy
|
|
@@ -86,6 +86,7 @@ description: This is an admin panel gem
|
|
|
86
86
|
email:
|
|
87
87
|
- sajinprasadkm@gmail.com
|
|
88
88
|
- anbublacky@gmail.com
|
|
89
|
+
- taditya.tiwari007@gmail.com
|
|
89
90
|
executables: []
|
|
90
91
|
extensions: []
|
|
91
92
|
extra_rdoc_files: []
|
|
@@ -125,6 +126,7 @@ files:
|
|
|
125
126
|
- app/assets/stylesheets/cm_admin/helpers/_mixins.scss
|
|
126
127
|
- app/assets/stylesheets/cm_admin/helpers/_variable.scss
|
|
127
128
|
- app/assets/stylesheets/cm_admin/helpers/index.scss
|
|
129
|
+
- app/assets/stylesheets/cm_admin/scaffold.scss
|
|
128
130
|
- app/controllers/cm_admin/application_controller.rb
|
|
129
131
|
- app/controllers/cm_admin/exports_controller.rb
|
|
130
132
|
- app/controllers/cm_admin/static_controller.rb
|
|
@@ -151,6 +153,8 @@ files:
|
|
|
151
153
|
- app/views/cm_admin/main/new.html.slim
|
|
152
154
|
- app/views/cm_admin/main/show.html.slim
|
|
153
155
|
- app/views/cm_admin/static/error_401.html.slim
|
|
156
|
+
- app/views/layouts/_custom_action_modals.html.slim
|
|
157
|
+
- app/views/layouts/_flash_message.html.slim
|
|
154
158
|
- app/views/layouts/_left_sidebar_nav.html.slim
|
|
155
159
|
- app/views/layouts/_quick_links.html.slim
|
|
156
160
|
- app/views/layouts/cm_admin.html.slim
|
|
@@ -179,6 +183,7 @@ files:
|
|
|
179
183
|
- lib/cm_admin/models/cm_show_section.rb
|
|
180
184
|
- lib/cm_admin/models/column.rb
|
|
181
185
|
- lib/cm_admin/models/controller_method.rb
|
|
186
|
+
- lib/cm_admin/models/custom_action.rb
|
|
182
187
|
- lib/cm_admin/models/dsl_method.rb
|
|
183
188
|
- lib/cm_admin/models/export.rb
|
|
184
189
|
- lib/cm_admin/models/field.rb
|
|
@@ -223,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
223
228
|
- !ruby/object:Gem::Version
|
|
224
229
|
version: '0'
|
|
225
230
|
requirements: []
|
|
226
|
-
rubygems_version: 3.
|
|
231
|
+
rubygems_version: 3.2.32
|
|
227
232
|
signing_key:
|
|
228
233
|
specification_version: 4
|
|
229
234
|
summary: This is an admin panel gem
|