effective_resources 1.8.17 → 1.8.22

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: 0162db8b9e57f6f0289551a07214bbba02f4154d8786fa38a92e51c023317f17
4
- data.tar.gz: b993410fb958c5efa5a8d281a8def12f8b1e02c209e56ba9835d283a0e33ef44
3
+ metadata.gz: '0995557680ae1cce106214f47b32fcbb0e3250d3f9d07c2c80dfddbae0a2c133'
4
+ data.tar.gz: 4d707fb4403abdb45f86930f8375d91bdfcc74aaa6a3fd96df8e625cdef12ae2
5
5
  SHA512:
6
- metadata.gz: a8d89ebcead9ac5fee2263e5dc6fe83703a103f7daa6e3501a53fdc169b14a0adc65176a46b8fa7ac3310e348afce0b805fe007d14c48a07d38811bdad2f7f6c
7
- data.tar.gz: 8f59af5c2225dce3a7378317688f53a4ce79b6db2502f10cd0632b605e9ad5c02c21eba28ec45d8b428c1e1e9ba229d976c4bc1b9a944cfdbf27771f988cde95
6
+ metadata.gz: d336a5ee4cb5bff6e76addb1693e6abc57539dec033ad0803f20b03a73761b0a44a3838aef4e2c19258adf4906767cef45ff328f5906e22d3ee3726a265cb571
7
+ data.tar.gz: 30741bdd66aad37d4773f4d66a999c180658d58cce8f6b70dfcfe0951967f5a76d996a2f3cb76d9bf721f594698cdf0b613fddb913e5be3dbdfe8e183bc9df24
@@ -125,8 +125,10 @@ module Effective
125
125
  end
126
126
 
127
127
  def resource_layout
128
- namespace = controller_path.include?('admin/') ? 'admin' : 'application'
129
- defined?(Tenant) ? "#{Tenant.current}/#{namespace}" : namespace
128
+ if defined?(Tenant)
129
+ namespace = controller_path.include?('admin/') ? 'admin' : 'application'
130
+ "#{Tenant.current}/#{namespace}"
131
+ end
130
132
  end
131
133
 
132
134
  def resource_params_method_name
@@ -41,7 +41,7 @@ module Effective
41
41
 
42
42
  messages = resource.errors.map do |error|
43
43
  attribute = error.respond_to?(:attribute) ? error.attribute : error
44
- message = error.respond_to?(:message) ? error.message : resource.errors[attribute].to_sentence
44
+ message = error.respond_to?(:attribute) ? error.message : resource.errors[attribute].to_sentence
45
45
 
46
46
  if message[0] == message[0].upcase # If the error begins with a capital letter
47
47
  message
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EffectiveActsAsEmailFormHelper
4
+
5
+ def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
6
+ raise('expected a form') unless form.respond_to?(:object)
7
+
8
+ resource = form.object
9
+ raise('expected an acts_as_email_form resource') unless resource.class.respond_to?(:acts_as_email_form?)
10
+
11
+ # Load the template.
12
+ email_template = if action.present? && resource.email_form_effective_email_templates?
13
+ Effective::EmailTemplate.where(template_name: action).first!
14
+ end
15
+
16
+ # These defaults are only used when there is no email_template
17
+ email_defaults = form.object.email_form_defaults(action) unless email_template.present?
18
+
19
+ locals = {
20
+ form: form,
21
+ email_to: to,
22
+ email_skip: skip,
23
+ email_action: (action || true),
24
+ email_defaults: email_defaults,
25
+ email_template: email_template,
26
+ email_variables: variables
27
+ }
28
+
29
+ render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
30
+ end
31
+
32
+ end
@@ -0,0 +1,74 @@
1
+ # ActsAsEmailForm
2
+ # Adds an email_form_skip, email_form_from, email_form_subject, email_form_body attr_accessors
3
+ # And some helpful methods to render and validate a Email to Send form
4
+ # That should work with or without effective_email_templates to send an email on a model
5
+
6
+ module ActsAsEmailForm
7
+ extend ActiveSupport::Concern
8
+
9
+ module Base
10
+ def acts_as_email_form
11
+ include ::ActsAsEmailForm
12
+ end
13
+ end
14
+
15
+ included do
16
+ # Yes, we are submitting an email form
17
+ attr_accessor :email_form_action
18
+
19
+ # Skip sending the email entirely
20
+ attr_accessor :email_form_skip
21
+
22
+ # The email From / Subject / Body fields
23
+ attr_accessor :email_form_from
24
+ attr_accessor :email_form_subject
25
+ attr_accessor :email_form_body
26
+
27
+ effective_resource do
28
+ email_form_action :string, permitted: true
29
+ email_form_skip :boolean, permitted: true
30
+
31
+ email_form_from :string, permitted: true
32
+ email_form_subject :string, permitted: true
33
+ email_form_body :text, permitted: true
34
+ end
35
+
36
+ with_options(if: -> { email_form_action.present? && !email_form_skip? }) do
37
+ validates :email_form_from, presence: true
38
+ validates :email_form_subject, presence: true
39
+ validates :email_form_body, presence: true
40
+
41
+ validate(unless: -> { email_form_from.blank? }) do
42
+ self.errors.add(:email_form_from, 'must be a valid email address') unless email_form_from.include?('@')
43
+ end
44
+ end
45
+
46
+ if defined?(EffectiveEmailTemplates)
47
+ validates :email_form_subject, liquid: true, if: -> { email_form_effective_email_templates? }
48
+ validates :email_form_body, liquid: true, if: -> { email_form_effective_email_templates? }
49
+ end
50
+
51
+ def email_form_params
52
+ { from: email_form_from, subject: email_form_subject, body: email_form_body }.compact
53
+ end
54
+
55
+ def email_form_skip?
56
+ EffectiveResources.truthy?(email_form_skip)
57
+ end
58
+
59
+ def email_form_effective_email_templates?
60
+ !!defined?(EffectiveEmailTemplates)
61
+ end
62
+
63
+ # Only considered when not using an effective email template
64
+ def email_form_defaults(action)
65
+ { from: nil, subject: nil, body: nil }
66
+ end
67
+
68
+ end
69
+
70
+ module ClassMethods
71
+ def acts_as_email_form?; true; end
72
+ end
73
+
74
+ end
@@ -65,6 +65,8 @@ module EffectiveDeviseUser
65
65
  end
66
66
 
67
67
  module ClassMethods
68
+ def effective_devise_user?; true; end
69
+
68
70
  def permitted_sign_up_params # Should contain all fields as per views/users/_sign_up_fields
69
71
  raise('please define a self.permitted_sign_up_params')
70
72
  [:email, :password, :password_confirmation, :first_name, :last_name, :name, :login]
@@ -11,6 +11,11 @@ module Effective
11
11
  @attributes = {}
12
12
  end
13
13
 
14
+ # For EffectiveLogging. This is a protected keyword I think.
15
+ def message(*args)
16
+ method_missing(:message, args)
17
+ end
18
+
14
19
  def read(&block)
15
20
  instance_exec(&block)
16
21
  end
@@ -0,0 +1,33 @@
1
+ = form.hidden_field :email_form_action, value: email_action
2
+
3
+ - if email_skip
4
+ = form.check_box :email_form_skip, label: 'Do not send email'
5
+
6
+ = form.hide_if :email_form_skip, true do
7
+ - if email_to.present? && form.respond_to?(:static_field)
8
+ = form.static_field :email_form_to, label: 'To', value: (email_to.respond_to?(:email) ? email_to.email : email_to)
9
+
10
+ - if form.object.errors.present?
11
+ = form.text_field :email_form_from, label: 'From'
12
+ = form.text_field :email_form_subject, label: 'Subject'
13
+ = form.text_area :email_form_body, label: 'Body', rows: 10
14
+
15
+ - elsif email_template.present?
16
+ -# email_template is an Effective::EmailTemplate
17
+ = form.text_field :email_form_from, label: 'From', value: email_template.from
18
+ = form.text_field :email_form_subject, label: 'Subject', value: email_template.subject
19
+ = form.text_area :email_form_body, label: 'Body', value: email_template.body, rows: 10
20
+
21
+ - else
22
+ = form.text_field :email_form_from, label: 'From', value: (email_defaults[:from] || '')
23
+ = form.text_field :email_form_subject, label: 'Subject', value: (email_defaults[:subject] || '')
24
+ = form.text_area :email_form_body, label: 'Body', rows: 10, value: (email_defaults[:body] || '')
25
+
26
+ - if email_variables.present?
27
+ %p The available variables are:
28
+
29
+ %ul
30
+ - email_variables.each do |variable|
31
+ %li {{ #{variable} }}
32
+
33
+ %small.text-muted Only a developer can add additional variables
@@ -46,4 +46,22 @@ module EffectiveResources
46
46
  (config.respond_to?(:active_job) && config.active_job.queue_adapter) ? :deliver_later : :deliver_now
47
47
  end
48
48
 
49
+ def self.advance_date(date, business_days: 1, holidays: [:ca, :observed])
50
+ raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
51
+
52
+ business_days.times do
53
+ loop do
54
+ date = date + 1.day
55
+ break if business_day?(date, holidays: holidays)
56
+ end
57
+ end
58
+
59
+ date
60
+ end
61
+
62
+ def self.business_day?(date, holidays: [:ca, :observed])
63
+ require 'holidays' unless defined?(Holidays)
64
+ date.wday != 0 && date.wday != 6 && Holidays.on(date, *holidays).blank?
65
+ end
66
+
49
67
  end
@@ -23,6 +23,7 @@ module EffectiveResources
23
23
  initializer 'effective_resources.active_record' do |app|
24
24
  ActiveSupport.on_load :active_record do
25
25
  ActiveRecord::Base.extend(ActsAsArchived::Base)
26
+ ActiveRecord::Base.extend(ActsAsEmailForm::Base)
26
27
  ActiveRecord::Base.extend(ActsAsTokened::Base)
27
28
  ActiveRecord::Base.extend(ActsAsSlugged::Base)
28
29
  ActiveRecord::Base.extend(ActsAsStatused::Base)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.17'.freeze
2
+ VERSION = '1.8.22'.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.8.17
4
+ version: 1.8.22
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: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: holidays
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Make any controller an effective resource controller.
112
126
  email:
113
127
  - info@codeandeffect.com
@@ -133,10 +147,12 @@ files:
133
147
  - app/controllers/concerns/effective/wizard_controller/before_actions.rb
134
148
  - app/controllers/concerns/effective/wizard_controller/save.rb
135
149
  - app/controllers/concerns/effective/wizard_controller/wicked_overrides.rb
150
+ - app/helpers/effective_acts_as_email_form_helper.rb
136
151
  - app/helpers/effective_resources_helper.rb
137
152
  - app/helpers/effective_resources_private_helper.rb
138
153
  - app/helpers/effective_resources_wizard_helper.rb
139
154
  - app/models/concerns/acts_as_archived.rb
155
+ - app/models/concerns/acts_as_email_form.rb
140
156
  - app/models/concerns/acts_as_slugged.rb
141
157
  - app/models/concerns/acts_as_statused.rb
142
158
  - app/models/concerns/acts_as_tokened.rb
@@ -177,6 +193,7 @@ files:
177
193
  - app/views/application/show.html.haml
178
194
  - app/views/application/show.js.erb
179
195
  - app/views/application/update.js.erb
196
+ - app/views/effective/acts_as_email_form/_fields.html.haml
180
197
  - app/views/effective/resource/_actions.html.haml
181
198
  - app/views/effective/resource/_actions_dropleft.html.haml
182
199
  - app/views/effective/resource/_actions_glyphicons.html.haml