-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP-4407: Add model, view, controller, forms and steps for child care …
…assesments
- Loading branch information
Showing
15 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/controllers/providers/proceeding_merits_task/child_care_assessments_controller.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,38 @@ | ||
module Providers | ||
module ProceedingMeritsTask | ||
class ChildCareAssessmentsController < ProviderBaseController | ||
def show | ||
@form = ChildCareAssessmentForm.new(model: child_care_assessment) | ||
end | ||
|
||
def update | ||
@form = ChildCareAssessmentForm.new(form_params.merge(proceeding_id: proceeding.id)) | ||
render :show unless update_task_save_continue_or_draft(proceeding.ccms_code.to_sym, :client_child_care_assessment) | ||
end | ||
|
||
private | ||
|
||
def child_care_assessment | ||
@child_care_assessment ||= proceeding.child_care_assessment || proceeding.build_child_care_assessment | ||
end | ||
|
||
def proceeding | ||
@proceeding ||= Proceeding.find(params[:merits_task_list_id]) | ||
end | ||
|
||
def legal_aid_application | ||
@legal_aid_application ||= proceeding.legal_aid_application | ||
end | ||
|
||
def form_params | ||
merge_with_model(child_care_assessment) do | ||
params | ||
.require(:proceeding_merits_task_child_care_assessment) | ||
.permit( | ||
:assessed, | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
app/forms/providers/proceeding_merits_task/child_care_assessment_form.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,26 @@ | ||
module Providers | ||
module ProceedingMeritsTask | ||
class ChildCareAssessmentForm < BaseForm | ||
form_for ::ProceedingMeritsTask::ChildCareAssessment | ||
|
||
attr_accessor :proceeding_id, :assessed | ||
|
||
validates :assessed, inclusion: %w[true false], unless: :draft? | ||
|
||
set_callback :save, :before, :sync_result_details | ||
|
||
private | ||
|
||
def sync_result_details | ||
if assessed_changed? | ||
attributes["result"] = nil | ||
attributes["details"] = nil | ||
end | ||
end | ||
|
||
def assessed_changed? | ||
attributes["assessed"] != model.assessed.to_s | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module ProceedingMeritsTask | ||
class ChildCareAssessment < ApplicationRecord | ||
belongs_to :proceeding | ||
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
28 changes: 28 additions & 0 deletions
28
app/services/flow/steps/provider_merits/child_care_assessment_step.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,28 @@ | ||
module Flow | ||
module Steps | ||
module ProviderMerits | ||
ChildCareAssessmentStep = Step.new( | ||
path: lambda do |application| | ||
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"]) | ||
Steps.urls.providers_merits_task_list_child_care_assessment_path(proceeding) | ||
end, | ||
forward: lambda do |application| | ||
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"]) | ||
if proceeding.child_care_assessment.assessed? | ||
:child_care_assessment_result | ||
else | ||
Flow::MeritsLoop.forward_flow(application, proceeding.ccms_code.to_sym) | ||
end | ||
end, | ||
check_answers: lambda do |application| | ||
proceeding = application.proceedings.find(application.provider_step_params["merits_task_list_id"]) | ||
if proceeding.child_care_assessment.assessed? | ||
:child_care_assessment_result | ||
else | ||
:check_merits_answers | ||
end | ||
end, | ||
) | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
app/views/providers/proceeding_merits_task/child_care_assessments/show.html.erb
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,24 @@ | ||
<%= form_with( | ||
model: @form, | ||
url: providers_merits_task_list_child_care_assessment_path(@proceeding), | ||
method: :patch, | ||
local: true, | ||
) do |form| %> | ||
|
||
<%= page_template page_title: t(".h1-heading"), | ||
head_title: "#{@proceeding.meaning} - " + t(".h1-heading"), | ||
template: :basic, | ||
form: do %> | ||
<%= form.govuk_collection_radio_buttons :assessed, | ||
yes_no_options(yes: t(".radio_hint_yes")), | ||
:value, # value_method | ||
:label, # text_method | ||
:radio_hint, # hint_method | ||
bold_labels: false, | ||
caption: { text: @proceeding.meaning, size: "xl" }, | ||
legend: { text: content_for(:page_title), tag: "h1", size: "xl" }, | ||
hint: { text: t(".hint") } %> | ||
|
||
<%= next_action_buttons(show_draft: true, form:) %> | ||
<% 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
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
18 changes: 18 additions & 0 deletions
18
spec/factories/proceeding_merits_task/child_care_assessments.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,18 @@ | ||
FactoryBot.define do | ||
factory :child_care_assessment, class: "ProceedingMeritsTask::ChildCareAssessment" do | ||
proceeding | ||
assessed { false } | ||
|
||
trait :negative do | ||
assessed { true } | ||
result { false } | ||
details { Faker::Lorem.paragraph(sentence_count: 2) } | ||
end | ||
|
||
trait :positive do | ||
assessed { false } | ||
result { true } | ||
details { nil } | ||
end | ||
end | ||
end |