effective_resources 0.8.12 → 0.8.13
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/effective/crud_controller.rb +15 -14
- data/app/helpers/effective_resources_helper.rb +6 -1
- data/app/models/concerns/acts_as_tokened.rb +1 -1
- data/app/models/effective/resources/forms.rb +1 -1
- data/app/views/application/create.js.erb +1 -1
- data/app/views/application/destroy.js.erb +1 -1
- data/app/views/application/member_action.js.erb +5 -0
- data/app/views/application/update.js.erb +1 -1
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e0b794db680cc5d1128cec78d437057338870c
|
4
|
+
data.tar.gz: b5ce5e70f5abb3c49dd771ab6745fc859610e82a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e25d29b786c84a6337c1a655d90719dfecdeb4a824db2d37d2815cb9a6c485df6a5c7fe7e53da9cfc509c0f3d0d5e9e959bff939ee38f5f197dfe7c468f33bd
|
7
|
+
data.tar.gz: 41a58b98945b99b7725f45b7c7b7f4ff5de90f2c3cb1e659f1f031cf2e6d0ea05a4648fdf418360da6105a5b29fb43afff8ae40286ae95f3f8ffcb103244b418
|
@@ -199,11 +199,10 @@ module Effective
|
|
199
199
|
EffectiveResources.authorize!(self, action, resource) unless action == :save
|
200
200
|
EffectiveResources.authorize!(self, :create, resource) if action == :save
|
201
201
|
|
202
|
-
resource.assign_attributes(send(resource_params_method_name))
|
203
202
|
resource.created_by ||= current_user if resource.respond_to?(:created_by=)
|
204
203
|
|
205
204
|
respond_to do |format|
|
206
|
-
if save_resource(resource, action)
|
205
|
+
if save_resource(resource, action, send(resource_params_method_name))
|
207
206
|
format.html do
|
208
207
|
flash[:success] ||= resource_flash(:success, resource, action)
|
209
208
|
redirect_to(resource_redirect_path)
|
@@ -256,10 +255,8 @@ module Effective
|
|
256
255
|
EffectiveResources.authorize!(self, action, resource) unless action == :save
|
257
256
|
EffectiveResources.authorize!(self, :update, resource) if action == :save
|
258
257
|
|
259
|
-
resource.assign_attributes(send(resource_params_method_name))
|
260
|
-
|
261
258
|
respond_to do |format|
|
262
|
-
if save_resource(resource, action)
|
259
|
+
if save_resource(resource, action, send(resource_params_method_name))
|
263
260
|
format.html do
|
264
261
|
flash[:success] ||= resource_flash(:success, resource, action)
|
265
262
|
redirect_to(resource_redirect_path)
|
@@ -305,7 +302,7 @@ module Effective
|
|
305
302
|
redirect_to(resource_redirect_path)
|
306
303
|
else
|
307
304
|
flash.now[:success] ||= resource_flash(:success, resource, action)
|
308
|
-
#
|
305
|
+
# destroy.js.erb
|
309
306
|
end
|
310
307
|
end
|
311
308
|
else
|
@@ -327,12 +324,8 @@ module Effective
|
|
327
324
|
def member_post_action(action)
|
328
325
|
raise 'expected post, patch or put http action' unless (request.post? || request.patch? || request.put?)
|
329
326
|
|
330
|
-
# TODO: This is a recent change. Used to not assign attributes. Is this breaking?
|
331
|
-
valid_params = (send(resource_params_method_name) rescue {})
|
332
|
-
resource.assign_attributes(valid_params)
|
333
|
-
|
334
327
|
respond_to do |format|
|
335
|
-
if save_resource(resource, action)
|
328
|
+
if save_resource(resource, action, (send(resource_params_method_name) rescue {}))
|
336
329
|
format.html do
|
337
330
|
flash[:success] ||= resource_flash(:success, resource, action)
|
338
331
|
redirect_to(resource_redirect_path)
|
@@ -345,7 +338,7 @@ module Effective
|
|
345
338
|
else
|
346
339
|
flash.now[:success] ||= resource_flash(:success, resource, action)
|
347
340
|
reload_resource
|
348
|
-
|
341
|
+
render_member_action(action)
|
349
342
|
end
|
350
343
|
end
|
351
344
|
else
|
@@ -369,11 +362,17 @@ module Effective
|
|
369
362
|
end
|
370
363
|
end
|
371
364
|
|
372
|
-
format.js {
|
365
|
+
format.js { render_member_action(action) }
|
373
366
|
end
|
374
367
|
end
|
375
368
|
end
|
376
369
|
|
370
|
+
# Which member javascript view to render: #{action}.js or effective_resources member_action.js
|
371
|
+
def render_member_action(action)
|
372
|
+
view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
|
373
|
+
render(view, locals: { action: action })
|
374
|
+
end
|
375
|
+
|
377
376
|
# No attributes are assigned or saved. We purely call action! on the resource
|
378
377
|
def collection_post_action(action)
|
379
378
|
action = action.to_s.gsub('bulk_', '').to_sym
|
@@ -399,13 +398,15 @@ module Effective
|
|
399
398
|
protected
|
400
399
|
|
401
400
|
# This calls the appropriate member action, probably save!, on the resource.
|
402
|
-
def save_resource(resource, action = :save, &block)
|
401
|
+
def save_resource(resource, action = :save, to_assign = {}, &block)
|
403
402
|
raise "expected @#{resource_name} to respond to #{action}!" unless resource.respond_to?("#{action}!")
|
404
403
|
|
405
404
|
resource.current_user ||= current_user if resource.respond_to?(:current_user=)
|
406
405
|
|
407
406
|
ActiveRecord::Base.transaction do
|
408
407
|
begin
|
408
|
+
resource.assign_attributes(to_assign) if to_assign.present?
|
409
|
+
|
409
410
|
if resource.public_send("#{action}!") == false
|
410
411
|
raise("failed to #{action} #{resource}")
|
411
412
|
end
|
@@ -40,9 +40,14 @@ module EffectiveResourcesHelper
|
|
40
40
|
|
41
41
|
# When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
|
42
42
|
def render_resource_form(resource, atts = {})
|
43
|
+
raise 'expected attributes to be a Hash. Try passing action: action if rendering custom action' unless atts.kind_of?(Hash)
|
44
|
+
|
45
|
+
action = atts.delete(:action)
|
43
46
|
atts = {:namespace => (resource.namespace.to_sym if resource.namespace.present?), resource.name.to_sym => instance_variable_get('@' + resource.name)}.compact.merge(atts)
|
44
47
|
|
45
|
-
if lookup_context.template_exists?(
|
48
|
+
if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial)
|
49
|
+
render "form_#{action}", atts
|
50
|
+
elsif lookup_context.template_exists?('form', controller._prefixes, :partial)
|
46
51
|
render 'form', atts
|
47
52
|
elsif lookup_context.template_exists?('form', resource.plural_name, :partial)
|
48
53
|
render "#{resource.plural_name}/form", atts
|
@@ -28,7 +28,7 @@ module Effective
|
|
28
28
|
|
29
29
|
# Here we look at all available (class level) member actions, see which ones apply to the current resource
|
30
30
|
# This feeds into the helper simple_form_submit(f)
|
31
|
-
# Returns a Hash of {'Save': {
|
31
|
+
# Returns a Hash of {'Save': {class: 'btn btn-primary'}, 'Approve': {class: 'btn btn-secondary'}}
|
32
32
|
def submits_for(obj, controller:)
|
33
33
|
submits.select do |commit, args|
|
34
34
|
args[:class] = args[:class].to_s
|
@@ -1,5 +1,5 @@
|
|
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 =
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -1,5 +1,5 @@
|
|
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 =
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
|
2
|
+
<% @resource = instance_variable_get('@' + resource.name) if resource.name %>
|
3
|
+
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource, action: action) %>";
|
5
|
+
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
@@ -1,5 +1,5 @@
|
|
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 =
|
4
|
+
EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
|
5
5
|
EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
|
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.13
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- app/views/application/destroy.js.erb
|
60
60
|
- app/views/application/edit.html.haml
|
61
61
|
- app/views/application/index.html.haml
|
62
|
+
- app/views/application/member_action.js.erb
|
62
63
|
- app/views/application/new.html.haml
|
63
64
|
- app/views/application/show.html.haml
|
64
65
|
- app/views/application/update.js.erb
|