Browse Source

some basic extract method refactors

pull/252/head
MadeTech Dushan 3 years ago
parent
commit
47e17e2a3c
  1. 26
      app/models/form.rb

26
app/models/form.rb

@ -51,11 +51,26 @@ class Form
subsection_ids = subsections.map(&:id) subsection_ids = subsections.map(&:id)
if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log) if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log)
next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1]) return first_question_in_last_subsection(subsection_ids)
end
next_subsection = next_subsection(subsection, case_log, subsection_ids)
if next_subsection.status(case_log) == :completed
next_incomplete_section_redirect_path(next_subsection, case_log)
else
first_question_in_subsection = next_subsection.pages.first.id first_question_in_subsection = next_subsection.pages.first.id
return first_question_in_subsection.to_s.dasherize first_question_in_subsection.to_s.dasherize
end end
end
def first_question_in_last_subsection(subsection_ids)
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
end
def next_subsection(subsection, case_log, subsection_ids)
next_subsection_id_index = subsection_ids.index(subsection.id) + 1 next_subsection_id_index = subsection_ids.index(subsection.id) + 1
next_subsection = get_subsection(subsection_ids[next_subsection_id_index]) next_subsection = get_subsection(subsection_ids[next_subsection_id_index])
@ -63,12 +78,7 @@ class Form
next_subsection = get_subsection(subsection_ids[0]) next_subsection = get_subsection(subsection_ids[0])
end end
if next_subsection.status(case_log) == :completed return next_subsection
next_incomplete_section_redirect_path(next_subsection, case_log)
else
first_question_in_subsection = next_subsection.pages.first.id
first_question_in_subsection.to_s.dasherize
end
end end
def all_subsections_except_declaration_completed?(case_log) def all_subsections_except_declaration_completed?(case_log)

Loading…
Cancel
Save