cm-admin 0.7.5 → 0.7.6

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: 8603d897651307b80517b9918c60ab3d2d62abdc2931af5ea7d8def1453b4865
4
- data.tar.gz: 0afafa900d9c51bee526e9781df8dd41baf1603cf768bb8db3e1d8353fc4adc0
3
+ metadata.gz: d15eef9e06296f53028093dfc869ae0f0ecba8ba271bc3d39ef48e2f1bd09f16
4
+ data.tar.gz: 9ae45db5314a0187bf45a1f6864e97f18bfcb9de5cc32dc2ce1c5d388188e1b1
5
5
  SHA512:
6
- metadata.gz: '02398dcf148b0d90bd6de2dfd2fdeae4fd4d3353d75c33433a75518da87c6d6c739349279f9f6f3a4632256c37e463009838e9ec21821d224728730a8656b87b'
7
- data.tar.gz: 2f390a32636c40fdeb3afc5128ad824135565450d0b833aafc9ac828d8d4178d5dda2316e01f654a45266514a4a31e0b22985c41d3e1b10cf049ee56b6cf663c
6
+ metadata.gz: 31116fa28dcabfbbbfb404156e8aca01d2d3b12e04bfb82b08a8bf34520b416b4609167c43e921ff652f7ff1ef268b67df2f52f436fb08197062c0f91379b847
7
+ data.tar.gz: 3b1c8a5007cdb2d2d26a276ad77d261c99a354983c2ce782646c183093383e5526cb77cb027a89454bd1d2574dde61963a7adcd96b16dade5fcf194a4db4e0ab
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (0.7.5)
4
+ cm-admin (0.7.6)
5
5
  axlsx_rails (~> 0.6.1)
6
6
  cocoon (~> 1.2.15)
7
+ local_time (~> 2.1.0)
7
8
  pagy (~> 4.11.0)
8
9
  pundit (~> 2.2.0)
9
10
  slim (~> 4.1.0)
@@ -47,13 +48,16 @@ GEM
47
48
  htmlentities (4.3.4)
48
49
  i18n (1.10.0)
49
50
  concurrent-ruby (~> 1.0)
51
+ local_time (2.1.0)
50
52
  loofah (2.18.0)
51
53
  crass (~> 1.0.2)
52
54
  nokogiri (>= 1.5.9)
53
55
  marcel (1.0.2)
54
56
  method_source (1.0.0)
57
+ mini_portile2 (2.8.0)
55
58
  minitest (5.15.0)
56
- nokogiri (1.13.6-arm64-darwin)
59
+ nokogiri (1.13.6)
60
+ mini_portile2 (~> 2.8.0)
57
61
  racc (~> 1.4)
58
62
  pagy (4.11.0)
59
63
  pundit (2.2.0)
@@ -1,10 +1,8 @@
1
1
  module CmAdmin
2
2
  class ApplicationController < ::ActionController::Base
3
- include Pundit::Authorization
4
- include Pagy::Backend
3
+
5
4
  # before_action :check_cm_admin
6
5
  layout 'cm_admin'
7
- helper CmAdmin::ViewHelpers
8
6
 
9
7
 
10
8
  def check_cm_admin
@@ -3,6 +3,8 @@ module CmAdmin
3
3
  include Pundit::Authorization
4
4
  include Pagy::Backend
5
5
 
6
+ helper CmAdmin::ViewHelpers
7
+
6
8
  def cm_index(params)
7
9
  @current_action = CmAdmin::Models::Action.find_by(@model, name: 'index')
8
10
  # Based on the params the filter and pagination object to be set
@@ -15,9 +15,11 @@ require('./filters.js')
15
15
  require('./exports.js')
16
16
 
17
17
  import jQuery from 'jquery'
18
+ import LocalTime from "local-time"
18
19
  window.$ = jQuery
19
20
  window.jQuery = jQuery
20
21
 
22
+ LocalTime.start()
21
23
  require("@nathanvda/cocoon")
22
24
  import "@fortawesome/fontawesome-free/css/all"
23
25
  import "daterangepicker"
@@ -0,0 +1,52 @@
1
+ - edit_action = available_actions(cm_model, 'edit')
2
+ - destroy_action = available_actions(cm_model, 'destroy')
3
+ - custom_actions = available_actions(cm_model, 'custom_actions')
4
+ - custom_actions_modals = custom_actions.select{ |act| act if act.display_type.eql?(:modal) }
5
+
6
+ - if custom_actions.any? || edit_action.present? || destroy_action.present?
7
+ td.row-action-cell
8
+ .row-action-tool
9
+ button.secondary-btn.tool-btn
10
+ span
11
+ i.fa.fa-bars.bolder
12
+ span
13
+ i.fa.fa-angle-down
14
+ .popup-card.table-export-popup.hidden
15
+ - if edit_action.present?
16
+ = link_to "#{page_url('edit', ar_object)}" do
17
+ .popup-option
18
+ span
19
+ i.fa.fa-edit
20
+ | Edit
21
+ - if destroy_action.present?
22
+ = link_to "#{page_url('destroy', ar_object)}", method: :delete do
23
+ .popup-option
24
+ span
25
+ i.fa.fa-trash
26
+ | Destroy
27
+ - custom_actions.each do |custom_action|
28
+ - if custom_action.display_if.call(ar_object)
29
+ - case custom_action.display_type
30
+ - when :button
31
+ = link_to cm_admin.send("#{cm_model.name.underscore}_index_path") + '/' + custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb do
32
+ .popup-option
33
+ span
34
+ i class="#{custom_action.icon_name}"
35
+ = custom_action.name.humanize
36
+ - when :modal
37
+ = link_to '', data: { bs_toggle: 'modal', bs_target: "##{custom_action.name.classify}Modal-#{ar_object.id.to_s}" } do
38
+ .popup-option
39
+ span
40
+ i class="#{custom_action.icon_name}"
41
+ = custom_action.name.humanize
42
+
43
+ - if custom_actions_modals.any?
44
+ - custom_actions_modals.each do |custom_action|
45
+ .modal.fade id="#{custom_action.name.classify}Modal-#{ar_object.id.to_s}" aria-hidden='true' aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex='1'
46
+ .modal-dialog
47
+ .modal-content
48
+ .modal-header
49
+ h5.modal-title id="#{custom_action.name.classify}ModalLabel" = custom_action.name.classify
50
+ button.btn-close aria-label='Close' data-bs-dismiss='modal'
51
+ .modal-body
52
+ = render partial: custom_action.partial, locals: { ar_object: ar_object }
@@ -36,43 +36,10 @@
36
36
  a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/#{ar_object.id}" = show_field_value(ar_object, column)
37
37
  - else
38
38
  span class="#{column.cm_css_class}" = show_field_value(ar_object, column)
39
- - associated_model_actions = @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}
40
- - if associated_model_actions.present?
41
- td.row-action-cell
42
- .row-action-tool
43
- button.secondary-btn.tool-btn type="button"
44
- span
45
- i.fa.fa-bars.bolder
46
- span
47
- i.fa.fa-angle-down
48
- .popup-card.table-export-popup.hidden
49
- // To be added once the associated model has edit actions
50
- / .popup-option
51
- / a href="#{page_url('edit', ar_object)}"
52
- / | Edit
53
- - associated_model_actions.each do |custom_action|
54
- - if custom_action.display_if.call(ar_object)
55
- .popup-option
56
- - if custom_action.display_type == :button
57
- = link_to cm_admin.send("#{@associated_model.name.underscore}_index_path") + '/' + custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb do
58
- span
59
- i class="#{custom_action.icon_name}"
60
- = custom_action.name.humanize
61
- - elsif custom_action.display_type == :modal
62
- = link_to custom_action.name.humanize, '', data: { bs_toggle: 'modal', bs_target: "##{custom_action.name.classify}Modal-#{ar_object.id.to_s}" }
39
+ - if @associated_model
40
+ == render partial: 'cm_admin/main/actions_dropdown', locals: { cm_model: @associated_model, ar_object: ar_object }
63
41
 
64
42
  .cm-pagination
65
43
  .cm-pagination__lhs Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
66
44
  .cm-pagination__rhs
67
45
  == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
68
-
69
- - @associated_ar_object.data.each do |ar_object|
70
- - @associated_model && @associated_model.available_actions.select{|act| act if (act.route_type == 'member' && act.display_type == :modal)}.each do |custom_action|
71
- .modal.fade id="#{custom_action.name.classify}Modal-#{ar_object.id.to_s}" aria-hidden='true' aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex='1'
72
- .modal-dialog
73
- .modal-content
74
- .modal-header
75
- h5.modal-title id="#{custom_action.name.classify}ModalLabel" = custom_action.name.classify
76
- button.btn-close aria-label='Close' data-bs-dismiss='modal'
77
- .modal-body
78
- = render partial: custom_action.partial, locals: { ar_object: ar_object }
@@ -31,40 +31,9 @@
31
31
  - else
32
32
  = show_field_value(ar_object, column)
33
33
  - if column.field_type == :drawer
34
- = render partial: column.drawer_partial, locals: { ar_object: ar_object}
35
-
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')}
38
- - custom_actions = @model.available_actions.select{|act| act if act.route_type == 'member' && [:button, :modal].include?(act.display_type)}
39
- - if custom_actions.any? || edit_action.any? || destroy_action.any?
40
- td.row-action-cell
41
- .row-action-tool
42
- button.secondary-btn.tool-btn type="button"
43
- span
44
- i.fa.fa-bars.bolder
45
- span
46
- i.fa.fa-angle-down
47
- .popup-card.table-export-popup.hidden
48
- - if edit_action.any? && policy([:cm_admin, @model.name.classify.constantize]).edit?
49
- = link_to "#{page_url('edit', ar_object)}" do
50
- .popup-option
51
- span
52
- i.fa.fa-edit
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
60
- - custom_actions.each do |custom_action|
61
- - if custom_action.name.present? && has_valid_policy(@model.name, custom_action.name)
62
- - if custom_action.display_if.call(ar_object)
63
- = link_to cm_admin.send("#{@model.name.underscore}_index_path") + '/' + custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb do
64
- .popup-option
65
- span
66
- i class="#{custom_action.icon_name}"
67
- = custom_action.name.humanize
34
+ = render partial: column.drawer_partial, locals: { ar_object: ar_object }
35
+ - if @model
36
+ == render partial: 'cm_admin/main/actions_dropdown', locals: { cm_model: @model, ar_object: ar_object }
68
37
 
69
38
  .cm-pagination
70
39
  .cm-pagination__lhs Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
data/cm_admin.gemspec CHANGED
@@ -26,10 +26,11 @@ 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 'pagy', '~> 4.11.0'
30
- spec.add_runtime_dependency 'slim', '~> 4.1.0'
31
- spec.add_runtime_dependency 'webpacker', '~> 5.2.1'
32
29
  spec.add_runtime_dependency 'axlsx_rails', '~> 0.6.1'
33
30
  spec.add_runtime_dependency 'cocoon', '~> 1.2.15'
31
+ spec.add_runtime_dependency 'local_time', '~> 2.1.0'
32
+ spec.add_runtime_dependency 'pagy', '~> 4.11.0'
34
33
  spec.add_runtime_dependency 'pundit', '~> 2.2.0'
34
+ spec.add_runtime_dependency 'slim', '~> 4.1.0'
35
+ spec.add_runtime_dependency 'webpacker', '~> 5.2.1'
35
36
  end
@@ -14,6 +14,7 @@ require 'pagy'
14
14
  require 'axlsx'
15
15
  require 'cocoon'
16
16
  require 'pundit'
17
+ require 'local_time'
17
18
 
18
19
  module CmAdmin
19
20
  class Model
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
@@ -0,0 +1,21 @@
1
+ module CmAdmin
2
+ module ViewHelpers
3
+ module ActionDropdownHelper
4
+ def available_actions(cm_model, action_type)
5
+ if action_type.eql?('custom_actions')
6
+ cm_model.available_actions.select {
7
+ |act| act if act.route_type.eql?('member') &&
8
+ [:button, :modal].include?(act.display_type) &&
9
+ act.name.present? &&
10
+ has_valid_policy(cm_model.name, act.name)
11
+ }
12
+ else
13
+ cm_model.available_actions.select {
14
+ |act| act if act.action_type.eql?(:default) &&
15
+ act.name.eql?(action_type)
16
+ } if has_valid_policy(cm_model.name, action_type)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,6 @@
1
1
  module CmAdmin
2
2
  module ViewHelpers
3
3
  module FieldDisplayHelper
4
-
5
4
  def show_field(ar_object, field)
6
5
  content_tag(:div, class: "info-split") do
7
6
  concat show_field_label(ar_object, field)
@@ -33,7 +32,8 @@ module CmAdmin
33
32
  when :string
34
33
  ar_object.send(field.field_name).to_s
35
34
  when :datetime
36
- ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s if ar_object.send(field.field_name)
35
+ self.extend LocalTimeHelper
36
+ local_time(ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s) if ar_object.send(field.field_name)
37
37
  when :text
38
38
  ar_object.send(field.field_name)
39
39
  when :custom
@@ -2,12 +2,15 @@ module CmAdmin
2
2
  module ViewHelpers
3
3
  Dir[File.expand_path("view_helpers", __dir__) + "/*.rb"].each { |f| require f }
4
4
 
5
- include PageInfoHelper
6
- include NavigationHelper
7
- include FormHelper
5
+ include ActionDropdownHelper
8
6
  include FieldDisplayHelper
9
7
  include FilterHelper
8
+ include FormHelper
10
9
  include ManageColumnPopupHelper
10
+ include NavigationHelper
11
+ include PageInfoHelper
12
+
13
+ # Included Rails view helper
11
14
  include ActionView::Helpers::FormTagHelper
12
15
  include ActionView::Helpers::TagHelper
13
16