cm-admin 0.5.5 → 0.5.6
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/app/javascript/packs/cm_admin/scaffolds.js +10 -8
- data/app/views/cm_admin/main/_table.html.slim +5 -6
- data/app/views/cm_admin/main/index.html.slim +1 -1
- data/lib/cm_admin/models/action.rb +5 -1
- data/lib/cm_admin/models/column.rb +1 -1
- data/lib/cm_admin/models/controller_method.rb +2 -0
- data/lib/cm_admin/models/dsl_method.rb +29 -10
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/field_display_helper.rb +5 -0
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- data/yarn.lock +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e71407dad6f3a42e093faa7247489382dd4b650b3c61f85b6758286a7d2ee45
|
4
|
+
data.tar.gz: e50e11e94676d06e9044a58b84f20cb416d92e8a0a92507afa5ff362b98d9640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07bf22fe0ea5157252da7a3b17b012f6842ce5da4815764fd6ace17af0203db2dd09158d97efc9f19c51e9df5529f742c7284e501b5879b3694e48aed4283cf3
|
7
|
+
data.tar.gz: 9433f9fd8d71db8f7d1a95668e723cf655cc91e66df19b73d73f405336a7649e8c2a1f011c901a898990512a1e4eefe5092ed7f6502feabf75599a2e0ac0ff1d
|
@@ -45,21 +45,23 @@ $(document).on('click', '.row-action-cell', function(e) {
|
|
45
45
|
|
46
46
|
$(document).on('click', '.drawer-btn', function(e) {
|
47
47
|
e.stopPropagation();
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
drawer_el = $(this).parent().closest('.drawer').find('.cm-drawer')
|
49
|
+
if (drawer_el.hasClass('hidden')) {
|
50
|
+
drawer_el.removeClass('hidden');
|
51
|
+
drawer_container = drawer_el.find('.drawer-container')
|
52
|
+
if (drawer_container.hasClass('drawer-slide-out')) {
|
53
|
+
drawer_container.removeClass('drawer-slide-out');
|
52
54
|
}
|
53
|
-
|
55
|
+
drawer_container.addClass('drawer-slide-in');
|
54
56
|
} else {
|
55
|
-
return
|
57
|
+
return drawer_el.addClass('hidden');
|
56
58
|
}
|
57
59
|
});
|
58
60
|
|
59
61
|
$(document).on('click', '.drawer-close', function(e) {
|
60
62
|
e.stopPropagation();
|
61
|
-
$('
|
62
|
-
$('
|
63
|
+
$('.drawer-container').removeClass('drawer-slide-in');
|
64
|
+
$('.drawer-container').addClass('drawer-slide-out');
|
63
65
|
setTimeout(() => {
|
64
66
|
$('.cm-drawer').addClass('hidden');
|
65
67
|
}, 300);
|
@@ -16,7 +16,6 @@
|
|
16
16
|
input.cm-checkbox type="checkbox"
|
17
17
|
- @model.available_fields[:index].each do |column|
|
18
18
|
th = column.header
|
19
|
-
// th Drawer
|
20
19
|
tbody.cm-table__body
|
21
20
|
- @ar_object.data.each do |ar_object|
|
22
21
|
tr.body-row
|
@@ -25,13 +24,13 @@
|
|
25
24
|
input.cm-checkbox type="checkbox"
|
26
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.field_type.to_s} #{column.cm_css_class} "
|
29
28
|
- if index == 0
|
30
29
|
= link_to ar_object.send(column.field_name), "/cm_admin/#{ar_object.model_name.collection}/#{ar_object.id}"
|
31
30
|
- else
|
32
31
|
= show_field_value(ar_object, column)
|
33
|
-
|
34
|
-
|
32
|
+
- if column.field_type == :drawer
|
33
|
+
= render partial: column.drawer_partial, locals: { ar_object: ar_object}
|
35
34
|
td.row-action-cell
|
36
35
|
.row-action-tool
|
37
36
|
button.secondary-btn.tool-btn type="button"
|
@@ -43,10 +42,10 @@
|
|
43
42
|
.popup-option
|
44
43
|
a href="#{page_url('edit', ar_object)}"
|
45
44
|
| Edit
|
46
|
-
- @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
|
45
|
+
- @model.available_actions.select{|act| act if act.route_type == 'member' && [:button, :modal].include?(act.display_type)}.each do |custom_action|
|
47
46
|
- if custom_action.display_if.call(ar_object)
|
48
47
|
.popup-option
|
49
|
-
= link_to custom_action.name, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
|
48
|
+
= link_to custom_action.name.titleize, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
|
50
49
|
|
51
50
|
.cm-pagination
|
52
51
|
.cm-pagination__lhs Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
|
@@ -6,7 +6,9 @@ module CmAdmin
|
|
6
6
|
include Actions::Blocks
|
7
7
|
attr_accessor :name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
|
8
8
|
:child_records, :is_nested_field, :nested_table_name, :parent, :display_if, :route_type, :code_block,
|
9
|
-
:display_type, :action_type, :redirection_url
|
9
|
+
:display_type, :action_type, :redirection_url, :sort_direction, :sort_column
|
10
|
+
|
11
|
+
VALID_SORT_DIRECTION = Set[:asc, :desc].freeze
|
10
12
|
|
11
13
|
def initialize(attributes = {}, &block)
|
12
14
|
if attributes[:layout_type].present? && attributes[:layout].nil? && attributes[:partial].nil?
|
@@ -30,6 +32,8 @@ module CmAdmin
|
|
30
32
|
self.display_if = lambda { |arg| return true }
|
31
33
|
self.display_type = :button
|
32
34
|
self.action_type = :default
|
35
|
+
self.sort_column = :created_at
|
36
|
+
self.sort_direction = :desc
|
33
37
|
end
|
34
38
|
|
35
39
|
class << self
|
@@ -2,7 +2,7 @@ module CmAdmin
|
|
2
2
|
module Models
|
3
3
|
class Column
|
4
4
|
attr_accessor :field_name, :field_type, :header, :format, :prefix, :suffix, :exportable, :round,
|
5
|
-
:cm_css_class, :link, :url, :custom_method, :helper_method, :managable, :lockable
|
5
|
+
:cm_css_class, :link, :url, :custom_method, :helper_method, :managable, :lockable, :drawer_partial
|
6
6
|
|
7
7
|
def initialize(field_name, attributes = {})
|
8
8
|
@field_name = field_name
|
@@ -41,6 +41,8 @@ module CmAdmin
|
|
41
41
|
sort_direction = %w[asc desc].include?(sort_params[:sort_direction]) ? sort_params[:sort_direction] : "asc"
|
42
42
|
sort_params = {sort_column: sort_column, sort_direction: sort_direction}
|
43
43
|
records = self.name.constantize.where(nil) if records.nil?
|
44
|
+
records = records.order("#{current_action.sort_column} #{current_action.sort_direction}")
|
45
|
+
|
44
46
|
final_data = CmAdmin::Models::Filter.filtered_data(filter_params, records, @filters)
|
45
47
|
pagy, records = pagy(final_data)
|
46
48
|
filtered_result.data = records
|
@@ -24,14 +24,14 @@ module CmAdmin
|
|
24
24
|
@current_action.page_description = page_description
|
25
25
|
yield
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def cm_edit(page_title: nil,page_description: nil, &block)
|
29
29
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'edit')
|
30
30
|
@current_action.page_title = page_title
|
31
31
|
@current_action.page_description = page_description
|
32
32
|
yield
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def cm_new(page_title: nil,page_description: nil,&block)
|
36
36
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'new')
|
37
37
|
@current_action.page_title = page_title
|
@@ -44,13 +44,13 @@ module CmAdmin
|
|
44
44
|
@current_action.page_title = title
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def page_description(description)
|
49
49
|
if @current_action
|
50
50
|
@current_action.page_description = description
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, &block)
|
55
55
|
if custom_action.to_s == ''
|
56
56
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
|
@@ -65,12 +65,12 @@ module CmAdmin
|
|
65
65
|
end
|
66
66
|
yield if block
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def cm_show_section(section_name, &block)
|
70
70
|
@available_fields[@current_action.name.to_sym] ||= []
|
71
71
|
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::CmShowSection.new(section_name, &block)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def form_field(field_name, options={}, arg=nil)
|
75
75
|
unless @current_action.is_nested_field
|
76
76
|
@available_fields[@current_action.name.to_sym][:fields] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
@@ -79,23 +79,24 @@ module CmAdmin
|
|
79
79
|
@available_fields[@current_action.name.to_sym][@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def nested_form_field(field_name, &block)
|
84
84
|
@current_action.is_nested_field = true
|
85
85
|
@current_action.nested_table_name = field_name
|
86
86
|
yield
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def column(field_name, options={})
|
90
90
|
@available_fields[@current_action.name.to_sym] ||= []
|
91
91
|
if @available_fields[@current_action.name.to_sym].select{|x| x.lockable}.size > 0 && options[:lockable]
|
92
92
|
raise "Only one column can be locked in a table."
|
93
93
|
end
|
94
|
+
|
94
95
|
unless @available_fields[@current_action.name.to_sym].map{|x| x.field_name.to_sym}.include?(field_name)
|
95
96
|
@available_fields[@current_action.name.to_sym] << CmAdmin::Models::Column.new(field_name, options)
|
96
97
|
end
|
97
98
|
end
|
98
|
-
|
99
|
+
|
99
100
|
def all_db_columns(options={})
|
100
101
|
field_names = self.instance_variable_get(:@ar_model)&.columns&.map{|x| x.name.to_sym}
|
101
102
|
if options.include?(:exclude) && field_names
|
@@ -130,6 +131,24 @@ module CmAdmin
|
|
130
131
|
def filter(db_column_name, filter_type, options={})
|
131
132
|
@filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
|
132
133
|
end
|
134
|
+
|
135
|
+
def sort_direction(direction = :desc)
|
136
|
+
raise ArgumentError, "Select a valid sort direction like #{CmAdmin::Models::Action::VALID_SORT_DIRECTION.join(' or ')} instead of #{direction}" unless CmAdmin::Models::Action::VALID_SORT_DIRECTION.include?(direction.to_sym.downcase)
|
137
|
+
|
138
|
+
@current_action.sort_direction = direction.to_sym if @current_action
|
139
|
+
end
|
140
|
+
|
141
|
+
def sort_column(column = :created_at)
|
142
|
+
model = if @current_action.child_records
|
143
|
+
CmAdmin::Model.find_by(name: @current_action.child_records.to_s.classify)
|
144
|
+
else
|
145
|
+
self
|
146
|
+
end
|
147
|
+
db_columns = model.instance_variable_get(:@ar_model)&.columns&.map{|x| x.name.to_sym}
|
148
|
+
raise "Sorting for custom column #{column} does not exist." unless db_columns.include?(column.to_sym)
|
149
|
+
|
150
|
+
@current_action.sort_column = column.to_sym if @current_action
|
151
|
+
end
|
133
152
|
end
|
134
153
|
end
|
135
|
-
end
|
154
|
+
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -47,6 +47,11 @@ module CmAdmin
|
|
47
47
|
end
|
48
48
|
when :attachment
|
49
49
|
concat show_attachment_value(ar_object, field)
|
50
|
+
when :drawer
|
51
|
+
content_tag :span do
|
52
|
+
concat content_tag(:span, truncate(ar_object.send(field.field_name).to_s, length: 25))
|
53
|
+
concat content_tag(:a, " View", class: "drawer-btn")
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
d5850cd60f91abe79ff8a84a45a9e24c75cb0e4b
|
data/yarn.lock
CHANGED
@@ -6589,9 +6589,9 @@ urix@^0.1.0:
|
|
6589
6589
|
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
|
6590
6590
|
|
6591
6591
|
url-parse@^1.4.3, url-parse@^1.5.1:
|
6592
|
-
version "1.5.
|
6593
|
-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.
|
6594
|
-
integrity sha512-
|
6592
|
+
version "1.5.10"
|
6593
|
+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
|
6594
|
+
integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
|
6595
6595
|
dependencies:
|
6596
6596
|
querystringify "^2.1.1"
|
6597
6597
|
requires-port "^1.0.0"
|
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: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sajinmp
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-02
|
13
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pagy
|