cm-admin 0.6.9 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/javascript/packs/cm_admin/application.js +1 -0
- data/app/javascript/packs/cm_admin/scaffolds.js +3 -1
- data/app/views/cm_admin/main/_top_navbar.html.slim +4 -4
- data/app/views/cm_admin/main/new.html.slim +1 -1
- data/lib/cm_admin/models/controller_method.rb +11 -6
- data/lib/cm_admin/models/export.rb +4 -0
- data/lib/cm_admin/models/form_field.rb +1 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +3 -1
- data/lib/generators/cm_admin/install_generator.rb +3 -0
- data/lib/generators/cm_admin/policy_generator.rb +2 -2
- data/lib/generators/cm_admin/templates/actiontext.scss +36 -0
- data/lib/generators/cm_admin/templates/custom.css +5 -0
- data/lib/generators/cm_admin/templates/policy.rb +1 -1
- data/package.json +1 -0
- data/tmp/cache/webpacker/last-compilation-digest-development +1 -1
- data/yarn.lock +8 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72119a5aae30fb36067825d4ed89fc085907b1a31a7b79e18dd30690b8379991
|
4
|
+
data.tar.gz: 917b3dc2d4d59d4099c77e169694579f1d82c5dc53664025fb98edbd9ccc3ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42bbbf83a0d81aa5d193cb23a3469ed3392f13fe573605a55886611805c2e388e3a3664c2be6202eea743f13658cd6faf7870a2ba786339620d87484b823ccab
|
7
|
+
data.tar.gz: e6474599f0f7de99642a056713baf93f9f7dcb6352d2385fc080059d310fa22b4b7199c28dff7b9a36be9d025aacf0fa395206e225e4ec26843befa2a640a3d3
|
@@ -1,6 +1,8 @@
|
|
1
1
|
$(document).on('turbolinks:load', function () {
|
2
2
|
$('.select-2').select2();
|
3
|
-
flatpickr("[data-behaviour='date-only']", {
|
3
|
+
flatpickr("[data-behaviour='date-only']", {
|
4
|
+
dateFormat: "d-m-Y"
|
5
|
+
})
|
4
6
|
flatpickr("[data-behaviour='date-time']", {
|
5
7
|
enableTime: true
|
6
8
|
})
|
@@ -1,9 +1,9 @@
|
|
1
1
|
.cm-navbar
|
2
2
|
.cm-navbar__lhs
|
3
|
-
- if cm_admin.method_defined?(:"#{@model.name.
|
3
|
+
- if cm_admin.method_defined?(:"#{@model.name.underscore}_index_path") && (@model.current_action.name == 'show' || @model.current_action.layout_type.present?)
|
4
4
|
.bread-crumb-area
|
5
5
|
.breadcrumb-text
|
6
|
-
= link_to @model.name + ' /', cm_admin.send(:"#{@model.name.
|
6
|
+
= link_to @model.name + ' /', cm_admin.send(:"#{@model.name.underscore}_index_path")
|
7
7
|
.nav-title-area
|
8
8
|
p.title-text = action_title
|
9
9
|
p.title-sub-text = action_description
|
@@ -24,7 +24,7 @@
|
|
24
24
|
span Export
|
25
25
|
- new_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('new')}
|
26
26
|
- if new_action.any? && policy([:cm_admin, @model.name.classify.constantize]).new?
|
27
|
-
= link_to 'Add', "#{
|
27
|
+
= link_to 'Add', cm_admin.send(:"#{@model.name.underscore}_new_path"), class: 'primary-btn ml-2'
|
28
28
|
- @model.available_actions.select{|act| act if act.route_type == 'collection'}.each do |custom_action|
|
29
29
|
= custom_action_items(custom_action, 'index')
|
30
30
|
- elsif @model.current_action.name == 'show'
|
@@ -33,4 +33,4 @@
|
|
33
33
|
|
34
34
|
- edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
|
35
35
|
- if edit_action.any? && policy([:cm_admin, @model.name.classify.constantize]).edit?
|
36
|
-
= link_to "Edit #{@model.name}", "#{
|
36
|
+
= link_to "Edit #{@model.name}", cm_admin.send(:"#{@model.name.underscore}_edit_path", @ar_object), class: 'primary-btn ml-2'
|
@@ -33,7 +33,7 @@ module CmAdmin
|
|
33
33
|
|
34
34
|
|
35
35
|
def create(params)
|
36
|
-
@ar_object = @ar_model.new(resource_params(params))
|
36
|
+
@ar_object = @ar_model.name.classify.constantize.new(resource_params(params))
|
37
37
|
end
|
38
38
|
|
39
39
|
def filter_by(params, records, filter_params={}, sort_params={})
|
@@ -57,11 +57,15 @@ module CmAdmin
|
|
57
57
|
|
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
|
-
permittable_fields += @ar_model.
|
61
|
-
if x.
|
62
|
-
x.name
|
63
|
-
|
64
|
-
|
60
|
+
permittable_fields += @ar_model.name.constantize.reflect_on_all_associations.map {|x|
|
61
|
+
if x.klass.name == "ActiveStorage::Attachment"
|
62
|
+
if x.class.name.include?('HasOne')
|
63
|
+
x.name
|
64
|
+
elsif x.class.name.include?('HasMany')
|
65
|
+
Hash[x.name.to_s, []]
|
66
|
+
end
|
67
|
+
elsif x.klass.name == "ActionText::RichText"
|
68
|
+
x.name.to_s.gsub('rich_text_', '').to_sym
|
65
69
|
end
|
66
70
|
}.compact
|
67
71
|
nested_tables = self.available_fields[:new].except(:fields).keys
|
@@ -74,6 +78,7 @@ module CmAdmin
|
|
74
78
|
}
|
75
79
|
permittable_fields += nested_fields
|
76
80
|
@ar_model.columns.map { |col| permittable_fields << col.name.split('_cents') if col.name.include?('_cents') }
|
81
|
+
|
77
82
|
params.require(self.name.underscore.to_sym).permit(*permittable_fields)
|
78
83
|
end
|
79
84
|
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
|
@@ -2,7 +2,7 @@ module CmAdmin
|
|
2
2
|
module Models
|
3
3
|
class FormField
|
4
4
|
attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled
|
5
|
-
VALID_INPUT_TYPES = [:integer, :decimal, :string, :single_select, :multi_select, :date, :date_time, :text, :single_file_upload, :multi_file_upload, :hidden].freeze
|
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 = {})
|
8
8
|
raise ArgumentError, "Kindly select a valid filter type like #{VALID_INPUT_TYPES.sort.to_sentence(last_word_connector: ', or ')} instead of #{input_type} for column #{field_name}" unless VALID_INPUT_TYPES.include?(input_type.to_sym)
|
data/lib/cm_admin/version.rb
CHANGED
@@ -17,11 +17,13 @@ module CmAdmin
|
|
17
17
|
when :multi_select
|
18
18
|
return f.select field.field_name, options_for_select((field.collection || []), 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, placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}", data: { behaviour: 'date-only' }
|
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
|
24
24
|
return f.text_area field.field_name, class: "normal-input #{required_class}", placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}"
|
25
|
+
when :rich_text
|
26
|
+
return f.rich_text_area field.field_name, class: "normal-input #{required_class}", placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}"
|
25
27
|
when :single_file_upload
|
26
28
|
return f.file_field field.field_name, class: "normal-input #{required_class}"
|
27
29
|
when :multi_file_upload
|
@@ -6,9 +6,12 @@ module CmAdmin
|
|
6
6
|
source_root File.expand_path('templates', __dir__)
|
7
7
|
|
8
8
|
def copy_initializer
|
9
|
+
generate 'action_text:install'
|
9
10
|
copy_file 'cm_admin_initializer.rb', 'config/initializers/zcm_admin.rb'
|
10
11
|
copy_file 'custom.js', 'app/assets/javascripts/cm_admin/custom.js'
|
11
12
|
copy_file 'custom.css', 'app/assets/stylesheets/cm_admin/custom.css'
|
13
|
+
copy_file 'actiontext.scss', 'app/assets/stylesheets/cm_admin/actiontext.scss'
|
14
|
+
remove_file 'app/assets/stylesheets/actiontext.scss'
|
12
15
|
copy_file 'application_policy.rb', 'app/policies/application_policy.rb'
|
13
16
|
route 'mount CmAdmin::Engine => "/admin"'
|
14
17
|
end
|
@@ -6,8 +6,8 @@ module CmAdmin
|
|
6
6
|
source_root File.expand_path('templates', __dir__)
|
7
7
|
|
8
8
|
def copy_policy_files
|
9
|
-
cm_model = CmAdmin::Model.find_by({name: file_name})
|
10
|
-
raise "cm_admin is not defined inside #{file_name} model" unless cm_model.present?
|
9
|
+
@cm_model = CmAdmin::Model.find_by({name: file_name.classify})
|
10
|
+
raise "cm_admin is not defined inside #{file_name} model" unless @cm_model.present?
|
11
11
|
template "policy.rb", "app/policies/cm_admin/#{file_name}_policy.rb"
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
//
|
2
|
+
// Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
|
3
|
+
// the trix-editor content (whether displayed or under editing). Feel free to incorporate this
|
4
|
+
// inclusion directly in any other asset bundle and remove this file.
|
5
|
+
//
|
6
|
+
//= require trix/dist/trix
|
7
|
+
|
8
|
+
// We need to override trix.css’s image gallery styles to accommodate the
|
9
|
+
// <action-text-attachment> element we wrap around attachments. Otherwise,
|
10
|
+
// images in galleries will be squished by the max-width: 33%; rule.
|
11
|
+
.trix-content {
|
12
|
+
.attachment-gallery {
|
13
|
+
> action-text-attachment,
|
14
|
+
> .attachment {
|
15
|
+
flex: 1 0 33%;
|
16
|
+
padding: 0 0.5em;
|
17
|
+
max-width: 33%;
|
18
|
+
}
|
19
|
+
|
20
|
+
&.attachment-gallery--2,
|
21
|
+
&.attachment-gallery--4 {
|
22
|
+
> action-text-attachment,
|
23
|
+
> .attachment {
|
24
|
+
flex-basis: 50%;
|
25
|
+
max-width: 50%;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
action-text-attachment {
|
31
|
+
.attachment {
|
32
|
+
padding: 0 !important;
|
33
|
+
max-width: 100% !important;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class CmAdmin::<%= class_name %>Policy < ApplicationPolicy
|
2
|
-
<%- available_action_names = (cm_model.available_actions.map{|action| action.name}.uniq - ['custom_action', 'new', 'edit']) %>
|
2
|
+
<%- available_action_names = (@cm_model.available_actions.map{|action| action.name}.uniq - ['custom_action', 'new', 'edit']) %>
|
3
3
|
<%- available_action_names.each do |action_name| %>
|
4
4
|
def <%= action_name %>?
|
5
5
|
<%= CmAdmin.authorized_roles.map {|role| "@user.#{role}" }.join(' && ') %>
|
data/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
09d7dd65a776413eb9615ccfd2071782565b6619
|
data/yarn.lock
CHANGED
@@ -2697,9 +2697,9 @@ events@^3.0.0:
|
|
2697
2697
|
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
|
2698
2698
|
|
2699
2699
|
eventsource@^1.0.7:
|
2700
|
-
version "1.1.
|
2701
|
-
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.
|
2702
|
-
integrity sha512-
|
2700
|
+
version "1.1.1"
|
2701
|
+
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.1.tgz#4544a35a57d7120fba4fa4c86cb4023b2c09df2f"
|
2702
|
+
integrity sha512-qV5ZC0h7jYIAOhArFJgSfdyz6rALJyb270714o7ZtNnw2WSJ+eexhKtE0O8LYPRsHZHf2osHKZBxGPvm3kPkCA==
|
2703
2703
|
dependencies:
|
2704
2704
|
original "^1.0.0"
|
2705
2705
|
|
@@ -6458,6 +6458,11 @@ toidentifier@1.0.0:
|
|
6458
6458
|
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
|
6459
6459
|
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
|
6460
6460
|
|
6461
|
+
trix@^2.0.0-beta.0:
|
6462
|
+
version "2.0.0-beta.0"
|
6463
|
+
resolved "https://registry.yarnpkg.com/trix/-/trix-2.0.0-beta.0.tgz#e7034867182356c023abdef90c7bdc341bb3e105"
|
6464
|
+
integrity sha512-D1c7FxP1hGXM/MnTd/+fGUbSDLkfxsqjA0NxOTzByQywVJVNHDOkn8xAScCKVOiAN6hXlqUR2qX4CPJHTGj+cQ==
|
6465
|
+
|
6461
6466
|
ts-pnp@^1.1.6:
|
6462
6467
|
version "1.2.0"
|
6463
6468
|
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
|
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.
|
4
|
+
version: 0.7.2
|
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-
|
13
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pagy
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/cm_admin/view_helpers/page_info_helper.rb
|
224
224
|
- lib/generators/cm_admin/install_generator.rb
|
225
225
|
- lib/generators/cm_admin/policy_generator.rb
|
226
|
+
- lib/generators/cm_admin/templates/actiontext.scss
|
226
227
|
- lib/generators/cm_admin/templates/application_policy.rb
|
227
228
|
- lib/generators/cm_admin/templates/cm_admin_initializer.rb
|
228
229
|
- lib/generators/cm_admin/templates/custom.css
|