effective_resources 1.4.8 → 1.4.13
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/actions.rb +6 -1
- data/app/controllers/concerns/effective/crud_controller/respond.rb +0 -48
- data/app/controllers/concerns/effective/crud_controller/save.rb +3 -1
- data/app/helpers/effective_resources_helper.rb +24 -0
- data/app/models/concerns/acts_as_archived.rb +1 -1
- data/app/models/concerns/acts_as_slugged.rb +1 -1
- data/app/models/concerns/acts_as_statused.rb +2 -2
- data/app/models/concerns/acts_as_tokened.rb +1 -1
- data/app/models/concerns/effective_resource.rb +1 -1
- data/app/models/validators/email_cc_validator.rb +15 -0
- data/app/views/application/show.html.haml +1 -1
- data/app/views/application/show.js.erb +1 -1
- data/lib/effective_resources/engine.rb +5 -5
- data/lib/effective_resources/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26fb7f4bb20f9558578037580acce364d1069fdb99210ef0e2b533874a9f9d6a
|
4
|
+
data.tar.gz: 98d7be06b5bae25e286eebf1e48607ccf4e235eade22ecbd2c622e24c5f09301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0484e04a8f4159a40af9c25d4ecac702f5c37c6ddd6323817a2cedb2840604feb7276791382518ff7a79e87a1b3934e539a5a60956d336ec35039767f13993
|
7
|
+
data.tar.gz: 67c2b83cce754e80b998241cc463d1c7b8b93049a53169dd4ab92d7c6acdc99043d922f9912b0df206b063fcf727ef479f40c9fbedaf0c58ee5788a7f517cb4e
|
@@ -63,9 +63,11 @@ module Effective
|
|
63
63
|
self.resource ||= resource_scope.new
|
64
64
|
action = (commit_action[:action] == :save ? :create : commit_action[:action])
|
65
65
|
|
66
|
-
resource.
|
66
|
+
resource.current_user ||= current_user if resource.respond_to?(:current_user=)
|
67
67
|
resource.created_by ||= current_user if resource.respond_to?(:created_by=)
|
68
68
|
|
69
|
+
resource.assign_attributes(send(resource_params_method_name))
|
70
|
+
|
69
71
|
EffectiveResources.authorize!(self, action, resource)
|
70
72
|
@page_title ||= "New #{resource_name.titleize}"
|
71
73
|
|
@@ -119,6 +121,9 @@ module Effective
|
|
119
121
|
EffectiveResources.authorize!(self, action, resource)
|
120
122
|
@page_title ||= "Edit #{resource}"
|
121
123
|
|
124
|
+
resource.current_user ||= current_user if resource.respond_to?(:current_user=)
|
125
|
+
resource.updated_by ||= current_user if resource.respond_to?(:updated_by=)
|
126
|
+
|
122
127
|
resource.assign_attributes(send(resource_params_method_name))
|
123
128
|
|
124
129
|
if save_resource(resource, action)
|
@@ -79,54 +79,6 @@ module Effective
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
# def respond_with_error(resource, action)
|
83
|
-
# return if response.body.present?
|
84
|
-
|
85
|
-
# flash.delete(:success)
|
86
|
-
# flash.now[:danger] ||= resource_flash(:danger, resource, action)
|
87
|
-
|
88
|
-
# respond_to do |format|
|
89
|
-
# case action.to_sym
|
90
|
-
# when :create
|
91
|
-
# format.html { render :new }
|
92
|
-
# when :update
|
93
|
-
# format.html { render :edit }
|
94
|
-
# when :destroy
|
95
|
-
# format.html do
|
96
|
-
# redirect_flash
|
97
|
-
# redirect_to(resource_redirect_path(action))
|
98
|
-
# end
|
99
|
-
# else # member action
|
100
|
-
# from_path = referer_redirect_path.to_s
|
101
|
-
|
102
|
-
# format.html do
|
103
|
-
# if resource_edit_path && from_path.end_with?(resource_edit_path)
|
104
|
-
# @page_title ||= "Edit #{resource}"
|
105
|
-
# render :edit
|
106
|
-
# elsif resource_new_path && from_path.end_with?(resource_new_path)
|
107
|
-
# @page_title ||= "New #{resource_name.titleize}"
|
108
|
-
# render :new
|
109
|
-
# elsif resource_action_path(action) && from_path.end_with?(resource_action_path(action)) && template_present?(action)
|
110
|
-
# @page_title ||= "#{action.to_s.titleize} #{resource}"
|
111
|
-
# render(action, locals: { action: action })
|
112
|
-
# elsif resource_show_path && from_path.end_with?(resource_show_path)
|
113
|
-
# @page_title ||= resource_name.titleize
|
114
|
-
# render :show
|
115
|
-
# else
|
116
|
-
# @page_title ||= resource.to_s
|
117
|
-
# redirect_flash
|
118
|
-
# redirect_to(from_path.presence || resource_redirect_path(action))
|
119
|
-
# end
|
120
|
-
# end
|
121
|
-
# end
|
122
|
-
|
123
|
-
# format.js do
|
124
|
-
# view = template_present?(action) ? action : :member_action
|
125
|
-
# render(view, locals: { action: action }) # action.js.erb
|
126
|
-
# end
|
127
|
-
# end
|
128
|
-
# end
|
129
|
-
|
130
82
|
private
|
131
83
|
|
132
84
|
def redirect_flash
|
@@ -4,7 +4,9 @@ module Effective
|
|
4
4
|
|
5
5
|
# Based on the incoming params[:commit] or passed action. Merges all options.
|
6
6
|
def commit_action(action = nil)
|
7
|
-
config = (['create', 'update'].include?(params[:action]) ? self.class.submits : self.class.buttons)
|
7
|
+
#config = (['create', 'update'].include?(params[:action]) ? self.class.submits : self.class.buttons)
|
8
|
+
|
9
|
+
config = self.class.submits
|
8
10
|
ons = self.class.ons
|
9
11
|
|
10
12
|
commit = config[params[:commit].to_s]
|
@@ -146,6 +146,30 @@ module EffectiveResourcesHelper
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
+
# Similar to render_resource_form
|
150
|
+
def render_resource_partial(resource, atts = {})
|
151
|
+
unless resource.kind_of?(ActiveRecord::Base) || resource.class.ancestors.include?(ActiveModel::Model)
|
152
|
+
raise 'expected first argument to be an ActiveRecord or ActiveModel object'
|
153
|
+
end
|
154
|
+
|
155
|
+
raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
|
156
|
+
|
157
|
+
effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
|
158
|
+
|
159
|
+
action = atts.delete(:action)
|
160
|
+
atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts)
|
161
|
+
|
162
|
+
if lookup_context.template_exists?(effective_resource.name, controller._prefixes, :partial)
|
163
|
+
render(effective_resource.name, atts)
|
164
|
+
elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.plural_name], :partial)
|
165
|
+
render(effective_resource.plural_name + '/' + effective_resource.name, atts)
|
166
|
+
elsif lookup_context.template_exists?(effective_resource.name, [effective_resource.name], :partial)
|
167
|
+
render(effective_resource.name + '/' + effective_resource.name, atts)
|
168
|
+
else
|
169
|
+
render(resource, atts) # Will raise the regular error
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
149
173
|
# Tableize attributes
|
150
174
|
# This is used by effective_orders, effective_logging, effective_trash and effective_mergery
|
151
175
|
def tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true)
|
@@ -8,8 +8,8 @@
|
|
8
8
|
module ActsAsStatused
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
-
module
|
12
|
-
#
|
11
|
+
module Base
|
12
|
+
# acts_as_statused :pending, :approved, :declined, option_key: :option_value
|
13
13
|
def acts_as_statused(*args)
|
14
14
|
options = args.extract_options!
|
15
15
|
statuses = Array(args).compact
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# An ActiveRecord validator for any email field that you would use with effective_email or otherwise
|
2
|
+
#
|
3
|
+
# validates :cc, email_cc: true
|
4
|
+
|
5
|
+
class EmailCcValidator < ActiveModel::EachValidator
|
6
|
+
PATTERN = /\A.+@.+\..+\Z/
|
7
|
+
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
if value.present?
|
10
|
+
unless value.to_s.split(',').all? { |email| PATTERN =~ email }
|
11
|
+
record.errors.add(attribute, 'is invalid')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
|
2
2
|
<% @resource = instance_variable_get('@' + resource.name) if resource.name %>
|
3
3
|
|
4
|
-
EffectiveForm.remote_form_payload = "<%= j
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_partial(@resource) %>";
|
5
5
|
EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
|
6
6
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -17,11 +17,11 @@ module EffectiveResources
|
|
17
17
|
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
18
18
|
initializer 'effective_resources.active_record' do |app|
|
19
19
|
ActiveSupport.on_load :active_record do
|
20
|
-
ActiveRecord::Base.extend(ActsAsArchived::
|
21
|
-
ActiveRecord::Base.extend(ActsAsTokened::
|
22
|
-
ActiveRecord::Base.extend(ActsAsSlugged::
|
23
|
-
ActiveRecord::Base.extend(ActsAsStatused::
|
24
|
-
ActiveRecord::Base.extend(EffectiveResource::
|
20
|
+
ActiveRecord::Base.extend(ActsAsArchived::Base)
|
21
|
+
ActiveRecord::Base.extend(ActsAsTokened::Base)
|
22
|
+
ActiveRecord::Base.extend(ActsAsSlugged::Base)
|
23
|
+
ActiveRecord::Base.extend(ActsAsStatused::Base)
|
24
|
+
ActiveRecord::Base.extend(EffectiveResource::Base)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
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.4.
|
4
|
+
version: 1.4.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- app/models/effective/resources/paths.rb
|
72
72
|
- app/models/effective/resources/relation.rb
|
73
73
|
- app/models/effective/resources/sql.rb
|
74
|
+
- app/models/validators/email_cc_validator.rb
|
74
75
|
- app/models/validators/email_validator.rb
|
75
76
|
- app/models/validators/url_validator.rb
|
76
77
|
- app/views/application/_flash.html.haml
|
@@ -97,7 +98,7 @@ homepage: https://github.com/code-and-effect/effective_resources
|
|
97
98
|
licenses:
|
98
99
|
- MIT
|
99
100
|
metadata: {}
|
100
|
-
post_install_message:
|
101
|
+
post_install_message:
|
101
102
|
rdoc_options: []
|
102
103
|
require_paths:
|
103
104
|
- lib
|
@@ -112,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
113
|
- !ruby/object:Gem::Version
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
116
|
+
rubygems_version: 3.1.2
|
117
|
+
signing_key:
|
117
118
|
specification_version: 4
|
118
119
|
summary: Make any controller an effective resource controller.
|
119
120
|
test_files: []
|