cm-admin 0.4.4 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -21
- data/app/assets/stylesheets/cm_admin/base/table.scss +3 -4
- data/app/assets/stylesheets/cm_admin/scaffold.scss +10 -0
- data/app/views/cm_admin/main/_associated_table.html.slim +21 -19
- data/app/views/cm_admin/main/_nested_fields.html.slim +6 -5
- data/app/views/cm_admin/main/_nested_table_form.html.slim +3 -2
- data/app/views/cm_admin/main/_table.html.slim +12 -9
- data/app/views/cm_admin/main/_top_navbar.html.slim +13 -3
- data/app/views/cm_admin/main/associated_index.html.slim +2 -2
- data/app/views/layouts/_custom_action_modals.html.slim +9 -0
- data/app/views/layouts/cm_admin.html.slim +8 -4
- data/cm_admin.gemspec +2 -2
- data/config/routes.rb +2 -2
- data/lib/cm_admin/engine.rb +2 -0
- data/lib/cm_admin/model.rb +21 -8
- data/lib/cm_admin/models/action.rb +6 -2
- data/lib/cm_admin/models/controller_method.rb +1 -1
- data/lib/cm_admin/models/dsl_method.rb +16 -3
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_helper.rb +2 -2
- data/lib/cm_admin/view_helpers/navigation_helper.rb +19 -17
- data/lib/cm_admin/view_helpers/page_info_helper.rb +7 -2
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 590c14bc3ee438f00943ac40316aaf1e0850639a5eda8da1d4c73dec80b11963
|
4
|
+
data.tar.gz: df5b1269f85267cc86e123c15b950e50292396771cb83cc10dc27bb3337d7416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b530f87e1a584d25e43684491ddee0156d7544bcb31f13c8b4d53aedff611ff0ffae7fc4ea9898d5186f4a3453463d7d77b7ecf4f39bee8020fcb4c753f6e76
|
7
|
+
data.tar.gz: ec22d42e7c47f2755642a902821db15616378361b661b0a609d22fe5b678527ae6ddddf62d902ba0aa55fc647eb215bb4704df046f5b7bbf5625c1b7ffceaa2f
|
data/README.md
CHANGED
@@ -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/)
|
@@ -74,7 +74,6 @@
|
|
74
74
|
position: relative;
|
75
75
|
min-width: fit-content;
|
76
76
|
border-collapse: collapse;
|
77
|
-
white-space: nowrap;
|
78
77
|
border: 1px solid $grey-lighter-clr;
|
79
78
|
border-radius: $radius-8;
|
80
79
|
&__header {
|
@@ -222,7 +221,7 @@
|
|
222
221
|
box-shadow: inset 0px 1px 0px rgba(148, 151, 155, 0.15);
|
223
222
|
}
|
224
223
|
}
|
225
|
-
}
|
224
|
+
}
|
226
225
|
|
227
226
|
.columns-list {
|
228
227
|
.column-item {
|
@@ -266,7 +265,7 @@
|
|
266
265
|
}
|
267
266
|
}
|
268
267
|
}
|
269
|
-
}
|
268
|
+
}
|
270
269
|
}
|
271
270
|
|
272
271
|
.cm-pagination {
|
@@ -317,4 +316,4 @@
|
|
317
316
|
}
|
318
317
|
}
|
319
318
|
}
|
320
|
-
}
|
319
|
+
}
|
@@ -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
|
@@ -37,24 +37,26 @@
|
|
37
37
|
.popup-option
|
38
38
|
a href="#{page_url('edit', ar_object)}"
|
39
39
|
| Edit
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
56
|
-
|
40
|
+
- @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
41
|
+
- if custom_action.display_if.call(ar_object)
|
42
|
+
.popup-option
|
43
|
+
- if custom_action.display_type == :button
|
44
|
+
= link_to custom_action.name.titleize, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
|
45
|
+
- elsif custom_action.display_type == :modal
|
46
|
+
= link_to custom_action.name.titleize, '', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal-#{ar_object.id.to_s}" }
|
47
|
+
|
57
48
|
.cm-pagination
|
58
49
|
.cm-pagination__lhs Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
|
59
50
|
.cm-pagination__rhs
|
60
|
-
== render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
|
51
|
+
== render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
|
52
|
+
|
53
|
+
- @associated_ar_object.data.each do |ar_object|
|
54
|
+
- @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
55
|
+
.modal.fade id="#{custom_action.name.classify}Modal-#{ar_object.id.to_s}" aria-hidden="true" aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex="1"
|
56
|
+
.modal-dialog
|
57
|
+
.modal-content
|
58
|
+
.modal-header
|
59
|
+
h5.modal-title id="#{custom_action.name.classify}ModalLabel" = custom_action.name.classify
|
60
|
+
button.btn-close aria-label="Close" data-bs-dismiss="modal" type="button"
|
61
|
+
.modal-body
|
62
|
+
= render partial: custom_action.partial, locals: { ar_object: ar_object }
|
@@ -1,7 +1,8 @@
|
|
1
1
|
.nested-fields
|
2
2
|
- @model.available_fields[action_name.to_sym][assoc_name].each do |field|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
.row
|
4
|
+
.col-sm-10
|
5
|
+
= input_field_for_column(f, field)
|
6
|
+
.col-sm-2
|
7
|
+
- if @reflections.select {|x| x if x.name == assoc_name}.first.macro == :has_many
|
8
|
+
= link_to_remove_association "x", f
|
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
.nested-field-wrapper
|
2
|
+
label.field-label = table_name.to_s.titleize
|
2
3
|
= f.fields_for table_name do |record|
|
3
4
|
= render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: table_name }
|
4
5
|
- if @reflections.select {|x| x if x.name == table_name}.first.macro == :has_many
|
5
6
|
.links
|
6
|
-
= link_to_add_association "
|
7
|
+
= link_to_add_association "+ Add #{table_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: table_name }}
|
@@ -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].
|
25
|
+
- @model.available_fields[:index].each_with_index do |column, index|
|
27
26
|
td.text-ellipsis
|
28
|
-
span class="#{column.cm_css_class}"
|
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"
|
@@ -24,8 +24,18 @@
|
|
24
24
|
a.primary-btn.ml-2 href="#{page_url('new')}"
|
25
25
|
| Add
|
26
26
|
- @model.available_actions.select{|act| act if act.route_type == 'collection'}.each do |custom_action|
|
27
|
-
|
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" }
|
28
31
|
- elsif @model.current_action.name == 'show'
|
29
32
|
- @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
30
|
-
- if custom_action.display_if.call(@ar_object)
|
31
|
-
= link_to custom_action.name, custom_action.path.gsub(':id', params[:id]), class: 'primary-btn ml-2', method: custom_action.verb
|
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" }
|
37
|
+
|
38
|
+
- edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
|
39
|
+
- if edit_action.any?
|
40
|
+
a.primary-btn.ml-2 href="#{page_url('edit', @ar_object)}"
|
41
|
+
= "Edit #{@model.name}"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
- @model.available_actions.select{|act| act if act.display_type == :modal}.each do |custom_action|
|
2
|
+
.modal.fade id="#{custom_action.name.classify}Modal" aria-hidden="true" aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex="1"
|
3
|
+
.modal-dialog
|
4
|
+
.modal-content
|
5
|
+
.modal-header
|
6
|
+
h5.modal-title id="#{custom_action.name.classify}ModalLabel" = 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
|
@@ -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,16 +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
|
42
|
-
= render 'layouts/flash_message'
|
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/engine.rb
CHANGED
data/lib/cm_admin/model.rb
CHANGED
@@ -22,7 +22,7 @@ module CmAdmin
|
|
22
22
|
include Models::DslMethod
|
23
23
|
include Models::ControllerMethod
|
24
24
|
attr_accessor :available_actions, :actions_set, :available_fields, :permitted_fields, :current_action, :params, :filters, :available_tabs
|
25
|
-
attr_reader :name, :ar_model
|
25
|
+
attr_reader :name, :ar_model, :is_visible_on_sidebar
|
26
26
|
|
27
27
|
# Class variable for storing all actions
|
28
28
|
# CmAdmin::Model.all_actions
|
@@ -31,6 +31,7 @@ module CmAdmin
|
|
31
31
|
def initialize(entity, &block)
|
32
32
|
@name = entity.name
|
33
33
|
@ar_model = entity
|
34
|
+
@is_visible_on_sidebar = true
|
34
35
|
@available_actions ||= []
|
35
36
|
@current_action = nil
|
36
37
|
@available_tabs ||= []
|
@@ -85,6 +86,10 @@ module CmAdmin
|
|
85
86
|
@actions_set = true
|
86
87
|
end
|
87
88
|
|
89
|
+
def visible_on_sidebar(visible_option)
|
90
|
+
@is_visible_on_sidebar = visible_option
|
91
|
+
end
|
92
|
+
|
88
93
|
|
89
94
|
private
|
90
95
|
|
@@ -92,7 +97,6 @@ module CmAdmin
|
|
92
97
|
# If model is User, controller will be UsersController
|
93
98
|
def define_controller
|
94
99
|
klass = Class.new(CmAdmin::ApplicationController) do
|
95
|
-
|
96
100
|
$available_actions.each do |action|
|
97
101
|
define_method action.name.to_sym do
|
98
102
|
|
@@ -100,8 +104,11 @@ module CmAdmin
|
|
100
104
|
@model = CmAdmin::Model.find_by(name: controller_name.classify)
|
101
105
|
@model.params = params
|
102
106
|
@action = CmAdmin::Models::Action.find_by(@model, name: action_name)
|
107
|
+
@model.current_action = @action
|
103
108
|
@ar_object = @model.try(@action.parent || action_name, params)
|
104
109
|
@ar_object, @associated_model, @associated_ar_object = @model.custom_controller_action(action_name, params.permit!) if !@ar_object.present? && params[:id].present?
|
110
|
+
aar_model = request.url.split('/')[-2].classify.constantize if params[:aar_id]
|
111
|
+
@associated_ar_object = aar_model.find(params[:aar_id]) if params[:aar_id]
|
105
112
|
nested_tables = @model.available_fields[:new].except(:fields).keys
|
106
113
|
nested_tables += @model.available_fields[:edit].except(:fields).keys
|
107
114
|
@reflections = @model.ar_model.reflect_on_all_associations
|
@@ -126,13 +133,19 @@ module CmAdmin
|
|
126
133
|
else
|
127
134
|
format.html { render '/cm_admin/main/new' }
|
128
135
|
end
|
129
|
-
elsif action.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
136
|
+
elsif action.action_type == :custom
|
137
|
+
if action.child_records
|
138
|
+
format.html { render action.layout }
|
139
|
+
elsif action.display_type == :page
|
140
|
+
data = @action.parent == "index" ? @ar_object.data : @ar_object
|
141
|
+
format.html { render action.partial }
|
134
142
|
else
|
135
|
-
|
143
|
+
if @action.code_block.call(@ar_object)
|
144
|
+
redirect_url = @action.redirection_url || request.referrer || "/cm_admin/#{@model.ar_model.table_name}/#{@ar_object.id}"
|
145
|
+
format.html { redirect_to redirect_url }
|
146
|
+
else
|
147
|
+
format.html { redirect_to request.referrer }
|
148
|
+
end
|
136
149
|
end
|
137
150
|
elsif action.layout.present?
|
138
151
|
if request.xhr? && action.partial.present?
|
@@ -4,7 +4,9 @@ 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, :redirection_url
|
8
10
|
|
9
11
|
def initialize(attributes = {}, &block)
|
10
12
|
if attributes[:layout_type].present? && attributes[:layout].nil? && attributes[:partial].nil?
|
@@ -25,7 +27,9 @@ module CmAdmin
|
|
25
27
|
|
26
28
|
def set_default_values
|
27
29
|
self.is_nested_field = false
|
28
|
-
self.display_if = true
|
30
|
+
self.display_if = lambda { |arg| return true }
|
31
|
+
self.display_type = :button
|
32
|
+
self.action_type = :default
|
29
33
|
end
|
30
34
|
|
31
35
|
class << self
|
@@ -65,7 +65,7 @@ module CmAdmin
|
|
65
65
|
nested_fields = nested_tables.map {|table|
|
66
66
|
Hash[
|
67
67
|
table.to_s + '_attributes',
|
68
|
-
table.to_s.
|
68
|
+
table.to_s.classify.constantize.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym) + [:id, :_destroy]
|
69
69
|
]
|
70
70
|
}
|
71
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,8 +118,12 @@ 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, display_if: lambda { |arg| return true }, route_type: nil, &block)
|
113
|
-
|
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
|
114
127
|
# self.class.class_eval(&block)
|
115
128
|
end
|
116
129
|
|
data/lib/cm_admin/version.rb
CHANGED
@@ -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)
|
@@ -5,26 +5,28 @@ module CmAdmin
|
|
5
5
|
include Pagy::Frontend
|
6
6
|
def navigation_links(navigation_type)
|
7
7
|
CmAdmin.cm_admin_models.map { |model|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
content_tag(:
|
12
|
-
content_tag(:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
elsif navigation_type == "quick_links"
|
19
|
-
content_tag(:a, href: path, class: 'visible') do
|
20
|
-
content_tag(:div, class: 'result-item') do
|
21
|
-
content_tag(:span) do
|
22
|
-
concat tag.i class: 'fa fa-th-large'
|
23
|
-
end +
|
24
|
-
content_tag(:span) do
|
8
|
+
if model.is_visible_on_sidebar
|
9
|
+
path = CmAdmin::Engine.mount_path + '/' + model.name.underscore.pluralize
|
10
|
+
if navigation_type == "sidebar"
|
11
|
+
content_tag(:a, href: path) do
|
12
|
+
content_tag(:div, class: 'menu-item') do
|
13
|
+
content_tag(:span, class: 'menu-icon') do
|
14
|
+
concat tag.i class: 'fa fa-th-large'
|
15
|
+
end +
|
25
16
|
model.name
|
26
17
|
end
|
27
18
|
end
|
19
|
+
elsif navigation_type == "quick_links"
|
20
|
+
content_tag(:a, href: path, class: 'visible') do
|
21
|
+
content_tag(:div, class: 'result-item') do
|
22
|
+
content_tag(:span) do
|
23
|
+
concat tag.i class: 'fa fa-th-large'
|
24
|
+
end +
|
25
|
+
content_tag(:span) do
|
26
|
+
model.name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
}.join.html_safe
|
@@ -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
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
33d3c35c58c8db0310c4cb3ec7ff742813910e07
|
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.4
|
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: 2022-
|
13
|
+
date: 2022-02-15 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: []
|
@@ -152,6 +153,7 @@ files:
|
|
152
153
|
- app/views/cm_admin/main/new.html.slim
|
153
154
|
- app/views/cm_admin/main/show.html.slim
|
154
155
|
- app/views/cm_admin/static/error_401.html.slim
|
156
|
+
- app/views/layouts/_custom_action_modals.html.slim
|
155
157
|
- app/views/layouts/_flash_message.html.slim
|
156
158
|
- app/views/layouts/_left_sidebar_nav.html.slim
|
157
159
|
- app/views/layouts/_quick_links.html.slim
|