From 5d787cf85c8416547778ae6618bf823f5192d58e Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 15 Sep 2021 14:02:44 +0100 Subject: [PATCH 1/5] Refactor case logs --- app/controllers/case_logs_controller.rb | 32 ++++++++++++--- app/controllers/form_controller.rb | 24 ------------ app/javascript/styles/_task-list.scss | 5 +++ app/views/case_logs/_tasklist.html.erb | 2 +- .../case_logs/household/tenant_age.html.erb | 3 +- .../case_logs/household/tenant_code.html.erb | 3 +- .../household/tenant_gender.html.erb | 3 +- app/views/case_logs/index.html.erb | 2 +- app/views/case_logs/new.html.erb | 8 ---- config/routes.rb | 4 +- spec/controllers/case_logs_controller_spec.rb | 15 +++++-- spec/features/case_log_spec.rb | 39 +++++++++++-------- 12 files changed, 75 insertions(+), 65 deletions(-) delete mode 100644 app/controllers/form_controller.rb delete mode 100644 app/views/case_logs/new.html.erb diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 1c681047f..0f7b3c288 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -4,6 +4,11 @@ class CaseLogsController < ApplicationController @in_progress_case_logs = CaseLog.where(status: 0) end + def create + @case_log = CaseLog.create! + redirect_to @case_log + end + # We don't have a dedicated non-editable show view def show @case_log = CaseLog.find(params[:id]) @@ -14,9 +19,26 @@ class CaseLogsController < ApplicationController @case_log = CaseLog.find(params[:id]) end - # def update - # @case_log = CaseLog.find(params[:id]) - # @case_log.update!(tenant_code: params[:case_log][:tenant_code]) if params[:case_log] - # render_next_question(@case_log) - # end + FIRST_QUESTION_FOR_SUBSECTION = { + "Household characteristics" => "case_logs/household/tenant_code", + }.freeze + + NEXT_QUESTION = { + "tenant_code" => "case_logs/household/tenant_age", + "tenant_age" => "case_logs/household/tenant_gender", + "tenant_gender" => "case_logs/household/tenant_ethnic_group", + "tenant_ethnic_group" => "case_logs/household/tenant_nationality", + }.freeze + + def next_question + @subsection = params[:subsection] + @case_log_id = params[:case_log_id] + result = if @subsection + FIRST_QUESTION_FOR_SUBSECTION[@subsection] + else + @previous_question = params[:previous_question] + NEXT_QUESTION[@previous_question] + end + render result, locals: { case_log_id: @case_log_id } + end end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb deleted file mode 100644 index 489f2f86e..000000000 --- a/app/controllers/form_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -class FormController < ApplicationController - - FIRST_QUESTION_FOR_SUBSECTION = { - "Household characteristics" => "case_logs/household/tenant_code", - } - - NEXT_QUESTION = { - "tenant_code" => "case_logs/household/tenant_age", - "tenant_age" => "case_logs/household/tenant_gender", - "tenant_gender" => "case_logs/household/tenant_ethnic_group", - "tenant_ethnic_group" => "case_logs/household/tenant_nationality" - } - - - def next_question - subsection = params[:subsection] - result = if subsection - FIRST_QUESTION_FOR_SUBSECTION[subsection] - else - NEXT_QUESTION[params[:previous_question]] - end - render result - end -end diff --git a/app/javascript/styles/_task-list.scss b/app/javascript/styles/_task-list.scss index 88755e077..d00cd8aeb 100644 --- a/app/javascript/styles/_task-list.scss +++ b/app/javascript/styles/_task-list.scss @@ -80,3 +80,8 @@ } } } + +turbo-frame { + display: block; + border: 1px solid blue +} diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index 9e79f4c01..024835b5d 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -18,7 +18,7 @@