Skip to content

Commit

Permalink
AP-5531: Add appeal court type quesion 3 and 4
Browse files Browse the repository at this point in the history
Add the controllers, forms, views and steps to complete
the ECCT question flow as per the designs.
  • Loading branch information
jsugarman committed Dec 17, 2024
1 parent fed766f commit dc5ae67
Show file tree
Hide file tree
Showing 33 changed files with 958 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Providers
module ApplicationMeritsTask
class BaseAppealCourtTypesController < ProviderBaseController
def show
@form = form.new(model: appeal)
end

def update
@form = form.new(form_params)

render :show unless update_task_save_continue_or_draft(:application, :second_appeal)
end

private

# :nocov:
def form
raise "Implement in subclass"
end
# :nocov:

def appeal
legal_aid_application.appeal
end

def form_params
merge_with_model(appeal) do
return {} unless params[:application_merits_task_appeal]

params.require(:application_merits_task_appeal).permit(:court_type)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Providers
module ApplicationMeritsTask
class FirstAppealCourtTypesController < BaseAppealCourtTypesController
private

def form
FirstAppealCourtTypeForm
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Providers
module ApplicationMeritsTask
class SecondAppealCourtTypesController < BaseAppealCourtTypesController
private

def form
SecondAppealCourtTypeForm
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Providers
module ApplicationMeritsTask
class BaseAppealCourtTypeForm < BaseForm
SECOND_APPEAL_COURT_TYPES = %w[
court_of_appeal
supreme_court
].freeze

FIRST_APPEAL_COURT_TYPES =
SECOND_APPEAL_COURT_TYPES + %w[
other_court
].freeze

# :nocov:
def court_types
raise "Implement in subclass"
end
# :nocov:
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Providers
module ApplicationMeritsTask
class FirstAppealCourtTypeForm < BaseAppealCourtTypeForm
form_for ::ApplicationMeritsTask::Appeal

attr_accessor :court_type

validates :court_type, presence: true, inclusion: { in: FIRST_APPEAL_COURT_TYPES }, unless: :draft?

def court_types
FIRST_APPEAL_COURT_TYPES
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class OriginalJudgeLevelForm < BaseForm

attr_accessor :original_judge_level

set_callback :save, :before, :sync_court_type

JUDGE_LEVELS = %w[
family_panel_magistrates
deputy_district_judge
Expand All @@ -18,6 +20,18 @@ class OriginalJudgeLevelForm < BaseForm
def judge_levels
JUDGE_LEVELS
end

private

def sync_court_type
if original_judge_level_changed?
attributes["court_type"] = nil
end
end

def original_judge_level_changed?
attributes["original_judge_level"] != model.original_judge_level
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Providers
module ApplicationMeritsTask
class SecondAppealCourtTypeForm < BaseAppealCourtTypeForm
form_for ::ApplicationMeritsTask::Appeal

attr_accessor :court_type

validates :court_type, presence: true, inclusion: { in: SECOND_APPEAL_COURT_TYPES }, unless: :draft?

def court_types
SECOND_APPEAL_COURT_TYPES
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class SecondAppealForm < BaseForm

validates :second_appeal, presence: true, unless: :draft?

set_callback :save, :before, :sync_original_judge_level

# Alternative callback
# set_callback :validation, :after, :sync_original_judge_level
set_callback :save, :before, :sync_second_appeal_details

private

def sync_original_judge_level
attributes["original_judge_level"] = nil if second_appeal?
def sync_second_appeal_details
if second_appeal_changed?
attributes["original_judge_level"] = nil
attributes["court_type"] = nil
end
end

def second_appeal?
attributes["second_appeal"] == "true"
def second_appeal_changed?
attributes["second_appeal"] != model.second_appeal.to_s
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/flow/flows/provider_merits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ProviderMerits < FlowSteps
nature_of_urgencies: Steps::ProviderMerits::NatureOfUrgenciesStep,
matter_opposed_reasons: Steps::ProviderMerits::MatterOpposedReasonsStep,
second_appeals: Steps::ProviderMerits::SecondAppealsStep,
second_appeal_court_types: Steps::ProviderMerits::SecondAppealCourtTypesStep,
first_appeal_court_types: Steps::ProviderMerits::FirstAppealCourtTypesStep,
original_judge_levels: Steps::ProviderMerits::OriginalJudgeLevelsStep,
chances_of_success: Steps::ProviderMerits::ChancesOfSuccessStep,
success_prospects: Steps::ProviderMerits::SuccessProspectsStep,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Flow
module Steps
module ProviderMerits
FirstAppealCourtTypesStep = Step.new(
path: ->(application) { Steps.urls.providers_legal_aid_application_first_appeal_court_type_path(application) },
forward: lambda do |application|
Flow::MeritsLoop.forward_flow(application, :application)
end,
check_answers: :check_merits_answers,
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@ module ProviderMerits
OriginalJudgeLevelsStep = Step.new(
path: ->(application) { Steps.urls.providers_legal_aid_application_original_judge_level_path(application) },
forward: lambda do |application|
Flow::MeritsLoop.forward_flow(application, :application)
# TODO: AP-5531/5532 - should goto question 4 or Next question
# NOTE: should/could use same form but setup with different options/content for "second" or "first" appeal court
#
# if application.appeal.original_judge_level.in?(%i[family_panel_magistrates deputy_district_judge district_judge])
# :appeal_court
# elsif application.appeal.original_judge_level.in?(%i[recorder_circuit_judge high_court_judge])
# :second_appeal_court
# else
# Flow::MeritsLoop.forward_flow(application, :application)
# end
#
# OR
#
# if application.appeal.original_judge_level.present?
# :appeal_court # And let that form handle difference between 3 and 4 based on second_appeal true (question 3) or false (question 4)
# else
# Flow::MeritsLoop.forward_flow(application, :application)
# end
if application.appeal.original_judge_level.in?(%w[recorder_circuit_judge high_court_judge])
:first_appeal_court_types
else
Flow::MeritsLoop.forward_flow(application, :application)
end
end,
check_answers: lambda do |application|
if application.appeal.original_judge_level.in?(%w[recorder_circuit_judge high_court_judge])
:first_appeal_court_types
else
:check_merits_answers
end
end,
# TODO: AP-5531/5532 - should goto question 4 or Next question
check_answers: :check_merits_answers,
)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Flow
module Steps
module ProviderMerits
SecondAppealCourtTypesStep = Step.new(
path: ->(application) { Steps.urls.providers_legal_aid_application_second_appeal_court_type_path(application) },
forward: lambda do |application|
Flow::MeritsLoop.forward_flow(application, :application)
end,
check_answers: :check_merits_answers,
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ module ProviderMerits
path: ->(application) { Steps.urls.providers_legal_aid_application_second_appeal_path(application) },
forward: lambda do |application|
if application.appeal.second_appeal?
# TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?"
Flow::MeritsLoop.forward_flow(application, :application)
:second_appeal_court_types
else
:original_judge_levels
end
end,
check_answers: lambda do |application|
if application.appeal.second_appeal?
# TODO: AP-5531/5532 - should go to question 3 "Which court will the second appeal be heard in?"
# :appeal_court
:check_merits_answers
:second_appeal_court_types
else
:original_judge_levels
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_with(
url: providers_legal_aid_application_first_appeal_court_type_path,
model: @form,
method: :patch,
local: true,
) do |form| %>
<%= page_template page_title: t(".page_title"),
template: :basic,
form: do %>

<%= form.govuk_radio_buttons_fieldset(:court_type,
legend: { text: content_for(:page_title), tag: "h1", size: "xl" },
hint: { text: t(".hint") })do %>

<% form.object.court_types.each_with_index do |court_type, idx| %>
<%= form.govuk_radio_button :court_type,
court_type,
link_errors: idx.zero?,
label: { text: t(".#{court_type}.label") } %>
<% end %>
<% end %>

<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_with(
url: providers_legal_aid_application_second_appeal_court_type_path,
model: @form,
method: :patch,
local: true,
) do |form| %>
<%= page_template page_title: t(".page_title"),
template: :basic,
form: do %>

<%= form.govuk_radio_buttons_fieldset(:court_type,
legend: { text: content_for(:page_title), tag: "h1", size: "xl" },
hint: { text: t(".hint") })do %>

<% form.object.court_types.each_with_index do |court_type, idx| %>
<%= form.govuk_radio_button :court_type,
court_type,
link_errors: idx.zero?,
label: { text: t(".#{court_type}.label") } %>
<% end %>
<% end %>

<%= next_action_buttons(show_draft: true, form:) %>
<% end %>
<% end %>
9 changes: 8 additions & 1 deletion app/views/shared/check_answers/_second_appeal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
<% unless @legal_aid_application.appeal.second_appeal? %>
<%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__original_judge_level-row" }) do |row| %>
<%= row.with_key(text: t(".original_judge_level_question"), classes: "govuk-!-width-one-half") %>
<%= row.with_value(text: t("providers.application_merits_task.original_judge_levels.show.#{@legal_aid_application.appeal.original_judge_level}.label")) %>
<%= row.with_value(text: t("original_judge_levels.#{@legal_aid_application.appeal.original_judge_level}")) %>
<% end %>
<% end %>

<% if @legal_aid_application.appeal.court_type? %>
<%= summary_list.with_row(html_attributes: { id: "app-check-your-answers__court_type-row" }) do |row| %>
<%= row.with_key(text: t(".court_type_question"), classes: "govuk-!-width-one-half") %>
<%= row.with_value(text: t("appeal_court_types.#{@legal_aid_application.appeal.court_type}")) %>
<% end %>
<% end %>
<% end %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en/activemodel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ en:
original_judge_level:
blank: Select what level of judge heard the original case
inclusion: Select what level of judge heard the original case from the available list
court_type:
blank: Select which court the appeal will be heard in
inclusion: Select which court the appeal will be heard in from the available list
opponent:
attributes:
police_notified_details_true:
Expand Down
Loading

0 comments on commit dc5ae67

Please sign in to comment.