15 changed files with 433 additions and 111 deletions
@ -1,46 +1,59 @@ |
|||||||
class Form < ApplicationRecord |
class Form |
||||||
self.abstract_class = true |
|
||||||
|
attr_reader :form_definition, :all_sections, :all_subsections, :all_pages |
||||||
SECTIONS = { |
|
||||||
"About the household" => %w[household_characteristics household_situation household_needs], |
def initialize(start_year, end_year) |
||||||
"Tenancy and property information" => %w[tenancy_information property_information], |
form_json = "config/forms/#{start_year}_#{end_year}.json" |
||||||
"Rent and charges" => %w[income_and_benefits rent], |
raise "No form definition file exists for given year".freeze unless File.exist?(form_json) |
||||||
"Local Authority" => %w[local_authority], |
|
||||||
"Submission" => %w[declaration], |
@form_definition = JSON.load(File.new(form_json)) |
||||||
}.freeze |
end |
||||||
|
|
||||||
SUBSECTIONS = { |
# Returns a hash with sections as keys |
||||||
"household_characteristics" => "tenant_code", |
def all_sections |
||||||
"household_situation" => "previous_housing_situation", |
@sections ||= @form_definition["sections"] |
||||||
"household_needs" => "tenant_code", |
end |
||||||
"tenancy_information" => "tenant_code", |
|
||||||
"property_information" => "tenant_code", |
# Returns a hash with subsections as keys |
||||||
"income_and_benefits" => "tenant_code", |
def all_subsections |
||||||
"rent" => "tenant_code", |
@subsections ||= all_sections.map do |section_key, section_value| |
||||||
"local_authority" => "tenant_code", |
section_value["subsections"] |
||||||
"declaration" => "tenant_code", |
end.reduce(:merge) |
||||||
}.freeze |
end |
||||||
|
|
||||||
QUESTIONS = { |
# Returns a hash with pages as keys |
||||||
"tenant_code" => "tenant_age", |
def all_pages |
||||||
"tenant_age" => "tenant_gender", |
@all_pages ||= all_subsections.map do |subsection_key, subsection_value| |
||||||
"tenant_gender" => "tenant_ethnic_group", |
subsection_value["pages"] |
||||||
"tenant_ethnic_group" => "tenant_nationality", |
end.reduce(:merge) |
||||||
"tenant_nationality" => "tenant_economic_status", |
end |
||||||
"tenant_economic_status" => "household_number_of_other_members", |
|
||||||
"household_number_of_other_members" => "household_number_of_other_members", |
# Returns a hash with the pages as keys |
||||||
"previous_housing_situation" => "previous_housing_situation", |
def pages_for_subsection(subsection) |
||||||
}.freeze |
all_subsections[subsection]["pages"] |
||||||
|
end |
||||||
def self.first_question_for_subsection(subsection) |
|
||||||
SUBSECTIONS[subsection] |
def first_page_for_subsection(subsection) |
||||||
end |
pages_for_subsection(subsection).keys.first |
||||||
|
end |
||||||
def self.next_question(previous_question) |
|
||||||
Form::QUESTIONS[previous_question] |
def subsection_for_page(page) |
||||||
end |
all_subsections.find do |subsection_key, subsection_value| |
||||||
|
subsection_value["pages"].keys.include?(page) |
||||||
def self.previous_question(current_question) |
end.first |
||||||
Hash[QUESTIONS.to_a.map(&:reverse)][current_question] |
end |
||||||
|
|
||||||
|
def next_page(previous_page) |
||||||
|
subsection = subsection_for_page(previous_page) |
||||||
|
previous_page_idx = pages_for_subsection(subsection).keys.index(previous_page) |
||||||
|
pages_for_subsection(subsection).keys[previous_page_idx + 1] || previous_page # Placeholder until we have a check answers page |
||||||
|
end |
||||||
|
|
||||||
|
def previous_page(current_page) |
||||||
|
subsection = subsection_for_page(current_page) |
||||||
|
current_page_idx = pages_for_subsection(subsection).keys.index(current_page) |
||||||
|
return unless current_page_idx > 0 |
||||||
|
|
||||||
|
pages_for_subsection(subsection).keys[current_page_idx - 1] |
||||||
end |
end |
||||||
end |
end |
||||||
|
@ -1,18 +1,18 @@ |
|||||||
<% previous_question = Form.previous_question("household_number_of_other_members") %> |
<% previous_page = form.previous_page("household_number_of_other_members") %> |
||||||
<% content_for :before_content do %> |
<% content_for :before_content do %> |
||||||
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> |
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> |
||||||
Back |
Back |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
|
|
||||||
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
||||||
<%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<%= f.govuk_number_field :household_number_of_other_members, |
<%= f.govuk_number_field :household_number_of_other_members, |
||||||
hint: { text: "The maximum number of others is 7" }, |
hint: { text: "The maximum number of others is 7" }, |
||||||
label: { text: "How many other people are there in the household?", size: "l"}, |
label: { text: "How many other people are there in the household?", size: "l"}, |
||||||
min: 0, max: 7, step: 1, width: 20 |
min: 0, max: 7, step: 1, width: 20 |
||||||
%> |
%> |
||||||
<%= f.hidden_field :previous_question, value: :household_number_of_other_members %> |
<%= f.hidden_field :previous_page, value: :household_number_of_other_members %> |
||||||
<%= f.hidden_field :case_log_id, value: case_log_id %> |
<%= f.hidden_field :case_log_id, value: case_log_id %> |
||||||
<%= f.govuk_submit "Save and continue" %> |
<%= f.govuk_submit "Save and continue" %> |
||||||
<% end %> |
<% end %> |
@ -1,18 +1,18 @@ |
|||||||
<% previous_question = Form.previous_question("tenant_age") %> |
<% previous_page = form.previous_page("tenant_age") %> |
||||||
<% content_for :before_content do %> |
<% content_for :before_content do %> |
||||||
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> |
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> |
||||||
Back |
Back |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
|
|
||||||
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
||||||
<%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<%= f.govuk_number_field :tenant_age, |
<%= f.govuk_number_field :tenant_age, |
||||||
hint: { text: "More detail" }, |
hint: { text: "More detail" }, |
||||||
label: { text: "What is the tenant's age?", size: "l"}, |
label: { text: "What is the tenant's age?", size: "l"}, |
||||||
min: 0, max: 150, step: 1, width: 20 |
min: 0, max: 150, step: 1, width: 20 |
||||||
%> |
%> |
||||||
<%= f.hidden_field :previous_question, value: :tenant_age %> |
<%= f.hidden_field :previous_page, value: :tenant_age %> |
||||||
<%= f.hidden_field :case_log_id, value: case_log_id %> |
<%= f.hidden_field :case_log_id, value: case_log_id %> |
||||||
<%= f.govuk_submit "Save and continue" %> |
<%= f.govuk_submit "Save and continue" %> |
||||||
<% end %> |
<% end %> |
@ -1,18 +1,18 @@ |
|||||||
<% previous_question = Form.previous_question("tenant_code") %> |
<% previous_page = form.previous_page("tenant_code") %> |
||||||
<% content_for :before_content do %> |
<% content_for :before_content do %> |
||||||
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_question}" do %> |
<%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> |
||||||
Back |
Back |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
|
|
||||||
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
<%= turbo_frame_tag "case_log_form", target: "_top" do %> |
||||||
<%= form_with action: '/case_logs', method: "next_question", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<%= f.govuk_text_field :tenant_code, |
<%= f.govuk_text_field :tenant_code, |
||||||
hint: { text: "More detail" }, |
hint: { text: "More detail" }, |
||||||
label: { text: "What is the tenant code?", size: "l"}, |
label: { text: "What is the tenant code?", size: "l"}, |
||||||
width: 20 |
width: 20 |
||||||
%> |
%> |
||||||
<%= f.hidden_field :previous_question, value: :tenant_code %> |
<%= f.hidden_field :previous_page, value: :tenant_code %> |
||||||
<%= f.hidden_field :case_log_id, value: case_log_id %> |
<%= f.hidden_field :case_log_id, value: case_log_id %> |
||||||
<%= f.govuk_submit "Save and continue" %> |
<%= f.govuk_submit "Save and continue" %> |
||||||
<% end %> |
<% end %> |
@ -0,0 +1,304 @@ |
|||||||
|
{ |
||||||
|
"form_type": "lettings", |
||||||
|
"start_year": 2021, |
||||||
|
"end_year": 2022, |
||||||
|
"sections": { |
||||||
|
"household": { |
||||||
|
"label": "About the household", |
||||||
|
"subsections": { |
||||||
|
"household_characteristics": { |
||||||
|
"label": "Household characteristics", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenant_age":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_age": { |
||||||
|
"header": "What is the tenant's age?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "numeric", |
||||||
|
"min": 0, |
||||||
|
"max": 150 |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenant_gender":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_gender": { |
||||||
|
"header": "Which of these best describes the tenant's gender identity?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "radio", |
||||||
|
"answer_options": { |
||||||
|
"1": "Female", |
||||||
|
"2": "Male", |
||||||
|
"3": "Non-binary", |
||||||
|
"4": "Prefer not to say" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenant_ethnic_group":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_ethnic_group": { |
||||||
|
"header": "What is the tenant's ethnic group?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "radio", |
||||||
|
"answer_options": { |
||||||
|
"0": "White: English/Scottish/Welsh/Northern Irish/British", |
||||||
|
"1": "White: Irish", |
||||||
|
"2": "White: Gypsy/Irish Traveller", |
||||||
|
"3": "White: Other", |
||||||
|
"4": "Mixed: White & Black Caribbean", |
||||||
|
"5": "Mixed: White & Black African", |
||||||
|
"6": "Mixed: White & Asian", |
||||||
|
"7": "Mixed: Other", |
||||||
|
"8": "Asian or Asian British: Indian", |
||||||
|
"9": "Asian or Asian British: Pakistani", |
||||||
|
"10": "Asian or Asian British: Bangladeshi", |
||||||
|
"11": "Asian or Asian British: Chinese", |
||||||
|
"12": "Asian or Asian British: Other", |
||||||
|
"13": "Black: Caribbean", |
||||||
|
"14": "Black: African", |
||||||
|
"15": "Black: Other", |
||||||
|
"16": "Other Ethnic Group: Arab", |
||||||
|
"17": "Other Ethnic Group: Other", |
||||||
|
"18": "Prefer not to say" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenant_nationality":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_nationality": { |
||||||
|
"header": "What is the tenant's nationality?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "radio", |
||||||
|
"answer_options": { |
||||||
|
"0": "UK national resident in UK", |
||||||
|
"1": "A current or former reserve in the UK Armed Forces (exc. National Service)", |
||||||
|
"2": "UK national returning from residence overseas", |
||||||
|
"3": "Czech Republic", |
||||||
|
"4": "Estonia", |
||||||
|
"5": "Hungary", |
||||||
|
"6": "Latvia", |
||||||
|
"7": "Lithuania", |
||||||
|
"8": "Poland", |
||||||
|
"9": "Slovakia", |
||||||
|
"10": "Bulgaria", |
||||||
|
"11": "Romania", |
||||||
|
"12": "Ireland", |
||||||
|
"13": "Other EU Economic Area (EEA country)", |
||||||
|
"14": "Any other country", |
||||||
|
"15": "Prefer not to say" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenant_economic_status":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_economic_status": { |
||||||
|
"header": "Which of these best describes the tenant's working situation?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "radio", |
||||||
|
"answer_options": { |
||||||
|
"0": "Part-time - Less than 30 hours", |
||||||
|
"1": "Full-time - 30 hours or more", |
||||||
|
"2": "In government training into work, such as New Deal", |
||||||
|
"3": "Jobseeker", |
||||||
|
"4": "Retired", |
||||||
|
"5": "Not seeking work", |
||||||
|
"6": "Full-time student", |
||||||
|
"7": "Unable to work because of long term sick or disability", |
||||||
|
"8": "Child under 16", |
||||||
|
"9": "Other", |
||||||
|
"10": "Prefer not to say" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"household_number_of_other_members":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"household_number_of_other_members": { |
||||||
|
"header": "How many other people are there in the household?", |
||||||
|
"hint_text": "The maximum number of others is 7", |
||||||
|
"type": "numeric", |
||||||
|
"min": 0, |
||||||
|
"max": 7 |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"household_situation": { |
||||||
|
"label": "Household situation", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"household_needs": { |
||||||
|
"label": "Household needs", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"tenancy_and_property": { |
||||||
|
"label": "Tenancy and property information", |
||||||
|
"subsections": { |
||||||
|
"tenancy_information": { |
||||||
|
"label": "Tenancy information", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"property_information": { |
||||||
|
"label": "Property information", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"rent_and_charges": { |
||||||
|
"label": "Rent and charges", |
||||||
|
"subsections": { |
||||||
|
"income_and_benefits": { |
||||||
|
"label": "Income and benefits", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"rent": { |
||||||
|
"label": "Rent", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"local_authority": { |
||||||
|
"label": "Local authority", |
||||||
|
"subsections": { |
||||||
|
"local_authority": { |
||||||
|
"label": "Local authority", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"submission": { |
||||||
|
"label": "Submission", |
||||||
|
"subsections": { |
||||||
|
"declaration": { |
||||||
|
"label": "Declaration", |
||||||
|
"pages": { |
||||||
|
"tenant_code":{ |
||||||
|
"header": "", |
||||||
|
"description": "", |
||||||
|
"questions":{ |
||||||
|
"tenant_code": { |
||||||
|
"header": "What is the tenant code?", |
||||||
|
"hint_text": "", |
||||||
|
"type": "text" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue