five-two-nw-olivander 0.1.2.4 → 0.1.2.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0e0ab6690c2db84473cb79a4287db92eacc150390017c848b84a9297bcf182f
|
4
|
+
data.tar.gz: d075048882ce46be84002ee1e14618777bc9d0a3b6ded2709fb002b39b446d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8310faaad17dcdf36bfdcf63aeb1378ae1b5a630e4cbe8bd1d75ae9745f4d8bfd363514ff4150d0027ac1015487b1febcaa863c9ed86a7f990ab917242f1c440
|
7
|
+
data.tar.gz: d033c74985c4e1e963b44932c4cf9a7aabd3b31d1f283d1fd89443e37375dc0343da80300d7608c3069b89e7f776f8718979538bd8163628ca94a49182d7e123
|
@@ -25,29 +25,43 @@ module Olivander
|
|
25
25
|
def initialize(model, crud_actions)
|
26
26
|
self.model = model
|
27
27
|
self.actions = []
|
28
|
-
|
29
|
-
|
28
|
+
%i[index new create edit show update destroy].each do |ca|
|
29
|
+
next unless crud_actions.include?(ca)
|
30
|
+
actions << ResourceAction.new(ca, controller: model, verb: resolve_crud_action_verb(ca), collection: resolve_crud_action_collection(ca), crud_action: true)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
-
|
34
|
+
def resolve_crud_action_verb(ca)
|
35
|
+
case ca
|
36
|
+
when :create
|
37
|
+
:post
|
38
|
+
when :update
|
39
|
+
:patch
|
40
|
+
when :destroy
|
41
|
+
:delete
|
42
|
+
else
|
43
|
+
:get
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def resolve_crud_action_collection(ca)
|
48
|
+
%i[index new create].include?(ca)
|
35
49
|
end
|
36
50
|
|
37
|
-
def
|
38
|
-
actions.select{ |x|
|
51
|
+
def crud_actions
|
52
|
+
actions.select{ |x| x.crud_action }
|
39
53
|
end
|
40
54
|
|
41
55
|
def member_actions
|
42
|
-
|
56
|
+
actions.select{ |x| !x.collection }
|
43
57
|
end
|
44
58
|
|
45
59
|
def collection_actions
|
46
|
-
|
60
|
+
actions.select{ |x| x.collection }
|
47
61
|
end
|
48
62
|
|
49
63
|
def datatable_bulk_actions
|
50
|
-
collection_actions.select{ |x| x.show_in_datatable }
|
64
|
+
collection_actions.select{ |x| x.show_in_datatable && !x.crud_action }
|
51
65
|
end
|
52
66
|
|
53
67
|
def unpersisted_crud_actions
|
@@ -96,7 +110,25 @@ module Olivander
|
|
96
110
|
def build_resource_routes(mapper)
|
97
111
|
resources.keys.each do |k|
|
98
112
|
r = resources[k]
|
99
|
-
mapper.resources r.model, only:
|
113
|
+
mapper.resources r.model, only: [] do
|
114
|
+
mapper.collection do
|
115
|
+
r.collection_actions.each do |ba|
|
116
|
+
next if ba.no_route
|
117
|
+
next if ba.action == :new
|
118
|
+
|
119
|
+
if ba.confirm
|
120
|
+
mapper.get ba.action, action: "confirm_#{ba.action}"
|
121
|
+
mapper.post ba.action
|
122
|
+
else
|
123
|
+
mapper.send(ba.verb, ba.action)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
mapper.new do
|
129
|
+
mapper.get :new
|
130
|
+
end if r.collection_actions.select{ |x| x.action == :new }.size.positive?
|
131
|
+
|
100
132
|
mapper.member do
|
101
133
|
r.member_actions.each do |ma|
|
102
134
|
next if ma.no_route
|
@@ -108,18 +140,6 @@ module Olivander
|
|
108
140
|
end
|
109
141
|
end
|
110
142
|
end
|
111
|
-
|
112
|
-
mapper.collection do
|
113
|
-
r.collection_actions.each do |ba|
|
114
|
-
next if ba.no_route
|
115
|
-
if ba.confirm
|
116
|
-
mapper.get ba.action, action: "confirm_#{ba.action}"
|
117
|
-
mapper.post ba.action
|
118
|
-
else
|
119
|
-
mapper.send(ma.verb, ba.action)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
143
|
end
|
124
144
|
end
|
125
145
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
- if @context.nil?
|
2
|
+
- parts = datatable.class.name.split('::')
|
3
|
+
- parts[parts.size-1] = 'Controller'
|
4
|
+
- parts.join('::').constantize.new.build_context
|
1
5
|
= dropdown(variation: :dropleft, btn_class: btn_class) do
|
2
|
-
- authorized_resource_actions(resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
|
6
|
+
- authorized_resource_actions(@context.route_builder, resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
|
3
7
|
= dropdown_link_to a.sym, { controller: a.controller, action: a.action, id: resource.id }
|
data/lib/olivander/version.rb
CHANGED