cm-admin 1.5.39 → 1.5.40

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fefeb86ee44a447393ca13e95d50acef37ecad2512b85518b24aaf09d307b777
4
- data.tar.gz: 993f0514720d1af46c50f43ce7f2a00086b1823b0621b726e0f3c400170c30ab
3
+ metadata.gz: f475032d34987ece76840fc174951e055960b8dfbd98ee71b8b57616eddc501d
4
+ data.tar.gz: e745cc4fafd087fcbc19edcb14d66a11c15ec04d072d6e0a8512a34f3438a91a
5
5
  SHA512:
6
- metadata.gz: 602dbdb98de4efd9c28149c8b3bb501d41274d36c13aa8053cb5e3c2e1e2b9581bfeeeb35d1650eebd81787c164cf821df146e5c030eb2ba882246dbc2d5e033
7
- data.tar.gz: 7c90ad69eafc91876869dbbe5064d59fd698435d49bcdca6fca5fc43049055b0a0786dd0a563ba05e8cf09551b17114c2f5bf9195833b6dd90aab62d983294c5
6
+ metadata.gz: 804bebee2f580d8ad4b63c389bc5f5af3c84de8ebc3aa71ead30392baf104a25b106983138d3ac12cbdabce6ebdb7987ddc864ed9cdf26174c7bc0fdc7cbbddf
7
+ data.tar.gz: bb9ef705565cafdd1229281da4ad28dedf126557943779390db4c1c53f8d5d88f9b0bd4220c3d609e5cf19070a9a8c502c6c0f7cfbd9413d8502783aa327c932
@@ -0,0 +1,45 @@
1
+ name: Deploy Yard Docs
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: "3.3"
15
+ - name: Install Yard gem
16
+ run: gem install yard
17
+ - name: Build Yard Docs
18
+ run: yardoc lib/cm_admin/models/dsl_method.rb
19
+ - name: Upload artifact
20
+ uses: actions/upload-pages-artifact@v1
21
+ with:
22
+ name: github-pages # name of the artifact
23
+ path: ./doc
24
+ if-no-files-found: error
25
+
26
+ deploy:
27
+ # Add a dependency to the build job
28
+ needs: build
29
+
30
+ # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
31
+ permissions:
32
+ pages: write # to deploy to Pages
33
+ id-token: write # to verify the deployment originates from an appropriate source
34
+
35
+ # Deploy to the github-pages environment
36
+ environment:
37
+ name: github-pages # artifact name
38
+ url: ${{ steps.deployment.outputs.page_url }}
39
+
40
+ # Specify runner + deployment step
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - name: Deploy to GitHub Pages
44
+ id: deployment
45
+ uses: actions/deploy-pages@v2
data/CNAME ADDED
@@ -0,0 +1 @@
1
+ docs.cm-admin.commutatus.com
data/Gemfile.lock CHANGED
@@ -12,6 +12,7 @@ PATH
12
12
  rails (>= 6.0)
13
13
  slim (~> 4.1.0)
14
14
  webpacker (~> 5.4.3)
15
+ yard
15
16
 
16
17
  GEM
17
18
  remote: https://rubygems.org/
@@ -257,6 +258,7 @@ GEM
257
258
  websocket-driver (0.7.6)
258
259
  websocket-extensions (>= 0.1.0)
259
260
  websocket-extensions (0.1.5)
261
+ yard (0.9.36)
260
262
  zeitwerk (2.6.15)
261
263
 
262
264
  PLATFORMS
@@ -109,6 +109,18 @@
109
109
  }
110
110
 
111
111
  //checkbox-style
112
+
113
+ .cm-checkbox-section {
114
+ width: 100%;
115
+ float: left;
116
+ .cm-checkbox-label {
117
+ float: left;
118
+ padding-left: 10px;
119
+ }
120
+ .cm-checkbox-tag {
121
+ float: left;
122
+ }
123
+ }
112
124
  input.cm-checkbox[type="checkbox"] {
113
125
  position: relative;
114
126
  // display: block;
@@ -89,7 +89,7 @@ module CmAdmin
89
89
  end
90
90
 
91
91
  def import
92
- @model = Model.find_by({name: controller_name.titleize})
92
+ @model = Model.find_by({name: controller_name.classify})
93
93
  allowed_params = params.permit(file_import: [:associated_model_name, :import_file]).to_h
94
94
  file_import = ::FileImport.new(allowed_params[:file_import])
95
95
  file_import.added_by = Current.user
@@ -101,7 +101,7 @@ module CmAdmin
101
101
  end
102
102
 
103
103
  def import_form
104
- @model = Model.find_by({name: controller_name.titleize})
104
+ @model = Model.find_by({name: controller_name.classify})
105
105
  respond_to do |format|
106
106
  format.html { render '/cm_admin/main/import_form' }
107
107
  end
data/cm_admin.gemspec CHANGED
@@ -37,5 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_runtime_dependency('rails', '>= 6.0')
38
38
  spec.add_runtime_dependency 'slim', '~> 4.1.0'
39
39
  spec.add_runtime_dependency 'webpacker', '~> 5.4.3'
40
+ spec.add_runtime_dependency 'yard'
40
41
  spec.add_dependency 'importmap-rails'
41
42
  end
@@ -3,42 +3,84 @@ module CmAdmin
3
3
  module DslMethod
4
4
  extend ActiveSupport::Concern
5
5
 
6
- def cm_index(page_title: nil, page_description: nil, partial: nil, view_type: :table, &block)
6
+ # Create a table for index page with pagination.
7
+ #
8
+ # @param page_title [String] the title of page
9
+ # @param page_description [String] the description of page
10
+ # @param partial [String] the partial path of page
11
+ # @param view_type [Symbol] view type of page, `:table`, `:card` or `:kanban
12
+ # @example Index page
13
+ # cm_index(page_title: "Home", page_description: 'Home page', partial: 'pages/home', view_type: :table)
14
+ def cm_index(page_title: nil, page_description: nil, partial: nil, view_type: :table)
7
15
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'index')
8
16
  @current_action.set_values(page_title, page_description, partial, view_type)
9
17
  yield
10
18
  end
11
19
 
12
- def cm_show(page_title: nil, page_description: nil, partial: nil, &block)
20
+ # Create a view for show page
21
+ #
22
+ # @param page_title [String] or [Symbol] the title of page, if symbol passed, it will be a method name on model
23
+ # @param page_description [String] the description of page
24
+ # @param partial [String] the partial path of page
25
+ #
26
+ # @example Showing page
27
+ # cm_show(page_title: "Home", page_description: 'Home page', partial: 'pages/home')
28
+ def cm_show(page_title: nil, page_description: nil, partial: nil)
13
29
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
14
30
  @current_action.set_values(page_title, page_description, partial)
15
31
  yield
16
32
  end
17
33
 
18
- def cm_edit(page_title: nil, page_description: nil, partial: nil, redirect_to: nil, &block)
34
+ # Create a form for edit action
35
+ #
36
+ # @param page_title [String] or [Symbol] the title of page, if symbol passed, it will be a method name on model
37
+ # @param page_description [String] the description of page
38
+ # @param partial [String] the partial path of page
39
+ # @param redirect_to [Proc, nil] A lambda that takes the current object and redirect to path after update
40
+ #
41
+ # @example Editing page with a redirect
42
+ # cm_edit(page_title: "Home", redirect_to: ->(current_object) { "/pages/#{current_object.id}" })
43
+ def cm_edit(page_title: nil, page_description: nil, partial: nil, redirect_to: nil)
19
44
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'edit')
20
45
  @current_action.set_values(page_title, page_description, partial, redirect_to)
21
46
  yield
22
47
  end
23
48
 
24
- def cm_new(page_title: nil, page_description: nil, partial: nil, redirect_to: nil, &block)
49
+ # Create a form for new action
50
+ #
51
+ # @param page_title [String] the title of page
52
+ # @param page_description [String] the description of page
53
+ # @param partial [String] the partial path of page
54
+ # @param redirect_to [Proc, nil] A lambda that takes the current object and redirect to path after create
55
+ #
56
+ # @example Creating a new page with a redirect
57
+ # cm_new(page_title: "Home", redirect_to: ->(current_object) { "/pages/#{current_object.id}" })
58
+ def cm_new(page_title: nil, page_description: nil, partial: nil, redirect_to: nil)
25
59
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'new')
26
60
  @current_action.set_values(page_title, page_description, partial, redirect_to)
27
61
  yield
28
62
  end
29
63
 
64
+ # Set page title for current action
65
+ # @param title [String] the title of page
30
66
  def page_title(title)
31
67
  return unless @current_action
32
68
 
33
69
  @current_action.page_title = title
34
70
  end
35
71
 
72
+ # Set page description for current action
73
+ # @param description [String] the description of page
36
74
  def page_description(description)
37
75
  return unless @current_action
38
76
 
39
77
  @current_action.page_description = description
40
78
  end
41
79
 
80
+ # Set kanban view for current action
81
+ # @param column_name [String] the name of column
82
+ # @param exclude [Array] the array of fields to exclude
83
+ # @param only [Array] the array of fields to include
42
84
  def kanban_view(column_name, exclude: [], only: [])
43
85
  return unless @current_action
44
86
 
@@ -47,19 +89,33 @@ module CmAdmin
47
89
  @current_action.kanban_attr[:only] = only
48
90
  end
49
91
 
92
+ # Set scopes for current action
93
+ # @param scopes [Array] the array of scopes
50
94
  def scope_list(scopes = [])
51
95
  return unless @current_action
52
96
 
53
97
  @current_action.scopes = scopes
54
98
  end
55
99
 
100
+ # Create a new tab on show page.
101
+ #
102
+ # @param tab_name [String] or [Symbol] the name of tab
103
+ # @param custom_action [String] the name of custom action
104
+ # @param associated_model [String] the name of associated model
105
+ # @param layout_type [String] the layout type of tab, `'cm_association_index'`, `'cm_association_show'`
106
+ # @param layout [String] the layout of tab
107
+ # @param partial [String] the partial path of tab
108
+ # @param display_if [Proc] A lambda that takes the current object and return true or false
109
+ #
110
+ # @example Creating a tab
111
+ # tab(:comments, 'comment', associated_model: 'comments', layout_type: 'cm_association_index')
56
112
  def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, display_if: nil, &block)
57
113
  if custom_action.to_s == ''
58
114
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
59
115
  @available_tabs << CmAdmin::Models::Tab.new(tab_name, '', display_if, &block)
60
116
  else
61
117
  action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/' + custom_action,
62
- layout_type: layout_type, layout: layout, partial: partial, child_records: associated_model,
118
+ layout_type:, layout:, partial:, child_records: associated_model,
63
119
  action_type: :custom, display_type: :page, model_name: name)
64
120
  @available_actions << action
65
121
  @current_action = action
@@ -68,21 +124,47 @@ module CmAdmin
68
124
  yield if block
69
125
  end
70
126
 
127
+ # Create a new row on page or form.
128
+ # @param display_if [Proc] A lambda that takes the current object and return true or false
129
+ # @param html_attrs [Hash] A hash that contains html attributes
130
+ # @example Creating a row
131
+ # row(display_if: ->(current_object) { current_object.name == 'John' }, html_attrs: { class: 'row-class' }) do
71
132
  def row(display_if: nil, html_attrs: nil, &block)
72
133
  @available_fields[@current_action.name.to_sym] ||= []
73
134
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Row.new(@current_action, @model, display_if, html_attrs, &block)
74
135
  end
75
136
 
137
+ # Create a new section on page or form.
138
+ # @param section_name [String] the name of section
139
+ # @param display_if [Proc] A lambda that takes the current object and return true or false
140
+ # @param col_size [Integer] the size of column according to grid view
141
+ # @param html_attrs [Hash] A hash that contains html attributes
142
+
143
+ # @example Creating a section
144
+ # cm_section('Basic Information', display_if: ->(current_object) { current_object.name == 'John' }, col_size: 6, html_attrs: { class: 'section-class' }) do
76
145
  def cm_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
77
146
  @available_fields[@current_action.name.to_sym] ||= []
78
147
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
79
148
  end
80
149
 
81
- # This method is deprecated. Use cm_section instead.
150
+ # @deprecated Use {#cm_section} instead of this method
82
151
  def cm_show_section(section_name, display_if: nil, html_attrs: nil, &block)
83
- cm_section(section_name, display_if: display_if, html_attrs: html_attrs, &block)
152
+ cm_section(section_name, display_if:, html_attrs:, &block)
84
153
  end
85
154
 
155
+ # Create a new column on index layout.
156
+ # @param field_name [String] the name of field
157
+ # @param field_type [Symbol] the type of field, :string, :text, :image, :date, :rich_text, :time, :integer, :decimal, :custom, :datetime, :money, :money_with_symbol, :link, :association, :enum, :tag, :attachment, :drawer
158
+ # @param header [String] the header of field
159
+ # @param format [String] the format of field for date field
160
+ # @param helper_method [Symbol] the helper method for field, should be defined in custom_helper.rb file, will take two arguments, `record` and `field_name`
161
+ # @param height [Integer] the height of field for image field
162
+ # @param width [Integer] the width of field for image field
163
+ # @params custom_link [String] the custom link for field
164
+ # @params tag_class [Hash] the tag class for field, example: { approved: 'completed', draft: 'active-two', rejected: 'danger' }, this will add css class to tag
165
+ # @params display_if [Proc] A lambda that takes the current object and return true or false
166
+ # @example Creating a column
167
+ # column('name', field_type: :string)
86
168
  def column(field_name, options = {})
87
169
  @available_fields[@current_action.name.to_sym] ||= []
88
170
  raise 'Only one column can be locked in a table.' if @available_fields[@current_action.name.to_sym].select { |x| x.lockable }.size > 0 && options[:lockable]
@@ -105,6 +187,10 @@ module CmAdmin
105
187
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Column.new(field_name, options)
106
188
  end
107
189
 
190
+ # Get all columns for a model for index layout.
191
+ # @param exclude [Array] the array of fields to exclude
192
+ # @example Getting all columns
193
+ # all_db_columns(exclude: ['id'])
108
194
  def all_db_columns(options = {})
109
195
  field_names = instance_variable_get(:@ar_model)&.columns&.map { |x| x.name.to_sym }
110
196
  if options.include?(:exclude) && field_names
@@ -116,49 +202,90 @@ module CmAdmin
116
202
  end
117
203
  end
118
204
 
119
- # Custom actions
120
- # eg
121
- # class User < ApplicationRecord
122
- # cm_admin do
123
- # custom_action name: 'submit', verb: 'post', path: ':id/submit' do
124
- # def user_submit
125
- # Code for action here...
126
- # end
127
- # end
128
- # end
129
- # end
130
- def custom_action(name: nil, page_title: nil, page_description: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, modal_configuration: {}, url_params: {}, display_if: ->(arg) { true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
205
+ # Create a new custom action for model
206
+ # @param name [String] the name of action
207
+ # @param page_title [String] the title of page
208
+ # @param page_description [String] the description of page
209
+ # @param display_name [String] the display name of action
210
+ # @param verb [String] the verb of action, `get`, `post`, `put`, `patch` or `delete`
211
+ # @param layout [String] the layout of action
212
+ # @param layout_type [String] the layout type of action, `'cm_association_index'`, `'cm_association_show'`
213
+ # @param partial [String] the partial path of action
214
+ # @param path [String] the path of action
215
+ # @param display_type [Symbol] the display type of action, `:button`, `:modal`
216
+ # @param modal_configuration [Hash] the configuration of modal
217
+ # @param url_params [Hash] the url params of action
218
+ # @param display_if [Proc] A lambda that takes the current object and return true or false
219
+ # @param route_type [String] the route type of action, `member`, `collection`
220
+ # @param icon_name [String] the icon name of action, follow font-awesome icon name
221
+ # @example Creating a custom action with modal
222
+ # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :modal, display_if: lambda(&:draft?), modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' }
223
+ # @example Creating a custom action with button
224
+ # custom_action name: 'approve', route_type: 'member', verb: 'patch', icon_name: 'fa-regular fa-circle-check', path: ':id/approve', display_type: :button, display_if: lambda(&:draft?)
225
+ def custom_action(name: nil, page_title: nil, page_description: nil, display_name: nil, verb: nil, layout: nil, layout_type: nil, partial: nil, path: nil, display_type: nil, modal_configuration: {}, url_params: {}, display_if: ->(_arg) { true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
131
226
  action = CmAdmin::Models::CustomAction.new(
132
- page_title: page_title, page_description: page_description,
133
- name: name, display_name: display_name, verb: verb, layout: layout,
134
- layout_type: layout_type, partial: partial, path: path,
135
- parent: current_action.name, display_type: display_type, display_if: display_if,
136
- action_type: :custom, route_type: route_type, icon_name: icon_name, modal_configuration: modal_configuration,
137
- model_name: self.name, url_params: url_params, &block
227
+ page_title:, page_description:,
228
+ name:, display_name:, verb:, layout:,
229
+ layout_type:, partial:, path:,
230
+ parent: current_action.name, display_type:, display_if:,
231
+ action_type: :custom, route_type:, icon_name:, modal_configuration:,
232
+ model_name: self.name, url_params:, &block
138
233
  )
139
234
  @available_actions << action
140
- # self.class.class_eval(&block)
141
235
  end
142
236
 
143
- def bulk_action(name: nil, display_name: nil, display_if: ->(arg) { true }, redirection_url: nil, icon_name: nil, verb: nil, display_type: nil, modal_configuration: {}, route_type: nil, partial: nil, &block)
237
+ # Create a new bulk action for model
238
+ # @param name [String] the name of action
239
+ # @param display_name [String] the display name of action
240
+ # @param display_if [Proc] A lambda that takes the current object and return true or false
241
+ # @param redirection_url [String] the redirection url of action
242
+ # @param icon_name [String] the icon name of action, follow font-awesome icon name
243
+ # @param verb [String] the verb of action, `get`, `post`, `put`, `patch` or `delete`
244
+ # @param display_type [Symbol] the display type of action, `:page`, `:modal`
245
+ # @param modal_configuration [Hash] the configuration of modal
246
+ # @param route_type [String] the route type of action, `member`, `collection`
247
+ # @param partial [String] the partial path of action
248
+ # @example Creating a bulk action
249
+ # bulk_action name: 'approve', display_name: 'Approve', display_if: lambda { |arg| arg.draft? }, redirection_url: '/posts', icon_name: 'fa-regular fa-circle-check', verb: :patch, display_type: :modal, modal_configuration: { title: 'Approve Post', description: 'Are you sure you want approve this post', confirmation_text: 'Approve' }
250
+ def bulk_action(name: nil, display_name: nil, display_if: ->(_arg) { true }, redirection_url: nil, icon_name: nil, verb: nil, display_type: nil, modal_configuration: {}, route_type: nil, partial: nil, &block)
144
251
  bulk_action = CmAdmin::Models::BulkAction.new(
145
- name: name, display_name: display_name, display_if: display_if, modal_configuration: modal_configuration,
146
- redirection_url: redirection_url, icon_name: icon_name, action_type: :bulk_action,
147
- verb: verb, display_type: display_type, route_type: route_type, partial: partial, &block
252
+ name:, display_name:, display_if:, modal_configuration:,
253
+ redirection_url:, icon_name:, action_type: :bulk_action,
254
+ verb:, display_type:, route_type:, partial:, &block
148
255
  )
149
256
  @available_actions << bulk_action
150
257
  end
151
258
 
259
+ # Create a new filter for model
260
+ # @param db_column_name [String] the name of column
261
+ # @param filter_type [String] the type of filter, :date, :multi_select, :range, :search, :single_select
262
+ # @param placeholder [String] the placeholder of filter
263
+ # @param helper_method [String] the helper method for filter, should be defined in custom_helper.rb file
264
+ # @param filter_with [Symbol] filter with scope name on model
265
+ # @param collection [Array] the collection of filter, use with single_select or multi_select
266
+ # @example Creating a filter
267
+ # filter('name', :search)
268
+ # filter('created_at', :date)
269
+ # filter('status', :single_select, collection: ['draft', 'published'])
270
+ # filter('status', :multi_select, helper_method: 'status_collection')
152
271
  def filter(db_column_name, filter_type, options = {})
153
- @filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
272
+ @filters << CmAdmin::Models::Filter.new(db_column_name:, filter_type:, options:)
154
273
  end
155
274
 
275
+ # Set sort direction for filters
276
+ # @param direction [Symbol] the direction of sort, `:asc`, `:desc`
277
+ # @example Setting sort direction
278
+ # sort_direction(:asc)
156
279
  def sort_direction(direction = :desc)
157
280
  raise ArgumentError, "Select a valid sort direction like #{CmAdmin::Models::Action::VALID_SORT_DIRECTION.join(' or ')} instead of #{direction}" unless CmAdmin::Models::Action::VALID_SORT_DIRECTION.include?(direction.to_sym.downcase)
158
281
 
159
282
  @current_action.sort_direction = direction.to_sym if @current_action
160
283
  end
161
284
 
285
+ # Set sort column for filters
286
+ # @param column [Symbol] the column name
287
+ # @example Setting sort column
288
+ # sort_column(:created_at)
162
289
  def sort_column(column = :created_at)
163
290
  @current_action.sort_column = column.to_sym if @current_action
164
291
  end
@@ -43,6 +43,12 @@ module CmAdmin
43
43
  def cm_show_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, &block)
44
44
  cm_section(section_name, col_size: col_size, display_if: display_if, html_attrs: html_attrs, &block)
45
45
  end
46
+
47
+ def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
48
+ nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, &block)
49
+ nested_section.parent_section = self
50
+ @row_fields << nested_section
51
+ end
46
52
  end
47
53
  end
48
54
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.5.39'
2
+ VERSION = '1.5.40'
3
3
  end
@@ -56,7 +56,7 @@ module CmAdmin
56
56
 
57
57
  def cm_switch_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)\
58
58
  content_tag :div, class: 'form-check form-switch' do
59
- form_obj.check_box cm_field.field_name,
59
+ concat form_obj.check_box cm_field.field_name,
60
60
  merge_wrapper_options(
61
61
  {
62
62
  class: "field-control form-check-input #{required_class}",
@@ -65,6 +65,7 @@ module CmAdmin
65
65
  role: 'switch'
66
66
  }, cm_field.html_attrs
67
67
  )
68
+ concat content_tag(:div, cm_field.field_name.to_s.titleize, class: 'cm-switch-label')
68
69
  end
69
70
  end
70
71
 
@@ -272,18 +273,10 @@ module CmAdmin
272
273
  if value.instance_of?(Array)
273
274
  format_check_box_array(value, form_obj, cm_field, required_class, target_action)
274
275
  else
275
- form_obj.check_box cm_field.field_name,
276
- merge_wrapper_options(
277
- {
278
- class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
279
- disabled: cm_field.disabled.call(form_obj.object),
280
- data: {
281
- field_name: cm_field.field_name,
282
- target_action: target_action&.name,
283
- target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
284
- }
285
- }, cm_field.html_attrs
286
- )
276
+ content_tag :div, class: 'cm-checkbox-section' do
277
+ concat single_checkbox_tag(value, form_obj, cm_field, required_class, target_action)
278
+ concat content_tag(:div, cm_field.field_name.to_s.titleize, class: 'cm-checkbox-label')
279
+ end
287
280
  end
288
281
  end
289
282
 
@@ -302,8 +295,25 @@ module CmAdmin
302
295
  end
303
296
  end
304
297
 
298
+ def single_checkbox_tag(value, form_obj, cm_field, required_class, target_action)
299
+ content_tag :div, class: 'cm-checkbox-tag' do
300
+ concat form_obj.check_box cm_field.field_name,
301
+ merge_wrapper_options(
302
+ {
303
+ class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
304
+ disabled: cm_field.disabled.call(form_obj.object),
305
+ data: {
306
+ field_name: cm_field.field_name,
307
+ target_action: target_action&.name,
308
+ target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
309
+ }
310
+ }, cm_field.html_attrs
311
+ )
312
+ end
313
+ end
314
+
305
315
  def format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
306
- content_tag :div, class: 'cm-radio-tag' do
316
+ content_tag :div, class: 'cm-checkbox-tag' do
307
317
  if val.present?
308
318
  concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]", value: '0', hidden: true, disabled: 'disabled'
309
319
  else
@@ -74,7 +74,11 @@ module CmAdmin
74
74
  rows.each do |row|
75
75
  concat(content_tag(:div, class: 'row') do
76
76
  row.row_fields.each do |field|
77
- concat set_form_field(resource, form_obj, field)
77
+ if field.is_a?(CmAdmin::Models::Section)
78
+ concat set_nested_section_form_fields(resource, form_obj, Array(field))
79
+ else
80
+ concat set_form_field(resource, form_obj, field)
81
+ end
78
82
  end
79
83
  end)
80
84
  end
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: 1.5.39
4
+ version: 1.5.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -11,10 +11,10 @@ authors:
11
11
  - Pranav
12
12
  - Mahaveer
13
13
  - Austin
14
- autorequire:
14
+ autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2024-07-24 00:00:00.000000000 Z
17
+ date: 2024-07-25 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails
@@ -142,6 +142,20 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: 5.4.3
145
+ - !ruby/object:Gem::Dependency
146
+ name: yard
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: importmap-rails
147
161
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - ".github/ISSUE_TEMPLATE/bug_report.md"
176
190
  - ".github/ISSUE_TEMPLATE/config.yml"
177
191
  - ".github/ISSUE_TEMPLATE/feature_request.md"
192
+ - ".github/workflows/deploy-yard-docs.yml"
178
193
  - ".github/workflows/linters.yml"
179
194
  - ".github/workflows/release-gem.yml"
180
195
  - ".gitignore"
@@ -184,6 +199,7 @@ files:
184
199
  - ".stylelintrc.json"
185
200
  - ".travis.yml"
186
201
  - ".vscode/settings.json"
202
+ - CNAME
187
203
  - CODE_OF_CONDUCT.md
188
204
  - Gemfile
189
205
  - Gemfile.lock
@@ -490,7 +506,7 @@ licenses:
490
506
  metadata:
491
507
  homepage_uri: https://github.com/commutatus/cm-admin
492
508
  source_code_uri: https://github.com/commutatus/cm-admin
493
- post_install_message:
509
+ post_install_message:
494
510
  rdoc_options: []
495
511
  require_paths:
496
512
  - lib
@@ -505,8 +521,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
505
521
  - !ruby/object:Gem::Version
506
522
  version: '0'
507
523
  requirements: []
508
- rubygems_version: 3.5.11
509
- signing_key:
524
+ rubygems_version: 3.0.9
525
+ signing_key:
510
526
  specification_version: 4
511
527
  summary: CmAdmin is a robust gem designed to assist in creating admin panels for Rails
512
528
  applications