effective_resources 2.4.7 → 2.5.1
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_private_helper.rb +14 -6
- data/app/models/effective/resources/controller.rb +36 -34
- data/app/models/effective/resources/i18n.rb +23 -0
- data/config/locales/effective_resources.en.yml +10 -0
- data/lib/effective_resources/version.rb +1 -1
- data/lib/validators/boolean_validator.rb +11 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9190fab385cb6ea0b026e4a2e4d1bb5e809cc7d448a3f581271d262325e6c0c1
|
4
|
+
data.tar.gz: ba468d6d469b61b565ea0779e1c7cfe27f3e6e343208dff29a41d1c8644d5b3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2ba197572e219bbeaab6845951a22373ea26f053315e847854653c3e319f813759f787ae435fda09f021991ad5efdef8464992ae45547e16f797cf5b6a96f3
|
7
|
+
data.tar.gz: 5d797d7b736068f367401d5f215d774e5e3e41bbf474e0c4ec0c4ce66a74556f2f76cdb59cd8b102f6549a026fb0e78d8951597396e263622bfaa7930677e76a
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module EffectiveResourcesPrivateHelper
|
4
4
|
REPLACE_PAGE_ACTIONS = {'update' => :edit, 'create' => :new}
|
5
5
|
BLACKLIST = [:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass]
|
6
|
+
REPLACE_RESOURCE_METHODS = Regexp.new('@resource\.\w+')
|
6
7
|
|
7
8
|
def permitted_resource_actions(resource, actions)
|
8
9
|
page_action = REPLACE_PAGE_ACTIONS[params[:action]] || params[:action].try(:to_sym) || :save
|
@@ -20,7 +21,7 @@ module EffectiveResourcesPrivateHelper
|
|
20
21
|
next unless permitted
|
21
22
|
|
22
23
|
opts = args.except(:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass)
|
23
|
-
resource_to_s = resource.to_s.presence || resource
|
24
|
+
resource_to_s = resource.to_s.presence || EffectiveResources.et(resource)
|
24
25
|
|
25
26
|
# Transform data: { ... } hash into 'data-' keys
|
26
27
|
if opts.key?(:data)
|
@@ -35,9 +36,16 @@ module EffectiveResourcesPrivateHelper
|
|
35
36
|
opts[:href] = opts.delete(:url)
|
36
37
|
end
|
37
38
|
|
38
|
-
#
|
39
|
+
# Replaces @resource.emails_send_to and @resource in data-confirm
|
39
40
|
if opts.key?('data-confirm') && opts['data-confirm'].to_s.include?('@resource')
|
40
|
-
|
41
|
+
confirm = opts['data-confirm']
|
42
|
+
|
43
|
+
confirm.gsub!(REPLACE_RESOURCE_METHODS) do |value|
|
44
|
+
method = value.to_s.split('.').last
|
45
|
+
resource.public_send(method)
|
46
|
+
end
|
47
|
+
|
48
|
+
opts['data-confirm'] = confirm.gsub('@resource', resource_to_s)
|
41
49
|
end
|
42
50
|
|
43
51
|
# Assign class
|
@@ -56,10 +64,10 @@ module EffectiveResourcesPrivateHelper
|
|
56
64
|
# Assign title
|
57
65
|
opts[:title] ||= case opts[:action]
|
58
66
|
when :save then commit
|
59
|
-
when :edit then "
|
67
|
+
when :edit then "#{et("effective_resources.actions.edit")} #{resource_to_s}"
|
60
68
|
when :show then "#{resource_to_s}"
|
61
|
-
when :destroy then "
|
62
|
-
when :index then "
|
69
|
+
when :destroy then "#{et("effective_resources.actions.destroy")} #{resource_to_s}"
|
70
|
+
when :index then "#{et("effective_resources.actions.index")} #{ets(resource)}"
|
63
71
|
else "#{opts[:action].to_s.titleize} #{resource_to_s}"
|
64
72
|
end
|
65
73
|
|
@@ -25,44 +25,45 @@ module Effective
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def buttons
|
28
|
+
human_index = EffectiveResources.et("effective_resources.actions.index")
|
29
|
+
human_new = EffectiveResources.et("effective_resources.actions.new")
|
30
|
+
|
28
31
|
{}.tap do |buttons|
|
29
32
|
member_get_actions.each do |action| # default true means it will be overwritten by dsl methods
|
30
|
-
buttons[action
|
33
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
31
34
|
end
|
32
35
|
|
33
36
|
(member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods
|
34
|
-
|
37
|
+
name = human_action_name(action)
|
38
|
+
confirm = human_action_confirm(action)
|
35
39
|
|
36
|
-
buttons[
|
40
|
+
buttons[name] = case action
|
37
41
|
when :archive
|
38
|
-
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' =>
|
42
|
+
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
|
39
43
|
when :unarchive
|
40
|
-
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' =>
|
44
|
+
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
|
41
45
|
else
|
42
|
-
{ action: action, default: true, 'data-method' => :post, 'data-confirm' =>
|
46
|
+
{ action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
50
|
member_delete_actions.each do |action|
|
47
|
-
|
51
|
+
name = human_action_name(action)
|
52
|
+
confirm = human_action_confirm(action)
|
48
53
|
|
49
|
-
|
50
|
-
buttons['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
51
|
-
else
|
52
|
-
buttons[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
53
|
-
end
|
54
|
+
buttons[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
|
54
55
|
end
|
55
56
|
|
56
57
|
if collection_get_actions.find { |a| a == :index }
|
57
|
-
buttons["
|
58
|
+
buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
|
58
59
|
end
|
59
60
|
|
60
61
|
if collection_get_actions.find { |a| a == :new }
|
61
|
-
buttons["
|
62
|
+
buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
|
62
63
|
end
|
63
64
|
|
64
65
|
(collection_get_actions - crud_actions).each do |action|
|
65
|
-
buttons[action
|
66
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
@@ -73,37 +74,35 @@ module Effective
|
|
73
74
|
{}.tap do |actions|
|
74
75
|
member_get_actions.reverse_each do |action|
|
75
76
|
next unless crud_actions.include?(action)
|
76
|
-
actions[action
|
77
|
+
actions[human_action_name(action)] = { action: action, default: true }
|
77
78
|
end
|
78
79
|
|
79
80
|
member_get_actions.each do |action|
|
80
81
|
next if crud_actions.include?(action)
|
81
|
-
actions[action
|
82
|
+
actions[human_action_name(action)] = { action: action, default: true }
|
82
83
|
end
|
83
84
|
|
84
85
|
member_post_actions.each do |action|
|
85
86
|
next if crud_actions.include?(action)
|
86
87
|
|
87
|
-
|
88
|
+
name = human_action_name(action)
|
89
|
+
confirm = human_action_confirm(action)
|
88
90
|
|
89
|
-
actions[
|
91
|
+
actions[name] = case action
|
90
92
|
when :archive
|
91
|
-
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' =>
|
93
|
+
{ action: action, default: true, if: -> { !resource.archived? }, class: 'btn btn-danger', 'data-method' => :post, 'data-confirm' => confirm }
|
92
94
|
when :unarchive
|
93
|
-
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' =>
|
95
|
+
{ action: action, default: true, if: -> { resource.archived? }, 'data-method' => :post, 'data-confirm' => confirm }
|
94
96
|
else
|
95
|
-
{ action: action, default: true, 'data-method' => :post, 'data-confirm' =>
|
97
|
+
{ action: action, default: true, 'data-method' => :post, 'data-confirm' => confirm }
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
101
|
member_delete_actions.each do |action|
|
100
|
-
|
102
|
+
name = human_action_name(action)
|
103
|
+
confirm = human_action_confirm(action)
|
101
104
|
|
102
|
-
|
103
|
-
actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
|
104
|
-
else
|
105
|
-
actions[action_name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action_name} @resource?" }
|
106
|
-
end
|
105
|
+
actions[name] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => confirm }
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
@@ -111,26 +110,29 @@ module Effective
|
|
111
110
|
# Used by datatables
|
112
111
|
def fallback_resource_actions
|
113
112
|
{
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
human_action_name(:show) => { action: :show, default: true },
|
114
|
+
human_action_name(:edit) => { action: :edit, default: true },
|
115
|
+
human_action_name(:destroy) => { action: :destroy, default: true, 'data-method' => :delete, 'data-confirm' => human_action_confirm(:destroy) }
|
117
116
|
}
|
118
117
|
end
|
119
118
|
|
120
119
|
# This is the fallback for render_resource_actions when no actions are specified, but a class is given
|
121
120
|
# Used by Datatables new
|
122
121
|
def resource_klass_actions
|
122
|
+
human_index = EffectiveResources.et("effective_resources.actions.index")
|
123
|
+
human_new = EffectiveResources.et("effective_resources.actions.new")
|
124
|
+
|
123
125
|
{}.tap do |buttons|
|
124
126
|
if collection_get_actions.find { |a| a == :index }
|
125
|
-
buttons["
|
127
|
+
buttons["#{human_index} #{human_plural_name}"] = { action: :index, default: true }
|
126
128
|
end
|
127
129
|
|
128
130
|
if collection_get_actions.find { |a| a == :new }
|
129
|
-
buttons["
|
131
|
+
buttons["#{human_new} #{human_name}"] = { action: :new, default: true }
|
130
132
|
end
|
131
133
|
|
132
134
|
(collection_get_actions - crud_actions).each do |action|
|
133
|
-
buttons[action
|
135
|
+
buttons[human_action_name(action)] = { action: action, default: true }
|
134
136
|
end
|
135
137
|
end
|
136
138
|
end
|
@@ -4,6 +4,29 @@ module Effective
|
|
4
4
|
module Resources
|
5
5
|
module I18n
|
6
6
|
|
7
|
+
def human_action_name(action)
|
8
|
+
if klass.respond_to?(:model_name)
|
9
|
+
value = ::I18n.t("activerecord.actions.#{klass.model_name.i18n_key}.#{action}")
|
10
|
+
return value unless value.start_with?('translation missing:')
|
11
|
+
end
|
12
|
+
|
13
|
+
if(crud_actions.include?(action))
|
14
|
+
# Raises exception if not present
|
15
|
+
return EffectiveResources.et("effective_resources.actions.#{action}")
|
16
|
+
end
|
17
|
+
|
18
|
+
action.to_s.titleize
|
19
|
+
end
|
20
|
+
|
21
|
+
def human_action_confirm(action)
|
22
|
+
if klass.respond_to?(:model_name)
|
23
|
+
value = ::I18n.t("activerecord.actions.#{klass.model_name.i18n_key}.#{action}_confirm")
|
24
|
+
return value unless value.start_with?('translation missing:')
|
25
|
+
end
|
26
|
+
|
27
|
+
"Really #{human_action_name(action)} @resource?"
|
28
|
+
end
|
29
|
+
|
7
30
|
def human_name
|
8
31
|
if klass.respond_to?(:model_name)
|
9
32
|
klass.model_name.human
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# An ActiveRecord validator for any radio buttons or select fields with true false
|
2
|
+
#
|
3
|
+
# validates :has_credits, boolean: true
|
4
|
+
|
5
|
+
class BooleanValidator < ActiveModel::EachValidator
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
if value.nil?
|
8
|
+
record.errors.add(attribute, "can't be blank")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
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: 2.
|
4
|
+
version: 2.5.1
|
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: 2023-03-
|
11
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -212,12 +212,14 @@ files:
|
|
212
212
|
- app/views/effective/resource/_actions_glyphicons.html.haml
|
213
213
|
- app/views/layouts/effective_mailer_layout.html.haml
|
214
214
|
- config/effective_resources.rb
|
215
|
+
- config/locales/effective_resources.en.yml
|
215
216
|
- config/routes.rb
|
216
217
|
- lib/effective_resources.rb
|
217
218
|
- lib/effective_resources/effective_gem.rb
|
218
219
|
- lib/effective_resources/engine.rb
|
219
220
|
- lib/effective_resources/version.rb
|
220
221
|
- lib/generators/effective_resources/install_generator.rb
|
222
|
+
- lib/validators/boolean_validator.rb
|
221
223
|
- lib/validators/email_cc_validator.rb
|
222
224
|
- lib/validators/email_validator.rb
|
223
225
|
- lib/validators/url_validator.rb
|