effective_cpd 0.1.1 → 0.1.2

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: de3c5aff3c8b80fd7399e397e1c4968bb8b0bfe59c393e7163f6ac122a6060ba
4
- data.tar.gz: fe0ac220660ae96ed5ec5ef3323cb999232ba5dfddbe9e0189e6e977f197d0ae
3
+ metadata.gz: 789dc178c0c706f7d63d166f48e512b36b3f905eb6e70abd242f98924773a679
4
+ data.tar.gz: 86e4bb9b95b8a53dd810316b3d4ea9ca2031c8063155cc57d1e192f29b3a84b5
5
5
  SHA512:
6
- metadata.gz: 712935d335c2873f55782a8cef4d2f3ba88bb84478dd856294a563c325d25eccd52fef3a07310c49f87b64d7e55eaa26500653fee4d0c307bc442e6682261846
7
- data.tar.gz: 5dfdad26cf708b8ff43c9b03a66e7a45e82fd1d3c4c9510958a056548c64068b908fd7b984ea9350f745aa477c803fd88e132706cecd61e5b6ac4c8aa3f31ee6
6
+ metadata.gz: d96d0a42c29587ab1ead57f7b6707f3acc9e607f0eb9fdf9c05336242491351833a2e14ddb81b883c1f8b811ca3a8712a8814ba97fec679ebc0d5b635b04f69a
7
+ data.tar.gz: e9d5453a4816d34b7668027b96c82a3a2208d7158a656ebaf02fff1776f5dc03e642b2e3b9d34272dcd28d94d6ced94310470d85fdd532c51eb4628ab9ba6f97
data/README.md CHANGED
@@ -134,6 +134,31 @@ As an admin, visit the CPD Categories, then CPD Cycles, and CPD Audit levels.
134
134
 
135
135
  Once all these 3 areas have been configured, users can submit statements and audits can be performed.
136
136
 
137
+ ## Required Score
138
+
139
+ You can specify the required score in the CPD Cycle.
140
+
141
+ You can also programatically do it. Add the following to your user class.
142
+
143
+ ```
144
+ # This is an ActiveRecord concern to add the has_many :cpd_statements
145
+ effective_cpd_user
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
149
+ 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
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
157
+
158
+ (100 - existing)
159
+ end
160
+ ```
161
+
137
162
  ## Authorization
138
163
 
139
164
  All authorization checks are handled via the effective_resources gem found in the `config/initializers/effective_resources.rb` file.
@@ -0,0 +1,29 @@
1
+ # EffectiveCpdUser
2
+ #
3
+ # Mark your user model with effective_cpd_user to get a few helpers
4
+ # And user specific point required scores
5
+
6
+ module EffectiveCpdUser
7
+ extend ActiveSupport::Concern
8
+
9
+ module Base
10
+ def effective_cpd_user
11
+ include ::EffectiveCpdUser
12
+ end
13
+ end
14
+
15
+ included do
16
+ has_many :cpd_statements, -> { Effective::CpdStatement.sorted }, class_name: 'Effective::CpdStatement'
17
+ has_many :cpd_audits, -> { Effective::CpdAudit.sorted }, inverse_of: :user, class_name: 'Effective::CpdAudit'
18
+ has_many :cpd_audit_reviews, -> { Effective::CpdAuditReview.sorted }, inverse_of: :user, class_name: 'Effective::CpdAuditReview'
19
+ end
20
+
21
+ def cpd_statement_required_score(cpd_statement)
22
+ nil
23
+ end
24
+
25
+ module ClassMethods
26
+ def effective_cpd_user?; true; end
27
+ end
28
+
29
+ end
@@ -54,9 +54,9 @@ module Effective
54
54
  self.score ||= 0
55
55
  end
56
56
 
57
- validate(if: -> { completed? && cpd_cycle.required_score.present? }) do
58
- min = cpd_cycle.required_score
59
- self.errors.add(:score, "must be #{min} or greater to submit statement") if score < min
57
+ validate(if: -> { completed? }) do
58
+ min = required_score()
59
+ self.errors.add(:score, "must be #{min} or greater to submit a statement") if score < min
60
60
  end
61
61
 
62
62
  with_options(if: -> { current_step == :agreements }) do
@@ -87,6 +87,13 @@ module Effective
87
87
  submitted_at.present?
88
88
  end
89
89
 
90
+ def required_score
91
+ required_by_cycle = cpd_cycle&.required_score
92
+ required_by_user = user.cpd_statement_required_score(self) if user.respond_to?(:cpd_statement_required_score)
93
+
94
+ [required_by_cycle.to_i, required_by_user.to_i].max
95
+ end
96
+
90
97
  def carry_forward
91
98
  cpd_statement_activities.sum { |activity| activity.carry_forward.to_i }
92
99
  end
@@ -22,10 +22,7 @@
22
22
  %h4= resource.score.to_i
23
23
 
24
24
  %td
25
- - if cpd_cycle.required_score.to_i > 0
26
- #{cpd_credits_label} out of #{cpd_cycle.required_score} required
27
- - else
28
- #{cpd_credits_label} in current #{cpd_cycle_label}
25
+ #{cpd_credits_label} out of #{resource.required_score} required
29
26
 
30
27
  %tr
31
28
  %td
@@ -7,5 +7,12 @@ module EffectiveCpd
7
7
  eval File.read("#{config.root}/config/effective_cpd.rb")
8
8
  end
9
9
 
10
+ # Include acts_as_addressable concern and allow any ActiveRecord object to call it
11
+ initializer 'effective_cpd.active_record' do |app|
12
+ ActiveSupport.on_load :active_record do
13
+ ActiveRecord::Base.extend(EffectiveCpdUser::Base)
14
+ end
15
+ end
16
+
10
17
  end
11
18
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
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.1
4
+ version: 0.1.2
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-03 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -212,6 +212,7 @@ files:
212
212
  - app/helpers/effective_cpd_audits_helper.rb
213
213
  - app/helpers/effective_cpd_helper.rb
214
214
  - app/mailers/effective/cpd_mailer.rb
215
+ - app/models/concerns/effective_cpd_user.rb
215
216
  - app/models/effective/cpd_activity.rb
216
217
  - app/models/effective/cpd_audit.rb
217
218
  - app/models/effective/cpd_audit_level.rb