9 changed files with 289 additions and 54 deletions
@ -0,0 +1,75 @@ |
|||||||
|
class CheckErrorsController < ApplicationController |
||||||
|
include DuplicateLogsHelper |
||||||
|
|
||||||
|
before_action :authenticate_user! |
||||||
|
before_action :find_resource_by_named_id |
||||||
|
|
||||||
|
def confirm_clear_answer |
||||||
|
return render_not_found unless @log |
||||||
|
|
||||||
|
@related_question_ids = params["lettings_log"].keys.reject { |id| id == "page_id" } |
||||||
|
question_id = @related_question_ids.find { |id| !params[id].nil? } |
||||||
|
@question = @log.form.get_question(question_id, @log) |
||||||
|
@page = @log.form.get_page(params["lettings_log"]["page_id"]) |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def find_resource_by_named_id |
||||||
|
@log = if params[:sales_log_id].present? |
||||||
|
current_user.sales_logs.visible.find_by(id: params[:sales_log_id]) |
||||||
|
else |
||||||
|
current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id]) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
# def restore_error_field_values(questions) |
||||||
|
# return unless questions |
||||||
|
|
||||||
|
# questions.each do |question| |
||||||
|
# if question&.type == "date" && @log.attributes.key?(question.id) |
||||||
|
# @log[question.id] = @log.send("#{question.id}_was") |
||||||
|
# end |
||||||
|
# end |
||||||
|
# end |
||||||
|
|
||||||
|
def responses_for_page(page) |
||||||
|
page.questions.each_with_object({}) do |question, result| |
||||||
|
question_params = params[@log.model_name.param_key][question.id] |
||||||
|
if question.type == "date" |
||||||
|
day = params[@log.model_name.param_key]["#{question.id}(3i)"] |
||||||
|
month = params[@log.model_name.param_key]["#{question.id}(2i)"] |
||||||
|
year = params[@log.model_name.param_key]["#{question.id}(1i)"] |
||||||
|
next unless [day, month, year].any?(&:present?) |
||||||
|
|
||||||
|
result[question.id] = if Date.valid_date?(year.to_i, month.to_i, day.to_i) && year.to_i.positive? |
||||||
|
Date.new(year.to_i, month.to_i, day.to_i) |
||||||
|
else |
||||||
|
Date.new(0, 1, 1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
if question.id == "saledate" && set_managing_organisation_to_assigned_to_organisation?(result["saledate"]) |
||||||
|
result["managing_organisation_id"] = @log.assigned_to.organisation_id |
||||||
|
end |
||||||
|
|
||||||
|
next unless question_params |
||||||
|
|
||||||
|
if %w[checkbox validation_override].include?(question.type) |
||||||
|
question.answer_keys_without_dividers.each do |option| |
||||||
|
result[option] = question_params.include?(option) ? 1 : 0 |
||||||
|
end |
||||||
|
else |
||||||
|
result[question.id] = question_params |
||||||
|
end |
||||||
|
|
||||||
|
if question.id == "owning_organisation_id" |
||||||
|
owning_organisation = result["owning_organisation_id"].present? ? Organisation.find(result["owning_organisation_id"]) : nil |
||||||
|
|
||||||
|
result["managing_organisation_id"] = owning_organisation.id if set_managing_organisation_to_owning_organisation?(owning_organisation) |
||||||
|
end |
||||||
|
|
||||||
|
result |
||||||
|
end |
||||||
|
end |
@ -1,23 +0,0 @@ |
|||||||
class CheckYourErrorsController < ApplicationController |
|
||||||
include DuplicateLogsHelper |
|
||||||
|
|
||||||
before_action :authenticate_user! |
|
||||||
before_action :find_resource_by_named_id |
|
||||||
|
|
||||||
def index |
|
||||||
return render_not_found unless @log |
|
||||||
|
|
||||||
related_question_ids = params[:related_question_ids] |
|
||||||
@questions = @log.form.questions.select { |q| related_question_ids.include?(q.id.to_s) } |
|
||||||
end |
|
||||||
|
|
||||||
private |
|
||||||
|
|
||||||
def find_resource_by_named_id |
|
||||||
@log = if params[:sales_log_id].present? |
|
||||||
current_user.sales_logs.visible.find_by(id: params[:sales_log_id]) |
|
||||||
else |
|
||||||
current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id]) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,31 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% content_for :title, "Are you sure you want to clear #{@question.check_answer_label}?" %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<h1 class="govuk-heading-xl"> |
||||||
|
<%= content_for(:title) %> |
||||||
|
</h1> |
||||||
|
|
||||||
|
<%= govuk_warning_text(text: "This action is permanent") %> |
||||||
|
<%= form_with model: @log, url: send("lettings_log_#{@page.id}_path", @log), method: "post", local: true do |f| %> |
||||||
|
|
||||||
|
<% @related_question_ids.each do |id| %> |
||||||
|
<%= f.hidden_field id, value: @log[id] %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= f.hidden_field :clear_question_id, value: @question.id %> |
||||||
|
<%= f.hidden_field :page, value: @page.id %> |
||||||
|
|
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit "Confirm and continue", name: "check_errors" %> |
||||||
|
<%= govuk_button_link_to( |
||||||
|
"Cancel", |
||||||
|
"javascript:history.back()", |
||||||
|
secondary: true, |
||||||
|
) %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -1,20 +1,63 @@ |
|||||||
<div class="govuk-grid-row"> |
<div class="govuk-grid-row"> |
||||||
<div class="govuk-grid-column-three-quarters-from-desktop"> |
<div class="govuk-grid-column-three-quarters-from-desktop"> |
||||||
<%= form_with model: @log, url: request.original_url, method: "post", local: true do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<h1 class="govuk-heading-m govuk-!-margin-bottom-6"> |
|
||||||
<span class="govuk-grid-column-two-thirds"> |
<%= form_with model: @log, url: lettings_log_confirm_clear_answer_path(@log), method: "post", local: true do |f| %> |
||||||
Make sure these answers are correct: |
<%= f.govuk_error_summary %> |
||||||
</span> |
<%= f.hidden_field :page_id, value: @page.id %> |
||||||
<span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third"> |
|
||||||
<%= govuk_link_to "Clear all", lettings_log_confirm_clear_all_answers_path(@log) %> |
<h1 class="govuk-heading-m govuk-!-margin-bottom-6"> |
||||||
</span> |
<span class="govuk-grid-column-two-thirds"> |
||||||
</h1> |
Make sure these answers are correct: |
||||||
|
</span> |
||||||
|
<span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third"> |
||||||
|
<%= govuk_link_to "Clear all", lettings_log_confirm_clear_all_answers_path(@log) %> |
||||||
|
</span> |
||||||
|
</h1> |
||||||
|
|
||||||
|
<div class="govuk-summary-card__content"> |
||||||
|
<% applicable_questions = @questions.reject { |q| q.hidden_in_check_answers?(@log, current_user) }%> |
||||||
|
<% applicable_questions.each do |question| %> |
||||||
|
<%= f.hidden_field question.id, value: @log[question.id] %> |
||||||
|
<dl class="govuk-summary-list"> |
||||||
|
<div class="govuk-summary-list__row"> |
||||||
|
<dt class="govuk-summary-list__key"> |
||||||
|
<%= get_question_label(question) %> |
||||||
|
</dt> |
||||||
|
<dd class="govuk-summary-list__value"> |
||||||
|
<%= simple_format( |
||||||
|
get_answer_label(question, @log), |
||||||
|
wrapper_tag: "span", |
||||||
|
class: "govuk-!-margin-right-4", |
||||||
|
) %> |
||||||
|
|
||||||
<%= render CheckAnswersSummaryListCardComponent.new(questions: @questions, log: @log, user: current_user, correcting_hard_validation: true) %> |
<% extra_value = question.get_extra_check_answer_value(@log) %> |
||||||
|
|
||||||
|
<% if extra_value && question.answer_label(@log).present? %> |
||||||
|
<%= simple_format( |
||||||
|
extra_value, |
||||||
|
wrapper_tag: "span", |
||||||
|
class: "govuk-!-font-weight-regular app-!-colour-muted", |
||||||
|
) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<% question.get_inferred_answers(@log).each do |inferred_answer| %> |
||||||
|
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> |
||||||
|
<% end %> |
||||||
|
</dd> |
||||||
|
<dd class="govuk-summary-list__actions"> |
||||||
|
<% if question.displayed_as_answered?(@log) %> |
||||||
|
<input type="submit" value="Clear" name=<%= question.id %> class="govuk-body govuk-link submit-button-link" > |
||||||
|
<% else %> |
||||||
|
<%= govuk_link_to "Answer", send("#{@log.model_name.param_key}_#{question.page.id}_path", @log, referrer: "check_errors", original_page_id: @page.id, related_question_ids: applicable_questions.map(&:id)) %> |
||||||
|
<% end %> |
||||||
|
</dd> |
||||||
|
</div> |
||||||
|
</dl> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
|
||||||
<%= govuk_button_link_to "Confirm and continue", "/" %> |
<%= govuk_button_link_to "Confirm and continue", "/" %> |
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
|
Loading…
Reference in new issue