Skip to content

Commit

Permalink
Ollie suggestions and page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie committed Nov 22, 2024
1 parent d4e2de1 commit 4e5d6e8
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 120 deletions.
2 changes: 2 additions & 0 deletions app/controllers/claims/schools/claims/add_claim_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Claims::Schools::Claims::AddClaimController < Claims::ApplicationControlle
before_action :set_wizard
before_action :authorize_claim

helper_method :index_path

def update
if !@wizard.save_step
render "edit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ class Claims::Support::Schools::Claims::AddClaimController < Claims::Support::Ap
before_action :set_wizard
before_action :authorize_claim

helper_method :index_path

def update
if !@wizard.save_step
render "edit"
elsif @wizard.next_step.present?
redirect_to step_path(@wizard.next_step)
elsif @wizard.valid?
@wizard.create_claim
@wizard.reset_state
redirect_to claims_support_school_claims_path(@school), flash: {
heading: t(".success"),
}
else
begin
@wizard.create_claim
@wizard.reset_state
redirect_to claims_support_school_claims_path(@school), flash: {
heading: t(".success"),
}
rescue StandardError
redirect_to rejected_claims_support_school_claims_path(@school)
end
redirect_to rejected_claims_support_school_claims_path(@school)
end
end

Expand Down
4 changes: 1 addition & 3 deletions app/policies/claims/claim_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def confirmation?

# TODO: Remove record.draft? and not create drafts for existing drafts
def draft?
return true if record.new_record?

current_claim_window? && user.support_user? && (record.internal_draft? || record.draft?)
current_claim_window? && user.support_user? && (record.internal_draft? || record.draft? || record.new_record?)
end

def check?
Expand Down
10 changes: 2 additions & 8 deletions app/services/claims/claim/create_draft.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Claims::Claim::CreateDraft < ApplicationService
include Claims::Claim::Referencable

def initialize(claim:)
@claim = claim
end
Expand Down Expand Up @@ -33,12 +35,4 @@ def updated_claim
claim
end
end

def generate_reference
loop do
reference = SecureRandom.random_number(99_999_999)

break reference unless Claims::Claim.exists?(reference:)
end
end
end
10 changes: 2 additions & 8 deletions app/services/claims/claim/submit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Claims::Claim::Submit < ApplicationService
include Claims::Claim::Referencable

def initialize(claim:, user:)
@claim = claim
@user = user
Expand Down Expand Up @@ -39,12 +41,4 @@ def updated_claim
claim
end
end

def generate_reference
loop do
reference = SecureRandom.random_number(99_999_999)

break reference unless Claims::Claim.exists?(reference:)
end
end
end
13 changes: 13 additions & 0 deletions app/services/concerns/claims/claim/referencable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Claims::Claim::Referencable
extend ActiveSupport::Concern

included do
def generate_reference
loop do
reference = SecureRandom.random_number(99_999_999)

break reference unless Claims::Claim.exists?(reference:)
end
end
end
end
2 changes: 1 addition & 1 deletion app/views/claims/schools/claims/add_claim/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<%= render_wizard(@wizard, contextual_text: t(".caption")) %>

<p class="govuk-body">
<%= govuk_link_to(t(".cancel"), claims_school_claims_path(@school), no_visited_state: true) %>
<%= govuk_link_to(t(".cancel"), index_path, no_visited_state: true) %>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<%= render_wizard(@wizard, contextual_text: t(".caption", school_name: @school.name)) %>

<p class="govuk-body">
<%= govuk_link_to(t(".cancel"), claims_support_school_claims_path(@school), no_visited_state: true) %>
<%= govuk_link_to(t(".cancel"), index_path, no_visited_state: true) %>
</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<% content_for :page_title, title_with_error_prefix(
t(".page_title", contextual_text:),
error: current_step.errors.any?,
) %>

<%= form_for(current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1>
<span class="govuk-caption-l"><%= contextual_text %></span>
<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<%= govuk_summary_list do |summary_list| %>
<% unless current_user.support_user? %>
Expand All @@ -21,7 +26,7 @@

<% summary_list.with_row do |row| %>
<% row.with_key(text: Claims::Claim.human_attribute_name(:accredited_provider)) %>
<% row.with_value(text: @wizard.steps[:provider].provider.name) %>
<% row.with_value(text: @wizard.provider.name) %>
<% row.with_action(text: t("change"),
href: step_path(:provider),
visually_hidden_text: Claims::Claim.human_attribute_name(:accredited_provider),
Expand Down Expand Up @@ -52,18 +57,18 @@

<%= govuk_summary_list do |summary_list| %>
<% @wizard.steps[:mentor].selected_mentors.each do |mentor| %>
<% mentor_training = @wizard.steps["mentor_training_#{mentor.id}".to_sym] %>
<% mentor_training = @wizard.steps[@wizard.step_name_for_mentor(mentor)] %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: mentor_training.mentor.full_name) %>
<% row.with_value(
text: pluralize(
mentor_training.total_hours_completed,
mentor_training.hours_completed,
t(".hour"),
),
) %>
<% row.with_action(
text: t("change"),
href: step_path("mentor_training_#{mentor.id}".to_sym),
href: step_path(@wizard.step_name_for_mentor(mentor)),
visually_hidden_text: "Hours of training for #{mentor.full_name}",
html_attributes: { class: "govuk-link--no-visited-state" },
) %>
Expand Down Expand Up @@ -100,10 +105,7 @@
<li><%= t(".provide_evidence") %></li>
</ul>

<div class="govuk-warning-text">
<span class="govuk-warning-text__icon" aria-hidden="true">!</span>
<strong class="govuk-warning-text__text"><%= t(".warning") %></strong>
</div>
<%= govuk_warning_text(text: t(".warning")) %>
<% end %>

<%= f.govuk_submit current_user.support_user? ? t(".save") : t(".submit") %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<% content_for :page_title, title_with_error_prefix(
t(".page_title", contextual_text:, provider_name: @wizard.provider.name),
error: current_step.errors.any?,
) %>

<%= form_for(current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l"><%= contextual_text %></span>
<h1 class="govuk-heading-l"><%= t(".heading", provider_name: @wizard.steps[:provider].provider.name) %></h1>
<h1 class="govuk-heading-l"><%= t(".heading", provider_name: @wizard.provider.name) %></h1>

<%= render Claims::Claim::MentorsForm::DisclaimerComponent.new(mentors_form: current_step) %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% content_for :page_title, title_with_error_prefix(
t(".page_title", contextual_text:, provider_name: @wizard.provider.name, mentor: current_step.mentor.full_name),
error: current_step.errors.any?,
) %>

<%= form_for(current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

Expand All @@ -6,24 +11,25 @@
<span class="govuk-caption-l"><%= contextual_text %> - <%= @wizard.steps[:provider].provider.name %></span>
<h1 class="govuk-heading-l"><%= t(".hours_of_training_for_mentor", mentor: current_step.mentor.full_name) %> </h1>

<!-- TODO: Add disclaimer (see app/views/claims/schools/claims/mentor_trainings/edit.html.erb)-->
<%= render Claims::Claim::MentorTrainingForm::DisclaimerComponent.new(mentor_training_form: current_step) %>

<%= f.govuk_radio_buttons_fieldset(
:hours_completed,
:hours_to_claim,
legend: {
size: "m",
text: t(".hours_of_training"),
},
) do %>
<%= f.govuk_radio_button :hours_completed, current_step.max_hours, label: { text: t(".hours", count: current_step.max_hours) }, hint: { text: t(".hours_hint.#{current_step.max_hours == 20 ? "full" : "remaining"}", count: current_step.max_hours) } %>
<%= f.govuk_radio_button :hours_to_claim, "maximum", label: { text: t(".hours", count: current_step.max_hours) }, hint: { text: t(".hours_hint.#{current_step.max_hours == 20 ? "full" : "remaining"}", count: current_step.max_hours) } %>

<%= f.govuk_radio_divider %>

<%= f.govuk_radio_button(:hours_completed, "custom", label: { text: t(".other_amount") }) do %>
<%= f.govuk_radio_button(:hours_to_claim, "custom", label: { text: t(".other_amount") }) do %>
<%= f.govuk_number_field(
:custom_hours_completed,
:custom_hours,
class: "govuk-input--width-2",
min: 1,
max: current_step.max_hours,
label: { text: t(".number_of_hours"), class: "govuk-!-font-weight-bold" },
hint: { text: t(".custom_hours_completed_hint", count: current_step.max_hours) },
) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<% content_for :page_title, title_with_error_prefix(
t(".page_title", contextual_text:, provider_name: @wizard.provider.name),
error: current_step.errors.any?,
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t(".heading_empty", provider_name: @wizard.provider.name) %></h1>
Expand Down
14 changes: 9 additions & 5 deletions app/wizards/claims/add_claim_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def academic_year
end

def total_hours
mentor_training_steps.values.map(&:total_hours_completed).sum
mentor_training_steps.map(&:hours_completed).sum
end

def claim
Expand All @@ -42,10 +42,10 @@ def claim
school:,
created_by:,
claim_window: Claims::ClaimWindow.current,
mentor_trainings_attributes: mentor_training_steps.map do |_k, v|
mentor_trainings_attributes: mentor_training_steps.map do |mentor_training_step|
{
mentor_id: v.mentor_id,
hours_completed: v.total_hours_completed,
mentor_id: mentor_training_step.mentor_id,
hours_completed: mentor_training_step.hours_completed,
provider:,
}
end,
Expand Down Expand Up @@ -76,6 +76,10 @@ def provider
steps.fetch(:provider).provider
end

def step_name_for_mentor(mentor)
step_name(MentorTrainingStep, mentor.id)
end

private

def step_name(step_class, id = nil)
Expand All @@ -96,7 +100,7 @@ def step_attributes(name, step_class, preset_attributes = {})
end

def mentor_training_steps
steps.select { |k, _v| k.to_s.include?("mentor_training_") }
steps.values.select { |step| step.is_a?(MentorTrainingStep) }
end
end
end
28 changes: 10 additions & 18 deletions app/wizards/claims/add_claim_wizard/mentor_training_step.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
class Claims::AddClaimWizard::MentorTrainingStep < BaseStep
attribute :hours_completed
attribute :mentor_id
attribute :custom_hours_completed
attribute :hours_to_claim, :string
attribute :custom_hours

HOURS_TO_CLAIM = %w[maximum custom].freeze

validates :mentor_id, presence: true
validates :hours_completed, presence: true
validates(
:hours_completed,
presence: true,
numericality: {
only_integer: true,
greater_than_or_equal_to: 1,
less_than_or_equal_to: :max_hours,
},
unless: :custom_hours_selected?,
)
validates :hours_to_claim, presence: true, inclusion: { in: HOURS_TO_CLAIM }

validates(
:custom_hours_completed,
:custom_hours,
presence: true,
numericality: { only_integer: true },
between: { min: 1, max: :max_hours },
Expand All @@ -33,7 +25,7 @@ def initialize(wizard:, attributes:)

return if custom_hours_selected?

self.custom_hours_completed = nil
self.custom_hours = nil
end

def mentor
Expand All @@ -52,13 +44,13 @@ def training_allowance
)
end

def total_hours_completed
(custom_hours_selected? ? custom_hours_completed : hours_completed).to_i
def hours_completed
(hours_to_claim == "maximum" ? max_hours : custom_hours).to_i
end

private

def custom_hours_selected?
hours_completed == "custom"
hours_to_claim == "custom"
end
end
6 changes: 2 additions & 4 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ en:
attributes:
mentor_id:
blank: Select a mentor
custom_hours_completed:
custom_hours:
blank: Enter the number of hours
not_an_integer: Enter whole numbers only
between: Enter the number of hours between %{min} and %{max}
hours_completed:
hours_to_claim:
blank: Select the number of hours
not_an_integer: Enter whole numbers only
between: Enter the number of hours between %{min} and %{max}
claims/add_claim_wizard/check_your_answers_step:
attributes:
base:
Expand Down
7 changes: 5 additions & 2 deletions config/locales/en/wizards/claims/add_claim_wizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ en:
page_title: Accredited provider - %{contextual_text}
title: Accredited provider
mentor_step:
page_title: Mentors for %{provider_name} - %{contextual_text}
continue: Continue
label: Mentor
heading: Mentors for %{provider_name}
select_all_that_apply: Select all that apply
mentor_training_step:
page_title: Hours of training for %{mentor} - %{contextual_text} - %{provider_name}
hours_of_training_for_mentor: Hours of training for %{mentor}
hours_of_training: Hours of training
hours:
Expand All @@ -26,8 +28,8 @@ en:
other: Enter whole numbers up to a maximum of %{count} hours
number_of_hours: Number of hours
check_your_answers_step:
page_title: Check your answers
caption: Add claim
page_title: Check your answers - %{contextual_text}
title: Check your answers
warning: You will not be able to change any of the claim details once you have submitted it.
submit: Submit claim
declaration: Declaration
Expand All @@ -43,6 +45,7 @@ en:
hours_of_training: Hours of training
save: Save claim
no_mentors_step:
page_title: No mentors for %{provider_name} - %{contextual_text}
heading_empty: No mentors for %{provider_name}
no_mentors_with_claimable_hours: There are no mentors you can include in a claim because they have already had 20 hours of training claimed for with %{provider_name}.
change_provider: Change the accredited provider
Loading

0 comments on commit 4e5d6e8

Please sign in to comment.