cm-admin 0.7.1 → 0.7.4

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: 4cd6e52585c8e5905473e55c80965b14da5679c38bbff1aee74a97e436552dbe
4
- data.tar.gz: ec82f91588d998b19a6361365599e13223ad7254998481cfd7b83843b0908f3e
3
+ metadata.gz: 810496f7dd375b4849ce820652272c6d36dec1767807beab966e4abc1a00a922
4
+ data.tar.gz: 522f04bc7abeddf95dceebfe980c3b7d955b3d3907de9060af5923803622ed59
5
5
  SHA512:
6
- metadata.gz: 8644e740f96af96d2a88ade91b50f697585e7b9e95a124a4a07afe84ea9cc6ef9302ff73f1311ea0ebc0ba49eb367d601bc5bb5bb09085406934d416f0222ff3
7
- data.tar.gz: 55c444fdf18df0a8710014a361765268068561eb7d5704650d3a7ba1b296dcc8780510f948c161d36ceeae3c2a5a3a3fbc32e076c9b2459312dead070b1a951c
6
+ metadata.gz: fc0a6ebd3f81ee0c8df337d630c71cff47d49bb7e422e1d39f9f5f1663c21e7714bd740cf8b1a37d37cbbc3827d18ccc58822031794a228696043633886466ec
7
+ data.tar.gz: 6a13e1994ea27658ac281f88970b1d5b471ee52982be02af9e8ce55dd1b9f6706085543a3f0cbddced246371254b8143243ed6e2756e413d6302fde891718c9d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (0.5.7)
4
+ cm-admin (0.7.3)
5
5
  axlsx_rails (~> 0.6.1)
6
6
  cocoon (~> 1.2.15)
7
7
  pagy (~> 4.11.0)
@@ -47,21 +47,19 @@ GEM
47
47
  htmlentities (4.3.4)
48
48
  i18n (1.10.0)
49
49
  concurrent-ruby (~> 1.0)
50
- loofah (2.15.0)
50
+ loofah (2.17.0)
51
51
  crass (~> 1.0.2)
52
52
  nokogiri (>= 1.5.9)
53
53
  marcel (1.0.2)
54
54
  method_source (1.0.0)
55
- mini_portile2 (2.8.0)
56
55
  minitest (5.15.0)
57
- nokogiri (1.13.4)
58
- mini_portile2 (~> 2.8.0)
56
+ nokogiri (1.13.5-arm64-darwin)
59
57
  racc (~> 1.4)
60
58
  pagy (4.11.0)
61
59
  pundit (2.2.0)
62
60
  activesupport (>= 3.0.0)
63
61
  racc (1.6.0)
64
- rack (2.2.3)
62
+ rack (2.2.3.1)
65
63
  rack-proxy (0.7.2)
66
64
  rack
67
65
  rack-test (1.1.0)
@@ -13,5 +13,16 @@ module CmAdmin
13
13
  return true unless policy([:cm_admin, model_name.classify.constantize]).methods.include?(:"#{action_name}?")
14
14
  policy([:cm_admin, model_name.classify.constantize]).send(:"#{action_name}?")
15
15
  end
16
+
17
+ def action(action_name)
18
+ case action_name.to_sym
19
+ when :update
20
+ return :edit
21
+ when :create
22
+ return :new
23
+ else
24
+ return action_name.to_sym
25
+ end
26
+ end
16
27
  end
17
28
  end
@@ -2,6 +2,11 @@
2
2
  .table-top
3
3
  p.table-top__total-count = "#{@associated_ar_object.pagy.count} #{@action.child_records.to_s.gsub('_', ' ')} found"
4
4
  .table-top__column-action
5
+ - if @associated_model && @associated_model.available_actions.map(&:name).include?('new')
6
+ - association = @ar_object.class.reflect_on_all_associations.select{|x| x.name == @associated_model.name.tableize.to_sym }.first
7
+ - polymorphic_name = (association && association.inverse_of && association.inverse_of.options[:polymorphic]) ? association.inverse_of.name : ''
8
+ a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/new?associated_id=#{@ar_object.id}&associated_class=#{@ar_object.class.name.underscore}&polymorphic_name=#{polymorphic_name}&referrer=#{request.path}"
9
+ button.secondary-btn.column-btn Add
5
10
  / button.secondary-btn.column-btn data-target="#columnActionModal" data-toggle="modal" type="button"
6
11
  / span
7
12
  / i.fa.fa-columns.bolder
@@ -17,7 +22,7 @@
17
22
  / span
18
23
  / input.cm-checkbox type="checkbox"
19
24
  - @model.available_fields[@action.name.to_sym].each do |column|
20
- th = column.header
25
+ th = column.header
21
26
  tbody.cm-table__body
22
27
  - @associated_ar_object.data.each do |ar_object|
23
28
  tr.body-row
@@ -25,9 +30,12 @@
25
30
  / td.check-box-space
26
31
  / span
27
32
  / input.cm-checkbox type="checkbox"
28
- - @model.available_fields[@action.name.to_sym].each do |column|
33
+ - @model.available_fields[@action.name.to_sym].each_with_index do |column, index|
29
34
  td class="text-ellipsis"
30
- span class="#{column.cm_css_class}" = show_field_value(ar_object, column)
35
+ - if index == 0 && @associated_model && @associated_model.available_actions.map(&:name).include?('show')
36
+ a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/#{ar_object.id}" = show_field_value(ar_object, column)
37
+ - else
38
+ span class="#{column.cm_css_class}" = show_field_value(ar_object, column)
31
39
  - associated_model_actions = @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}
32
40
  - if associated_model_actions.present?
33
41
  td.row-action-cell
@@ -1,5 +1,5 @@
1
1
  .nested-fields
2
- - @model.available_fields[action_name.to_sym][assoc_name].each do |field|
2
+ - @model.available_fields[ action(action_name) ][assoc_name].each do |field|
3
3
  .row
4
4
  .col-sm-10
5
5
  = input_field_for_column(f, field)
@@ -34,8 +34,9 @@
34
34
  = render partial: column.drawer_partial, locals: { ar_object: ar_object}
35
35
 
36
36
  - edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
37
+ - destroy_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('destroy')}
37
38
  - custom_actions = @model.available_actions.select{|act| act if act.route_type == 'member' && [:button, :modal].include?(act.display_type)}
38
- - if custom_actions.any? || edit_action.any?
39
+ - if custom_actions.any? || edit_action.any? || destroy_action.any?
39
40
  td.row-action-cell
40
41
  .row-action-tool
41
42
  button.secondary-btn.tool-btn type="button"
@@ -50,6 +51,12 @@
50
51
  span
51
52
  i.fa.fa-edit
52
53
  | Edit
54
+ - if destroy_action.any? && policy([:cm_admin, @model.name.classify.constantize]).destroy?
55
+ = link_to "#{page_url('destroy', ar_object)}", method: :delete do
56
+ .popup-option
57
+ span
58
+ i.fa.fa-trash
59
+ | Destroy
53
60
  - custom_actions.each do |custom_action|
54
61
  - if custom_action.name.present? && has_valid_policy(@model.name, custom_action.name)
55
62
  - if custom_action.display_if.call(ar_object)
@@ -1,6 +1,7 @@
1
1
  ul.nav.nav-pills
2
2
  - @model.available_tabs.each do |nav_item|
3
- - if nav_item.custom_action.empty? || (nav_item.custom_action.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{nav_item.custom_action}?"))
4
- li.nav-item
5
- - nav_item_action_name = nav_item.custom_action.present? ? nav_item.custom_action : 'show'
6
- = link_to nav_item.nav_item_name.to_s.titleize, "/cm_admin/#{@model.name.underscore.pluralize}/#{@ar_object.id}/#{nav_item.custom_action}", class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
3
+ - if nav_item.display_if.call(@ar_object)
4
+ - if nav_item.custom_action.empty? || (nav_item.custom_action.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{nav_item.custom_action}?"))
5
+ li.nav-item
6
+ - nav_item_action_name = nav_item.custom_action.present? ? nav_item.custom_action : 'show'
7
+ = link_to nav_item.nav_item_name.to_s.titleize, "/cm_admin/#{@model.name.underscore.pluralize}/#{@ar_object.id}/#{nav_item.custom_action}", class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
@@ -140,12 +140,14 @@ module CmAdmin
140
140
  format.html { render '/cm_admin/main/'+action_name }
141
141
  end
142
142
  elsif %w(create update destroy).include?(action_name)
143
- if %w(create update).include?(action_name)
143
+ if params["referrer"]
144
+ redirect_url = params["referrer"]
145
+ elsif %w(create update).include?(action_name)
144
146
  redirect_url = CmAdmin::Engine.mount_path + "/#{@model.name.underscore.pluralize}/#{@ar_object.id}"
145
147
  else
146
148
  redirect_url = CmAdmin::Engine.mount_path + "/#{@model.name.underscore.pluralize}"
147
149
  end
148
- if @ar_object.save
150
+ if action_name.eql?('destroy') || @ar_object.save
149
151
  format.html { redirect_to redirect_url, notice: "#{action_name.titleize} #{@ar_object.class.name.downcase} is successful" }
150
152
  else
151
153
  format.html { render '/cm_admin/main/new', notice: "#{action_name.titleize} #{@ar_object.class.name.downcase} is unsuccessful" }
@@ -36,6 +36,11 @@ module CmAdmin
36
36
  @ar_object = @ar_model.name.classify.constantize.new(resource_params(params))
37
37
  end
38
38
 
39
+ def destroy(params)
40
+ @ar_object = @ar_model.name.classify.constantize.find(params[:id])
41
+ @ar_object.destroy
42
+ end
43
+
39
44
  def filter_by(params, records, filter_params={}, sort_params={})
40
45
  filtered_result = OpenStruct.new
41
46
  sort_column = "created_at"
@@ -58,11 +63,19 @@ module CmAdmin
58
63
  def resource_params(params)
59
64
  permittable_fields = @permitted_fields || @ar_model.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym)
60
65
  permittable_fields += @ar_model.name.constantize.reflect_on_all_associations.map {|x|
61
- if x.klass.name == "ActiveStorage::Attachment"
66
+ next if x.options[:polymorphic]
67
+ # The first if statement is added for compatibilty with cm-page-builder.
68
+ # One of the associated models of cm-page-builder was throwing error.
69
+ # The associated model is CmPageBuilder::Rails::PageComponent.
70
+ # When using reflection, the value of klass of the above association is uninitialized.
71
+ # As a result, it was throwing error in the 2nd elsif statement.
72
+ if x.name == :page_components
73
+ x.name
74
+ elsif x.klass.name == "ActiveStorage::Attachment"
62
75
  if x.class.name.include?('HasOne')
63
- x.name
76
+ x.name.to_s.gsub('_attachment', '').to_sym
64
77
  elsif x.class.name.include?('HasMany')
65
- Hash[x.name.to_s, []]
78
+ Hash[x.name.to_s.gsub('_attachment', ''), []]
66
79
  end
67
80
  elsif x.klass.name == "ActionText::RichText"
68
81
  x.name.to_s.gsub('rich_text_', '').to_sym
@@ -39,17 +39,17 @@ module CmAdmin
39
39
  end
40
40
  end
41
41
 
42
- def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, &block)
42
+ def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, display_if: nil, &block)
43
43
  if custom_action.to_s == ''
44
44
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
45
- @available_tabs << CmAdmin::Models::Tab.new(tab_name, '', &block)
45
+ @available_tabs << CmAdmin::Models::Tab.new(tab_name, '', display_if, &block)
46
46
  else
47
47
  action = CmAdmin::Models::Action.new(name: custom_action.to_s, verb: :get, path: ':id/'+custom_action,
48
48
  layout_type: layout_type, layout: layout, partial: partial, child_records: associated_model,
49
49
  action_type: :custom, display_type: :page)
50
50
  @available_actions << action
51
51
  @current_action = action
52
- @available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, &block)
52
+ @available_tabs << CmAdmin::Models::Tab.new(tab_name, custom_action, display_if, &block)
53
53
  end
54
54
  yield if block
55
55
  end
@@ -25,6 +25,10 @@ module CmAdmin
25
25
  records_arr = []
26
26
  records.includes(deserialized_columns[:include].keys).find_each do |record|
27
27
  record_hash = record.as_json({only: columns.map(&:to_sym)})
28
+ columns.each do |column|
29
+ break unless model.available_fields[:index].map(&:field_name).include?(column.to_sym)
30
+ record_hash[column.to_sym] = record.send(column.to_sym)
31
+ end
28
32
  custom_fields.each do |field|
29
33
  record_hash[field.field_name.to_sym] = helpers.send(field.helper_method, record, field.field_name)
30
34
  end
@@ -1,7 +1,7 @@
1
1
  module CmAdmin
2
2
  module Models
3
3
  class FormField
4
- attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled
4
+ attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled, :collection_method
5
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 = {})
@@ -2,11 +2,12 @@ module CmAdmin
2
2
  module Models
3
3
  class Tab
4
4
 
5
- attr_accessor :nav_item_name, :custom_action
5
+ attr_accessor :nav_item_name, :custom_action, :display_if
6
6
 
7
- def initialize(nav_item_name, custom_action)
7
+ def initialize(nav_item_name, custom_action, display_if)
8
8
  @nav_item_name = nav_item_name
9
9
  @custom_action = custom_action
10
+ @display_if = display_if || lambda { |arg| return true }
10
11
  end
11
12
  end
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.4"
3
3
  end
@@ -13,9 +13,9 @@ module CmAdmin
13
13
  when :string
14
14
  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('_', ' ')}"
15
15
  when :single_select
16
- 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
16
+ return f.select field.field_name, options_for_select(select_collection_value(field), value), {include_blank: "Select #{field.field_name.to_s.downcase.gsub('_', ' ')}"}, class: "normal-input #{required_class} select-2", disabled: field.disabled
17
17
  when :multi_select
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
18
+ return f.select field.field_name, options_for_select(select_collection_value(field), 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
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
@@ -32,6 +32,16 @@ module CmAdmin
32
32
  return f.hidden_field field.field_name, value: field.custom_value
33
33
  end
34
34
  end
35
+
36
+ def select_collection_value(field)
37
+ if field.collection_method
38
+ collection = send(field.collection_method)
39
+ elsif field.collection
40
+ collection = field.collection
41
+ else
42
+ collection = []
43
+ end
44
+ end
35
45
  end
36
46
  end
37
47
  end
@@ -38,6 +38,15 @@ module CmAdmin
38
38
 
39
39
  def set_form_for_fields(resource, available_fields_hash, url, method)
40
40
  form_for(resource, url: url, method: method, html: { class: "cm_#{resource.class.name.downcase}_form" } ) do |f|
41
+ if params[:referrer]
42
+ concat f.text_field "referrer", class: "normal-input", hidden: true, value: params[:referrer], name: 'referrer'
43
+ end
44
+ if params[:polymorphic_name].present?
45
+ concat f.text_field params[:polymorphic_name] + '_type', class: "normal-input", hidden: true, value: params[:associated_class].classify
46
+ concat f.text_field params[:polymorphic_name] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
47
+ elsif params[:associated_class] && params[:associated_id]
48
+ concat f.text_field params[:associated_class] + '_id', class: "normal-input", hidden: true, value: params[:associated_id]
49
+ end
41
50
  available_fields_hash.each do |key, fields_array|
42
51
  if key == :fields
43
52
  fields_array.each do |field|
@@ -51,6 +51,8 @@ module CmAdmin
51
51
  base_path + '/new'
52
52
  when 'edit'
53
53
  base_path + "/#{ar_object.id}" + '/edit'
54
+ when 'destroy'
55
+ base_path + "/#{ar_object.id}"
54
56
  end
55
57
  end
56
58
 
@@ -1 +1 @@
1
- d5850cd60f91abe79ff8a84a45a9e24c75cb0e4b
1
+ 09d7dd65a776413eb9615ccfd2071782565b6619
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.7.1
4
+ version: 0.7.4
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-06-02 00:00:00.000000000 Z
13
+ date: 2022-06-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pagy
@@ -240,7 +240,7 @@ licenses:
240
240
  metadata:
241
241
  homepage_uri: https://github.com/commutatus/cm-admin
242
242
  source_code_uri: https://github.com/commutatus/cm-admin
243
- post_install_message:
243
+ post_install_message:
244
244
  rdoc_options: []
245
245
  require_paths:
246
246
  - lib
@@ -255,8 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  requirements: []
258
- rubygems_version: 3.2.3
259
- signing_key:
258
+ rubygems_version: 3.2.32
259
+ signing_key:
260
260
  specification_version: 4
261
261
  summary: This is an admin panel gem
262
262
  test_files: []