diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index e4eb6f44d..dddcaee35 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -36,10 +36,10 @@ class CaseLogsController < ApplicationController end form = Form.new(2021, 2022) - form.all_pages.keys.map do |page| - define_method(page) do + form.all_pages.map do |page_key, page_info| + define_method(page_key) do @case_log = CaseLog.find(params[:case_log_id]) - render "form/pages/#{page}", locals: { case_log_id: @case_log.id, form: form } + render "form/page", locals: { case_log_id: @case_log.id, form: form, page_key: page_key, page_info: page_info } end end end diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb new file mode 100644 index 000000000..92fb1a2c5 --- /dev/null +++ b/app/views/form/_numeric_question.html.erb @@ -0,0 +1,8 @@ +<%= f.govuk_number_field question_key, + hint: { text: question["hint_text"] }, + label: { text: question["header"], size: "l"}, + min: question["min"], max: question["max"], step: question["step"], width: 20 +%> +<%= f.hidden_field :previous_page, value: question_key %> +<%= f.hidden_field :case_log_id, value: case_log_id %> +<%= f.govuk_submit "Save and continue" %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb new file mode 100644 index 000000000..2ecdc5e83 --- /dev/null +++ b/app/views/form/_radio_question.html.erb @@ -0,0 +1,6 @@ +<% answer_options = question["answer_options"].map { |k, v| OpenStruct.new(id: k.to_i, value: v) } %> + +<%= f.govuk_collection_radio_buttons question_key, answer_options, :id, :value, legend: { text: question["header"], size: "l" } %> +<%= f.hidden_field :previous_page, value: question_key %> +<%= f.hidden_field :case_log_id, value: case_log_id %> +<%= f.govuk_submit "Save and continue" %> diff --git a/app/views/form/_text_question.html.erb b/app/views/form/_text_question.html.erb new file mode 100644 index 000000000..5c16e6852 --- /dev/null +++ b/app/views/form/_text_question.html.erb @@ -0,0 +1,8 @@ +<%= f.govuk_text_field question_key, + hint: { text: question["hint_text"] }, + label: { text: question["header"], size: "l"}, + width: 20 +%> +<%= f.hidden_field :previous_page, value: question_key %> +<%= f.hidden_field :case_log_id, value: case_log_id %> +<%= f.govuk_submit "Save and continue" %> diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb new file mode 100644 index 000000000..aa7d52b1a --- /dev/null +++ b/app/views/form/page.html.erb @@ -0,0 +1,14 @@ +<% previous_page = form.previous_page(page_key) %> +<% content_for :before_content do %> + <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> + Back + <% end %> +<% end %> + +<%= turbo_frame_tag "case_log_form", target: "_top" do %> + <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <% page_info["questions"].map do |question_key, question| %> + <%= render partial: "form/#{question["type"]}_question", locals: { case_log_id: case_log_id, question_key: question_key, question: question, f: f } %> + <% end %> + <% end %> +<% end %> diff --git a/app/views/form/pages/household_number_of_other_members.html.erb b/app/views/form/pages/household_number_of_other_members.html.erb deleted file mode 100644 index 54113f0ba..000000000 --- a/app/views/form/pages/household_number_of_other_members.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% previous_page = form.previous_page("household_number_of_other_members") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_number_field :household_number_of_other_members, - hint: { text: "The maximum number of others is 7" }, - label: { text: "How many other people are there in the household?", size: "l"}, - min: 0, max: 7, step: 1, width: 20 - %> - <%= f.hidden_field :previous_page, value: :household_number_of_other_members %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/previous_housing_situation.html.erb b/app/views/form/pages/previous_housing_situation.html.erb deleted file mode 100644 index 48cdfe79d..000000000 --- a/app/views/form/pages/previous_housing_situation.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -<% situations = [ - OpenStruct.new(id: 0, value: "Owner occupation (private)"), - OpenStruct.new(id: 1, value: "Owner occupation (low cost home ownership)"), - OpenStruct.new(id: 2, value: "Private sector tenancy"), - OpenStruct.new(id: 3, value: "Tied housing or rented with job"), - OpenStruct.new(id: 4, value: "Supported housing"), - OpenStruct.new(id: 5, value: "Sheltered accomodation"), - OpenStruct.new(id: 6, value: "Residential care home"), - OpenStruct.new(id: 7, value: "Living with friends or family"), - OpenStruct.new(id: 8, value: "Refuge"), - OpenStruct.new(id: 9, value: "Hospital"), - OpenStruct.new(id: 10, value: "Prison / Approved Probation Hostel"), - OpenStruct.new(id: 11, value: "Direct access hostel"), - OpenStruct.new(id: 12, value: "Bed & Breakfast"), - OpenStruct.new(id: 13, value: "Mobile home / caravan"), - OpenStruct.new(id: 14, value: "Any other temporary accommodation"), - OpenStruct.new(id: 15, value: "Home Office Asylum Support"), - OpenStruct.new(id: 16, value: "Children’s home / foster care"), - OpenStruct.new(id: 17, value: "Rough sleeping"), - OpenStruct.new(id: 18, value: "Other"), - OpenStruct.new(id: 19, value: "Fixed term Local Authority General Needs tenancy"), - OpenStruct.new(id: 20, value: "Lifetime Local Authority General Needs tenancy"), - OpenStruct.new(id: 21, value: "Fixed term PRP General Needs tenancy"), - OpenStruct.new(id: 22, value: "Lifetime PRP General Needs tenancy"), -] %> - -<% previous_page = form.previous_page("previous_housing_situation") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :previous_housing_situation, situations, :id, :value, legend: { text: "What was the tenant’s housing situation immediately before this letting?", size: "l" } %> - <%= f.hidden_field :previous_page, value: :previous_housing_situation %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_age.html.erb b/app/views/form/pages/tenant_age.html.erb deleted file mode 100644 index 03b8ea503..000000000 --- a/app/views/form/pages/tenant_age.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% previous_page = form.previous_page("tenant_age") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_number_field :tenant_age, - hint: { text: "More detail" }, - label: { text: "What is the tenant's age?", size: "l"}, - min: 0, max: 150, step: 1, width: 20 - %> - <%= f.hidden_field :previous_page, value: :tenant_age %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_code.html.erb b/app/views/form/pages/tenant_code.html.erb deleted file mode 100644 index 751408b2b..000000000 --- a/app/views/form/pages/tenant_code.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% previous_page = form.previous_page("tenant_code") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_text_field :tenant_code, - hint: { text: "More detail" }, - label: { text: "What is the tenant code?", size: "l"}, - width: 20 - %> - <%= f.hidden_field :previous_page, value: :tenant_code %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_economic_status.html.erb b/app/views/form/pages/tenant_economic_status.html.erb deleted file mode 100644 index 907066a9d..000000000 --- a/app/views/form/pages/tenant_economic_status.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<% economic_statuses = [ - OpenStruct.new(id: 0, value: "Part-time - Less than 30 hours"), - OpenStruct.new(id: 1, value: "Full-time - 30 hours or more"), - OpenStruct.new(id: 2, value: "In government training into work, such as New Deal"), - OpenStruct.new(id: 3, value: "Jobseeker"), - OpenStruct.new(id: 4, value: "Retired"), - OpenStruct.new(id: 5, value: "Not seeking work"), - OpenStruct.new(id: 6, value: "Full-time student"), - OpenStruct.new(id: 7, value: "Unable to work because of long term sick or disability"), - OpenStruct.new(id: 8, value: "Child under 16"), - OpenStruct.new(id: 9, value: "Other"), - OpenStruct.new(id: 10, value: "Prefer not to say") -] %> - -<% previous_page = form.previous_page("tenant_economic_status") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_economic_status, economic_statuses, :id, :value, legend: { text: "Which of these best describes the tenant's working situation?", size: "l" } %> - <%= f.hidden_field :previous_page, value: :tenant_economic_status %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_ethnic_group.html.erb b/app/views/form/pages/tenant_ethnic_group.html.erb deleted file mode 100644 index b79093406..000000000 --- a/app/views/form/pages/tenant_ethnic_group.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -<% ethnic_groups = [ - OpenStruct.new(id: 0, value: "White: English/Scottish/Welsh/Northern Irish/British"), - OpenStruct.new(id: 1, value: "White: Irish"), - OpenStruct.new(id: 2, value: "White: Gypsy/Irish Traveller"), - OpenStruct.new(id: 3, value: "White: Other"), - OpenStruct.new(id: 4, value: "Mixed: White & Black Caribbean"), - OpenStruct.new(id: 5, value: "Mixed: White & Black African"), - OpenStruct.new(id: 6, value: "Mixed: White & Asian"), - OpenStruct.new(id: 7, value: "Mixed: Other"), - OpenStruct.new(id: 8, value: "Asian or Asian British: Indian"), - OpenStruct.new(id: 9, value: "Asian or Asian British: Pakistani"), - OpenStruct.new(id: 10, value: "Asian or Asian British: Bangladeshi"), - OpenStruct.new(id: 11, value: "Asian or Asian British: Chinese"), - OpenStruct.new(id: 12, value: "Asian or Asian British: Other"), - OpenStruct.new(id: 13, value: "Black: Caribbean"), - OpenStruct.new(id: 14, value: "Black: African"), - OpenStruct.new(id: 15, value: "Black: Other"), - OpenStruct.new(id: 16, value: "Other Ethnic Group: Arab"), - OpenStruct.new(id: 17, value: "Other Ethnic Group: Other"), - OpenStruct.new(id: 18, value: "Prefer not to say") -] %> - -<% previous_page = form.previous_page("tenant_ethnic_group") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_ethnic_group, ethnic_groups, :id, :value, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> - <%= f.hidden_field :previous_page, value: :tenant_ethnic_group %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_gender.html.erb b/app/views/form/pages/tenant_gender.html.erb deleted file mode 100644 index be9695ee2..000000000 --- a/app/views/form/pages/tenant_gender.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<% genders = [ - OpenStruct.new(id: 0, value: "Male"), - OpenStruct.new(id: 1, value: "Female"), - OpenStruct.new(id: 2, value: "Non-binary"), - OpenStruct.new(id: 3, value: "Prefer not to say") -] %> - -<% previous_page = form.previous_page("tenant_gender") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_gender, genders, :id, :value, legend: { text: "Which of these best describes the tenant's gender identity?", size: "l" } %> - <%= f.hidden_field :previous_page, value: :tenant_gender %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/app/views/form/pages/tenant_nationality.html.erb b/app/views/form/pages/tenant_nationality.html.erb deleted file mode 100644 index 067dcf747..000000000 --- a/app/views/form/pages/tenant_nationality.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<% nationalities = [ - OpenStruct.new(id: 0, value: "UK national resident in UK"), - OpenStruct.new(id: 1, value: "A current or former reserve in the UK Armed Forces (exc. National Service)"), - OpenStruct.new(id: 2, value: "UK national returning from residence overseas"), - OpenStruct.new(id: 3, value: "Czech Republic"), - OpenStruct.new(id: 4, value: "Estonia"), - OpenStruct.new(id: 5, value: "Hungary"), - OpenStruct.new(id: 6, value: "Latvia"), - OpenStruct.new(id: 7, value: "Lithuania"), - OpenStruct.new(id: 8, value: "Poland"), - OpenStruct.new(id: 9, value: "Slovakia"), - OpenStruct.new(id: 10, value: "Bulgaria"), - OpenStruct.new(id: 11, value: "Romania"), - OpenStruct.new(id: 12, value: "Ireland"), - OpenStruct.new(id: 13, value: "Other EU Economic Area (EEA country)"), - OpenStruct.new(id: 14, value: "Any other country"), - OpenStruct.new(id: 15, value: "Prefer not to say") -] %> - -<% previous_page = form.previous_page("tenant_nationality") %> -<% content_for :before_content do %> - <%= govuk_back_link href: "/case_logs/#{case_log_id}/#{previous_page}" do %> - Back - <% end %> -<% end %> - -<%= turbo_frame_tag "case_log_form", target: "_top" do %> - <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_collection_radio_buttons :tenant_nationality, nationalities, :id, :value, legend: { text: "What is the tenant’s ethnic group?", size: "l" } %> - <%= f.hidden_field :previous_page, value: :tenant_nationality %> - <%= f.hidden_field :case_log_id, value: case_log_id %> - <%= f.govuk_submit "Save and continue" %> - <% end %> -<% end %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 47948d6b6..fe49c900d 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -29,7 +29,8 @@ "hint_text": "", "type": "numeric", "min": 0, - "max": 150 + "max": 150, + "step": 1 } } }, @@ -42,10 +43,10 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": "Female", - "2": "Male", - "3": "Non-binary", - "4": "Prefer not to say" + "0": "Female", + "1": "Male", + "2": "Non-binary", + "3": "Prefer not to say" } } } @@ -144,7 +145,8 @@ "hint_text": "The maximum number of others is 7", "type": "numeric", "min": 0, - "max": 7 + "max": 7, + "step": 1 } } }