Browse Source

feat: base lettings behaviour

pull/2142/head
natdeanlewissoftwire 2 years ago
parent
commit
495ccefb32
  1. 1
      Gemfile.lock
  2. 6
      app/controllers/bulk_upload_lettings_results_controller.rb
  3. 13
      app/helpers/logs_helper.rb
  4. 4
      app/policies/bulk_upload_policy.rb
  5. 27
      app/views/bulk_upload_lettings_results/deletion_report.html.erb
  6. 10
      app/views/bulk_upload_lettings_resume/confirm.html.erb
  7. 4
      app/views/bulk_upload_lettings_resume/fix_choice.html.erb
  8. 2
      app/views/bulk_upload_sales_resume/fix_choice.html.erb
  9. 1
      config/routes.rb

1
Gemfile.lock

@ -436,6 +436,7 @@ GEM
PLATFORMS PLATFORMS
arm64-darwin-21 arm64-darwin-21
arm64-darwin-22 arm64-darwin-22
arm64-darwin-23
x86_64-darwin-19 x86_64-darwin-19
x86_64-darwin-20 x86_64-darwin-20
x86_64-darwin-21 x86_64-darwin-21

6
app/controllers/bulk_upload_lettings_results_controller.rb

@ -29,6 +29,12 @@ class BulkUploadLettingsResultsController < ApplicationController
authorize @bulk_upload authorize @bulk_upload
end end
def deletion_report
@bulk_upload = BulkUpload.lettings.find(params[:id])
authorize @bulk_upload
end
private private
def reset_logs_filters def reset_logs_filters

13
app/helpers/logs_helper.rb

@ -49,9 +49,10 @@ module LogsHelper
end end
def logs_and_errors_warning(bulk_upload) def logs_and_errors_warning(bulk_upload)
this_or_these_errors = bulk_upload.bulk_upload_errors.count == 1 ? "This error" : "These errors" is_or_are = bulk_upload.total_logs_count == 1 ? "is" : "are"
need_or_needs = bulk_upload.bulk_upload_errors.count == 1 ? "needs" : "need"
"You will upload #{pluralize(bulk_upload.total_logs_count, 'log')}. There are errors in #{pluralize(bulk_upload.logs_with_errors_count, 'log')}, and #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in total. #{this_or_these_errors} will need to be fixed on the CORE site." "There #{is_or_are} #{pluralize(bulk_upload.total_logs_count, 'log')} in this bulk upload with #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} that still #{need_or_needs} to be fixed after upload."
end end
def logs_and_soft_validations_warning(bulk_upload) def logs_and_soft_validations_warning(bulk_upload)
@ -63,4 +64,12 @@ module LogsHelper
def bulk_upload_error_summary(bulk_upload) def bulk_upload_error_summary(bulk_upload)
"You have tried to upload #{bulk_upload.total_logs_count ? pluralize(bulk_upload.total_logs_count, 'log') : 'logs'}. There are errors in #{pluralize(bulk_upload.logs_with_errors_count, 'log')}, and #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in total." "You have tried to upload #{bulk_upload.total_logs_count ? pluralize(bulk_upload.total_logs_count, 'log') : 'logs'}. There are errors in #{pluralize(bulk_upload.logs_with_errors_count, 'log')}, and #{pluralize(bulk_upload.bulk_upload_errors.count, 'error')} in total."
end end
def deleted_errors_warning_text(bulk_upload)
unique_field_count = bulk_upload.bulk_upload_errors.uniq { |e| e.field }.count
this_or_these = unique_field_count == 1 ? "this" : "these"
it_is_or_they_are = unique_field_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."
end
end end

4
app/policies/bulk_upload_policy.rb

@ -18,6 +18,10 @@ class BulkUploadPolicy
owner? || same_org? || user.support? owner? || same_org? || user.support?
end end
def deletion_report?
owner? || same_org? || user.support?
end
private private
def owner? def owner?

27
app/views/bulk_upload_lettings_results/deletion_report.html.erb

@ -0,0 +1,27 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l"><%= @bulk_upload.bulk_upload_errors.count == 1 ? "This" : "These" %> <%= pluralize(@bulk_upload.bulk_upload_errors.count, "answer") %> will be deleted if you upload the logs</h1>
<p>The following cells contain data this is incorrect.</p>
<p>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.</p>
<p>If you do not want these answers to be deleted, correct the data in the CSV and upload the file again.</p>
<h2 class="govuk-heading-m">File: <%= @bulk_upload.filename %></h2>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<% @bulk_upload.bulk_upload_errors.order_by_row.order_by_cell.group_by(&:row).each do |_row, errors_for_row| %>
<%= render BulkUploadErrorRowComponent.new(bulk_upload_errors: errors_for_row) %>
<% end %>
</div>
</div>
<div class="govuk-button-group">
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit "Clear this data and upload the logs" %>
<%= govuk_button_link_to "I have fixed these errors and I want to reupload the file", start_bulk_upload_lettings_logs_path, secondary: true %>
<% end %>
</div>

10
app/views/bulk_upload_lettings_resume/confirm.html.erb

@ -5,9 +5,15 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span> <span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span>
<h1 class="govuk-heading-l">You have chosen to upload all logs from this bulk upload.</h1> <h1 class="govuk-heading-l">Are you sure you want to upload all logs from this bulk upload?</h1>
<p class="govuk-body"><%= logs_and_errors_warning(@bulk_upload) %></p> <p class="govuk-body">
<%= logs_and_errors_warning(@bulk_upload) %>
<%= govuk_link_to "View the error report", deletion_report_bulk_upload_lettings_result_path %>
</p>
<%= govuk_warning_text text: deleted_errors_warning_text(@bulk_upload) %>
<%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %> <%= form_with model: @form, scope: :form, url: page_bulk_upload_lettings_resume_path(@bulk_upload, page: "confirm"), method: :patch do |f| %>
<%= f.govuk_submit "Confirm" %> <%= f.govuk_submit "Confirm" %>

4
app/views/bulk_upload_lettings_resume/fix_choice.html.erb

@ -18,6 +18,10 @@
<%= @form.recommendation %> <%= @form.recommendation %>
</div> </div>
<div class="govuk-body">
<%= govuk_link_to "View the error report", deletion_report_bulk_upload_lettings_result_path %>
</div>
<%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %> <%= govuk_details(summary_text: "How to choose between fixing errors on the CORE site or in the CSV") do %>
<p class="govuk-body govuk-!-margin-bottom-2">You may find it easier to fix the errors in the CSV file if:</p> <p class="govuk-body govuk-!-margin-bottom-2">You may find it easier to fix the errors in the CSV file if:</p>
<ul class="govuk-list govuk-list--bullet"> <ul class="govuk-list govuk-list--bullet">

2
app/views/bulk_upload_sales_resume/fix_choice.html.erb

@ -39,7 +39,7 @@
:name, :name,
legend: { hidden: true } %> legend: { hidden: true } %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<%= f.govuk_submit %> <%= f.govuk_submit %>
<% if @soft_errors_only %> <% if @soft_errors_only %>
<%= govuk_button_link_to "Cancel", bulk_upload_sales_soft_validations_check_url(@bulk_upload, page: "confirm-soft-errors"), secondary: true %> <%= govuk_button_link_to "Cancel", bulk_upload_sales_soft_validations_check_url(@bulk_upload, page: "confirm-soft-errors"), secondary: true %>

1
config/routes.rb

@ -219,6 +219,7 @@ Rails.application.routes.draw do
member do member do
get :resume get :resume
get :summary get :summary
get "deletion-report"
end end
end end

Loading…
Cancel
Save