effective_resources 0.7.3 → 0.7.4
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 +28 -8
- data/app/helpers/effective_bootstrap3_helper.rb +1 -1
- data/app/helpers/effective_resources_helper.rb +15 -0
- data/app/views/application/edit.html.haml +1 -1
- data/app/views/application/new.html.haml +6 -3
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93a12b8c4e3ed0c19944e519a9744e2147df4dfd
|
4
|
+
data.tar.gz: ab6a80d74be88e195c5b456ec60d02637de9ddad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a9c3623d279ac5901cab849f8c67f8e980f70eba46f48d0259eb3fa7e8a80120f5c37b293ed64b75662f95601e70a30c341118b7746577444b7d3a98260d8a
|
7
|
+
data.tar.gz: 9b9a58a7686fab92936570e9add5116fcb45357ebfe829cbe0b306c5209aa64cff2c9e8e1f435a89dd8eccbdae1f2ec03da7412eeb2ede69aaa931f03051bd69
|
@@ -5,7 +5,11 @@ module Effective
|
|
5
5
|
included do
|
6
6
|
class << self
|
7
7
|
def member_actions
|
8
|
-
@_effective_member_actions ||= {
|
8
|
+
@_effective_member_actions ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def _default_member_actions
|
12
|
+
{
|
9
13
|
'Save' => { action: :save, data: { disable_with: 'Saving...' }},
|
10
14
|
'Continue' => { action: :save, data: { disable_with: 'Saving...' }},
|
11
15
|
'Add New' => { action: :save, data: { disable_with: 'Saving...' }}
|
@@ -95,6 +99,11 @@ module Effective
|
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
102
|
+
# Applies the default actions
|
103
|
+
def default_actions(args = {})
|
104
|
+
default_member_actions.each { |k, v| member_actions[k] = (args || {}).merge(v) }
|
105
|
+
end
|
106
|
+
|
98
107
|
# page_title 'My Title', only: [:new]
|
99
108
|
def page_title(label = nil, opts = {}, &block)
|
100
109
|
raise 'expected a label or block' unless (label || block_given?)
|
@@ -279,21 +288,32 @@ module Effective
|
|
279
288
|
render json: { status: 200, message: "Successfully #{action_verb(action)} #{successes} / #{resources.length} selected #{resource_plural_name}" }
|
280
289
|
end
|
281
290
|
|
291
|
+
|
292
|
+
|
293
|
+
# The block must implement a comparison between a and b and return an integer
|
294
|
+
# less than 0 when b follows a, 0 when a and b are equivalent, or an integer greater than 0 when a follows b.
|
295
|
+
|
282
296
|
# Here we look at all available (class level) member actions, see which ones apply to the current resource
|
283
297
|
# This feeds into the helper simple_form_submit(f)
|
284
298
|
# Returns a Hash of {'Save': {data-disable-with: 'Saving...'}, 'Approve': {data-disable-with: 'Approve'}}
|
285
299
|
def member_actions_for(obj)
|
286
|
-
self.class.member_actions.
|
300
|
+
actions = (self.class.member_actions.presence || self.class._default_member_actions)
|
301
|
+
|
302
|
+
actions.select do |commit, args|
|
303
|
+
args[:class] = args[:class].to_s
|
304
|
+
|
287
305
|
(args.key?(:if) ? obj.instance_exec(&args[:if]) : true) &&
|
288
306
|
(args.key?(:unless) ? !obj.instance_exec(&args[:unless]) : true)
|
289
307
|
end.sort do |(commit_x, x), (commit_y, y)|
|
290
|
-
|
291
|
-
|
308
|
+
# Sort to front
|
309
|
+
primary = (y[:class].include?('primary') ? 1 : 0) - (x[:class].include?('primary') ? 1 : 0)
|
310
|
+
primary = nil if primary == 0
|
292
311
|
|
293
|
-
|
294
|
-
|
312
|
+
# Sort to back
|
313
|
+
danger = (x[:class].include?('danger') ? 1 : 0) - (y[:class].include?('danger') ? 1 : 0)
|
314
|
+
danger = nil if danger == 0
|
295
315
|
|
296
|
-
|
316
|
+
primary || danger || actions.keys.index(commit_x) <=> actions.keys.index(commit_y)
|
297
317
|
end.inject({}) do |h, (commit, args)|
|
298
318
|
h[commit] = args.except(:action, :if, :unless, :redirect); h
|
299
319
|
end
|
@@ -422,7 +442,7 @@ module Effective
|
|
422
442
|
end
|
423
443
|
|
424
444
|
def commit_action
|
425
|
-
self.class.member_actions[params[:commit].to_s] ||
|
445
|
+
self.class.member_actions[params[:commit].to_s] || { action: :save }
|
426
446
|
end
|
427
447
|
|
428
448
|
# Returns an ActiveRecord relation based on the computed value of `resource_scope` dsl method
|
@@ -52,7 +52,7 @@ module EffectiveBootstrap3Helper
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def tab(label, &block)
|
55
|
-
controls = label.to_s.
|
55
|
+
controls = label.to_s.parameterize.gsub('_', '-')
|
56
56
|
active = (@_tab_active == :first || @_tab_active == label)
|
57
57
|
|
58
58
|
@_tab_active = nil if @_tab_active == :first
|
@@ -58,6 +58,21 @@ module EffectiveResourcesHelper
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
# When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
|
62
|
+
def render_resource_form(resource)
|
63
|
+
atts = {:namespace => (resource.namespace.to_sym if resource.namespace.present?), resource.name.to_sym => instance_variable_get('@' + resource.name)}.compact
|
64
|
+
|
65
|
+
if lookup_context.template_exists?('form', controller._prefixes, :partial)
|
66
|
+
render 'form', atts
|
67
|
+
elsif lookup_context.template_exists?('form', resource.plural_name, :partial)
|
68
|
+
render "#{resource.plural_name}/form", atts
|
69
|
+
elsif lookup_context.template_exists?('form', resource.name, :partial)
|
70
|
+
render "#{resource.name}/form", atts
|
71
|
+
else
|
72
|
+
render 'form', atts # Will raise the regular error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
61
76
|
def number_to_duration(duration)
|
62
77
|
duration = duration.to_i
|
63
78
|
value = duration.abs
|
@@ -13,4 +13,4 @@
|
|
13
13
|
- if EffectiveResources.authorized?(controller, :destroy, @resource) && (path = resource.action_path(:destroy, @resource)).present?
|
14
14
|
= link_to 'Delete', path, class: 'btn btn-sm btn-danger', data: { confirm: "Really delete #{@resource}?", method: :delete }
|
15
15
|
|
16
|
-
=
|
16
|
+
= render_resource_form(resource)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
2
|
+
- @resource = instance_variable_get('@' + resource.name) if resource.name
|
2
3
|
|
3
|
-
|
4
|
+
- if @resource
|
5
|
+
.row
|
6
|
+
.col-xs-8
|
7
|
+
%h1= @page_title
|
4
8
|
|
5
|
-
|
6
|
-
= render 'form', resource.name.to_sym => instance_variable_get('@' + resource.name)
|
9
|
+
= render_resource_form(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.7.
|
4
|
+
version: 0.7.4
|
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: 2017-12-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|