cm-admin 0.9.1 → 1.0.0

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +82 -0
  3. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  5. data/Gemfile.lock +95 -8
  6. data/app/assets/config/cm_admin_manifest.js +1 -0
  7. data/app/assets/javascripts/cm_admin/application.js +5 -0
  8. data/app/{javascript/packs → assets/javascripts}/cm_admin/exports.js +0 -0
  9. data/app/{javascript/packs → assets/javascripts}/cm_admin/filters.js +20 -31
  10. data/app/{javascript/packs → assets/javascripts}/cm_admin/form_validation.js +0 -0
  11. data/app/{javascript/packs → assets/javascripts}/cm_admin/quick_search.js +16 -3
  12. data/app/assets/javascripts/cm_admin/scaffolds.js +44 -0
  13. data/app/assets/stylesheets/cm_admin/components/_input.scss +12 -0
  14. data/app/controllers/cm_admin/resource_controller.rb +10 -7
  15. data/app/helpers/cm_admin/application_helper.rb +0 -3
  16. data/app/javascript/packs/cm_admin/application.js +4 -4
  17. data/app/javascript/packs/cm_admin/scaffolds.js +51 -0
  18. data/app/views/layouts/cm_admin.html.slim +9 -4
  19. data/app/views/layouts/static.html.slim +3 -2
  20. data/bin/importmap +15 -0
  21. data/bin/webpack +8 -8
  22. data/bin/webpack-dev-server +9 -9
  23. data/cm_admin.gemspec +3 -0
  24. data/config/importmap.rb +12 -0
  25. data/config/webpack/development.js +1 -1
  26. data/config/webpack/environment.js +1 -1
  27. data/config/webpack/production.js +1 -1
  28. data/config/webpacker.yml +2 -2
  29. data/lib/cm_admin/configuration.rb +5 -2
  30. data/lib/cm_admin/engine.rb +36 -15
  31. data/lib/cm_admin/models/form_field.rb +8 -2
  32. data/lib/cm_admin/version.rb +1 -1
  33. data/lib/cm_admin/version_manager.rb +21 -0
  34. data/lib/cm_admin/view_helpers/form_field_helper.rb +183 -35
  35. data/lib/cm_admin.rb +7 -2
  36. data/lib/generators/cm_admin/templates/actiontext.scss +0 -1
  37. data/lib/tasks/webpack_install.rake +15 -13
  38. data/package-lock.json +18 -27
  39. data/yarn.lock +9 -9
  40. metadata +43 -6
data/bin/importmap ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # NOTE: make sure we are loading the correct versions of things
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
6
+
7
+ # NOTE: importmap requires some rails goodness that we don't have in the engine,
8
+ # because we don't have config/application.rb that loads the environment.
9
+ require 'rails'
10
+
11
+ # importmap-rails is not loaded automatically
12
+ require 'importmap-rails'
13
+
14
+ # the actual command runner
15
+ require 'importmap/commands'
data/bin/webpack CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
- ENV["NODE_ENV"] ||= "development"
3
+ ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
4
+ ENV['NODE_ENV'] ||= 'development'
5
5
 
6
- require "pathname"
7
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
6
+ require 'pathname'
7
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "bundler/setup"
10
+ require 'bundler/setup'
11
11
 
12
- require "webpacker"
13
- require "webpacker/webpack_runner"
12
+ require 'webpacker'
13
+ require 'webpacker/webpack_runner'
14
14
 
15
- APP_ROOT = File.expand_path("..", __dir__)
15
+ APP_ROOT = File.expand_path('..', __dir__)
16
16
  Dir.chdir(APP_ROOT) do
17
17
  Webpacker::WebpackRunner.run(ARGV)
18
18
  end
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
- ENV["NODE_ENV"] ||= "development"
3
+ ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
4
+ ENV['NODE_ENV'] ||= 'development'
5
5
 
6
- require "pathname"
7
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
6
+ require 'pathname'
7
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "bundler/setup"
10
+ require 'bundler/setup'
11
11
 
12
- require "webpacker"
13
- require "webpacker/dev_server_runner"
12
+ require 'webpacker'
13
+ require 'webpacker/dev_server_runner'
14
14
 
15
- APP_ROOT = File.expand_path("..", __dir__)
15
+ APP_ROOT = File.expand_path('..', __dir__)
16
16
  Dir.chdir(APP_ROOT) do
17
17
  Webpacker::DevServerRunner.run(ARGV)
18
- end
18
+ end
data/cm_admin.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.bindir = "exe"
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
+ spec.add_runtime_dependency('rails', '>= 6.0')
29
30
  spec.add_runtime_dependency 'caxlsx_rails'
30
31
  spec.add_runtime_dependency 'cocoon', '~> 1.2.15'
31
32
  spec.add_runtime_dependency 'local_time', '~> 2.1.0'
@@ -34,4 +35,6 @@ Gem::Specification.new do |spec|
34
35
  spec.add_runtime_dependency 'slim', '~> 4.1.0'
35
36
  spec.add_runtime_dependency 'webpacker', '~> 5.4.3'
36
37
  spec.add_runtime_dependency 'csv-importer', '~> 0.8.2'
38
+ spec.add_dependency 'importmap-rails'
39
+
37
40
  end
@@ -0,0 +1,12 @@
1
+ pin 'cm_admin/application'
2
+ pin 'jquery', to: 'https://ga.jspm.io/npm:jquery@3.6.0/dist/jquery.js', preload: true
3
+ pin 'bootstrap', to: 'https://ga.jspm.io/npm:bootstrap@5.1.3/dist/js/bootstrap.esm.js', preload: true
4
+ pin '@popperjs/core', to: 'https://ga.jspm.io/npm:@popperjs/core@2.11.5/lib/index.js', preload: true
5
+ pin 'flatpickr', to: 'https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js'
6
+ pin 'jgrowl', to: 'https://ga.jspm.io/npm:jgrowl@1.4.8/jquery.jgrowl.js'
7
+ pin 'moment', to: 'https://ga.jspm.io/npm:moment@2.29.4/moment.js'
8
+ pin 'trix', to: 'https://ga.jspm.io/npm:trix@2.0.0-beta.0/dist/trix.js'
9
+ pin '@fortawesome/fontawesome-free', to: 'https://ga.jspm.io/npm:@fortawesome/fontawesome-free@6.1.1/js/all.js'
10
+ pin 'daterangepicker', to: 'https://ga.jspm.io/npm:daterangepicker@3.1.0/daterangepicker.js'
11
+ pin '@nathanvda/cocoon', to: 'https://ga.jspm.io/npm:@nathanvda/cocoon@1.2.14/cocoon.js'
12
+ pin 'select2', to: 'https://ga.jspm.io/npm:select2@4.1.0-rc.0/dist/js/select2.js'
@@ -2,4 +2,4 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2
2
 
3
3
  const environment = require('./environment')
4
4
 
5
- module.exports = environment.toWebpackConfig()
5
+ module.exports = environment.toWebpackConfig()
@@ -10,4 +10,4 @@ environment.plugins.prepend('Provide',
10
10
  })
11
11
  )
12
12
 
13
- module.exports = environment
13
+ module.exports = environment
@@ -2,4 +2,4 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
2
2
 
3
3
  const environment = require('./environment')
4
4
 
5
- module.exports = environment.toWebpackConfig()
5
+ module.exports = environment.toWebpackConfig()
data/config/webpacker.yml CHANGED
@@ -10,7 +10,7 @@ default: &default
10
10
 
11
11
  # Additional paths webpack should lookup modules
12
12
  # ['app/assets', 'engine/foo/app/assets']
13
- additional_paths: []
13
+ additional_paths: ['app/assets']
14
14
 
15
15
  # Reload manifest.json on all requests so we reload latest compiled packs
16
16
  cache_manifest: false
@@ -89,4 +89,4 @@ production:
89
89
  extract_css: true
90
90
 
91
91
  # Cache manifest.json for performance
92
- cache_manifest: true
92
+ cache_manifest: true
@@ -1,10 +1,13 @@
1
1
  module CmAdmin
2
2
  class Configuration
3
- attr_accessor :layout, :included_models, :cm_admin_models
4
-
3
+ attr_accessor :layout, :included_models, :cm_admin_models, :authorized_roles
4
+
5
5
  def initialize
6
+ @layout = 'admin'
6
7
  @included_models = []
7
8
  @cm_admin_models = []
9
+ @authorized_roles = []
8
10
  end
11
+
9
12
  end
10
13
  end
@@ -1,4 +1,7 @@
1
1
  require 'rails'
2
+ require 'importmap-rails'
3
+ require 'cm_admin/version_manager'
4
+
2
5
  module CmAdmin
3
6
  class Engine < Rails::Engine
4
7
  isolate_namespace CmAdmin
@@ -17,24 +20,42 @@ module CmAdmin
17
20
  )
18
21
  end
19
22
 
20
- initializer "webpacker.proxy" do |app|
21
- insert_middleware = begin
22
- CmAdmin.webpacker.config.dev_server.present?
23
- rescue
24
- nil
25
- end
26
- next unless insert_middleware
27
-
28
- app.middleware.insert_before(
29
- 0, Webpacker::DevServerProxy, # "Webpacker::DevServerProxy" if Rails version < 5
30
- ssl_verify_none: true,
31
- webpacker: CmAdmin.webpacker
32
- )
33
- end
34
-
35
23
  def mount_path
36
24
  CmAdmin::Engine.routes.find_script_name({})
37
25
  end
38
26
 
27
+ if VersionManager.rails6?
28
+ initializer "webpacker.proxy" do |app|
29
+ insert_middleware = begin
30
+ CmAdmin.webpacker.config.dev_server.present?
31
+ rescue
32
+ nil
33
+ end
34
+ next unless insert_middleware
35
+
36
+ app.middleware.insert_before(
37
+ 0, Webpacker::DevServerProxy, # "Webpacker::DevServerProxy" if Rails version < 5
38
+ ssl_verify_none: true,
39
+ webpacker: CmAdmin.webpacker
40
+ )
41
+ end
42
+ elsif VersionManager.rails7?
43
+ initializer "cm_admin.importmap", before: "importmap" do |app|
44
+ # NOTE: this will add pins from this engine to the main app
45
+ # https://github.com/rails/importmap-rails#composing-import-maps
46
+ app.config.importmap.paths << root.join("config/importmap.rb")
47
+
48
+ # NOTE: something about cache; I did not look into it.
49
+ # https://github.com/rails/importmap-rails#sweeping-the-cache-in-development-and-test
50
+ app.config.importmap.cache_sweepers << root.join("app/assets/javascripts")
51
+ end
52
+
53
+ # NOTE: add engine manifest to precompile assets in production
54
+ initializer "cm_admin.assets" do |app|
55
+ app.config.assets.precompile += %w[cm_admin_manifest]
56
+ end
57
+ end
58
+
59
+
39
60
  end
40
61
  end
@@ -1,8 +1,13 @@
1
1
  module CmAdmin
2
2
  module Models
3
3
  class FormField
4
- attr_accessor :field_name, :label, :header, :input_type, :collection, :disabled, :helper_method, :placeholder, :display_if, :html_attr
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
4
+ attr_accessor :field_name, :label, :header, :input_type, :collection, :disabled, :helper_method,
5
+ :placeholder, :display_if, :html_attr, :target
6
+
7
+ VALID_INPUT_TYPES = %i[
8
+ integer decimal string single_select multi_select date date_time text
9
+ single_file_upload multi_file_upload hidden rich_text check_box radio_button
10
+ ].freeze
6
11
 
7
12
  def initialize(field_name, input_type, attributes = {})
8
13
  @field_name = field_name
@@ -20,6 +25,7 @@ module CmAdmin
20
25
  self.input_type = :string
21
26
  self.placeholder = "Enter #{self.field_name.to_s.downcase.gsub('_', ' ')}"
22
27
  self.html_attr = {}
28
+ self.target = {}
23
29
  end
24
30
  end
25
31
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '0.9.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ module CmAdmin
2
+ class VersionManager
3
+ class << self
4
+ def rails6?
5
+ Rails::VERSION::MAJOR == 6
6
+ end
7
+
8
+ def rails7?
9
+ Rails::VERSION::MAJOR == 7
10
+ end
11
+
12
+ def use_importmap?
13
+ rails7? && File.exist?('config/importmap.rb')
14
+ end
15
+
16
+ def use_webpacker?
17
+ rails6? && defined?(Webpacker) == 'constant'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,50 +1,198 @@
1
1
  module CmAdmin
2
2
  module ViewHelpers
3
3
  module FormFieldHelper
4
- def input_field_for_column(f, field)
5
- return unless field.display_if.call(f.object)
6
- value = field.helper_method ? send(field.helper_method, f.object, field.field_name) : f.object.send(field.field_name)
7
- is_required = f.object._validators[field.field_name].map(&:kind).include?(:presence)
4
+ def input_field_for_column(form_obj, cm_field)
5
+ return unless cm_field.display_if.call(form_obj.object)
6
+
7
+ value = cm_field.helper_method ? send(cm_field.helper_method, form_obj.object, cm_field.field_name) : form_obj.object.send(cm_field.field_name)
8
+ is_required = form_obj.object._validators[cm_field.field_name].map(&:kind).include?(:presence)
8
9
  required_class = is_required ? 'required' : ''
9
- case field.input_type
10
- when :integer
11
- return f.text_field field.field_name, class: "normal-input #{required_class}", disabled: field.disabled, value: value, placeholder: "Enter #{field.field_name.to_s.humanize.downcase}", data: { behaviour: 'integer-only' }
12
- when :decimal
13
- return f.number_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: 'decimal-only' }
14
- when :string
15
- 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('_', ' ')}"
16
- when :single_select
17
- return f.select field.field_name, options_for_select(select_collection_value(f.object, field), f.object.send(field.field_name)), {include_blank: field.placeholder.to_s}, class: "normal-input #{required_class} select-2", disabled: field.disabled
18
- when :multi_select
19
- return f.select field.field_name, options_for_select(select_collection_value(f.object, field), f.object.send(field.field_name)), {include_blank: "Select #{field.field_name.to_s.downcase.gsub('_', ' ')}"}, class: "normal-input #{required_class} select-2", disabled: field.disabled, multiple: true
20
- when :date
21
- 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' }
22
- when :date_time
23
- 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' }
24
- when :text
25
- return f.text_area field.field_name, class: "normal-input #{required_class}", placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}"
26
- when :rich_text
27
- return f.rich_text_area field.field_name, class: "normal-input #{required_class}", placeholder: "Enter #{field.field_name.to_s.downcase.gsub('_', ' ')}"
28
- when :single_file_upload
29
- return f.file_field field.field_name, class: "normal-input #{required_class}"
30
- when :multi_file_upload
31
- return f.file_field field.field_name, multiple: true, class: "normal-input #{required_class}"
32
- when :hidden
33
- return f.hidden_field field.field_name, value: value, name: field.html_attr[:name] || "#{f.object_name}[#{field.field_name}]"
34
- end
10
+ target_action = @model.available_actions.select{|x| x.name == cm_field.target[:action_name].to_s}.first if cm_field.target.present?
11
+ send("cm_#{cm_field.input_type}_field", form_obj, cm_field, value, required_class, target_action)
12
+ end
13
+
14
+ def cm_integer_field(form_obj, cm_field, value, required_class, _target_action)
15
+ form_obj.text_field cm_field.field_name,
16
+ class: "normal-input #{required_class}",
17
+ disabled: cm_field.disabled,
18
+ value: value,
19
+ placeholder: "Enter #{cm_field.field_name.to_s.humanize.downcase}",
20
+ data: { behaviour: 'integer-only' }
21
+ end
22
+
23
+ def cm_decimal_field(form_obj, cm_field, value, required_class, _target_action)
24
+ form_obj.number_field cm_field.field_name,
25
+ class: "normal-input #{required_class}",
26
+ disabled: cm_field.disabled,
27
+ value: value,
28
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}",
29
+ data: { behaviour: 'decimal-only' }
30
+ end
31
+
32
+ def cm_string_field(form_obj, cm_field, value, required_class, _target_action)
33
+ form_obj.text_field cm_field.field_name,
34
+ class: "normal-input #{required_class}",
35
+ disabled: cm_field.disabled,
36
+ value: value,
37
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}"
38
+ end
39
+
40
+ def cm_single_select_field(form_obj, cm_field, value, required_class, target_action)
41
+ form_obj.select cm_field.field_name, options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
42
+ { include_blank: cm_field.placeholder.to_s },
43
+ class: "normal-input #{required_class} select-2",
44
+ disabled: cm_field.disabled,
45
+ data: {
46
+ field_name: cm_field.field_name,
47
+ field_type: 'linked-field',
48
+ target_action: target_action&.name,
49
+ target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
50
+ }
51
+ end
52
+
53
+ def cm_multi_select_field(form_obj, cm_field, value, required_class, target_action)
54
+ form_obj.select cm_field.field_name,
55
+ options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
56
+ { include_blank: "Select #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}" },
57
+ class: "normal-input #{required_class} select-2",
58
+ disabled: cm_field.disabled, multiple: true
59
+ end
60
+
61
+ def cm_date_field(form_obj, cm_field, value, required_class, _target_action)
62
+ form_obj.text_field cm_field.field_name,
63
+ class: "normal-input #{required_class}",
64
+ disabled: cm_field.disabled,
65
+ value: value&.strftime('%d-%m-%Y'),
66
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}",
67
+ data: { behaviour: 'date-only' }
68
+ end
69
+
70
+ def cm_date_time_field(form_obj, cm_field, value, required_class, _target_action)
71
+ form_obj.text_field cm_field.field_name,
72
+ class: "normal-input #{required_class}",
73
+ disabled: cm_field.disabled,
74
+ value: value,
75
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}",
76
+ data: { behaviour: 'date-time' }
77
+ end
78
+
79
+ def cm_text_field(form_obj, cm_field, value, required_class, _target_action)
80
+ form_obj.text_area cm_field.field_name,
81
+ class: "normal-input #{required_class}",
82
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}"
83
+ end
84
+
85
+ def cm_rich_text_field(form_obj, cm_field, value, required_class, _target_action)
86
+ form_obj.rich_text_area cm_field.field_name,
87
+ class: "normal-input #{required_class}",
88
+ placeholder: "Enter #{cm_field.field_name.to_s.downcase.gsub('_', ' ')}"
89
+ end
90
+
91
+ def cm_single_file_upload_field(form_obj, cm_field, value, required_class, _target_action)
92
+ form_obj.file_field cm_field.field_name, class: "normal-input #{required_class}"
93
+ end
94
+
95
+ def cm_single_multi_upload_field(form_obj, cm_field, value, required_class, _target_action)
96
+ form_obj.file_field cm_field.field_name, multiple: true, class: "normal-input #{required_class}"
97
+ end
98
+
99
+ def cm_check_box_field(form_obj, cm_field, value, required_class, target_action)
100
+ format_check_box_options(value, form_obj, cm_field, required_class, target_action)
101
+ end
102
+
103
+ def cm_radio_button_field(form_obj, cm_field, value, required_class, _target_action)
104
+ format_radio_button_options(value, form_obj)
105
+ end
106
+
107
+ def cm_hidden_field(form_obj, cm_field, value, required_class, _target_action)
108
+ form_obj.hidden_field cm_field.field_name,
109
+ value: value,
110
+ name: cm_field.html_attr[:name] || "#{form_obj.object_name}[#{cm_field.field_name}]"
35
111
  end
36
112
 
37
113
  # Refactor: Collection argument can be removed.
38
114
  # helper_method argument will accept a method where value can be passed.
39
- def select_collection_value(object, field)
40
- if field.helper_method
41
- collection = send(field.helper_method, object, field.field_name)
42
- elsif field.collection
43
- collection = field.collection
115
+ def select_collection_value(object, cm_field)
116
+ if cm_field.helper_method
117
+ collection = send(cm_field.helper_method, object, cm_field.field_name)
118
+ elsif cm_field.collection
119
+ collection = cm_field.collection
44
120
  else
45
121
  collection = []
46
122
  end
47
123
  end
124
+
125
+ def format_check_box_options(value, form_obj, cm_field, required_class, target_action)
126
+ if value.class == Array
127
+ format_check_box_array(value, form_obj, cm_field, required_class, target_action)
128
+ else
129
+ form_obj.check_box cm_field.field_name,
130
+ {
131
+ class: "normal-input cm-checkbox #{required_class}",
132
+ disabled: cm_field.disabled,
133
+ data: {
134
+ field_name: cm_field.field_name,
135
+ field_type: 'linked-field',
136
+ target_action: target_action&.name,
137
+ target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
138
+ }
139
+ }
140
+ end
141
+ end
142
+
143
+ def format_check_box_array(options, form_obj, cm_field, required_class, target_action)
144
+ content_tag :div do
145
+ options.each do |key, val|
146
+ concat format_check_box(val, key, form_obj, cm_field, required_class, target_action)
147
+ end
148
+ end
149
+ end
150
+
151
+ def format_check_box(val, key, form_obj, cm_field, required_class, target_action)
152
+ content_tag :div, class: 'cm-checkbox-section' do
153
+ concat format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
154
+ concat content_tag(:div, key, class: 'cm-checkbox-label')
155
+ end
156
+ end
157
+
158
+ def format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
159
+ content_tag :div, class: 'cm-radio-tag' do
160
+ concat form_obj.check_box cm_field.field_name,
161
+ {
162
+ class: "normal-input cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
163
+ disabled: cm_field.disabled,
164
+ name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
165
+ data: {
166
+ field_name: cm_field.field_name,
167
+ field_type: 'linked-field',
168
+ target_action: target_action&.name,
169
+ target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path", ':param_1') : ''
170
+ }
171
+ }, val
172
+ end
173
+ end
174
+
175
+
176
+ def format_radio_button_options(options, form_obj)
177
+ content_tag :div do
178
+ options.each do |val, key|
179
+ concat format_radio_option(val, key, form_obj)
180
+ end
181
+ end
182
+ end
183
+
184
+ def format_radio_option(val, key, form_obj)
185
+ content_tag :div, class: 'cm-radio-section' do
186
+ concat format_radio_button(val, form_obj)
187
+ concat content_tag(:div, key, class: 'cm-radio-label')
188
+ end
189
+ end
190
+
191
+ def format_radio_button(val, form_obj)
192
+ content_tag :div, class: 'cm-radio-tag' do
193
+ concat form_obj.radio_button :level, val, class: 'normal-input cm-radio'
194
+ end
195
+ end
48
196
  end
49
197
  end
50
198
  end
data/lib/cm_admin.rb CHANGED
@@ -14,9 +14,9 @@ module CmAdmin
14
14
  @@authorized_roles ||= []
15
15
  @@included_models ||= []
16
16
  @@cm_admin_models ||= []
17
-
18
17
 
19
18
  class << self
19
+
20
20
  def webpacker
21
21
  @webpacker ||= ::Webpacker::Instance.new(
22
22
  root_path: CmAdmin::Engine.root,
@@ -25,7 +25,12 @@ module CmAdmin
25
25
  end
26
26
 
27
27
  def configure(&block)
28
- instance_eval(&block)
28
+ # instance_eval(&block)
29
+ @config ||= Configuration.new
30
+ yield(@config)
31
+ end
32
+
33
+ def layout
29
34
  end
30
35
 
31
36
  def config
@@ -3,7 +3,6 @@
3
3
  // the trix-editor content (whether displayed or under editing). Feel free to incorporate this
4
4
  // inclusion directly in any other asset bundle and remove this file.
5
5
  //
6
- //= require trix/dist/trix
7
6
 
8
7
  // We need to override trix.css’s image gallery styles to accommodate the
9
8
  // <action-text-attachment> element we wrap around attachments. Otherwise,
@@ -4,11 +4,11 @@
4
4
  # end
5
5
 
6
6
  def ensure_log_goes_to_stdout
7
- old_logger = Webpacker.logger
8
- Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
9
- yield
7
+ old_logger = Webpacker.logger
8
+ Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
9
+ yield
10
10
  ensure
11
- Webpacker.logger = old_logger
11
+ Webpacker.logger = old_logger
12
12
  end
13
13
 
14
14
  namespace :cm_admin do
@@ -51,13 +51,15 @@ def enhance_assets_precompile
51
51
  end
52
52
  end
53
53
 
54
- # Compile packs after we've compiled all other assets during precompilation
55
- skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
54
+ if CmAdmin::VersionManager.rails6?
55
+ # Compile packs after we've compiled all other assets during precompilation
56
+ skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
56
57
 
57
- unless skip_webpacker_precompile
58
- if Rake::Task.task_defined?("assets:precompile")
59
- enhance_assets_precompile
60
- else
61
- Rake::Task.define_task("assets:precompile" =>"cm_admin:webpacker:compile")
62
- end
63
- end
58
+ unless skip_webpacker_precompile
59
+ if Rake::Task.task_defined?("assets:precompile")
60
+ enhance_assets_precompile
61
+ else
62
+ Rake::Task.define_task("assets:precompile" =>"cm_admin:webpacker:compile")
63
+ end
64
+ end
65
+ end