-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/frontend/styles/provider/_withdrawal_reasons_report.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.withdrawal-reasons-report-table { | ||
&__wrapper { | ||
overflow-x: auto; | ||
} | ||
|
||
&__heading { | ||
border-bottom: none; | ||
} | ||
|
||
&__cell--main-reason { | ||
font-weight: $govuk-font-weight-bold; | ||
|
||
background: govuk-colour("light-grey"); | ||
border-top: 2px solid $govuk-input-border-colour; | ||
} | ||
|
||
&__cell--second-level-reason { | ||
padding-left: govuk-spacing(3); | ||
} | ||
|
||
&__cell--third-level-reason { | ||
padding-left: govuk-spacing(5); | ||
} | ||
|
||
&__cell--second-level-with-nested-reasons { | ||
padding-left: govuk-spacing(3); | ||
|
||
background: govuk-colour("light-grey"); | ||
} | ||
|
||
&__cell--light-grey-background { | ||
background: govuk-colour("light-grey"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
app/services/provider_interface/candidate_withdrawal_reasons_data_by_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
module ProviderInterface | ||
class CandidateWithdrawalReasonsDataByProvider | ||
def initialize(provider) | ||
@provider = provider | ||
end | ||
|
||
ReasonRow = Struct.new(:reason, :before_accepting, :after_accepting, :total) | ||
|
||
def show_report? | ||
all_rows.any? | ||
end | ||
|
||
def all_rows | ||
return [] if withdrawal_reasons.count < 10 | ||
|
||
rows = [] | ||
nested_reasons.each_key do |level_one_reason| | ||
rows << build_reason_row(level_one_reason, 'level_one') | ||
|
||
nested_reasons[level_one_reason].each_key do |level_two_reason| | ||
full_level_two_reason = [level_one_reason, level_two_reason].join('.') | ||
|
||
if nested_reasons[level_one_reason][level_two_reason].present? | ||
rows << build_reason_row(full_level_two_reason, 'level_two_with_nested_reasons') | ||
nested_reasons[level_one_reason][level_two_reason].each_key do |level_three_reason| | ||
full_level_three_reason = [level_one_reason, level_two_reason, level_three_reason].join('.') | ||
rows << build_reason_row(full_level_three_reason, 'level_three') | ||
end | ||
else | ||
rows << build_reason_row(full_level_two_reason, 'level_two') | ||
end | ||
end | ||
end | ||
rows | ||
end | ||
|
||
private | ||
|
||
def build_reason_row(reason, level) | ||
ReasonRow.new( | ||
reason: { | ||
text: translate(reason), | ||
html_attributes: reason_attributes_for(level), | ||
}, | ||
before_accepting: { | ||
text: before_accepting_count(reason), | ||
html_attributes: numeric_attributes_for(level), | ||
numeric: true, | ||
}, | ||
after_accepting: { | ||
text: after_accepting_count(reason), | ||
html_attributes: numeric_attributes_for(level), | ||
numeric: true, | ||
}, | ||
total: { | ||
text: before_accepting_count(reason) + after_accepting_count(reason), | ||
html_attributes: numeric_attributes_for(level), numeric: true | ||
}, | ||
) | ||
end | ||
|
||
def reason_attributes_for(level) | ||
case level | ||
when 'level_one' | ||
{ class: 'withdrawal-reasons-report-table__cell--main-reason' } | ||
when 'level_two' | ||
{ class: 'withdrawal-reasons-report-table__cell--second-level-reason' } | ||
when 'level_two_with_nested_reasons' | ||
{ class: 'withdrawal-reasons-report-table__cell--second-level-with-nested-reasons' } | ||
when 'level_three' | ||
{ class: 'withdrawal-reasons-report-table__cell--third-level-reason' } | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def numeric_attributes_for(level) | ||
case level | ||
when 'level_one' | ||
{ class: 'withdrawal-reasons-report-table__cell--main-reason' } | ||
when 'level_two_with_nested_reasons' | ||
{ class: 'withdrawal-reasons-report-table__cell--light-grey-background' } | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def translate(string) | ||
translation_string = string.dup.gsub('-', '_') | ||
I18n.t("candidate_interface.withdrawal_reasons.reasons.#{translation_string}.label") | ||
end | ||
|
||
def before_accepting_count(reason) | ||
withdrawal_reasons_before_acceptance.filter { |r| r.starts_with?(reason) }.length | ||
end | ||
|
||
def after_accepting_count(reason) | ||
withdrawal_reasons_after_acceptance.filter { |r| r.starts_with?(reason) }.length | ||
end | ||
|
||
def nested_reasons | ||
@nested_reasons ||= WithdrawalReason.selectable_reasons | ||
end | ||
|
||
def withdrawal_reasons_before_acceptance | ||
@withdrawal_reasons_before_acceptance ||= | ||
withdrawal_reasons | ||
.where(application_choices: { accepted_at: nil }) | ||
.uniq | ||
.pluck(:reason) | ||
end | ||
|
||
def withdrawal_reasons_after_acceptance | ||
@withdrawal_reasons_after_acceptance ||= | ||
withdrawal_reasons | ||
.where.not(application_choices: { accepted_at: nil }) | ||
.uniq | ||
.pluck(:reason) | ||
end | ||
|
||
def withdrawal_reasons | ||
@withdrawal_reasons ||= | ||
WithdrawalReason | ||
.joins(:application_choice) | ||
.published | ||
.where('application_choices.provider_ids @> ARRAY[?]::bigint[]', @provider.id) | ||
.where(application_choices: { current_recruitment_cycle_year: RecruitmentCycle.current_year }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
config/locales/provider_interface/withdrawal_reasons_report.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
en: | ||
provider_interface: | ||
withdrawal_reasons: | ||
show: | ||
report_description: TBD placeholder text for when the report is visible | ||
report_not_visible: TBD placeholder text for when the report is not visible | ||
table_caption: Withdrawal reason report data | ||
withdrawal_reason: Withdrawal reason | ||
before_accepting: Before accepting | ||
after_accepting: After accepting | ||
total: Total |