effective_cpd 1.4.4 → 1.4.6

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: 6b3ab431275c110356affc6c6a2f7fd4291b974f1f5ac5d2ab289cc5a6426b1e
4
- data.tar.gz: 78eca26e37a10c4b1d832738ea92cccbe43c20c157deba577b1a4509e0786294
3
+ metadata.gz: 41c07110b8b5814d4ff968ffb44dc82d102ad50234907afb644ea887222a1992
4
+ data.tar.gz: 61546891dc6371599ade1e82e7ff75badab344d4eda831b96244131cf6347f88
5
5
  SHA512:
6
- metadata.gz: 9be8da936ad87f771a1c3deed17301140e4d15a60d0d15ba14353b60d69f53b39683efe05351bfb147a7f6ccdfcb5fdb74163bd55628f30a0c7cfd6d98326061
7
- data.tar.gz: a6e902aaa8115ec5b0e9dfdc246884207fc941597ab38fc0fc49e56cfcb68b6ca0e3c02fb083991183c529375dbce4750898205f36a063036c2094a542160260
6
+ metadata.gz: c21fc17a84dab2f37c2c5429109e2a723525f7624236b60210360132c854365038e49a78b9fa57fb2737f5fa2e3b6bb9adc03d50c1fa1e7635157d23ae1956c1
7
+ data.tar.gz: 9da9b7474edd7e464f369b9e2c03517dc25f9b8bdeb5b6c986f018ba3387b7fc3f10d713828db62b0774270b390448c9fa5690689e5e40b48a0731e61af6e9c0
@@ -14,7 +14,7 @@ class EffectiveCpdAvailableCyclesDatatable < Effective::Datatable
14
14
  end
15
15
 
16
16
  actions_col(actions: []) do |cpd_cycle|
17
- statement = cpd_cycle.cpd_statements.where(user: current_user).first
17
+ statement = current_user.cpd_statement(cpd_cycle: cpd_cycle)
18
18
 
19
19
  if statement.blank?
20
20
  dropdown_link_to('Start', effective_cpd.cpd_cycle_cpd_statement_build_path(cpd_cycle, :new, :start))
@@ -26,7 +26,7 @@ module EffectiveCpdUser
26
26
 
27
27
  # Effective scoped
28
28
  has_many :cpd_targets, -> { order(:cpd_cycle_id) }, inverse_of: :user, class_name: 'Effective::CpdTarget', dependent: :delete_all
29
- accepts_nested_attributes_for :cpd_targets
29
+ accepts_nested_attributes_for :cpd_targets, reject_if: proc { |atts| atts['score'].blank? && atts['required_to_submit'].blank? }
30
30
 
31
31
  # These two should not be sorted
32
32
  scope :cpd_audit_auditees, -> { without_role(:cpd_audit_reviewer).without_role(:admin) }
@@ -43,11 +43,17 @@ module EffectiveCpdUser
43
43
  }
44
44
  end
45
45
 
46
+ # Requires for this user
46
47
  def cpd_target_score(cpd_cycle:)
47
48
  target = cpd_target(cpd_cycle: cpd_cycle)
48
49
  return target.score if target&.score.present?
49
50
 
50
- # Otherwise calculate default by membership category
51
+ default_cpd_target_score(cpd_cycle: cpd_cycle)
52
+ end
53
+
54
+ # Required for this user category without the targets
55
+ # Otherwise calculate default by membership category
56
+ def default_cpd_target_score(cpd_cycle:)
51
57
  if self.class.try(:effective_memberships_user?)
52
58
  category = membership_categories_on(cpd_cycle.start_at)&.first if cpd_cycle.start_at.present?
53
59
  category ||= membership_categories_on(cpd_cycle.end_at)&.first if cpd_cycle.end_at.present?
@@ -73,19 +79,20 @@ module EffectiveCpdUser
73
79
  end
74
80
 
75
81
  def cpd_statement(cpd_cycle:)
76
- raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
82
+ raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
77
83
  cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle.id }
78
84
  end
79
85
 
80
86
  # Find or build
81
87
  def build_cpd_statement(cpd_cycle:)
82
- raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cycle?)
88
+ raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
83
89
  cpd_statement(cpd_cycle: cpd_cycle) || cpd_statements.build(cpd_cycle: cpd_cycle)
84
90
  end
85
91
 
92
+ # Dont use IDs here
86
93
  def cpd_target(cpd_cycle:)
87
94
  raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?)
88
- cpd_targets.find { |cpd_target| cpd_target.cpd_cycle_id == cpd_cycle.id }
95
+ cpd_targets.find { |cpd_target| cpd_target.cpd_cycle == cpd_cycle }
89
96
  end
90
97
 
91
98
  # Find or build
@@ -96,7 +103,9 @@ module EffectiveCpdUser
96
103
 
97
104
  # For the form
98
105
  def build_cpd_targets
99
- Effective::CpdCycle.sorted.all.each { |cpd_cycle| build_cpd_target(cpd_cycle: cpd_cycle) }
106
+ Effective::CpdCycle.sorted.all.each do |cpd_cycle|
107
+ cpd_target(cpd_cycle: cpd_cycle) || cpd_targets.new(cpd_cycle: cpd_cycle)
108
+ end
100
109
  cpd_targets.sort_by(&:cpd_cycle_id).reverse
101
110
  end
102
111
 
@@ -20,8 +20,10 @@ module Effective
20
20
  scope :deep, -> { includes(:user, :cpd_cycle) }
21
21
  scope :sorted, -> { order(:cpd_cycle_id) }
22
22
 
23
- validates :score, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
24
- validates :score, presence: true, if: -> { required_to_submit? }
23
+ validates :score, numericality: { greater_than_or_equal_to: 0 }
24
+ validates :required_to_submit, inclusion: { in: [true, false], message: "can't be blank" }
25
+
26
+ validates :cpd_cycle_id, uniqueness: { scope: [:user_id, :user_type], message: 'target already exists' }
25
27
 
26
28
  def to_s
27
29
  score&.to_s || model_name.human
@@ -18,17 +18,17 @@
18
18
  - collection = Effective::CpdTarget::REQUIRED_TO_SUBMIT
19
19
  - cpd_cycle = ctf.object.cpd_cycle
20
20
  - target = f.object.cpd_target_score(cpd_cycle: cpd_cycle)
21
+ - target_placeholder = f.object.default_cpd_target_score(cpd_cycle: cpd_cycle) || '-'
21
22
  - required_to_submit = f.object.cpd_target_score_required_to_submit?(cpd_cycle: cpd_cycle)
22
23
  - required_to_submit_placeholder = collection.find { |label, value| value == required_to_submit }.first
23
24
 
24
25
  %tr
25
26
  %td= link_to(cpd_cycle, effective_cpd.edit_admin_cpd_cycle_path(cpd_cycle), target: '_blank')
26
-
27
27
  %td
28
28
  .row
29
29
  .col
30
- = ctf.number_field :score, label: false, required: false, placeholder: target.to_s
30
+ = ctf.number_field :score, label: false, required: false, placeholder: target_placeholder.to_s
31
31
  .col
32
- = ctf.select :required_to_submit, Effective::CpdTarget::REQUIRED_TO_SUBMIT, label: false, placeholder: required_to_submit_placeholder.to_s
32
+ = ctf.select :required_to_submit, Effective::CpdTarget::REQUIRED_TO_SUBMIT, label: false, required: false, placeholder: required_to_submit_placeholder.to_s
33
33
 
34
34
  = f.save "Save #{cpd_targets_label}", 'data-confirm': "Really Save #{cpd_targets_label} for #{user}?"
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '1.4.4'
2
+ VERSION = '1.4.6'
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: 1.4.4
4
+ version: 1.4.6
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: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails