From a0653e2c3b3baa8225bce85ddba308bb516958b0 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 4 Oct 2021 14:15:44 +0100 Subject: [PATCH] Make skip to next incomplete section functional --- app/helpers/tasklist_helper.rb | 19 +++++++++++++++---- app/views/case_logs/_tasklist.html.erb | 2 +- app/views/case_logs/edit.html.erb | 2 +- spec/features/case_log_spec.rb | 5 +++++ spec/helpers/tasklist_helper_spec.rb | 16 +++++++++++++++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 6512be4d2..61fb7dbe5 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -29,10 +29,6 @@ module TasklistHelper :in_progress end - def all_questions_completed(case_log) - case_log.attributes.all? { |_question, answer| answer.present?} - end - def get_status_style(status_label) STYLES[status_label] end @@ -40,4 +36,19 @@ module TasklistHelper def get_status_label(status) STATUSES[status] end + + def get_next_incomplete_section(form, case_log) + subsections = form.all_subsections.keys + return subsections.find { |subsection| is_incomplete?(subsection, case_log) } + end + + private + def all_questions_completed(case_log) + case_log.attributes.all? { |_question, answer| answer.present?} + end + + def is_incomplete?(subsection, case_log) + status = get_subsection_status(subsection, case_log) + return status == :not_started || status == :in_progress + end end diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index dd139fe9b..df9c6d28b 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -8,7 +8,7 @@