cm-admin 0.6.8 → 0.7.1
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 +2 -1
- 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/form_field.rb +1 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/field_display_helper.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/yarn.lock +8 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd6e52585c8e5905473e55c80965b14da5679c38bbff1aee74a97e436552dbe
|
4
|
+
data.tar.gz: ec82f91588d998b19a6361365599e13223ad7254998481cfd7b83843b0908f3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8644e740f96af96d2a88ade91b50f697585e7b9e95a124a4a07afe84ea9cc6ef9302ff73f1311ea0ebc0ba49eb367d601bc5bb5bb09085406934d416f0222ff3
|
7
|
+
data.tar.gz: 55c444fdf18df0a8710014a361765268068561eb7d5704650d3a7ba1b296dcc8780510f948c161d36ceeae3c2a5a3a3fbc32e076c9b2459312dead070b1a951c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CmAdmin
|
2
2
|
|
3
|
-
|
3
|
+
An admin gem for Ruby on Rails application. Get your admin panel setup running quickly.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -31,6 +31,7 @@ You can find more detailed documentation [here](https://github.com/commutatus/cm
|
|
31
31
|
## Demo
|
32
32
|
|
33
33
|
For demo check [here](http://cm-admin.labs.commutatus.com/admin/users/)
|
34
|
+
For demo repo check [here](https://github.com/commutatus/cm-admin-panel-demo)
|
34
35
|
|
35
36
|
## Development
|
36
37
|
|
@@ -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
|
@@ -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
@@ -55,7 +55,7 @@ module CmAdmin
|
|
55
55
|
ar_object.send(field.field_name).to_s.upcase
|
56
56
|
end
|
57
57
|
when :attachment
|
58
|
-
|
58
|
+
show_attachment_value(ar_object, field)
|
59
59
|
when :drawer
|
60
60
|
content_tag :div, class: 'd-flex' do
|
61
61
|
concat content_tag(:div, ar_object.send(field.field_name).to_s, class: 'text-ellipsis')
|
@@ -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
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,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.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sajinmp
|
8
8
|
- anbublacky
|
9
9
|
- AdityaTiwari2102
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-06-02 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
|
@@ -239,7 +240,7 @@ licenses:
|
|
239
240
|
metadata:
|
240
241
|
homepage_uri: https://github.com/commutatus/cm-admin
|
241
242
|
source_code_uri: https://github.com/commutatus/cm-admin
|
242
|
-
post_install_message:
|
243
|
+
post_install_message:
|
243
244
|
rdoc_options: []
|
244
245
|
require_paths:
|
245
246
|
- lib
|
@@ -254,8 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
255
|
- !ruby/object:Gem::Version
|
255
256
|
version: '0'
|
256
257
|
requirements: []
|
257
|
-
rubygems_version: 3.2.
|
258
|
-
signing_key:
|
258
|
+
rubygems_version: 3.2.3
|
259
|
+
signing_key:
|
259
260
|
specification_version: 4
|
260
261
|
summary: This is an admin panel gem
|
261
262
|
test_files: []
|