effective_resources 0.8.16 → 0.8.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/effective_resources_helper.rb +27 -0
- data/app/models/effective/resources/actions.rb +6 -0
- data/app/views/effective/resource/_actions.html.haml +15 -0
- data/app/views/effective/resource/_actions_dropleft.html.haml +16 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c0e50888b940fed7fd30a30e86abf390c57612d
|
4
|
+
data.tar.gz: c3cf4e2fbf45755c70a3886a055f0d6f945c1885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 915f86a6d94c9a928c17e8c8b2ac92990e61dc11625409942e9b95ec2aedc0814b85cc25a4afa0e71a362d84dd7e8216f6dddcb0d3001714e1f81128964a6e96
|
7
|
+
data.tar.gz: ef320f2ce953259fff1db2745e20d3c9a78b9cef271bfea2676587a61af5f14c7819b40830f2897a3cfbced147fb6b14982db4c33cd7a376e8d65dbd3f615b5b
|
@@ -38,6 +38,33 @@ module EffectiveResourcesHelper
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
# resource: resource is an
|
42
|
+
# show: true, edit: true, destroy: true
|
43
|
+
def render_resource_actions(resource, effective_resource: nil, namespace: nil, partial: nil, **atts, &block)
|
44
|
+
effective_resource ||= atts.delete(:resource)
|
45
|
+
effective_resource ||= controller.class.effective_resource if controller.class.respond_to?(:effective_resource)
|
46
|
+
effective_resource ||= Effective::Resource.new(controller_path)
|
47
|
+
raise 'Expected resource: value to be an Effective::Resource instance' unless effective_resource.kind_of?(Effective::Resource)
|
48
|
+
|
49
|
+
namespace ||= effective_resource.namespace&.to_sym
|
50
|
+
|
51
|
+
partial = case partial
|
52
|
+
when String
|
53
|
+
partial
|
54
|
+
when Symbol
|
55
|
+
['effective/resource/actions', partial.to_s].join('_')
|
56
|
+
else
|
57
|
+
'effective/resource/actions'
|
58
|
+
end
|
59
|
+
|
60
|
+
actions = effective_resource.resource_actions - atts.reject { |_, v| v }.keys + atts.select { |_, v| v }.keys
|
61
|
+
actions = actions.uniq.select { |action| EffectiveResources.authorized?(controller, action, resource) }
|
62
|
+
|
63
|
+
locals = { resource: resource, effective_resource: effective_resource, namespace: namespace, actions: actions }
|
64
|
+
|
65
|
+
block_given? ? render(partial, locals) { yield } : render(partial, locals)
|
66
|
+
end
|
67
|
+
|
41
68
|
# When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
|
42
69
|
def render_resource_form(resource, atts = {})
|
43
70
|
raise 'expected attributes to be a Hash. Try passing action: action if rendering custom action' unless atts.kind_of?(Hash)
|
@@ -67,6 +67,12 @@ module Effective
|
|
67
67
|
routes.keys
|
68
68
|
end
|
69
69
|
|
70
|
+
# Used by render_resource_actions helper
|
71
|
+
# All the actions we can actually make a link to
|
72
|
+
def resource_actions
|
73
|
+
(routes.keys & [:show, :edit, :destroy]) + member_actions
|
74
|
+
end
|
75
|
+
|
70
76
|
# GET actions
|
71
77
|
def collection_actions
|
72
78
|
routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) }.compact - crud_actions
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- if actions.index(:edit)
|
2
|
+
= link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}", class: 'btn btn-secondary'
|
3
|
+
|
4
|
+
- if actions.index(:show)
|
5
|
+
= link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s, class: 'btn btn-secondary'
|
6
|
+
|
7
|
+
- (actions - [:edit, :show, :destroy]).each do |action|
|
8
|
+
= link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
|
9
|
+
title: "#{action} #{resource}", data: { method: :post, confirm: "Really #{action} #{resource}?"}
|
10
|
+
|
11
|
+
= yield
|
12
|
+
|
13
|
+
- if actions.index(:destroy)
|
14
|
+
= link_to "Delete #{resource}", effective_resource.action_path(:destroy, resource), class: 'btn btn-danger',
|
15
|
+
title: "Delete #{resource}", data: { method: :delete, confirm: "Really delete #{resource}?" }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
= dropdown(variation: :dropleft) do
|
2
|
+
- if actions.index(:edit)
|
3
|
+
= dropdown_link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}"
|
4
|
+
|
5
|
+
- if actions.index(:show)
|
6
|
+
= dropdown_link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s
|
7
|
+
|
8
|
+
- (actions - [:edit, :show, :destroy]).each do |action|
|
9
|
+
= dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource),
|
10
|
+
title: "#{action} #{resource}", data: { method: :post, confirm: "Really #{action} #{resource}?"}
|
11
|
+
|
12
|
+
= yield
|
13
|
+
|
14
|
+
- if actions.index(:destroy)
|
15
|
+
= dropdown_link_to "Delete #{resource}", effective_resource.action_path(:destroy, resource),
|
16
|
+
title: "Delete #{resource}", data: { method: :delete, confirm: "Really delete #{resource}?" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- app/views/application/new.html.haml
|
65
65
|
- app/views/application/show.html.haml
|
66
66
|
- app/views/application/update.js.erb
|
67
|
+
- app/views/effective/resource/_actions.html.haml
|
68
|
+
- app/views/effective/resource/_actions_dropleft.html.haml
|
67
69
|
- config/effective_resources.rb
|
68
70
|
- lib/effective_resources.rb
|
69
71
|
- lib/effective_resources/engine.rb
|