Browse Source

Generate page/question views dynamically

pull/23/head
baarkerlounger 3 years ago committed by Daniel Baark
parent
commit
17853f7b9f
  1. 6
      app/controllers/case_logs_controller.rb
  2. 8
      app/views/form/_numeric_question.html.erb
  3. 6
      app/views/form/_radio_question.html.erb
  4. 8
      app/views/form/_text_question.html.erb
  5. 14
      app/views/form/page.html.erb
  6. 19
      app/views/form/pages/household_number_of_other_members.html.erb
  7. 41
      app/views/form/pages/previous_housing_situation.html.erb
  8. 19
      app/views/form/pages/tenant_age.html.erb
  9. 19
      app/views/form/pages/tenant_code.html.erb
  10. 29
      app/views/form/pages/tenant_economic_status.html.erb
  11. 38
      app/views/form/pages/tenant_ethnic_group.html.erb
  12. 22
      app/views/form/pages/tenant_gender.html.erb
  13. 34
      app/views/form/pages/tenant_nationality.html.erb
  14. 14
      config/forms/2021_2022.json

6
app/controllers/case_logs_controller.rb

@ -36,10 +36,10 @@ class CaseLogsController < ApplicationController
end end
form = Form.new(2021, 2022) form = Form.new(2021, 2022)
form.all_pages.keys.map do |page| form.all_pages.map do |page_key, page_info|
define_method(page) do define_method(page_key) do
@case_log = CaseLog.find(params[:case_log_id]) @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 end
end end

8
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" %>

6
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" %>

8
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" %>

14
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 %>

19
app/views/form/pages/household_number_of_other_members.html.erb

@ -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 %>

41
app/views/form/pages/previous_housing_situation.html.erb

@ -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 %>

19
app/views/form/pages/tenant_age.html.erb

@ -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 %>

19
app/views/form/pages/tenant_code.html.erb

@ -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 %>

29
app/views/form/pages/tenant_economic_status.html.erb

@ -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 %>

38
app/views/form/pages/tenant_ethnic_group.html.erb

@ -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 %>

22
app/views/form/pages/tenant_gender.html.erb

@ -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 %>

34
app/views/form/pages/tenant_nationality.html.erb

@ -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 %>

14
config/forms/2021_2022.json

@ -29,7 +29,8 @@
"hint_text": "", "hint_text": "",
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"max": 150 "max": 150,
"step": 1
} }
} }
}, },
@ -42,10 +43,10 @@
"hint_text": "", "hint_text": "",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {
"1": "Female", "0": "Female",
"2": "Male", "1": "Male",
"3": "Non-binary", "2": "Non-binary",
"4": "Prefer not to say" "3": "Prefer not to say"
} }
} }
} }
@ -144,7 +145,8 @@
"hint_text": "The maximum number of others is 7", "hint_text": "The maximum number of others is 7",
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"max": 7 "max": 7,
"step": 1
} }
} }
} }

Loading…
Cancel
Save