effective_resources 0.10.1 → 1.0.0

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: 297715acf66f40c204bce59ebb58873f0499afaa
4
- data.tar.gz: b9a0766cc92594a8f6f0cae06bfecd6aefdb24b5
3
+ metadata.gz: 3ef79c2ff4b11e7b6fc7c81007b82f1ecb0fa8a0
4
+ data.tar.gz: 98158d2296aac5e0290d515a1bf82e3a4ace8138
5
5
  SHA512:
6
- metadata.gz: baa1604c9325e9b8f0259ad4657dd209bc89e9a1dc9dfccdf106a1030f066d77a043896da6c430b19971c15d005bfba401d591c48b4f3057b552c9b83c7ae3d5
7
- data.tar.gz: 68077fb078d34ad68d0a5122bcdc56fcddf567969d7a0bb432e8ac95cca6fde7aa56bd70f882c99456ddbe5e70106c9837e417fd0f1797f10ac5504efccce4b4
6
+ metadata.gz: 1d49fb28d6eafa486291070b6e3aca1c2f8381f02598d5ef9d0a33f1bf449e701a8f8ecf6e76ae82bf463fc1b002f4e84e8d540eef1f64db2365ecbecffe91ed
7
+ data.tar.gz: fdb49fb1b934cbf11428eaab0ee6906e813fa782f0b6dee6bfb936705b7edfa24a05d7f211b6370f67d0585a7e08b984c7d3e97c3f5538d6f297566ede2dc845
@@ -44,6 +44,11 @@ module Effective
44
44
  @page_title ||= "New #{resource_name.titleize}"
45
45
 
46
46
  run_callbacks(:resource_render)
47
+
48
+ respond_to do |format|
49
+ format.html { }
50
+ format.js { render('new.js') }
51
+ end
47
52
  end
48
53
 
49
54
  def create
@@ -63,17 +68,17 @@ module Effective
63
68
  request.format = :html if specific_redirect_path?
64
69
 
65
70
  format.html do
66
- flash[:success] ||= resource_flash(:success, resource, action)
71
+ flash[:success] ||= resource_flash(:success, resource, (action == :save ? :create : action))
67
72
  redirect_to(resource_redirect_path)
68
73
  end
69
74
 
70
75
  format.js do
71
- flash.now[:success] ||= resource_flash(:success, resource, action)
76
+ flash.now[:success] ||= resource_flash(:success, resource, (action == :save ? :create : action))
72
77
  reload_resource # create.js.erb
73
78
  end
74
79
  else
75
80
  flash.delete(:success)
76
- flash.now[:danger] ||= resource_flash(:danger, resource, action)
81
+ flash.now[:danger] ||= resource_flash(:danger, resource, (action == :save ? :create : action))
77
82
 
78
83
  run_callbacks(:resource_render)
79
84
 
@@ -103,6 +108,12 @@ module Effective
103
108
  @page_title ||= "Edit #{resource}"
104
109
 
105
110
  run_callbacks(:resource_render)
111
+
112
+ respond_to do |format|
113
+ format.html { }
114
+ format.js { render('edit.js') }
115
+ end
116
+
106
117
  end
107
118
 
108
119
  def update
@@ -145,6 +156,10 @@ module Effective
145
156
  def destroy
146
157
  Rails.logger.info 'Processed by Effective::CrudController#destroy'
147
158
 
159
+ if params[:ids].present?
160
+ return collection_action(:destroy)
161
+ end
162
+
148
163
  self.resource = resource_scope.find(params[:id])
149
164
  action = :destroy
150
165
 
@@ -65,11 +65,13 @@ module EffectiveResourcesHelper
65
65
  spacer_template = locals.delete(:spacer_template)
66
66
 
67
67
  effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
68
- actions = atts.delete(:actions) || effective_resource.resource_actions
69
68
  namespace = atts.delete(:namespace) || (effective_resource.namespace.to_sym if effective_resource.namespace)
70
69
 
70
+ actions = atts.delete(:actions)
71
+ actions ||= (resource.kind_of?(Class) ? effective_resource.resource_klass_actions : effective_resource.resource_actions)
72
+
71
73
  # Filter Actions
72
- action_keys = actions.map { |_, v| v[:action] }
74
+ action_keys = effective_resource.actions #actions.map { |_, v| v[:action] }
73
75
  raise "unknown action for #{effective_resource.name}: #{(atts.keys - action_keys).join(' ')}." if (atts.keys - action_keys).present?
74
76
  actions = actions.select { |_, v| atts[v[:action]].respond_to?(:call) ? instance_exec(&atts[v[:action]]) : (atts[v[:action]] != false) }
75
77
 
@@ -22,18 +22,9 @@ module EffectiveResourcesPrivateHelper
22
22
  data.each { |k, v| opts["data-#{k}"] ||= v }
23
23
  end
24
24
 
25
- # Assign data method and confirm
26
- if effective_resource.member_post_actions.include?(action)
27
- opts['data-method'] ||= :post
28
- opts['data-confirm'] ||= "Really #{action} @resource?"
29
- elsif effective_resource.member_delete_actions.include?(action)
30
- opts['data-method'] ||= :delete
31
- opts['data-confirm'] ||= "Really #{action == :destroy ? 'delete' : action.to_s.titleize} @resource?"
32
- end
33
-
34
25
  # Assign class
35
26
  opts[:class] ||= (
36
- if opts['data-method'] == :delete
27
+ if opts['data-method'].to_s == 'delete'
37
28
  'btn btn-danger'
38
29
  elsif index == 0
39
30
  'btn btn-primary'
@@ -44,15 +44,15 @@ module Effective
44
44
  def belongs_to(name)
45
45
  if name.kind_of?(String) || name.kind_of?(Symbol)
46
46
  name = (name.to_s.end_with?('_id') ? name.to_s[0...-3] : name).to_sym
47
- belong_tos.find { |ass| ass.name == name && !ass.options[:polymorphic] }
47
+ belong_tos.find { |ass| !ass.options[:polymorphic] && ass.name == name }
48
48
  else
49
- belong_tos.find { |ass| ass.klass == name.class && !ass.options[:polymorphic] }
49
+ belong_tos.find { |ass| !ass.options[:polymorphic] && ass.klass == name.class }
50
50
  end
51
51
  end
52
52
 
53
53
  def belongs_to_polymorphic(name)
54
54
  name = (name.to_s.end_with?('_id') ? name.to_s[0...-3] : name).to_sym
55
- belong_tos.find { |ass| ass.name == name && ass.options[:polymorphic] }
55
+ belong_tos.find { |ass| ass.options[:polymorphic] && ass.name == name }
56
56
  end
57
57
 
58
58
  def has_and_belongs_to_many(name)
@@ -29,11 +29,15 @@ module Effective
29
29
  end
30
30
 
31
31
  (member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods
32
- buttons[action.to_s.titleize] = { action: action, default: true }
32
+ buttons[action.to_s.titleize] = { action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action} @reource?"}
33
33
  end
34
34
 
35
35
  member_delete_actions.each do |action|
36
- buttons[action == :destroy ? 'Delete' : action.to_s.titleize] = { action: action, default: true }
36
+ if action == :destroy
37
+ buttons['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
38
+ else
39
+ buttons[action.to_s.titleize] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action} @resource?" }
40
+ end
37
41
  end
38
42
 
39
43
  if collection_get_actions.find { |a| a == :index }
@@ -63,11 +67,33 @@ module Effective
63
67
  end
64
68
 
65
69
  (member_post_actions - crud_actions).each do |action|
66
- actions[action.to_s.titleize] = { action: action, default: true }
70
+ actions[action.to_s.titleize] = { action: action, default: true, 'data-method' => :post, 'data-confirm' => "Really #{action} @resource?" }
67
71
  end
68
72
 
69
73
  member_delete_actions.each do |action|
70
- actions[action == :destroy ? 'Delete' : action.to_s.titleize] = { action: action, default: true }
74
+ if action == :destroy
75
+ actions['Delete'] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really delete @resource?" }
76
+ else
77
+ actions[action.to_s.titleize] = { action: action, default: true, 'data-method' => :delete, 'data-confirm' => "Really #{action} @resource?" }
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ # This is the fallback for render_resource_actions when no actions are specified, but a class is given
84
+ # Used by Datatables new
85
+ def resource_klass_actions
86
+ {}.tap do |buttons|
87
+ if collection_get_actions.find { |a| a == :index }
88
+ buttons["All #{human_plural_name}".titleize] = { action: :index, default: true }
89
+ end
90
+
91
+ if collection_get_actions.find { |a| a == :new }
92
+ buttons["New #{human_name}".titleize] = { action: :new, default: true }
93
+ end
94
+
95
+ (collection_get_actions - crud_actions).each do |action|
96
+ buttons[action.to_s.titleize] = { action: action, default: true }
71
97
  end
72
98
  end
73
99
  end
@@ -236,7 +236,7 @@ module Effective
236
236
  # Order the target model for its matching records / keys
237
237
  sort_column = (sort unless sort == true) || resource.sort_column
238
238
 
239
- relation = resource.order(sort_column, direction, limit: limit, reorder: true).limit([limit, 1000].compact.min)
239
+ relation = resource.order(sort_column, direction, limit: limit, reorder: true).limit(1500)
240
240
 
241
241
  if association.options[:as] # polymorphic
242
242
  relation = relation.where(association.type => klass.name)
@@ -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) %>";
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) %>";
5
+ EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.10.1'.freeze
2
+ VERSION = '1.0.0'.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: 0.10.1
4
+ version: 1.0.0
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-09-03 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -70,9 +70,11 @@ files:
70
70
  - app/views/application/create.js.erb
71
71
  - app/views/application/destroy.js.erb
72
72
  - app/views/application/edit.html.haml
73
+ - app/views/application/edit.js.erb
73
74
  - app/views/application/index.html.haml
74
75
  - app/views/application/member_action.js.erb
75
76
  - app/views/application/new.html.haml
77
+ - app/views/application/new.js.erb
76
78
  - app/views/application/show.html.haml
77
79
  - app/views/application/update.js.erb
78
80
  - app/views/effective/resource/_actions.html.haml
@@ -103,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
105
  version: '0'
104
106
  requirements: []
105
107
  rubyforge_project:
106
- rubygems_version: 2.5.2.3
108
+ rubygems_version: 2.4.5.1
107
109
  signing_key:
108
110
  specification_version: 4
109
111
  summary: Make any controller an effective resource controller.