Browse Source

refactor to remove unnecessary method

pull/3010/head
Carolyn 1 month ago
parent
commit
9b185bd7e1
  1. 6
      app/controllers/form_controller.rb
  2. 12
      app/models/form.rb
  3. 2
      app/services/documentation_generator.rb

6
app/controllers/form_controller.rb

@ -38,7 +38,7 @@ class FormController < ApplicationController
end end
error_attributes = @log.errors.map(&:attribute) error_attributes = @log.errors.map(&:attribute)
Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}" Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}"
@subsection = form.subsection_for_page(@page) @subsection = @page.subsection
flash[:errors] = @log.errors.each_with_object({}) do |error, result| flash[:errors] = @log.errors.each_with_object({}) do |error, result|
if @page.questions.map(&:id).include?(error.attribute.to_s) if @page.questions.map(&:id).include?(error.attribute.to_s)
result[error.attribute.to_s] = error.message result[error.attribute.to_s] = error.message
@ -87,7 +87,7 @@ class FormController < ApplicationController
if @log if @log
page_id = request.path.split("/")[-1].underscore page_id = request.path.split("/")[-1].underscore
@page = form.get_page(page_id) @page = form.get_page(page_id)
@subsection = form.subsection_for_page(@page) @subsection = @page.subsection
@pages_with_errors_count = 0 @pages_with_errors_count = 0
if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen") || adding_answer_from_check_errors_page? if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen") || adding_answer_from_check_errors_page?
if updated_answer_from_check_errors_page? if updated_answer_from_check_errors_page?
@ -274,7 +274,7 @@ private
elsif pages_to_check.any? elsif pages_to_check.any?
return redirect_path_to_question(pages_to_check[0], pages_to_check) return redirect_path_to_question(pages_to_check[0], pages_to_check)
else else
return send("#{@log.log_type}_#{form.subsection_for_page(@page).id}_check_answers_path", @log) return send("#{@log.log_type}_#{@page.subsection.id}_check_answers_path", @log)
end end
end end
if previous_interruption_screen_page_id.present? if previous_interruption_screen_page_id.present?

12
app/models/form.rb

@ -78,14 +78,10 @@ class Form
routed_question || all_questions[0] routed_question || all_questions[0]
end end
def subsection_for_page(page)
subsections.find { |s| s.pages.find { |p| p.id == page.id } }
end
def next_page_id(page, log, current_user, ignore_answered: false) def next_page_id(page, log, current_user, ignore_answered: false)
return page.next_unresolved_page_id || :check_answers if log.unresolved return page.next_unresolved_page_id || :check_answers if log.unresolved
page_ids = subsection_for_page(page).pages.map(&:id) page_ids = page.subsection.pages.map(&:id)
page_index = page_ids.index(page.id) page_index = page_ids.index(page.id)
page_id = if page.interruption_screen? && log[page.questions[0].id] == 1 && page.routed_to?(log, current_user) page_id = if page.interruption_screen? && log[page.questions[0].id] == 1 && page.routed_to?(log, current_user)
previous_page_id(page, log, current_user) previous_page_id(page, log, current_user)
@ -104,14 +100,14 @@ class Form
def next_page_redirect_path(page, log, current_user, ignore_answered: false) def next_page_redirect_path(page, log, current_user, ignore_answered: false)
next_page_id = next_page_id(page, log, current_user, ignore_answered:) next_page_id = next_page_id(page, log, current_user, ignore_answered:)
if next_page_id == :check_answers if next_page_id == :check_answers
"#{type}_log_#{subsection_for_page(page).id}_check_answers_path" "#{type}_log_#{page.subsection.id}_check_answers_path"
else else
"#{type}_log_#{next_page_id}_path" "#{type}_log_#{next_page_id}_path"
end end
end end
def previous_page_id(page, log, current_user) def previous_page_id(page, log, current_user)
page_ids = subsection_for_page(page).pages.map(&:id) page_ids = page.subsection.pages.map(&:id)
page_index = page_ids.index(page.id) page_index = page_ids.index(page.id)
return :tasklist if page_index.zero? return :tasklist if page_index.zero?
@ -126,7 +122,7 @@ class Form
def previous_page_redirect_path(page, log, current_user, referrer) def previous_page_redirect_path(page, log, current_user, referrer)
previous_page_id = previous_page_id(page, log, current_user) previous_page_id = previous_page_id(page, log, current_user)
if referrer == "check_answers" if referrer == "check_answers"
"#{type}_log_#{subsection_for_page(page).id}_check_answers_path" "#{type}_log_#{page.subsection.id}_check_answers_path"
elsif previous_page_id == :tasklist elsif previous_page_id == :tasklist
"#{type}_log_path" "#{type}_log_path"
else else

2
app/services/documentation_generator.rb

@ -301,7 +301,7 @@ Look at these helper methods where needed to understand what is being checked in
end end
def save_soft_validation(form, page, validation_descriptions, log_type) def save_soft_validation(form, page, validation_descriptions, log_type)
subsection_pages = form.subsection_for_page(page).pages subsection_pages = page.subsection.pages
page_index = subsection_pages.index(page) page_index = subsection_pages.index(page)
page_the_validation_applied_to = subsection_pages[page_index - 1] page_the_validation_applied_to = subsection_pages[page_index - 1]

Loading…
Cancel
Save