five-two-nw-olivander 0.1.2.3 → 0.1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/olivander/resources/route_builder.rb +42 -22
- data/app/helpers/olivander/application_helper.rb +4 -4
- data/app/views/application/_form.html.haml +1 -1
- data/app/views/application/index.html.haml +1 -1
- data/app/views/effective/resource/_actions_dropleft.html.haml +5 -1
- data/lib/olivander/version.rb +1 -1
- metadata +1 -1
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
|
@@ -17,18 +17,18 @@ module Olivander
|
|
17
17
|
"avatar#{SecureRandom.random_number(4)}.png"
|
18
18
|
end
|
19
19
|
|
20
|
-
def authorized_resource_actions(resource, for_action: :show)
|
20
|
+
def authorized_resource_actions(route_builder, resource, for_action: :show)
|
21
21
|
plural_name = resource.is_a?(Class) ? resource.table_name : resource.class.table_name
|
22
|
-
routed_resource =
|
22
|
+
routed_resource = route_builder.resources[plural_name.to_sym]
|
23
23
|
actions = resource.is_a?(Class) ?
|
24
24
|
(routed_resource.unpersisted_crud_actions | routed_resource.collection_actions) :
|
25
25
|
(resource.persisted? ? (routed_resource.persisted_crud_actions | routed_resource.member_actions): [])
|
26
26
|
actions.reject{ |a| a.sym == for_action }
|
27
27
|
end
|
28
28
|
|
29
|
-
def resource_form_actions(resource, for_action: :show)
|
29
|
+
def resource_form_actions(route_builder, resource, for_action: :show)
|
30
30
|
[].tap do |output|
|
31
|
-
authorized_resource_actions(resource, for_action: for_action).select{ |x| x.show_in_form }.each do |a|
|
31
|
+
authorized_resource_actions(route_builder, resource, for_action: for_action).select{ |x| x.show_in_form }.each do |a|
|
32
32
|
output << link_to(a.sym, {controller: a.controller, action: a.action}, method: a.verb, class: 'btn btn-primary', data: { turbo: true })
|
33
33
|
end
|
34
34
|
end.join(' ').html_safe
|
@@ -3,7 +3,7 @@
|
|
3
3
|
.card
|
4
4
|
.card-header
|
5
5
|
.card-tools
|
6
|
-
= resource_form_actions(@resource, for_action: action_name.to_sym)
|
6
|
+
= resource_form_actions(@context.route_builder, @resource, for_action: action_name.to_sym)
|
7
7
|
.card-body
|
8
8
|
=f.error_notification
|
9
9
|
=f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
|
@@ -6,7 +6,7 @@
|
|
6
6
|
.card-header
|
7
7
|
%h3.card-title= @page_title
|
8
8
|
.card-tools
|
9
|
-
= resource_form_actions(resource.klass, for_action: :index)
|
9
|
+
= resource_form_actions(@context.route_builder, resource.klass, for_action: :index)
|
10
10
|
.card-body
|
11
11
|
- if @datatable
|
12
12
|
= render_datatable(@datatable)
|
@@ -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