effective_resources 1.4.10 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aabe6bb10943b7f4fd917281fc6ef5899b40df909f4d3030353fcad02dffcdb9
4
- data.tar.gz: e74f56ac701875012fdc23768a1897ab4d2799f5ea2f2e623c44d8b222f458de
3
+ metadata.gz: '0088b5cd07643454e1be8f7c9e01ccd0f5c1b7f93711b9cb86f90e03b74fa463'
4
+ data.tar.gz: e1e1fc6e1e3f3f2d025112681a0e868252f176e447ee9245800994f9b308e41e
5
5
  SHA512:
6
- metadata.gz: 18e727245b1522a36e61dc1f139d463d97503110d437a6b9f00e98bfed75c1d0370e3a12d085d510e579479ef912dc6b565efc24aa2176a8b95a546020752f63
7
- data.tar.gz: 0161a561455a9417aac613797a666b36226154ac1c2c363e209bb4f9fbda639ffdeb4d06d87e8edf30807f025cb024f3856f2d45ff0657ee030bbb8fe363ef0e
6
+ metadata.gz: 6a8171a67e5006edbe0b7e3fe17e9e826f8657325314d285fc866328306d54ae14865f5126024f378e77612846aa7d7b8498f102443cfb5e5b7392210dda8deb
7
+ data.tar.gz: b02c0e21f4263200e8cccec56e4948466a889028ea2ce8d3eb24386776e4e5549255befc769dcb1c60f3c3a2870a02faee3218e0fd74bdae103e5a576f638475
@@ -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.assign_attributes(send(resource_params_method_name))
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)
@@ -9,7 +9,7 @@ module ActsAsStatused
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  module Base
12
- # acts_as_statuses :pending, :approved, :declined, option_key: :option_value
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
@@ -51,4 +51,3 @@ module ActsAsTokened
51
51
  end
52
52
 
53
53
  end
54
-
@@ -75,11 +75,11 @@ module Effective
75
75
  when :date, :datetime
76
76
  if (digits = value.to_s.scan(/(\d+)/).flatten).present?
77
77
  date = if digits.first.length == 4 # 2017-01-10
78
- Time.zone.local(*digits)
78
+ (Time.zone.local(*digits) rescue nil)
79
79
  else # 01/10/2016
80
80
  year = digits.find { |d| d.length == 4}
81
81
  digits = [year] + (digits - [year])
82
- Time.zone.local(*digits)
82
+ (Time.zone.local(*digits) rescue nil)
83
83
  end
84
84
 
85
85
  name.to_s.start_with?('end_') ? date.end_of_day : date
@@ -87,7 +87,7 @@ module Effective
87
87
  when :time
88
88
  if (digits = value.to_s.scan(/(\d+)/).flatten).present?
89
89
  now = Time.zone.now
90
- Time.zone.local(now.year, now.month, now.day, *digits)
90
+ (Time.zone.local(now.year, now.month, now.day, *digits) rescue nil)
91
91
  end
92
92
  when :decimal, :currency
93
93
  (value.kind_of?(String) ? value.gsub(/[^0-9|\-|\.]/, '') : value).to_f
@@ -26,7 +26,10 @@ module Effective
26
26
 
27
27
  def has_ones
28
28
  return [] unless klass.respond_to?(:reflect_on_all_associations)
29
- klass.reflect_on_all_associations(:has_one).reject { |ass| ass.class_name.to_s.start_with?('ActiveStorage::') }
29
+
30
+ blacklist = ['ActiveStorage::', 'ActionText::']
31
+
32
+ klass.reflect_on_all_associations(:has_one).reject { |ass| blacklist.any? { |val| ass.class_name.start_with?(val) } }
30
33
  end
31
34
 
32
35
  def has_ones_ids
@@ -66,6 +69,14 @@ module Effective
66
69
  active_storage_has_ones.map { |ass| ass.name.to_s.gsub(/_attachment\z/, '').to_sym }
67
70
  end
68
71
 
72
+ def active_texts
73
+ klass.reflect_on_all_associations(:has_one).select { |ass| ass.class_name == 'ActionText::RichText' }
74
+ end
75
+
76
+ def active_texts_has_ones_ids
77
+ active_texts.map { |ass| ass.name.to_s.gsub(/\Arich_text_/, '').to_sym }
78
+ end
79
+
69
80
  def nested_resources
70
81
  return [] unless klass.respond_to?(:reflect_on_all_associations)
71
82
  klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] } +
@@ -153,7 +164,3 @@ module Effective
153
164
  end
154
165
  end
155
166
  end
156
-
157
-
158
-
159
-
@@ -52,6 +52,12 @@ module Effective
52
52
  end
53
53
  end
54
54
 
55
+ def active_text_attributes
56
+ {}.tap do |retval|
57
+ active_texts_has_ones_ids.each { |k, v| retval[k] = [:string] }
58
+ end
59
+ end
60
+
55
61
  # All will include primary_key, created_at, updated_at and belongs_tos
56
62
  # This is the attributes as defined by the effective_resources do .. end block
57
63
  # { :name => [:string, { permitted: false }], ... }
@@ -66,6 +72,7 @@ module Effective
66
72
  .merge(effective_addresses_attributes)
67
73
  .merge(effective_assets_attributes)
68
74
  .merge(active_storage_attributes)
75
+ .merge(active_text_attributes)
69
76
  .merge(atts)
70
77
  else # This is the migrator. This should match table_attributes
71
78
  belong_tos_attributes.merge(atts.reject { |_, v| v[0] == :permitted_param })
@@ -137,7 +144,3 @@ module Effective
137
144
  end
138
145
  end
139
146
  end
140
-
141
-
142
-
143
-
@@ -8,7 +8,7 @@
8
8
  .col-4.text-right
9
9
  = render_resource_buttons(@resource, show: false)
10
10
 
11
- = render @resource
11
+ = render_resource_partial(@resource)
12
12
 
13
13
  .form-actions
14
14
  = link_to 'Continue', (resource.action_path(:index) || root_path), class: 'btn btn-primary'
@@ -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 render(@resource) %>";
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 %>;
@@ -1,5 +1,4 @@
1
1
  require 'effective_resources/engine'
2
- require 'effective_resources/version'
3
2
 
4
3
  module EffectiveResources
5
4
 
@@ -3,9 +3,14 @@ module EffectiveResources
3
3
  engine_name 'effective_resources'
4
4
 
5
5
  config.autoload_paths += Dir[
6
- "#{config.root}/lib/",
7
6
  "#{config.root}/jobs/",
8
- "#{config.root}/app/models/validators/",
7
+ "#{config.root}/lib/validators/",
8
+ "#{config.root}/app/controllers/concerns/"
9
+ ]
10
+
11
+ config.eager_load_paths += Dir[
12
+ "#{config.root}/jobs/",
13
+ "#{config.root}/lib/validators/",
9
14
  "#{config.root}/app/controllers/concerns/"
10
15
  ]
11
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.4.10'.freeze
2
+ VERSION = '1.5.1'.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.4.10
4
+ version: 1.5.1
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-04-17 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -71,9 +71,6 @@ 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
75
- - app/models/validators/email_validator.rb
76
- - app/models/validators/url_validator.rb
77
74
  - app/views/application/_flash.html.haml
78
75
  - app/views/application/create.js.erb
79
76
  - app/views/application/destroy.js.erb
@@ -94,11 +91,14 @@ files:
94
91
  - lib/effective_resources/engine.rb
95
92
  - lib/effective_resources/version.rb
96
93
  - lib/generators/effective_resources/install_generator.rb
94
+ - lib/validators/email_cc_validator.rb
95
+ - lib/validators/email_validator.rb
96
+ - lib/validators/url_validator.rb
97
97
  homepage: https://github.com/code-and-effect/effective_resources
98
98
  licenses:
99
99
  - MIT
100
100
  metadata: {}
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.3
117
- signing_key:
116
+ rubygems_version: 3.1.4
117
+ signing_key:
118
118
  specification_version: 4
119
119
  summary: Make any controller an effective resource controller.
120
120
  test_files: []