Browse Source

Save all answers on page

pull/23/head
baarkerlounger 3 years ago committed by Daniel Baark
parent
commit
f17d480a12
  1. 9
      app/controllers/case_logs_controller.rb
  2. 5
      app/models/form.rb
  3. 30
      config/forms/2021_2022.json

9
app/controllers/case_logs_controller.rb

@ -24,12 +24,17 @@ class CaseLogsController < ApplicationController
form = Form.new(2021, 2022) form = Form.new(2021, 2022)
@case_log = CaseLog.find(params[:case_log_id]) @case_log = CaseLog.find(params[:case_log_id])
previous_page = params[:previous_page] previous_page = params[:previous_page]
previous_answer = params[previous_page] questions_for_page = form.questions_for_page(previous_page).keys
@case_log.update!(previous_page => previous_answer) answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) }
@case_log.update!(answers_for_page)
next_page = form.next_page(previous_page) next_page = form.next_page(previous_page)
redirect_to(send("case_log_#{next_page}_path", @case_log)) redirect_to(send("case_log_#{next_page}_path", @case_log))
end end
def page_params(questions_for_page)
params.permit(questions_for_page)
end
form = Form.new(2021, 2022) form = Form.new(2021, 2022)
form.all_pages.keys.map do |page| form.all_pages.keys.map do |page|
define_method(page) do define_method(page) do

5
app/models/form.rb

@ -32,6 +32,11 @@ class Form
all_subsections[subsection]["pages"] all_subsections[subsection]["pages"]
end end
# Returns a hash with the questions as keys
def questions_for_page(page)
all_pages[page]["questions"]
end
def first_page_for_subsection(subsection) def first_page_for_subsection(subsection)
pages_for_subsection(subsection).keys.first pages_for_subsection(subsection).keys.first
end end

30
config/forms/2021_2022.json

@ -169,12 +169,12 @@
"household_needs": { "household_needs": {
"label": "Household needs", "label": "Household needs",
"pages": { "pages": {
"tenant_code":{ "previous_housing_situation":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "previous_housing_situation": {
"header": "What is the tenant code?", "header": "What was the tenant’s housing situation immediately before this letting?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
} }
@ -190,11 +190,11 @@
"tenancy_information": { "tenancy_information": {
"label": "Tenancy information", "label": "Tenancy information",
"pages": { "pages": {
"tenant_code":{ "tenant_code_1":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_1": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -206,11 +206,11 @@
"property_information": { "property_information": {
"label": "Property information", "label": "Property information",
"pages": { "pages": {
"tenant_code":{ "tenant_code_2":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_2": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -227,11 +227,11 @@
"income_and_benefits": { "income_and_benefits": {
"label": "Income and benefits", "label": "Income and benefits",
"pages": { "pages": {
"tenant_code":{ "tenant_code_3":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_3": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -243,11 +243,11 @@
"rent": { "rent": {
"label": "Rent", "label": "Rent",
"pages": { "pages": {
"tenant_code":{ "tenant_code_4":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_4": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -264,11 +264,11 @@
"local_authority": { "local_authority": {
"label": "Local authority", "label": "Local authority",
"pages": { "pages": {
"tenant_code":{ "tenant_code_5":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_5": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"
@ -285,11 +285,11 @@
"declaration": { "declaration": {
"label": "Declaration", "label": "Declaration",
"pages": { "pages": {
"tenant_code":{ "tenant_code_6":{
"header": "", "header": "",
"description": "", "description": "",
"questions":{ "questions":{
"tenant_code": { "tenant_code_6": {
"header": "What is the tenant code?", "header": "What is the tenant code?",
"hint_text": "", "hint_text": "",
"type": "text" "type": "text"

Loading…
Cancel
Save