five-two-nw-olivander 0.1.2.51 → 0.1.2.52

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: cfc8a78839ba441c4f7f1588122feb30fafb585ded19b0b1d5fe663d7cb52ad7
4
- data.tar.gz: 0e8ad124a7cb6bf71446abe40cdb747c2feef9092bf8ef5b7616528f45a36317
3
+ metadata.gz: 2e93303d3b518b3409a10ca1d3ca08da710bbfee02e520c25dbca2fd14ff30f2
4
+ data.tar.gz: 803fc57772644b7ae0205e9c8df64d2fbba922e094ca53066916292b2bb8ca56
5
5
  SHA512:
6
- metadata.gz: 380be235b65bc45652b82f8f05beda410256fe16ebdb00fb17824952fc7ee7aafd90b731b52ea974bbb706b2b63d7e830e3710b301e14e38f95d5c943fe535ad
7
- data.tar.gz: c65a9b8f7fa4324f7ea1df8035dba342799e4e38310ebe04c644d0ff908a6850f8d15ed204e78359c16fee8e401e94fb5a0340b83bc69e8932910c7f96d8cdb6
6
+ metadata.gz: a931367c49c1001c860e979276c0d2e96a6cba7614ab1edd172d2e5306f01a005407aa3a6fac3493f640a113dc07bd0e6757e2a072e9430c209b3437c7d5076d
7
+ data.tar.gz: d2a97766f50abb22ca3947fe6eff851b7c443d3ef8d2397a4b8ed0400eb370d3756b1c4eb1ac72dc5ba36b678d6274f792464f5d0f25162169d8e1e8319c23b0
@@ -3,10 +3,12 @@ module Olivander
3
3
  class ResourceAction
4
4
  attr_accessor :sym, :action, :verb, :confirm, :turbo_frame, :collection,
5
5
  :controller, :crud_action, :show_in_form, :show_in_datatable,
6
- :no_route, :path_helper
6
+ :no_route, :path_helper, :confirm_with
7
7
 
8
- def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false, turbo_frame: nil, collection: false, crud_action: false,
9
- show_in_form: true, show_in_datatable: true, no_route: false, path_helper: nil)
8
+ def initialize(sym, action: nil, controller: nil, verb: :get, confirm: false,
9
+ turbo_frame: nil, collection: false, crud_action: false,
10
+ show_in_form: true, show_in_datatable: true, no_route: false,
11
+ path_helper: nil, confirm_with: nil)
10
12
  self.sym = sym
11
13
  self.action = action || sym
12
14
  self.controller = controller
@@ -19,6 +21,35 @@ module Olivander
19
21
  self.show_in_datatable = show_in_datatable
20
22
  self.no_route = no_route
21
23
  self.path_helper = path_helper
24
+ self.confirm_with = confirm_with
25
+ end
26
+
27
+ def args_hash(options = nil)
28
+ {}.tap do |h|
29
+ h.merge!(method: verb) if turbo_frame.blank?
30
+ h.merge!(data: data_hash)
31
+ h.merge!(options) if options.present?
32
+ end
33
+ end
34
+
35
+ def data_hash
36
+ {}.tap do |h|
37
+ h.merge!(turbo: true, turbo_method: verb, turbo_frame: turbo_frame) if turbo_frame.present?
38
+
39
+ message = confirmation_message
40
+ h.merge!(confirm_key => message) unless message.blank?
41
+ end
42
+ end
43
+
44
+ def confirm_key
45
+ turbo_frame.present? ? :turbo_confirm : :confirm
46
+ end
47
+
48
+ def confirmation_message
49
+ return confirm_with if confirm_with.present?
50
+ return I18n.t('activerecord.actions.delete-confirmation') if verb == :delete
51
+
52
+ nil
22
53
  end
23
54
  end
24
55
 
@@ -99,13 +130,16 @@ module Olivander
99
130
  end
100
131
 
101
132
  def action(sym, verb: :get, confirm: false, turbo_frame: nil, collection: false, show_in_datatable: true,
102
- show_in_form: true, no_route: false, controller: nil, action: nil, path_helper: nil)
133
+ show_in_form: true, no_route: false, controller: nil, action: nil, path_helper: nil,
134
+ confirm_with: nil
135
+ )
103
136
  raise 'Must be invoked in a resource block' unless current_resource.present?
104
137
 
105
138
  controller ||= current_resource.model
106
139
  current_resource.actions << ResourceAction.new(
107
140
  sym, action: action, controller: controller, verb: verb, confirm: confirm, turbo_frame: turbo_frame, collection: collection,
108
- show_in_datatable: show_in_datatable, show_in_form: show_in_form, no_route: no_route, path_helper: path_helper
141
+ show_in_datatable: show_in_datatable, show_in_form: show_in_form, no_route: no_route, path_helper: path_helper,
142
+ confirm_with: confirm_with
109
143
  )
110
144
  end
111
145
 
@@ -7,10 +7,6 @@
7
7
  %i.fa{ class: I18n.t(icon_key)}
8
8
  = resource_form_action_label(@resource, a.sym)
9
9
 
10
- - if a.turbo_frame.blank?
11
- = link_to({ controller: a.controller, action: a.action }, method: a.verb, class: 'btn btn-tool') do
12
- = yield cf_sym
13
- - else
14
- = link_to({ controller: a.controller, action: a.action }, class: 'btn btn-tool', data: { turbo: true, turbo_method: a.verb, turbo_frame: a.turbo_frame }) do
15
- = yield cf_sym
10
+ = link_to({ controller: a.controller, action: a.action }, a.args_hash(class: 'btn btn-tool')) do
11
+ = yield cf_sym
16
12
  &nbsp;
@@ -19,8 +19,7 @@
19
19
  = dropdown_link_to resource_form_action_label(resource, a.sym), path, data: data, method: a.verb
20
20
  - crud_actions.each do |a|
21
21
  - path = a.path_helper.is_a?(Proc) ? a.path_helper.call(resource) : send(a.path_helper, resource.id)
22
- - data = a.turbo_frame.present? ? { turbo: true, turbo_frame: a.turbo_frame } : {}
23
22
  - icon_class = (a.verb == :delete ? '' : '')
24
- = link_to path, data: data, method: a.verb, title: resource_form_action_label(resource, a.sym), class: "btn btn-sm #{icon_class}" do
23
+ = link_to path, a.args_hash(title: resource_form_action_label(resource, a.sym), class: "btn btn-sm #{icon_class}") do
25
24
  %i{ class: resource_form_action_icon(resource, a.sym), style: 'display: block; font-size: 10px' }
26
25
  %span{ style: 'font-size: 12px' }= resource_form_action_label(resource, a.sym)
@@ -1,3 +1,3 @@
1
1
  module Olivander
2
- VERSION = '0.1.2.51'.freeze
2
+ VERSION = '0.1.2.52'.freeze
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.51
4
+ version: 0.1.2.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dennis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-29 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chartkick