diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 1c681047f..279ba2e6c 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,29 @@ 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" => "form/questions/household/tenant_code", + "Household situation" => "case_logs/household_situation/previous_housing_situation" + }.freeze + + NEXT_QUESTION = { + "tenant_code" => "form/questions/household/tenant_age", + "tenant_age" => "form/questions/household/tenant_gender", + "tenant_gender" => "form/questions/household/tenant_ethnic_group", + "tenant_ethnic_group" => "form/questions/household/tenant_nationality", + }.freeze + + def next_question + subsection = params[:subsection] + @case_log = CaseLog.find(params[:case_log_id]) + result = if subsection + FIRST_QUESTION_FOR_SUBSECTION[subsection] + else + previous_question = params[:previous_question] + answer = params[previous_question] + @case_log.update!(previous_question => answer) + 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 dc59532e1..000000000 --- a/app/controllers/form_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class FormController < ApplicationController - - FIRST_QUESTION_FOR_SUBSECTION = { - "Household characteristics" => "case_logs/household/tenant_code", - "Household situation" => "case_logs/household_situation/previous_housing_situation" - } - - 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/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js index 5975c0789..6671d28a4 100644 --- a/app/javascript/controllers/hello_controller.js +++ b/app/javascript/controllers/hello_controller.js @@ -1,7 +1,18 @@ -import { Controller } from "@hotwired/stimulus" +// Visit The Stimulus Handbook for more details +// https://stimulusjs.org/handbook/introduction +// +// This example controller works with specially annotated HTML like: +// +//
+//

+//
+ +import { Controller } from "stimulus" export default class extends Controller { + static targets = [ "output" ] + connect() { - this.element.textContent = "Hello World!" + this.outputTarget.textContent = 'Hello, Stimulus!' } } diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index 4b51d5be3..6f53d84bb 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -1,14 +1,9 @@ -import { Application } from "@hotwired/stimulus" +// Load all the controllers within this directory and all subdirectories. +// Controller files must be named *_controller.js. -const application = Application.start() - -// Configure Stimulus development experience -application.warnings = true -application.debug = false -window.Stimulus = application +import { Application } from "stimulus" +import { definitionsFromContext } from "stimulus/webpack-helpers" -// Import and register all your controllers within this directory and all subdirectories -// Controller files must be named *_controller.js or *_controller.ts -import { definitionsFromContext } from "@hotwired/stimulus" -const context = require.context("controllers", true, /_controller\.(js|ts)$/) +const application = Application.start() +const context = require.context("controllers", true, /_controller\.js$/) application.load(definitionsFromContext(context)) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 53ae39dda..dc909ede8 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -15,3 +15,5 @@ import "@hotwired/turbo-rails" Rails.start() ActiveStorage.start() initAll() + +import "controllers" 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 @@