cm-admin 0.7.0 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -5
- data/app/helpers/cm_admin/application_helper.rb +11 -0
- data/app/views/cm_admin/main/_associated_table.html.slim +11 -3
- data/app/views/cm_admin/main/_nested_fields.html.slim +1 -1
- data/app/views/cm_admin/main/_tabs.html.slim +5 -4
- data/lib/cm_admin/model.rb +3 -1
- data/lib/cm_admin/models/controller_method.rb +9 -1
- data/lib/cm_admin/models/dsl_method.rb +3 -3
- data/lib/cm_admin/models/export.rb +4 -0
- data/lib/cm_admin/models/form_field.rb +1 -1
- data/lib/cm_admin/models/tab.rb +3 -2
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +13 -3
- data/lib/cm_admin/view_helpers/form_helper.rb +9 -0
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- 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: 38f55f5eb7db0ce9a1ef95f111085f1aa36132e6f729fc18e9d81f09a3896b68
|
4
|
+
data.tar.gz: 569e799bacc88c9bd811fbd55e0c8ee313c0af32874aa63a64786f4dd477923d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4802b0d59a4d4eed99d9ced6d3cbefb96af6cb4c610e2542e5fe5ca9035bcb432935cb7f4db61f0775d978fd0b83c8ed21de6f939c071498f26b888d25fe2fe5
|
7
|
+
data.tar.gz: bdcf0cda0c49c059ed6fc87abc960c04e59b611d079b5ce3a9aaccbebaa0feaba711ecd18546eec9a466129c39537056a28cbc98b4712ff4d5ba2bd45e0fd150
|
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.7.3)
|
5
5
|
axlsx_rails (~> 0.6.1)
|
6
6
|
cocoon (~> 1.2.15)
|
7
7
|
pagy (~> 4.11.0)
|
@@ -47,15 +47,13 @@ GEM
|
|
47
47
|
htmlentities (4.3.4)
|
48
48
|
i18n (1.10.0)
|
49
49
|
concurrent-ruby (~> 1.0)
|
50
|
-
loofah (2.
|
50
|
+
loofah (2.17.0)
|
51
51
|
crass (~> 1.0.2)
|
52
52
|
nokogiri (>= 1.5.9)
|
53
53
|
marcel (1.0.2)
|
54
54
|
method_source (1.0.0)
|
55
|
-
mini_portile2 (2.8.0)
|
56
55
|
minitest (5.15.0)
|
57
|
-
nokogiri (1.13.
|
58
|
-
mini_portile2 (~> 2.8.0)
|
56
|
+
nokogiri (1.13.5-arm64-darwin)
|
59
57
|
racc (~> 1.4)
|
60
58
|
pagy (4.11.0)
|
61
59
|
pundit (2.2.0)
|
@@ -13,5 +13,16 @@ module CmAdmin
|
|
13
13
|
return true unless policy([:cm_admin, model_name.classify.constantize]).methods.include?(:"#{action_name}?")
|
14
14
|
policy([:cm_admin, model_name.classify.constantize]).send(:"#{action_name}?")
|
15
15
|
end
|
16
|
+
|
17
|
+
def action(action_name)
|
18
|
+
case action_name.to_sym
|
19
|
+
when :update
|
20
|
+
return :edit
|
21
|
+
when :create
|
22
|
+
return :new
|
23
|
+
else
|
24
|
+
return action_name.to_sym
|
25
|
+
end
|
26
|
+
end
|
16
27
|
end
|
17
28
|
end
|
@@ -2,6 +2,11 @@
|
|
2
2
|
.table-top
|
3
3
|
p.table-top__total-count = "#{@associated_ar_object.pagy.count} #{@action.child_records.to_s.gsub('_', ' ')} found"
|
4
4
|
.table-top__column-action
|
5
|
+
- if @associated_model && @associated_model.available_actions.map(&:name).include?('new')
|
6
|
+
- association = @ar_object.class.reflect_on_all_associations.select{|x| x.name == @associated_model.name.tableize.to_sym }.first
|
7
|
+
- polymorphic_name = (association && association.inverse_of && association.inverse_of.options[:polymorphic]) ? association.inverse_of.name : ''
|
8
|
+
a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/new?associated_id=#{@ar_object.id}&associated_class=#{@ar_object.class.name.underscore}&polymorphic_name=#{polymorphic_name}&referrer=#{request.path}"
|
9
|
+
button.secondary-btn.column-btn Add
|
5
10
|
/ button.secondary-btn.column-btn data-target="#columnActionModal" data-toggle="modal" type="button"
|
6
11
|
/ span
|
7
12
|
/ i.fa.fa-columns.bolder
|
@@ -17,7 +22,7 @@
|
|
17
22
|
/ span
|
18
23
|
/ input.cm-checkbox type="checkbox"
|
19
24
|
- @model.available_fields[@action.name.to_sym].each do |column|
|
20
|
-
|
25
|
+
th = column.header
|
21
26
|
tbody.cm-table__body
|
22
27
|
- @associated_ar_object.data.each do |ar_object|
|
23
28
|
tr.body-row
|
@@ -25,9 +30,12 @@
|
|
25
30
|
/ td.check-box-space
|
26
31
|
/ span
|
27
32
|
/ input.cm-checkbox type="checkbox"
|
28
|
-
- @model.available_fields[@action.name.to_sym].
|
33
|
+
- @model.available_fields[@action.name.to_sym].each_with_index do |column, index|
|
29
34
|
td class="text-ellipsis"
|
30
|
-
|
35
|
+
- if index == 0 && @associated_model && @associated_model.available_actions.map(&:name).include?('show')
|
36
|
+
a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/#{ar_object.id}" = show_field_value(ar_object, column)
|
37
|
+
- else
|
38
|
+
span class="#{column.cm_css_class}" = show_field_value(ar_object, column)
|
31
39
|
- associated_model_actions = @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}
|
32
40
|
- if associated_model_actions.present?
|
33
41
|
td.row-action-cell
|
@@ -1,6 +1,7 @@
|
|
1
1
|
ul.nav.nav-pills
|
2
2
|
- @model.available_tabs.each do |nav_item|
|
3
|
-
- if nav_item.
|
4
|
-
|
5
|
-
-
|
6
|
-
|
3
|
+
- if nav_item.display_if.call(@ar_object)
|
4
|
+
- if nav_item.custom_action.empty? || (nav_item.custom_action.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{nav_item.custom_action}?"))
|
5
|
+
li.nav-item
|
6
|
+
- nav_item_action_name = nav_item.custom_action.present? ? nav_item.custom_action : 'show'
|
7
|
+
= link_to nav_item.nav_item_name.to_s.titleize, "/cm_admin/#{@model.name.underscore.pluralize}/#{@ar_object.id}/#{nav_item.custom_action}", class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
|
data/lib/cm_admin/model.rb
CHANGED
@@ -140,7 +140,9 @@ module CmAdmin
|
|
140
140
|
format.html { render '/cm_admin/main/'+action_name }
|
141
141
|
end
|
142
142
|
elsif %w(create update destroy).include?(action_name)
|
143
|
-
if
|
143
|
+
if params["referrer"]
|
144
|
+
redirect_url = params["referrer"]
|
145
|
+
elsif %w(create update).include?(action_name)
|
144
146
|
redirect_url = CmAdmin::Engine.mount_path + "/#{@model.name.underscore.pluralize}/#{@ar_object.id}"
|
145
147
|
else
|
146
148
|
redirect_url = CmAdmin::Engine.mount_path + "/#{@model.name.underscore.pluralize}"
|
@@ -58,7 +58,15 @@ module CmAdmin
|
|
58
58
|
def resource_params(params)
|
59
59
|
permittable_fields = @permitted_fields || @ar_model.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym)
|
60
60
|
permittable_fields += @ar_model.name.constantize.reflect_on_all_associations.map {|x|
|
61
|
-
if x.
|
61
|
+
next if x.options[:polymorphic]
|
62
|
+
# The first if statement is added for compatibilty with cm-page-builder.
|
63
|
+
# One of the associated models of cm-page-builder was throwing error.
|
64
|
+
# The associated model is CmPageBuilder::Rails::PageComponent.
|
65
|
+
# When using reflection, the value of klass of the above association is uninitialized.
|
66
|
+
# As a result, it was throwing error in the 2nd elsif statement.
|
67
|
+
if x.name == :page_components
|
68
|
+
x.name
|
69
|
+
elsif x.klass.name == "ActiveStorage::Attachment"
|
62
70
|
if x.class.name.include?('HasOne')
|
63
71
|
x.name
|
64
72
|
elsif x.class.name.include?('HasMany')
|
@@ -39,17 +39,17 @@ module CmAdmin
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, &block)
|
42
|
+
def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, display_if: nil, &block)
|
43
43
|
if custom_action.to_s == ''
|
44
44
|
@current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
|
45
|
-
@available_tabs << CmAdmin::Models::Tab.new(tab_name, '', &block)
|
45
|
+
@available_tabs << CmAdmin::Models::Tab.new(tab_name, '', display_if, &block)
|
46
46
|
else
|
47
47
|
action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/'+custom_action,
|
48
48
|
layout_type: layout_type, layout: layout, partial: partial, child_records: associated_model,
|
49
49
|
action_type: :custom, display_type: :page)
|
50
50
|
@available_actions << action
|
51
51
|
@current_action = action
|
52
|
-
@available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, &block)
|
52
|
+
@available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, display_if, &block)
|
53
53
|
end
|
54
54
|
yield if block
|
55
55
|
end
|
@@ -25,6 +25,10 @@ module CmAdmin
|
|
25
25
|
records_arr = []
|
26
26
|
records.includes(deserialized_columns[:include].keys).find_each do |record|
|
27
27
|
record_hash = record.as_json({only: columns.map(&:to_sym)})
|
28
|
+
columns.each do |column|
|
29
|
+
break unless model.available_fields[:index].map(&:field_name).include?(column.to_sym)
|
30
|
+
record_hash[column.to_sym] = record.send(column.to_sym)
|
31
|
+
end
|
28
32
|
custom_fields.each do |field|
|
29
33
|
record_hash[field.field_name.to_sym] = helpers.send(field.helper_method, record, field.field_name)
|
30
34
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module CmAdmin
|
2
2
|
module Models
|
3
3
|
class FormField
|
4
|
-
attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled
|
4
|
+
attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled, :collection_method
|
5
5
|
VALID_INPUT_TYPES = [:integer, :decimal, :string, :single_select, :multi_select, :date, :date_time, :text, :single_file_upload, :multi_file_upload, :hidden, :rich_text].freeze
|
6
6
|
|
7
7
|
def initialize(field_name, input_type, attributes = {})
|
data/lib/cm_admin/models/tab.rb
CHANGED
@@ -2,11 +2,12 @@ module CmAdmin
|
|
2
2
|
module Models
|
3
3
|
class Tab
|
4
4
|
|
5
|
-
attr_accessor :nav_item_name, :custom_action
|
5
|
+
attr_accessor :nav_item_name, :custom_action, :display_if
|
6
6
|
|
7
|
-
def initialize(nav_item_name, custom_action)
|
7
|
+
def initialize(nav_item_name, custom_action, display_if)
|
8
8
|
@nav_item_name = nav_item_name
|
9
9
|
@custom_action = custom_action
|
10
|
+
@display_if = display_if || lambda { |arg| return true }
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -13,11 +13,11 @@ module CmAdmin
|
|
13
13
|
when :string
|
14
14
|
return f.text_field field.field_name, class: "normal-input #{required_class}", disabled: field.disabled, value: value, placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}"
|
15
15
|
when :single_select
|
16
|
-
return f.select field.field_name, options_for_select((field
|
16
|
+
return f.select field.field_name, options_for_select(select_collection_value(field), value), {include_blank: "Select #{field.field_name.to_s.downcase.gsub('_', ' ')}"}, class: "normal-input #{required_class} select-2", disabled: field.disabled
|
17
17
|
when :multi_select
|
18
|
-
return f.select field.field_name, options_for_select((field
|
18
|
+
return f.select field.field_name, options_for_select(select_collection_value(field), value), {include_blank: "Select #{field.field_name.to_s.downcase.gsub('_', ' ')}"}, class: "normal-input #{required_class} select-2", disabled: field.disabled, multiple: true
|
19
19
|
when :date
|
20
|
-
return f.text_field field.field_name, class: "normal-input #{required_class}", disabled: field.disabled, value: value
|
20
|
+
return f.text_field field.field_name, class: "normal-input #{required_class}", disabled: field.disabled, value: value&.strftime('%d-%m-%Y'), placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}", data: { behaviour: 'date-only' }
|
21
21
|
when :date_time
|
22
22
|
return f.text_field field.field_name, class: "normal-input #{required_class}", disabled: field.disabled, value: value, placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}", data: { behaviour: 'date-time' }
|
23
23
|
when :text
|
@@ -32,6 +32,16 @@ module CmAdmin
|
|
32
32
|
return f.hidden_field field.field_name, value: field.custom_value
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
def select_collection_value(field)
|
37
|
+
if field.collection_method
|
38
|
+
collection = send(field.collection_method)
|
39
|
+
elsif field.collection
|
40
|
+
collection = field.collection
|
41
|
+
else
|
42
|
+
collection = []
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -38,6 +38,15 @@ module CmAdmin
|
|
38
38
|
|
39
39
|
def set_form_for_fields(resource, available_fields_hash, url, method)
|
40
40
|
form_for(resource, url: url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |f|
|
41
|
+
if params[:referrer]
|
42
|
+
concat f.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
|
43
|
+
end
|
44
|
+
if params[:polymorphic_name].present?
|
45
|
+
concat f.text_field params[:polymorphic_name] + '_type', class: "normal-input", hidden: true, value: params[:associated_class].classify
|
46
|
+
concat f.text_field params[:polymorphic_name] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
47
|
+
elsif params[:associated_class] && params[:associated_id]
|
48
|
+
concat f.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
|
49
|
+
end
|
41
50
|
available_fields_hash.each do |key, fields_array|
|
42
51
|
if key == :fields
|
43
52
|
fields_array.each do |field|
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
09d7dd65a776413eb9615ccfd2071782565b6619
|
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.7.
|
4
|
+
version: 0.7.3
|
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-06-
|
13
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pagy
|