cm-admin 0.6.9 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49fd7ed0a9a218cb0daf20adbc60425aef06257f63c540142c378f753a46fd2e
4
- data.tar.gz: 3bf484aae8a7a29d83dedbcb4164c0ce97f7081ee0b7d4acea6d4ea704e83cbb
3
+ metadata.gz: fe6c3a31ee4222884516e3f0cace7e5ef9f3bbee1a67ad34f5d5f3d4201c5859
4
+ data.tar.gz: db9eaa4f12d9353bacfc94e7a74bdab8450a1b3f6bc84722815c52b308ebe1b3
5
5
  SHA512:
6
- metadata.gz: 3f9a3fea9d9a14718bf34ed7a4eb8e7081fbac8f05d6c945f7e81d46a43de63c2bde20ef4e8c97db013609b8950d07a5db82221b73fc3a925293004438fee209
7
- data.tar.gz: ab11a6578e525cc1cdb6315b025d8fbcdb686e616a9cbac25a196f86d9ad470792ea7e8a03b0257b89d082d638c9854f1f19211d3fac74e2a3312618e4cec3f4
6
+ metadata.gz: 8677cceeb0829d35971662230da99ab04666e590e6f06e4645ef606714f5643c38ba0dfd510a41fa8b88639a1c5a73565813e781f503ae584768285177a4c782
7
+ data.tar.gz: 2b4179da8e301349e2af5a82a090bc8c4001def407c769c84a9a48caa3d5512c28a8cfea10086dc4da508e692ca6a6eb3f719f1eccfd43f824ed03c79dbf78bc
@@ -7,6 +7,7 @@ require("moment")
7
7
  require("bootstrap")
8
8
  require('flatpickr')
9
9
  require("jgrowl")
10
+ require("trix")
10
11
  require('./scaffolds.js')
11
12
  require('./form_validation.js')
12
13
  require('./quick_search.js')
@@ -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.downcase}_index_path") && (@model.current_action.name == 'show' || @model.current_action.layout_type.present?)
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.downcase}_index_path")
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', "#{page_url('new')}", class: 'primary-btn ml-2'
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}", "#{page_url('edit', @ar_object)}", class: 'primary-btn ml-2'
36
+ = link_to "Edit #{@model.name}", cm_admin.send(:"#{@model.name.underscore}_edit_path", @ar_object), class: 'primary-btn ml-2'
@@ -19,4 +19,4 @@
19
19
  p.form-title
20
20
  | Section heading
21
21
  .form-container__inner
22
- = generate_form(@ar_object, @model)
22
+ = generate_form(@ar_object.class.name.constantize.new, @model)
@@ -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.reflect_on_all_attachments.map {|x|
61
- if x.class.name.include?('HasOne')
62
- x.name
63
- elsif x.class.name.include?('HasMany')
64
- Hash[x.name.to_s, []]
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)
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.6.9"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require_tree .
3
+ *= require_self
4
+ */
5
+ @import "./actiontext.scss";
@@ -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
@@ -15,6 +15,7 @@
15
15
  "jquery": "^3.6.0",
16
16
  "moment": "^2.29.2",
17
17
  "popper.js": "^1.16.1",
18
+ "trix": "^2.0.0-beta.0",
18
19
  "turbolinks": "^5.2.0"
19
20
  },
20
21
  "version": "0.1.0",
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.0"
2701
- resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.0.tgz#00e8ca7c92109e94b0ddf32dac677d841028cfaf"
2702
- integrity sha512-VSJjT5oCNrFvCS6igjzPAt5hBzQ2qPBFIbJ03zLI9SE0mxwZpMw6BfJrbFHm1a141AavMEB8JHmBhWAd66PfCg==
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.6.9
4
+ version: 0.7.0
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-05-18 00:00:00.000000000 Z
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