five-two-nw-olivander 0.1.2.6 → 0.1.2.8

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: 8321bd8a5b34a8550a97d74784c9303f430ec4a4417cd8acadf564f8fcd92687
4
- data.tar.gz: 27697dcd2ca0669e2ad81f770b98760dacadb9d1e0bae849ccc047728a89e0c9
3
+ metadata.gz: 3f3115b1794baed9344d980ed505a3df7d1ae0cee954e4896163618a91d47f58
4
+ data.tar.gz: '09d31e3619bfa1d7111077c3be1c9f5c0005a1417dd041bc68aa71bf32014988'
5
5
  SHA512:
6
- metadata.gz: a9f824c7aa7a5a8356f2eceeb149e91daef1e7d94eb22bce75d70f3584508d2347b65cf66c383b4512bc26809d1052e09b72cda5e9e6d0224c6fe81c928af3c8
7
- data.tar.gz: 1f0b34e2dc130103bcaacf848e17ab6e76bd5f7db84414160201b265623f0fcdd55e391dcf85acebb2ae2946b97240d06edcace6018b08cd6c21e703d34ca3d9
6
+ metadata.gz: 7e34e263e6a3b6788b7764882d65e0caa54f5ca0c99109f3908c7d3c5f42af2a7328bc35fe2a6904643b6c624b9ca1ba3fcbeee671e5dd5f8a86a8b59dc5a58d
7
+ data.tar.gz: 18d6f99fba59c05f75b2c1e5394496be073965270682d778111a735600303734801c2e821a95cb41c62d0207bdfd9f8b71fc874fe0dbade368224b9df6957361
@@ -1,7 +1,9 @@
1
1
  module Olivander
2
2
  module Resources
3
3
  class ResourceAction
4
- attr_accessor :sym, :action, :verb, :confirm, :turbo_frame, :collection, :controller, :crud_action, :show_in_form, :show_in_datatable, :no_route
4
+ attr_accessor :sym, :action, :verb, :confirm, :turbo_frame, :collection,
5
+ :controller, :crud_action, :show_in_form, :show_in_datatable,
6
+ :no_route, :path_helper
5
7
 
6
8
  def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false, turbo_frame: nil, collection: false, crud_action: false,
7
9
  show_in_form: true, show_in_datatable: true, no_route: false)
@@ -83,6 +85,7 @@ module Olivander
83
85
  included do
84
86
  class_attribute :resources, default: {}
85
87
  class_attribute :current_resource
88
+ class_attribute :last_path_helper
86
89
  end
87
90
 
88
91
  class_methods do
@@ -107,6 +110,13 @@ module Olivander
107
110
  build_resource_routes(mapper)
108
111
  end
109
112
 
113
+ def set_controller_and_helper(a)
114
+ last_route = Rails.application.routes.routes.last
115
+ a.controller = last_route.defaults[:controller]
116
+ a.path_helper = last_route.name.blank? ? last_path_helper : "#{last_route.name}_path"
117
+ self.last_path_helper = a.path_helper
118
+ end
119
+
110
120
  def build_resource_routes(mapper)
111
121
  resources.keys.each do |k|
112
122
  r = resources[k]
@@ -118,9 +128,11 @@ module Olivander
118
128
 
119
129
  if ba.confirm
120
130
  mapper.get ba.action, action: "confirm_#{ba.action}"
131
+ set_controller_and_helper(ba)
121
132
  mapper.post ba.action
122
133
  else
123
134
  mapper.send(ba.verb, ba.action)
135
+ set_controller_and_helper(ba)
124
136
  end
125
137
  end
126
138
  end
@@ -134,9 +146,11 @@ module Olivander
134
146
  next if ma.no_route
135
147
  if ma.confirm
136
148
  mapper.get ma.action, action: "confirm_#{ma.action}"
149
+ set_controller_and_helper(ma)
137
150
  mapper.post ma.action
138
151
  else
139
152
  mapper.send(ma.verb, ma.action)
153
+ set_controller_and_helper(ma)
140
154
  end
141
155
  end
142
156
  end
@@ -14,5 +14,29 @@ module Olivander
14
14
  link_to r.send(field), send(path, args)
15
15
  end
16
16
  end
17
+
18
+ def self.auto_datatable(klazz, link_path: nil, only: [])
19
+ collection do
20
+ klazz.all
21
+ end
22
+
23
+ datatable do
24
+ bulk_actions_col
25
+ klazz.new.attributes.each do |att|
26
+ key = att[0]
27
+ next if only.size.positive? && !only.include?(key)
28
+ sym = key.gsub('_id', '').to_sym
29
+ visible = !['created', 'updated', 'created_at', 'updated_at', 'deleted_at', 'current_user', 'current_action'].include?(key)
30
+ if link_path.present? && sym == :id
31
+ link_col sym, link_path, :id
32
+ elsif link_path.present? && sym == :name
33
+ link_col sym, link_path, [:id, :name]
34
+ else
35
+ col sym, visible: visible
36
+ end
37
+ end
38
+ actions_col
39
+ end
40
+ end
17
41
  end
18
42
  end
@@ -1,5 +1,28 @@
1
1
  - resource = (@_effective_resource || Effective::Resource.new(controller_path))
2
2
 
3
+ - if @datatable
4
+ - content_for :datatable do
5
+ = render_datatable(@datatable, charts: false)
6
+ - content_for :datatable_charts do
7
+ - keys = @datatable._charts.keys
8
+ - ks = keys.size
9
+ - if ks.positive?
10
+ %br
11
+ .row
12
+ - @datatable._charts.keys.each do |k|
13
+ %div{ class: "#{col_class_num('xl', ks, 3)} #{col_class_num('lg', ks, 2)} #{col_class_num('md', ks, 6)} #{col_class_num('sm', ks, 6)}"}
14
+ .card.card-secondary
15
+ .card-header
16
+ %h3.card-title= I18n.t([@datatable.class.name.underscore, 'charts', k].join('.'))
17
+ .card-tools.text-right
18
+ %button.btn.btn-tool{ type: :button, 'data-card-widget': :maximize }
19
+ %i.fas.fa-expand
20
+ .card-body
21
+ = render_datatable_chart(@datatable, k)
22
+
23
+ - if @datatable
24
+ = content_for :datatable_charts
25
+
3
26
  .row
4
27
  .col-12
5
28
  .card
@@ -9,7 +32,7 @@
9
32
  = resource_form_actions(@context.route_builder, resource.klass, for_action: :index)
10
33
  .card-body
11
34
  - if @datatable
12
- = render_datatable(@datatable)
35
+ = content_for :datatable
13
36
 
14
37
  - elsif instance_variable_get('@' + resource.plural_name).respond_to?(:to_partial_path)
15
38
  = render instance_variable_get('@' + resource.plural_name)
@@ -1,7 +1,4 @@
1
- - if @context.nil?
2
- - parts = datatable.class.name.split('::')
3
- - parts[parts.size-1] = 'Controller'
4
- - parts.join('::').constantize.new.build_context
1
+ - route_builder = @context&.route_builder || datatable.class::ROUTE_BUILDER
5
2
  = dropdown(variation: :dropleft, btn_class: btn_class) do
6
- - authorized_resource_actions(@context.route_builder, resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
7
- = dropdown_link_to a.sym, { controller: a.controller, action: a.action, id: resource.id }
3
+ - authorized_resource_actions(route_builder, resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
4
+ = dropdown_link_to a.sym, send(a.path_helper, resource.id)
@@ -11,7 +11,7 @@
11
11
  .image
12
12
  %img.img-circle.elevation-2{:alt => "User Image", :src => image_path(user_image_path(nil))}/
13
13
  .info
14
- %a.d-block{:href => "#"}= 'current_user'
14
+ = link_to current_erp_user, destroy_erp_user_session_path, method: :delete, class: 'd-block'
15
15
  / SidebarSearch Form
16
16
  .form-inline
17
17
  .input-group{"data-widget" => "sidebar-search"}
@@ -5,3 +5,4 @@ require 'chartkick'
5
5
  require 'view_component'
6
6
  require 'simple_form'
7
7
  require 'olivander'
8
+ require 'devise'
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = "0.1.2.6"
2
+ VERSION = "0.1.2.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five-two-nw-olivander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.6
4
+ version: 0.1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-05 00:00:00.000000000 Z
11
+ date: 2023-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick