effective_resources 1.8.6 → 1.8.11
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 +4 -4
- data/app/controllers/concerns/effective/crud_controller.rb +25 -18
- data/app/controllers/concerns/effective/crud_controller/paths.rb +21 -5
- data/app/controllers/concerns/effective/crud_controller/respond.rb +5 -5
- data/app/controllers/concerns/effective/flash_messages.rb +8 -4
- data/app/controllers/concerns/effective/wizard_controller/save.rb +1 -1
- data/app/views/application/create.js.erb +1 -1
- data/app/views/application/destroy.js.erb +1 -0
- data/app/views/application/member_action.js.erb +4 -0
- data/app/views/application/update.js.erb +1 -0
- data/lib/effective_resources/effective_gem.rb +1 -1
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2703faba8c8b14643c0e0f75e958bf27471b5d54fba6461d24e583156f7badae
|
4
|
+
data.tar.gz: 917291289d6e5530f04ddf65d03da2f828d0bf00dce53d79fc6e3f67c7d7a421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7033816b0b5c53b7f6ebccf7269aa635effb7f792e6dbbf55d83d546980612ecba3f3d18b160c46c5f6e353724763e63efb55e8ffa23c2f360eea1d3e1057635
|
7
|
+
data.tar.gz: e7b77545e441aec916ecbe3ca0fc35e8c9d14eeb6b7d3553e8b8e5be7af7ef71b735c89b480d5a91a3288f03a48b2846ac6f7f05a744a6bdb1d758d83630e08b
|
@@ -11,7 +11,6 @@ module Effective
|
|
11
11
|
include Effective::CrudController::Submits
|
12
12
|
|
13
13
|
included do
|
14
|
-
define_actions_from_routes
|
15
14
|
define_callbacks :resource_render, :resource_before_save, :resource_after_save, :resource_after_commit, :resource_error
|
16
15
|
layout -> { resource_layout }
|
17
16
|
end
|
@@ -19,22 +18,11 @@ module Effective
|
|
19
18
|
module ClassMethods
|
20
19
|
include Effective::CrudController::Dsl
|
21
20
|
|
22
|
-
# This is used
|
21
|
+
# This is used for the buttons/submits/ons
|
23
22
|
# It doesn't really work with the resource_scope correctly but the routes are important here
|
24
23
|
def effective_resource
|
25
24
|
@_effective_resource ||= Effective::Resource.new(controller_path)
|
26
25
|
end
|
27
|
-
|
28
|
-
# Automatically respond to any action defined via the routes file
|
29
|
-
def define_actions_from_routes
|
30
|
-
(effective_resource.member_actions - effective_resource.crud_actions).each do |action|
|
31
|
-
define_method(action) { member_action(action) }
|
32
|
-
end
|
33
|
-
|
34
|
-
(effective_resource.collection_actions - effective_resource.crud_actions).each do |action|
|
35
|
-
define_method(action) { collection_action(action) }
|
36
|
-
end
|
37
|
-
end
|
38
26
|
end
|
39
27
|
|
40
28
|
def resource # @thing
|
@@ -53,22 +41,41 @@ module Effective
|
|
53
41
|
send(:instance_variable_set, "@#{resource_plural_name}", instance)
|
54
42
|
end
|
55
43
|
|
56
|
-
def effective_resource
|
44
|
+
def effective_resource(safe: false)
|
57
45
|
@_effective_resource ||= begin
|
58
46
|
relation = instance_exec(&resource_scope_relation) if respond_to?(:resource_scope_relation)
|
59
47
|
|
60
|
-
if respond_to?(:resource_scope_relation)
|
61
|
-
|
48
|
+
if respond_to?(:resource_scope_relation)
|
49
|
+
unless relation.kind_of?(ActiveRecord::Relation) || (relation.kind_of?(Class) && relation.ancestors.include?(ActiveModel::Model))
|
50
|
+
raise('resource_scope must return an ActiveRecord::Relation or class including ActiveModel::Model')
|
51
|
+
end
|
62
52
|
end
|
63
53
|
|
64
54
|
resource = Effective::Resource.new(controller_path, relation: relation)
|
65
55
|
|
66
56
|
unless resource.relation.kind_of?(ActiveRecord::Relation) || resource.active_model?
|
67
|
-
raise("unable to build resource_scope for #{resource.klass || 'unknown klass'}. Please name your controller to match an existing model, or manually define a resource_scope.")
|
57
|
+
raise("unable to build resource_scope for #{resource.klass || 'unknown klass'}. Please name your controller to match an existing model, or manually define a resource_scope.") unless safe
|
58
|
+
else
|
59
|
+
resource
|
68
60
|
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def action_missing(action, *args, &block)
|
65
|
+
effective_resource = self.effective_resource(safe: true)
|
66
|
+
return super if effective_resource.blank?
|
67
|
+
|
68
|
+
action = action.to_sym
|
69
69
|
|
70
|
-
|
70
|
+
if effective_resource.member_actions.include?(action)
|
71
|
+
return member_action(action)
|
71
72
|
end
|
73
|
+
|
74
|
+
if effective_resource.collection_actions.include?(action)
|
75
|
+
return collection_action(action)
|
76
|
+
end
|
77
|
+
|
78
|
+
super
|
72
79
|
end
|
73
80
|
|
74
81
|
private
|
@@ -2,7 +2,7 @@ module Effective
|
|
2
2
|
module CrudController
|
3
3
|
module Paths
|
4
4
|
|
5
|
-
def resource_redirect_path(action
|
5
|
+
def resource_redirect_path(resource, action)
|
6
6
|
submit = commit_action(action)
|
7
7
|
redirect = submit[:redirect].respond_to?(:call) ? instance_exec(&submit[:redirect]) : submit[:redirect]
|
8
8
|
|
@@ -39,13 +39,29 @@ module Effective
|
|
39
39
|
# Otherwise consider the action
|
40
40
|
commit_default_redirect = case action
|
41
41
|
when :create
|
42
|
-
[
|
42
|
+
[
|
43
|
+
(resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
|
44
|
+
(resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
|
45
|
+
(resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
|
46
|
+
]
|
43
47
|
when :update
|
44
|
-
[
|
48
|
+
[
|
49
|
+
(resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
|
50
|
+
(resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
|
51
|
+
(resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
|
52
|
+
]
|
45
53
|
when :destroy
|
46
|
-
[
|
54
|
+
[
|
55
|
+
referer_redirect_path,
|
56
|
+
(resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
|
57
|
+
]
|
47
58
|
else
|
48
|
-
[
|
59
|
+
[
|
60
|
+
referer_redirect_path,
|
61
|
+
(resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
|
62
|
+
(resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
|
63
|
+
(resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
|
64
|
+
]
|
49
65
|
end.compact.first
|
50
66
|
|
51
67
|
return commit_default_redirect if commit_default_redirect.present?
|
@@ -10,12 +10,12 @@ module Effective
|
|
10
10
|
respond_to do |format|
|
11
11
|
format.html do
|
12
12
|
flash[:success] ||= resource_flash(:success, resource, action)
|
13
|
-
redirect_to(resource_redirect_path(action))
|
13
|
+
redirect_to(resource_redirect_path(resource, action))
|
14
14
|
end
|
15
15
|
|
16
16
|
format.js do
|
17
17
|
flash[:success] ||= resource_flash(:success, resource, action)
|
18
|
-
|
18
|
+
render(action, locals: { remote_form_redirect: resource_redirect_path(resource, action)}) # action.js.erb
|
19
19
|
end
|
20
20
|
end
|
21
21
|
elsif template_present?(action)
|
@@ -35,7 +35,7 @@ module Effective
|
|
35
35
|
respond_to do |format|
|
36
36
|
format.html do
|
37
37
|
flash[:success] ||= resource_flash(:success, resource, action)
|
38
|
-
redirect_to(resource_redirect_path(action))
|
38
|
+
redirect_to(resource_redirect_path(resource, action))
|
39
39
|
end
|
40
40
|
|
41
41
|
format.js do
|
@@ -61,7 +61,7 @@ module Effective
|
|
61
61
|
when :destroy
|
62
62
|
format.html do
|
63
63
|
redirect_flash
|
64
|
-
redirect_to(resource_redirect_path(action))
|
64
|
+
redirect_to(resource_redirect_path(resource, action))
|
65
65
|
end
|
66
66
|
else
|
67
67
|
if template_present?(action)
|
@@ -73,7 +73,7 @@ module Effective
|
|
73
73
|
else
|
74
74
|
format.html do
|
75
75
|
redirect_flash
|
76
|
-
redirect_to(resource_redirect_path(action))
|
76
|
+
redirect_to(resource_redirect_path(resource, action))
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -8,8 +8,10 @@ module Effective
|
|
8
8
|
def flash_success(resource, action = nil, name: nil)
|
9
9
|
raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
|
10
10
|
|
11
|
-
name ||=
|
12
|
-
resource.
|
11
|
+
name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
|
12
|
+
resource.class.model_name.to_s.downcase.split('::').last
|
13
|
+
else
|
14
|
+
resource.to_s.presence
|
13
15
|
end
|
14
16
|
|
15
17
|
"Successfully #{action_verb(action)} #{name || 'resource'}".html_safe
|
@@ -24,8 +26,10 @@ module Effective
|
|
24
26
|
|
25
27
|
messages = flash_errors(resource, e: e)
|
26
28
|
|
27
|
-
name ||=
|
28
|
-
resource.
|
29
|
+
name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
|
30
|
+
resource.class.model_name.to_s.downcase.split('::').last
|
31
|
+
else
|
32
|
+
resource.to_s.presence
|
29
33
|
end
|
30
34
|
|
31
35
|
["Unable to #{action}", (" #{name}" if name), (": #{messages}" if messages)].compact.join.html_safe
|
@@ -7,7 +7,7 @@ module Effective
|
|
7
7
|
action ||= resource.respond_to?("#{step}!") ? step : :save
|
8
8
|
|
9
9
|
if save_resource(resource, action)
|
10
|
-
flash[:success]
|
10
|
+
flash[:success] ||= options.delete(:success) || resource_flash(:success, resource, action)
|
11
11
|
|
12
12
|
@skip_to ||= next_step
|
13
13
|
@redirect_to ||= resource_wizard_path(resource, @skip_to) if was_new_record
|
@@ -4,8 +4,8 @@
|
|
4
4
|
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
7
|
+
EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
|
7
8
|
|
8
9
|
<% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
|
9
10
|
EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
|
10
11
|
<% end %>
|
11
|
-
|
@@ -4,6 +4,7 @@
|
|
4
4
|
EffectiveForm.remote_form_payload = '';
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
7
|
+
EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
|
7
8
|
|
8
9
|
<% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
|
9
10
|
EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
|
@@ -5,6 +5,10 @@ EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource, actio
|
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
7
7
|
|
8
|
+
<% if !request.get? %>
|
9
|
+
EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
|
10
|
+
<% end %>
|
11
|
+
|
8
12
|
<% if !request.get? && @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
|
9
13
|
EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
|
10
14
|
<% end %>
|
@@ -4,6 +4,7 @@
|
|
4
4
|
EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
7
|
+
EffectiveForm.remote_form_redirect = "<%= raw local_assigns[:remote_form_redirect] %>";
|
7
8
|
|
8
9
|
<% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
|
9
10
|
EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
|
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: 1.8.
|
4
|
+
version: 1.8.11
|
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: 2021-
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|