From 908e81f2c861160079266fe55839ae50304b5e43 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 16 Jan 2024 15:15:00 +0000 Subject: [PATCH] refactor: simplify --- app/helpers/logs_helper.rb | 12 ++++++++---- .../deletion_report.html.erb | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/helpers/logs_helper.rb b/app/helpers/logs_helper.rb index e50c8b140..509208ad4 100644 --- a/app/helpers/logs_helper.rb +++ b/app/helpers/logs_helper.rb @@ -66,10 +66,14 @@ module LogsHelper end def deleted_errors_warning_text(bulk_upload) - unique_field_count = bulk_upload.bulk_upload_errors.uniq(&:field).count - this_or_these = unique_field_count == 1 ? "this" : "these" - it_is_or_they_are = unique_field_count == 1 ? "it is" : "they are" + unique_answers_to_be_cleared_count = unique_answers_to_be_cleared(bulk_upload).count + this_or_these = unique_answers_to_be_cleared_count == 1 ? "this" : "these" + it_is_or_they_are = unique_answers_to_be_cleared_count == 1 ? "it is" : "they are" - "#{pluralize(unique_field_count, 'answer')} will be deleted because #{it_is_or_they_are} invalid. You will have to answer #{this_or_these} #{'question'.pluralize(unique_field_count)} again on the site." + "#{pluralize(unique_answers_to_be_cleared_count, 'answer')} will be deleted because #{it_is_or_they_are} invalid. You will have to answer #{this_or_these} #{'question'.pluralize(unique_answers_to_be_cleared_count)} again on the site." + end + + def unique_answers_to_be_cleared(bulk_upload) + bulk_upload.bulk_upload_errors.reject { |e| e.category == :not_answered }.uniq(&:field) end end diff --git a/app/views/bulk_upload_lettings_results/deletion_report.html.erb b/app/views/bulk_upload_lettings_results/deletion_report.html.erb index 75f60a187..de37c2dee 100644 --- a/app/views/bulk_upload_lettings_results/deletion_report.html.erb +++ b/app/views/bulk_upload_lettings_results/deletion_report.html.erb @@ -5,7 +5,7 @@
Bulk upload for lettings (<%= @bulk_upload.year_combo %>) -

<%= @bulk_upload.bulk_upload_errors.reject { |e| e.category == :not_answered }.uniq(&:field).count == 1 ? "This" : "These" %> <%= pluralize(@bulk_upload.bulk_upload_errors.reject { |e| e.category == :not_answered }.uniq(&:field).count, "answer") %> will be deleted if you upload the <%= "log".pluralize(@bulk_upload.logs.count) %>

+

<%= unique_answers_to_be_cleared(@bulk_upload).count == 1 ? "This" : "These" %> <%= pluralize(unique_answers_to_be_cleared(@bulk_upload).count, "answer") %> will be deleted if you upload the <%= "log".pluralize(@bulk_upload.logs.count) %>

The following cells contain data this is incorrect.

If you upload the logs, these answers will be deleted. You will have to re-enter the data on the site and resolve these errors.