effective_cpd 0.1.2 → 0.1.3

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: 789dc178c0c706f7d63d166f48e512b36b3f905eb6e70abd242f98924773a679
4
- data.tar.gz: 86e4bb9b95b8a53dd810316b3d4ea9ca2031c8063155cc57d1e192f29b3a84b5
3
+ metadata.gz: '09c97e5c49d9195e2b402e395d3039510de53b4dda1503ad052af6e7dc28221b'
4
+ data.tar.gz: 24f617a5dd535b960ef3d9056956395f647a4a5581613014f8786b7d850b521e
5
5
  SHA512:
6
- metadata.gz: d96d0a42c29587ab1ead57f7b6707f3acc9e607f0eb9fdf9c05336242491351833a2e14ddb81b883c1f8b811ca3a8712a8814ba97fec679ebc0d5b635b04f69a
7
- data.tar.gz: e9d5453a4816d34b7668027b96c82a3a2208d7158a656ebaf02fff1776f5dc03e642b2e3b9d34272dcd28d94d6ced94310470d85fdd532c51eb4628ab9ba6f97
6
+ metadata.gz: e0d0aa17d7b171d1226a40852f79f8440a271cb7bd451bce1260887be7a2c722409d9d8fe4e96a1337e1911935985ef3b737e0cf75807e911714f945637afb3d
7
+ data.tar.gz: 46744c3a3cbd29b133958be01a375238c0e8d413ba9e64eb0e020fdae9505af907e03c3257d93cecd13df534c9dd7bedd309d58a9052596aad5552161b1aa9ff
data/README.md CHANGED
@@ -144,18 +144,26 @@ You can also programatically do it. Add the following to your user class.
144
144
  # This is an ActiveRecord concern to add the has_many :cpd_statements
145
145
  effective_cpd_user
146
146
 
147
- # Just this one magic method. Chcked when submitting the passed cpd_Statement
148
- # Must be 100 points in the last 3 years. Can submit 0 0 100 or 33 33 34
147
+ # We require 100 points in the last 3 years.
149
148
  def cpd_statement_required_score(cpd_statement)
150
- # All completed cpd statements before this cpd_statement
151
- existing = cpd_statements.select { |s| s.completed? && s.cpd_cycle_id < cpd_statement.cpd_cycle_id }
152
- return 0 if existing.length < 2
149
+ # We always consider the 3 year window, of the passed cpd_statement and the last two statements
150
+ last_two_statements = cpd_statements.select do |statement|
151
+ statement.completed? && statement.cpd_cycle_id < cpd_statement.cpd_cycle_id
152
+ end.last(2)
153
153
 
154
- existing_score = others.last(2).map { |statement| statement.score }.sum
155
- raise('expected existing to be >= 0') if existing < 0
156
- return 0 if existing >= 100
154
+ # They can submit 0 0 100
155
+ return 0 if last_two_statements.length < 2
157
156
 
158
- (100 - existing)
157
+ # 100 points in the last 3 years.
158
+ required_score = 100
159
+
160
+ # Score so far
161
+ existing_score = last_two_statements.sum { |statement| statement.score }
162
+ raise('expected existing_score to be >= 0') if existing_score < 0
163
+
164
+ # Required score minus previous
165
+ return 0 if existing_score >= required_score
166
+ (required_score - existing_score)
159
167
  end
160
168
  ```
161
169
 
@@ -30,6 +30,16 @@ module EffectiveCpdHelper
30
30
  end
31
31
  end
32
32
 
33
+ def cpd_statement_submit_label(cpd_statement)
34
+ label = "Yes, I understand I will not be able to submit more #{cpd_credits_label} or modify any of my activities for this #{cpd_cycle_label}, once I submit."
35
+
36
+ if (end_at = cpd_statement.cpd_cycle.end_at).present?
37
+ label += " The last date to submit this form is #{end_at.strftime("%B %d, %Y")}."
38
+ end
39
+
40
+ label
41
+ end
42
+
33
43
  def effective_cpd_categories
34
44
  @effective_cpd_categories ||= Effective::CpdCategory.deep.sorted
35
45
  end
@@ -1,6 +1,7 @@
1
1
  module Effective
2
2
  class CpdCycle < ActiveRecord::Base
3
3
  has_rich_text :all_steps_content # Update build_from_cycle() below if these change
4
+ has_rich_text :sidebar_content
4
5
  has_rich_text :start_content
5
6
  has_rich_text :activities_content
6
7
  has_rich_text :agreements_content
@@ -29,6 +30,7 @@ module Effective
29
30
 
30
31
  scope :deep, -> {
31
32
  with_rich_text_all_steps_content
33
+ .with_rich_text_sidebar_content
32
34
  .with_rich_text_start_content
33
35
  .with_rich_text_activities_content
34
36
  .with_rich_text_submit_content
@@ -76,13 +78,17 @@ module Effective
76
78
  attributes = cycle.dup.attributes.except('title', 'token', 'start_at', 'end_at')
77
79
  assign_attributes(attributes)
78
80
 
79
- [:all_steps_content, :start_content, :activities_content, :submit_content, :complete_content].each do |rich_text|
81
+ [:all_steps_content, :sidebar_content, :start_content, :activities_content, :submit_content, :complete_content].each do |rich_text|
80
82
  self.send("#{rich_text}=", cycle.send(rich_text))
81
83
  end
82
84
 
83
85
  cycle.cpd_rules.each do |rule|
84
86
  attributes = rule.dup.attributes.except('cpd_cycle_id')
85
- self.cpd_rules.build(attributes)
87
+ cpd_rule = self.cpd_rules.build(attributes)
88
+
89
+ if rule.category?
90
+ cpd_rule.category_credit_description = rule.category_credit_description
91
+ end
86
92
  end
87
93
 
88
94
  self
@@ -3,6 +3,9 @@ module Effective
3
3
  belongs_to :cpd_cycle
4
4
  belongs_to :ruleable, polymorphic: true # Activity or Category
5
5
 
6
+ # For a Category: A maximum of 35 PDHs/year may be claimed in the Contributions to Knowledge category
7
+ has_rich_text :category_credit_description
8
+
6
9
  if respond_to?(:log_changes)
7
10
  log_changes(to: :cpd_cycle)
8
11
  end
@@ -12,7 +15,6 @@ module Effective
12
15
 
13
16
  effective_resource do
14
17
  # A plaintext description of the formula
15
- # For a Category: A maximum of 35 PDHs/year may be claimed in the Contributions to Knowledge category
16
18
  # For a Activity: 15 hours of work equals 1 credit
17
19
  credit_description :text
18
20
 
@@ -23,6 +25,7 @@ module Effective
23
25
  formula :string
24
26
 
25
27
  # Maximum number of cycles can carry forward
28
+ # Only considered for activities
26
29
  max_cycles_can_carry_forward :integer
27
30
 
28
31
  # Cannot be entered in this cycle
@@ -31,19 +34,21 @@ module Effective
31
34
  timestamps
32
35
  end
33
36
 
34
- scope :deep, -> { includes(:cpd_cycle, :ruleable) }
37
+ scope :deep, -> { with_rich_text_category_credit_description.includes(:cpd_cycle, :ruleable) }
35
38
  scope :categories, -> { where(ruleable_type: 'Effective::CpdCategory') }
36
39
  scope :activities, -> { where(ruleable_type: 'Effective::CpdActivity') }
37
40
  scope :unavailable, -> { where(unavailable: true) }
38
41
 
39
42
  #validates :cpd_cycle_id, uniqueness: { scope: [:ruleable_id, :ruleable_type] }
40
- validates :credit_description, presence: true
41
43
  validates :max_credits_per_cycle, numericality: { greater_than: 0, allow_nil: true }
42
- validates :max_cycles_can_carry_forward, numericality: { greater_than: 0, allow_nil: true }
44
+ validates :max_cycles_can_carry_forward, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
43
45
 
44
46
  validates :formula, presence: true, if: -> { activity? }
45
47
  validates :formula, absence: true, if: -> { category? }
46
48
 
49
+ validates :credit_description, presence: true, if: -> { activity? }
50
+ validates :category_credit_description, presence: true, if: -> { category? }
51
+
47
52
  validate(if: -> { formula.present? }) do
48
53
  if formula.gsub('amount2', '').gsub('amount', '').gsub(' ', '').match(INVALID_FORMULA_CHARS).present?
49
54
  self.errors.add(:formula, "may only contain amount, amount2 and 0-9 + - / * ( ) characters")
@@ -1,9 +1,17 @@
1
1
  = effective_form_with(model: [:admin, cpd_cycle], engine: true) do |f|
2
+ %h2 All Steps Content
3
+
2
4
  .card.mb-4
3
5
  .card-body
4
6
  %h5.card-title All Steps Content
5
7
  = f.rich_text_area :all_steps_content, label: false, hint: 'displayed on all statement steps'
6
8
 
9
+ .card.mb-4
10
+ .card-body
11
+ %h5.card-title Sidebar Content
12
+ = f.rich_text_area :sidebar_content, label: false, hint: 'displayed on the sidebar on all statement steps'
13
+
14
+ %h2 Individual Steps Content
7
15
  .card.mb-4
8
16
  .card-body
9
17
  %h5.card-title Start Step
@@ -10,8 +10,8 @@
10
10
  label: "Max #{cpd_credits_label} per #{cpd_cycle_label}",
11
11
  hint: "The maximum number of #{cpd_credits_label} that may be earned in this category for this #{cpd_cycle_label}. Leave blank for no limit."
12
12
 
13
- = fc.text_field :credit_description,
14
- hint: "A simple description of the maximum #{cpd_credits_label} and carry forward policy of activities for this category"
13
+ = fc.rich_text_area :category_credit_description,
14
+ hint: "A description of the maximum #{cpd_credits_label} and carry forward policy of activities for this category"
15
15
 
16
16
  = fc.check_box :unavailable, label: "Unavailable in this #{cpd_cycle_label}"
17
17
 
@@ -49,7 +49,7 @@
49
49
 
50
50
  = fa.number_field :max_cycles_can_carry_forward,
51
51
  label: "Max #{cpd_cycles_label} can carry forward",
52
- hint: "leave blank for no limit"
52
+ hint: "leave blank for no limit. enter zero for no carry forward."
53
53
 
54
54
  = fa.check_box :unavailable, label: "Unavailable in this #{cpd_cycle_label}"
55
55
 
@@ -22,6 +22,7 @@
22
22
  .mb-3
23
23
  %strong #{cpd_credits_label.titleize} Calculation
24
24
  %br
25
+ = rule.category_credit_description
25
26
  = rule.credit_description
26
27
 
27
28
  %div
@@ -30,5 +30,7 @@
30
30
 
31
31
  %td #{cpd_credits_label} in last 3 #{cpd_cycles_label} (including this #{cpd_cycle_label})
32
32
 
33
+ = cpd_cycle.sidebar_content
34
+
33
35
  .col-9
34
36
  = yield
@@ -14,7 +14,6 @@
14
14
  = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
15
15
  = f.hidden_field :current_step
16
16
 
17
- = f.check_box :confirm_readonly,
18
- label: 'Yes, I understand that I will not be able to modify this statement after submission'
17
+ = f.check_box :confirm_readonly, label: cpd_statement_submit_label(f.object)
19
18
 
20
19
  = f.submit 'Submit Statement', center: true
data/db/seeds.rb CHANGED
@@ -9,7 +9,6 @@ if Rails.env.test?
9
9
  Effective::CpdRule.delete_all
10
10
 
11
11
  ActionText::RichText.where(record_type: ['Effective::CpdCycle', 'Effective::CpdCycle', 'Effective::CpdActivity', 'Effective::CpdAudit', 'Effective::CpdAuditLevelSection', 'Effective::CpdAuditLevelQuestion']).delete_all
12
-
13
12
  end
14
13
 
15
14
  # Build the first CpdCycle
@@ -18,11 +17,12 @@ cycle = Effective::CpdCycle.create!(
18
17
  start_at: now.beginning_of_year,
19
18
  end_at: now.end_of_year,
20
19
  required_score: 100,
21
- all_steps_content: "<div>All Steps Content</div>",
22
- start_content: "<div>Start Content</div>",
23
- activities_content: "<div>Activities Content</div>",
24
- submit_content: "<div>Submit Content</div>",
25
- complete_content: "<div>Complete Content</div>"
20
+ all_steps_content: "All Steps Content",
21
+ start_content: "Start Content",
22
+ activities_content: "Activities Content",
23
+ submit_content: "Submit Content",
24
+ complete_content: "Complete Content",
25
+ sidebar_content: "Sidebar Content"
26
26
  )
27
27
 
28
28
  # Professional Practice
@@ -33,7 +33,7 @@ category = Effective::CpdCategory.create!(
33
33
  Effective::CpdRule.create!(
34
34
  cpd_cycle: cycle,
35
35
  ruleable: category,
36
- credit_description: 'Upto a maximum of 20 claimable points per CPD year. Points cannot be carried forward to future years.',
36
+ category_credit_description: 'Upto a maximum of 20 claimable points per CPD year. Points cannot be carried forward to future years.',
37
37
  max_credits_per_cycle: 20
38
38
  )
39
39
 
@@ -74,7 +74,7 @@ category = Effective::CpdCategory.create!(
74
74
  Effective::CpdRule.create!(
75
75
  cpd_cycle: cycle,
76
76
  ruleable: category,
77
- credit_description: 'Upto a maximum of 20 claimable points per CPD year. Points cannot be carried forward to future years.',
77
+ category_credit_description: 'Upto a maximum of 20 claimable points per CPD year. Points cannot be carried forward to future years.',
78
78
  max_credits_per_cycle: 20
79
79
  )
80
80
 
@@ -144,7 +144,7 @@ category = Effective::CpdCategory.create!(
144
144
  Effective::CpdRule.create!(
145
145
  cpd_cycle: cycle,
146
146
  ruleable: category,
147
- credit_description: 'Upto a maximum of 35 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
147
+ category_credit_description: 'Upto a maximum of 35 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
148
148
  max_credits_per_cycle: 35
149
149
  )
150
150
 
@@ -183,7 +183,7 @@ category = Effective::CpdCategory.create!(
183
183
  Effective::CpdRule.create!(
184
184
  cpd_cycle: cycle,
185
185
  ruleable: category,
186
- credit_description: 'Upto a maximum of 15 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
186
+ category_credit_description: 'Upto a maximum of 15 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
187
187
  max_credits_per_cycle: 15
188
188
  )
189
189
 
@@ -265,7 +265,7 @@ category = Effective::CpdCategory.create!(
265
265
  Effective::CpdRule.create!(
266
266
  cpd_cycle: cycle,
267
267
  ruleable: category,
268
- credit_description: 'Upto a maximum of 15 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
268
+ category_credit_description: 'Upto a maximum of 15 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
269
269
  max_credits_per_cycle: 15
270
270
  )
271
271
 
@@ -319,7 +319,7 @@ category = Effective::CpdCategory.create!(
319
319
  Effective::CpdRule.create!(
320
320
  cpd_cycle: cycle,
321
321
  ruleable: category,
322
- credit_description: 'Upto a maximum of 30 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
322
+ category_credit_description: 'Upto a maximum of 30 claimable points per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
323
323
  max_credits_per_cycle: 30
324
324
  )
325
325
 
@@ -421,7 +421,7 @@ category = Effective::CpdCategory.create!(
421
421
  Effective::CpdRule.create!(
422
422
  cpd_cycle: cycle,
423
423
  ruleable: category,
424
- credit_description: 'Upto a maximum of 10 points per mentee or position per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
424
+ category_credit_description: 'Upto a maximum of 10 points per mentee or position per CPD year. Points may be carried over upto a maximum of 2 years after the year in which they were earned.',
425
425
  max_credits_per_cycle: nil
426
426
  )
427
427
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_cpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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-05-05 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails