-
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.
Implement new withdrawal reasons report, interstitial page and new co…
…ntent
- Loading branch information
Showing
16 changed files
with
404 additions
and
48 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-tint(govuk-colour('light-grey'), 50); | ||
} | ||
|
||
&__cell--light-grey-background { | ||
background: govuk-tint(govuk-colour('light-grey'), 50); | ||
} | ||
} |
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
135 changes: 135 additions & 0 deletions
135
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,135 @@ | ||
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 application_form_count < ProviderReports::MINIMUM_DATA_SIZE_REQUIRED | ||
|
||
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: text_cell_attributes_for(level), | ||
}, | ||
before_accepting: { | ||
text: before_accepting_count(reason), | ||
numeric: true, | ||
html_attributes: numeric_cell_attributes_for(level), | ||
}, | ||
after_accepting: { | ||
text: after_accepting_count(reason), | ||
numeric: true, | ||
html_attributes: numeric_cell_attributes_for(level), | ||
}, | ||
total: { | ||
text: before_accepting_count(reason) + after_accepting_count(reason), | ||
numeric: true, | ||
html_attributes: numeric_cell_attributes_for(level), | ||
}, | ||
) | ||
end | ||
|
||
def text_cell_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_cell_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 | ||
|
||
def application_form_count | ||
withdrawal_reasons.select('application_choices.application_form_id').distinct.count | ||
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
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
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
Oops, something went wrong.