cm-admin 1.5.35 → 1.5.36

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: e040c173b4dc72d86d645df5fd314f10cee91457e38589ebe85cc6ce4d15936a
4
- data.tar.gz: 0d423f9be6c3b5b99f44ff8618b11aaf67032404875a251eb346b10edf0c5389
3
+ metadata.gz: 7206f32a1a0f0a94b11d1005a34b2cabc4418aad7f1481be333e8b4eca2e760f
4
+ data.tar.gz: 58e0f084865aa2fe6846593d32533f48cbb8415e25316fcef1649cca5a961962
5
5
  SHA512:
6
- metadata.gz: f1c2c45019460ba876581ff9bfd28a56e94192212718610f37ccc6d7f13d88294f9fb72c85e41a074c68c3bc4b1eea645867a7d80228ed11bd68a1375a4dcc1c
7
- data.tar.gz: 516878f3063839d82fc0393dd6b66abd3e250671508f0d738d4689249e42f3ccce227e21e197cccb59c0dbad4875739ff6c483676bc66fd1d2528700cf8ebed1
6
+ metadata.gz: b657c82c245e115ef8b5ef3481c75de30fe9c39873a3ae41537733cffca35470ef4d8dd8d31a570c3bc1b7bc446942b67ec2140bfe7029a94f85fe517966569f
7
+ data.tar.gz: 9181f431af0474e8df9cfdf05b87a46d850dde9ab9d53e68c04f7e1457df89fef109bf39b4972f4fd5123a7a048227a951488b17331778259902951959c840d9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.5.35)
4
+ cm-admin (1.5.36)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
data/cm_admin.gemspec CHANGED
@@ -3,8 +3,8 @@ require_relative 'lib/cm_admin/version'
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'cm-admin'
5
5
  spec.version = CmAdmin::VERSION
6
- spec.authors = ['Michael', 'Anbazhagan', 'Ayza', 'Barath', 'Pranav', 'Mahaveer']
7
- spec.email = ['mkv@commutatus.com', 'anbublacky@gmail.com', 'ayza@commutatus.com', 'barath@commutatus.com', 'pranav@commutatus.com', 'mahaveer@commutatus.com']
6
+ spec.authors = %w[Michael Anbazhagan Ayza Barath Pranav Mahaveer Austin]
7
+ spec.email = ['mkv@commutatus.com', 'anbublacky@gmail.com', 'ayza@commutatus.com', 'barath@commutatus.com', 'pranav@commutatus.com', 'mahaveer@commutatus.com', 'austin@commutatus.com']
8
8
 
9
9
  spec.summary = 'CmAdmin is a robust gem designed to assist in creating admin panels for Rails applications'
10
10
  spec.description = 'CmAdmin providing a streamlined and efficient solution for building customized admin panels within the context of Rails applications. Its robust features empower developers to effortlessly generate and manage administrative interfaces with precision and ease.'
@@ -28,27 +28,26 @@ module CmAdmin
28
28
  end
29
29
 
30
30
  def page_title(title)
31
- if @current_action
32
- @current_action.page_title = title
33
- end
31
+ return unless @current_action
32
+
33
+ @current_action.page_title = title
34
34
  end
35
35
 
36
36
  def page_description(description)
37
- if @current_action
38
- @current_action.page_description = description
39
- end
37
+ return unless @current_action
38
+
39
+ @current_action.page_description = description
40
40
  end
41
41
 
42
42
  def kanban_view(column_name, exclude: [], only: [])
43
- if @current_action
44
- @current_action.kanban_attr[:column_name] = column_name
45
- @current_action.kanban_attr[:exclude] = exclude
46
- @current_action.kanban_attr[:only] = only
47
- end
43
+ return unless @current_action
48
44
 
45
+ @current_action.kanban_attr[:column_name] = column_name
46
+ @current_action.kanban_attr[:exclude] = exclude
47
+ @current_action.kanban_attr[:only] = only
49
48
  end
50
49
 
51
- def scope_list(scopes=[])
50
+ def scope_list(scopes = [])
52
51
  return unless @current_action
53
52
 
54
53
  @current_action.scopes = scopes
@@ -59,9 +58,9 @@ module CmAdmin
59
58
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
60
59
  @available_tabs << CmAdmin::Models::Tab.new(tab_name, '', display_if, &block)
61
60
  else
62
- action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/'+custom_action,
63
- layout_type: layout_type, layout: layout, partial: partial, child_records: associated_model,
64
- action_type: :custom, display_type: :page, model_name: self.name)
61
+ 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,
63
+ action_type: :custom, display_type: :page, model_name: name)
65
64
  @available_actions << action
66
65
  @current_action = action
67
66
  @available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, display_if, &block)
@@ -74,9 +73,9 @@ module CmAdmin
74
73
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Row.new(@current_action, @model, display_if, &block)
75
74
  end
76
75
 
77
- def cm_section(section_name, display_if: nil, col_size: nil, &block)
76
+ def cm_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
78
77
  @available_fields[@current_action.name.to_sym] ||= []
79
- @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, col_size, &block)
78
+ @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
80
79
  end
81
80
 
82
81
  # This method is deprecated. Use cm_section instead.
@@ -84,13 +83,11 @@ module CmAdmin
84
83
  cm_section(section_name, display_if: display_if, &block)
85
84
  end
86
85
 
87
- def column(field_name, options={})
86
+ def column(field_name, options = {})
88
87
  @available_fields[@current_action.name.to_sym] ||= []
89
- if @available_fields[@current_action.name.to_sym].select{|x| x.lockable}.size > 0 && options[:lockable]
90
- raise 'Only one column can be locked in a table.'
91
- end
88
+ 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]
92
89
 
93
- duplicate_columns = @available_fields[@current_action.name.to_sym].filter{|x| x.field_name.to_sym == field_name}
90
+ duplicate_columns = @available_fields[@current_action.name.to_sym].filter { |x| x.field_name.to_sym == field_name }
94
91
  terminate = false
95
92
 
96
93
  if duplicate_columns.size.positive?
@@ -103,15 +100,15 @@ module CmAdmin
103
100
  end
104
101
  end
105
102
 
106
- unless terminate
107
- @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Column.new(field_name, options)
108
- end
103
+ return if terminate
104
+
105
+ @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Column.new(field_name, options)
109
106
  end
110
107
 
111
- def all_db_columns(options={})
112
- field_names = self.instance_variable_get(:@ar_model)&.columns&.map{|x| x.name.to_sym}
108
+ def all_db_columns(options = {})
109
+ field_names = instance_variable_get(:@ar_model)&.columns&.map { |x| x.name.to_sym }
113
110
  if options.include?(:exclude) && field_names
114
- excluded_fields = (Array.new << options[:exclude]).flatten.map(&:to_sym)
111
+ excluded_fields = ([] << options[:exclude]).flatten.map(&:to_sym)
115
112
  field_names -= excluded_fields
116
113
  end
117
114
  field_names.each do |field_name|
@@ -130,19 +127,20 @@ module CmAdmin
130
127
  # end
131
128
  # end
132
129
  # end
133
- 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: lambda { |arg| return true }, route_type: nil, icon_name: 'fa fa-th-large', &block)
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)
134
131
  action = CmAdmin::Models::CustomAction.new(
135
132
  page_title: page_title, page_description: page_description,
136
133
  name: name, display_name: display_name, verb: verb, layout: layout,
137
134
  layout_type: layout_type, partial: partial, path: path,
138
- parent: self.current_action.name, display_type: display_type, display_if: display_if,
135
+ parent: current_action.name, display_type: display_type, display_if: display_if,
139
136
  action_type: :custom, route_type: route_type, icon_name: icon_name, modal_configuration: modal_configuration,
140
- model_name: self.name, url_params: url_params, &block)
137
+ model_name: self.name, url_params: url_params, &block
138
+ )
141
139
  @available_actions << action
142
140
  # self.class.class_eval(&block)
143
141
  end
144
142
 
145
- def bulk_action(name: nil, display_name: nil, display_if: lambda { |arg| return true }, redirection_url: nil, icon_name: nil, verb: nil, display_type: nil, modal_configuration: {}, route_type: nil, partial: nil, &block)
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)
146
144
  bulk_action = CmAdmin::Models::BulkAction.new(
147
145
  name: name, display_name: display_name, display_if: display_if, modal_configuration: modal_configuration,
148
146
  redirection_url: redirection_url, icon_name: icon_name, action_type: :bulk_action,
@@ -151,7 +149,7 @@ module CmAdmin
151
149
  @available_actions << bulk_action
152
150
  end
153
151
 
154
- def filter(db_column_name, filter_type, options={})
152
+ def filter(db_column_name, filter_type, options = {})
155
153
  @filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
156
154
  end
157
155
 
@@ -1,24 +1,24 @@
1
1
  module CmAdmin
2
2
  module Models
3
3
  class Row
4
-
5
4
  # Description
6
5
  # A row is like a container which holds a list of form_field or section.
7
6
  # These list of fields or section are iterated and displayed on new/edit page.
8
7
  # A row is like a wrapper on the HTML, which adds a div element 'row' class from bootstrap.
9
8
 
10
- attr_accessor :sections, :display_if, :row_fields
9
+ attr_accessor :sections, :display_if, :row_fields, :html_attrs
11
10
 
12
- def initialize(current_action, cm_model, display_if, &block)
11
+ def initialize(current_action, cm_model, display_if, html_attrs, &block)
13
12
  @sections = []
14
13
  @row_fields = []
15
- @display_if = display_if || lambda { |arg| return true }
14
+ @display_if = display_if || ->(arg) { true }
15
+ @html_attrs = html_attrs || {}
16
16
  @current_action = current_action
17
17
  @cm_model = cm_model
18
18
  instance_eval(&block)
19
19
  end
20
20
 
21
- def form_field(field_name, options={}, arg=nil)
21
+ def form_field(field_name, options = {}, arg = nil)
22
22
  if @current_action.is_nested_field
23
23
  @nested_table_fields[@current_action.nested_table_name] ||= []
24
24
  @nested_table_fields[@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
@@ -27,7 +27,7 @@ module CmAdmin
27
27
  end
28
28
  end
29
29
 
30
- def field(field_name, options={})
30
+ def field(field_name, options = {})
31
31
  if @current_nested_field
32
32
  @current_nested_field.fields << CmAdmin::Models::Field.new(field_name, options)
33
33
  else
@@ -35,13 +35,13 @@ module CmAdmin
35
35
  end
36
36
  end
37
37
 
38
- def cm_section(section_name, col_size: nil, display_if: nil, &block)
39
- @sections << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, col_size, &block)
38
+ def cm_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, &block)
39
+ @sections << CmAdmin::Models::Section.new(section_name, @current_action, @model, display_if, html_attrs, col_size, &block)
40
40
  end
41
41
 
42
42
  # This method is deprecated. Use cm_section instead.
43
- def cm_show_section(section_name, col_size: nil, display_if: nil, &block)
44
- cm_section(section_name, col_size: col_size, display_if: display_if, &block)
43
+ def cm_show_section(section_name, col_size: nil, display_if: nil, html_attrs: nil, &block)
44
+ cm_section(section_name, col_size: col_size, display_if: display_if, html_attrs: html_attrs, &block)
45
45
  end
46
46
  end
47
47
  end
@@ -1,15 +1,14 @@
1
1
  module CmAdmin
2
2
  module Models
3
3
  class Section
4
-
5
4
  # Description
6
5
  # A section is like a container which holds a list of fields or form fields
7
6
  # These list of fields are iterated and displayed on show/new/edit page.
8
7
  # It also contains rows, which contains sections and fields.
9
8
 
10
- attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields, :rows, :col_size, :current_nested_field
9
+ attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :nested_table_fields, :rows, :col_size, :current_nested_field, :html_attrs
11
10
 
12
- def initialize(section_name, current_action, cm_model, display_if, col_size, &block)
11
+ def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, &block)
13
12
  @section_fields = []
14
13
  @rows = []
15
14
  @nested_table_fields = []
@@ -17,12 +16,13 @@ module CmAdmin
17
16
  @section_name = section_name
18
17
  @current_action = current_action
19
18
  @cm_model = cm_model
20
- @display_if = display_if || lambda { |arg| return true }
19
+ @html_attrs = html_attrs || {}
20
+ @display_if = display_if || ->(arg) { true }
21
21
  @current_nested_field = nil
22
22
  instance_eval(&block)
23
23
  end
24
24
 
25
- def field(field_name, options={})
25
+ def field(field_name, options = {})
26
26
  if @current_nested_field
27
27
  @current_nested_field.fields << CmAdmin::Models::Field.new(field_name, options)
28
28
  else
@@ -30,7 +30,7 @@ module CmAdmin
30
30
  end
31
31
  end
32
32
 
33
- def form_field(field_name, options={}, arg=nil)
33
+ def form_field(field_name, options = {}, arg = nil)
34
34
  if @current_nested_field
35
35
  @current_nested_field.fields << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
36
36
  else
@@ -38,7 +38,7 @@ module CmAdmin
38
38
  end
39
39
  end
40
40
 
41
- def nested_form_field(field_name, options={}, &block)
41
+ def nested_form_field(field_name, options = {}, &block)
42
42
  # @current_action.is_nested_field = true
43
43
  # @current_action.nested_table_name = field_name
44
44
  nested_field = CmAdmin::Models::NestedField.new(field_name, options)
@@ -55,7 +55,6 @@ module CmAdmin
55
55
  @rows ||= []
56
56
  @rows << CmAdmin::Models::Row.new(@current_action, @model, display_if, &block)
57
57
  end
58
-
59
58
  end
60
59
  end
61
- end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.5.35'
2
+ VERSION = '1.5.36'
3
3
  end
@@ -6,7 +6,7 @@ module CmAdmin
6
6
  module ViewHelpers
7
7
  module FormHelper
8
8
  include FormFieldHelper
9
- REJECTABLE = %w(id created_at updated_at)
9
+ REJECTABLE = %w[id created_at updated_at]
10
10
 
11
11
  def generate_form(resource, cm_model)
12
12
  if resource.new_record?
@@ -16,11 +16,9 @@ module CmAdmin
16
16
  action = :edit
17
17
  method = :patch
18
18
  end
19
- if cm_model.available_fields[action].empty?
20
- return form_with_all_fields(resource, method)
21
- else
22
- return form_with_mentioned_fields(resource, cm_model.available_fields[action], method)
23
- end
19
+ return form_with_all_fields(resource, method) if cm_model.available_fields[action].empty?
20
+
21
+ form_with_mentioned_fields(resource, cm_model.available_fields[action], method)
24
22
  end
25
23
 
26
24
  def form_with_all_fields(resource, method)
@@ -47,7 +45,7 @@ module CmAdmin
47
45
  elsif entity.class == CmAdmin::Models::Section
48
46
  next unless entity.display_if.call(form_obj.object)
49
47
 
50
- concat(content_tag(:div, class: 'row') do
48
+ concat(content_tag(:div, class: 'row', **entity.html_attrs) do
51
49
  concat create_sections(resource, form_obj, entity)
52
50
  end)
53
51
  end
@@ -80,7 +78,7 @@ module CmAdmin
80
78
  end
81
79
  end)
82
80
  end
83
- return
81
+ nil
84
82
  end
85
83
 
86
84
  def set_form_for_fields(resource, form_obj, section)
@@ -97,7 +95,7 @@ module CmAdmin
97
95
  concat set_form_field(resource, form_obj, field)
98
96
  end)
99
97
  end
100
- return
98
+ nil
101
99
  end
102
100
 
103
101
  def set_form_field(resource, form_obj, field)
@@ -123,7 +121,7 @@ module CmAdmin
123
121
  def set_nested_form_fields(form_obj, section)
124
122
  content_tag(:div) do
125
123
  section.nested_table_fields.each do |nested_table_field|
126
- concat(render partial: '/cm_admin/main/nested_table_form', locals: { f: form_obj, nested_table_field: nested_table_field })
124
+ concat(render(partial: '/cm_admin/main/nested_table_form', locals: { f: form_obj, nested_table_field: nested_table_field }))
127
125
  end
128
126
  end
129
127
  end
@@ -131,34 +129,31 @@ module CmAdmin
131
129
  def set_form_with_sections(resource, entities, url, method)
132
130
  url_with_query_params = extract_query_params(url)
133
131
 
134
- form_for(resource, url: url_with_query_params || url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |form_obj|
135
- if params[:referrer]
136
- concat form_obj.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
137
- end
132
+ form_for(resource, url: url_with_query_params || url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" }) do |form_obj|
133
+ concat form_obj.text_field 'referrer', class: 'normal-input', hidden: true, value: params[:referrer], name: 'referrer' if params[:referrer]
138
134
  if params[:polymorphic_name].present?
139
- concat form_obj.text_field params[:polymorphic_name] + '_type', class: "normal-input", hidden: true, value: params[:associated_class].classify
140
- concat form_obj.text_field params[:polymorphic_name] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
135
+ concat form_obj.text_field params[:polymorphic_name] + '_type', class: 'normal-input', hidden: true, value: params[:associated_class].classify
136
+ concat form_obj.text_field params[:polymorphic_name] + '_id', class: 'normal-input', hidden: true, value: params[:associated_id]
141
137
  elsif params[:associated_class] && params[:associated_id]
142
- concat form_obj.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
138
+ concat form_obj.text_field params[:associated_class] + '_id', class: 'normal-input', hidden: true, value: params[:associated_id]
143
139
  end
144
140
 
145
141
  concat split_form_into_section(resource, form_obj, entities)
146
142
  concat tag.br
147
- concat form_obj.submit 'Save', class: 'btn-cta', data: {behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form"}
143
+ concat form_obj.submit 'Save', class: 'btn-cta', data: { behaviour: 'form_submit', form_class: "cm_#{form_obj.object.class.name.downcase}_form" }
148
144
  end
149
145
  end
150
146
 
151
-
152
147
  def extract_query_params(url)
153
148
  query_params = {}
154
- if params[:polymorphic_name].present? || params[:associated_id].present? && params[:associated_class].present?
155
- query_params[:polymorphic_name] = params[:polymorphic_name]
156
- query_params[:associated_id] = params[:associated_id]
157
- query_params[:associated_class] = params[:associated_class]
158
- query_params[:referrer] = params[:referrer] if params[:referrer].present?
149
+ return unless params[:polymorphic_name].present? || params[:associated_id].present? && params[:associated_class].present?
159
150
 
160
- return url + '?' + query_params.to_query unless query_params.empty?
161
- end
151
+ query_params[:polymorphic_name] = params[:polymorphic_name]
152
+ query_params[:associated_id] = params[:associated_id]
153
+ query_params[:associated_class] = params[:associated_class]
154
+ query_params[:referrer] = params[:referrer] if params[:referrer].present?
155
+
156
+ url + '?' + query_params.to_query unless query_params.empty?
162
157
  end
163
158
  end
164
159
  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.35
4
+ version: 1.5.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -10,10 +10,11 @@ authors:
10
10
  - Barath
11
11
  - Pranav
12
12
  - Mahaveer
13
+ - Austin
13
14
  autorequire:
14
15
  bindir: exe
15
16
  cert_chain: []
16
- date: 2024-07-12 00:00:00.000000000 Z
17
+ date: 2024-07-18 00:00:00.000000000 Z
17
18
  dependencies:
18
19
  - !ruby/object:Gem::Dependency
19
20
  name: caxlsx_rails
@@ -166,6 +167,7 @@ email:
166
167
  - barath@commutatus.com
167
168
  - pranav@commutatus.com
168
169
  - mahaveer@commutatus.com
170
+ - austin@commutatus.com
169
171
  executables: []
170
172
  extensions: []
171
173
  extra_rdoc_files: []