effective_resources 1.0.13 → 1.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 998ed6153bddd85970840b07e11a165512fcce3e
4
- data.tar.gz: 04d9581c21c2ff8499abf8bfc0995956b476eb96
3
+ metadata.gz: 7b28e265ce6c4288365663aa0bfc56adce448a02
4
+ data.tar.gz: 5ba116394c1a6a8d53c4f582a9a0118e99bfcbf8
5
5
  SHA512:
6
- metadata.gz: 484de341ce813ef6fe402dd59b33ad0a5e5c8d8dfab95fcccb1230359a60ad1a888ba75de70951138e5172087dc49f3a531af0742dd8ba19338f47ad6915f871
7
- data.tar.gz: 80059d4e5ce2b3fe4625ecfbfe6bda6cb6b4c5c924f37c2ba27861955cf6433f51d77dce5534814448cb940878a5b4af3994a3000340b6d133f6c515a45327d5
6
+ metadata.gz: 8bad6d3fb3a9d7c0c69babbeea1d9a53d25bd448772ad848b3361f2116a37044f3245634daa67e423c9eed4feb14e92e0c7815c0796c97363609c64acd3eb4cc
7
+ data.tar.gz: bafc5d5b585e8f1a9bfd02e7333313ad97f9cba5de1843e56aa59e76d58b850dca88f875dbb5ddf23435c2bc013394000bcdacec095f94b911ba21c376bf8f7f
@@ -101,8 +101,21 @@ module Effective
101
101
  resource_scope.where_values_hash.symbolize_keys
102
102
  end
103
103
 
104
- def resource_datatable_class
105
- effective_resource.datatable_klass
104
+ def resource_datatable(action)
105
+ datatable_klass = if action == :index
106
+ effective_resource.datatable_klass
107
+ else # Admin::ActionDatatable.new
108
+ "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.classify].compact.join('::')}Datatable".safe_constantize ||
109
+ "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.pluralize.classify].compact.join('::')}Datatable".safe_constantize ||
110
+ "#{[effective_resource.namespace.to_s.classify.presence, action.to_s.singularize.classify].compact.join('::')}Datatable".safe_constantize
111
+ end
112
+
113
+ return unless datatable_klass.present?
114
+
115
+ datatable = datatable_klass.new(resource_datatable_attributes)
116
+ datatable.view = view_context
117
+
118
+ datatable
106
119
  end
107
120
 
108
121
  def resource_params_method_name
@@ -9,11 +9,7 @@ module Effective
9
9
  @page_title ||= resource_plural_name.titleize
10
10
 
11
11
  self.resources ||= resource_scope.all
12
-
13
- if (datatable = resource_datatable_class).present?
14
- @datatable ||= datatable.new(resource_datatable_attributes)
15
- @datatable.view = view_context
16
- end
12
+ @datatable = resource_datatable(:index)
17
13
 
18
14
  run_callbacks(:resource_render)
19
15
  end
@@ -195,7 +191,12 @@ module Effective
195
191
  @page_title ||= "#{action.to_s.titleize} #{resource_plural_name.titleize}"
196
192
 
197
193
  if request.get?
198
- run_callbacks(:resource_render); return
194
+ @datatable = resource_datatable(action)
195
+ run_callbacks(:resource_render)
196
+
197
+ view = lookup_context.template_exists?(action, _prefixes) ? action : :index
198
+ render(view, locals: { action: action })
199
+ return
199
200
  end
200
201
 
201
202
  raise "expected all #{resource_name} objects to respond to #{action}!" if resources.to_a.present? && !resources.all? { |resource| resource.respond_to?("#{action}!") }
@@ -15,13 +15,13 @@ module Effective
15
15
  elsif lookup_context.template_exists?(action, _prefixes)
16
16
  format.html do
17
17
  flash.now[:success] ||= resource_flash(:success, resource, action)
18
- # action.html.haml
18
+ render(action) # action.html.haml
19
19
  end
20
20
 
21
21
  format.js do
22
22
  flash.now[:success] ||= resource_flash(:success, resource, action)
23
- reload_resource
24
- # action.js.erb
23
+ reload_resource unless action == :destroy
24
+ render(action) # action.js.erb
25
25
  end
26
26
  else # Default
27
27
  format.html do
@@ -42,18 +42,16 @@ module Effective
42
42
 
43
43
  run_callbacks(:resource_render)
44
44
 
45
- case params[:action]
46
- when 'create'
45
+ # HTML responder
46
+ case action.to_sym
47
+ when :create
47
48
  format.html { render :new }
48
- when 'update'
49
+ when :update
49
50
  format.html { render :edit }
50
- when 'destroy'
51
- # We always need to redirect here
51
+ when :destroy
52
52
  flash[:danger] = flash.now.delete(:danger)
53
-
54
53
  format.html { redirect_to(resource_redirect_path(action)) }
55
- format.js { redirect_to(resource_redirect_path(action)) }
56
- else # member_action
54
+ else # member action
57
55
  format.html do
58
56
  if lookup_context.template_exists?(action, _prefixes)
59
57
  @page_title ||= "#{action.to_s.titleize} #{resource}"
@@ -75,24 +73,16 @@ module Effective
75
73
  end
76
74
  end
77
75
 
78
- format.js do
79
- view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
80
- render(view, locals: { action: action })
81
- end
82
- end
83
-
84
- # For destroy.js
85
- def respond_with_error_and_redirect(format, resource, action)
86
- flash.delete(:success)
87
- flash[:danger] ||= resource_flash(:danger, resource, action)
88
-
89
- format.html do
90
- redirect_to(resource_redirect_path(action))
76
+ # Javascript responder
77
+ if action.to_sym == :destroy
78
+ format.js { redirect_to(resource_redirect_path(action)) }
79
+ else
80
+ format.js do
81
+ view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
82
+ render(view, locals: { action: action }) #
83
+ end
91
84
  end
92
85
 
93
- format.js do
94
- redirect_to(resource_redirect_path(action))
95
- end
96
86
  end
97
87
 
98
88
  end
@@ -3,6 +3,7 @@ module EffectiveResourcesHelper
3
3
  # effective_bootstrap
4
4
  def effective_submit(form, options = {}, &block)
5
5
  actions = (controller.respond_to?(:effective_resource) ? controller.class : find_effective_resource).submits
6
+ actions = actions.select { |k, v| v[:default] != true } if options.delete(:defaults) == false
6
7
  actions = permitted_resource_actions(form.object, actions)
7
8
 
8
9
  submits = actions.map { |name, opts| form.save(name, opts.except(:action, :title, 'data-method', 'data-confirm')) }.join.html_safe
@@ -4,7 +4,7 @@
4
4
  .col-8
5
5
  %h1= @page_title
6
6
  .col-4.text-right
7
- = render_resource_actions(resource.klass, index: false)
7
+ = render_resource_buttons(resource.klass, (action ||= :index) => false)
8
8
 
9
9
  - if @datatable
10
10
  = render_datatable(@datatable)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.0.13'.freeze
2
+ VERSION = '1.0.14'.freeze
3
3
  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: 1.0.13
4
+ version: 1.0.14
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-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails