effective_cpd 1.4.4 → 1.4.5

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: ea1c3574d959eac96d4ea26c8c0c4a25560c81d08bc5e54a85c238adb51f70f0
4
+ data.tar.gz: af871c4f6ec38aa0e1c1090c1877e857f65db572b087e422ecd2029a338fc0f2
5
5
  SHA512:
6
- metadata.gz: 9be8da936ad87f771a1c3deed17301140e4d15a60d0d15ba14353b60d69f53b39683efe05351bfb147a7f6ccdfcb5fdb74163bd55628f30a0c7cfd6d98326061
7
- data.tar.gz: a6e902aaa8115ec5b0e9dfdc246884207fc941597ab38fc0fc49e56cfcb68b6ca0e3c02fb083991183c529375dbce4750898205f36a063036c2094a542160260
6
+ metadata.gz: 405c0b8e3c5f5b21ac04f97bf8db864ed7a8a1994b25027aa41d535e1f7ce84585e38ec7d1fd1eeb77d58d51e080f96ee62aa57e0cca472c055978a3dc936992
7
+ data.tar.gz: 113e27bb06f1cc3a0ae4c664e0af1255de13f52e55a176912d25b064931ba7c6f41f0636c8ff5cdcdaab2eee27e15f260b611a2b1960708e0ad021035da63dc6
@@ -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
@@ -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.5'
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.5
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