Browse Source

fix bug with infinite recursion

pull/252/head
MadeTech Dushan 3 years ago
parent
commit
f27300b1b0
  1. 11
      app/models/form.rb
  2. 4
      app/views/form/check_answers.html.erb

11
app/models/form.rb

@ -50,7 +50,7 @@ class Form
def next_incomplete_section_redirect_path(subsection, case_log)
subsection_ids = subsections.map(&:id)
if case_log.status == "completed"
if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log)
next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1])
first_question_in_subsection = next_subsection.pages.first.id
return first_question_in_subsection.to_s.dasherize
@ -62,6 +62,7 @@ class Form
if next_subsection.id == "declaration" && case_log.status != "completed"
next_subsection = get_subsection(subsection_ids[0])
end
if next_subsection.status(case_log) == :completed
next_incomplete_section_redirect_path(next_subsection, case_log)
else
@ -70,6 +71,14 @@ class Form
end
end
def all_subsections_except_declaration_completed?(case_log)
subsection_ids = subsections.map(&:id)
subsection_ids.delete_at(subsection_ids.length - 1)
return true if subsection_ids.all? { |subsection_id| get_subsection(subsection_id).status(case_log) == :completed }
false
end
def conditional_question_conditions
conditions = questions.map { |q| Hash(q.id => q.conditional_for) if q.conditional_for.present? }.compact
conditions.map { |c|

4
app/views/form/check_answers.html.erb

@ -23,9 +23,9 @@
<%= form_with model: @case_log, method: "get" do |f| %>
<%= f.govuk_submit 'Save and continue' do %>
<% if @case_log.status == "in_progress" %>
<% if @case_log.status == "in_progress" && @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) == false %>
<a class="govuk-button govuk-button--secondary" href=<%= "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}" %>>Save and go to next incomplete section</a>
<% elsif @case_log.status == "completed" %>
<% elsif @case_log.status == "completed" || @case_log.form.all_subsections_except_declaration_completed?(@case_log) %>
<a class="govuk-button govuk-button--secondary" href=<%= "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}" %>>Save and go to submit</a>
<% end%>
<% end %>

Loading…
Cancel
Save