Browse Source

Fix lint

pull/2653/head
Manny Dinssa 2 years ago
parent
commit
6bd7a37150
  1. 4
      app/components/bulk_upload_summary_component.rb
  2. 2
      app/controllers/lettings_logs_controller.rb
  3. 2
      app/controllers/sales_logs_controller.rb
  4. 31
      app/helpers/bulk_upload_helper.rb
  5. 1
      app/helpers/filters_helper.rb
  6. 2
      app/models/bulk_upload.rb

4
app/components/bulk_upload_summary_component.rb

@ -53,13 +53,17 @@ class BulkUploadSummaryComponent < ViewComponent::Base
def view_error_report_link(bulk_upload) def view_error_report_link(bulk_upload)
return nil if %w[errors_fixed_in_service logs_uploaded_with_errors logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s) return nil if %w[errors_fixed_in_service logs_uploaded_with_errors logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s)
return link_to "View error report", send("summary_bulk_upload_#{bulk_upload.log_type}_result_url", bulk_upload), class: "govuk-link" if %w[important_errors].include?(bulk_upload.status.to_s) return link_to "View error report", send("summary_bulk_upload_#{bulk_upload.log_type}_result_url", bulk_upload), class: "govuk-link" if %w[important_errors].include?(bulk_upload.status.to_s)
link_to "View error report", send("bulk_upload_#{bulk_upload.log_type}_result_path", bulk_upload.id), class: "govuk-link" link_to "View error report", send("bulk_upload_#{bulk_upload.log_type}_result_path", bulk_upload.id), class: "govuk-link"
end end
def view_logs_link(bulk_upload) def view_logs_link(bulk_upload)
return nil if %w[errors_fixed_in_service logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s) return nil if %w[errors_fixed_in_service logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s)
return nil unless %w[logs_uploaded_with_errors].include?(bulk_upload.status.to_s) return nil unless %w[logs_uploaded_with_errors].include?(bulk_upload.status.to_s)
link_to "View logs", send("#{bulk_upload.log_type}_logs_path", bulk_upload_id: [bulk_upload.id]), class: "govuk-link" link_to "View logs", send("#{bulk_upload.log_type}_logs_path", bulk_upload_id: [bulk_upload.id]), class: "govuk-link"
end end
end end

2
app/controllers/lettings_logs_controller.rb

@ -134,7 +134,7 @@ class LettingsLogsController < LogsController
def download_bulk_upload def download_bulk_upload
bulk_upload = BulkUpload.find(params[:id]) bulk_upload = BulkUpload.find(params[:id])
downloader = BulkUpload::Downloader.new(bulk_upload: bulk_upload) downloader = BulkUpload::Downloader.new(bulk_upload:)
downloader.call downloader.call
send_file downloader.file_path, filename: bulk_upload.filename, type: "text/csv" send_file downloader.file_path, filename: bulk_upload.filename, type: "text/csv"

2
app/controllers/sales_logs_controller.rb

@ -104,7 +104,7 @@ class SalesLogsController < LogsController
def download_bulk_upload def download_bulk_upload
bulk_upload = BulkUpload.find(params[:id]) bulk_upload = BulkUpload.find(params[:id])
downloader = BulkUpload::Downloader.new(bulk_upload: bulk_upload) downloader = BulkUpload::Downloader.new(bulk_upload:)
downloader.call downloader.call
send_file downloader.file_path, filename: bulk_upload.filename, type: "text/csv" send_file downloader.file_path, filename: bulk_upload.filename, type: "text/csv"

31
app/helpers/bulk_upload_helper.rb

@ -9,35 +9,4 @@ module BulkUploadHelper
"Bulk uploads" "Bulk uploads"
end end
end end
def bulk_upload_status(bulk_upload)
validator = validator_class(bulk_upload).new(bulk_upload: bulk_upload, path: bulk_upload.file_path)
if validator.invalid?
"The bulk upload has failed due to validation errors."
elsif validator.any_setup_errors?
"The bulk upload has setup errors."
elsif validator.soft_validation_errors_only?
"The bulk upload has soft validation errors."
elsif bulk_upload.logs.where.not(status_cache: %w[completed]).count.positive?
"The bulk upload has created logs but some are incomplete."
elsif bulk_upload.logs.group(:status_cache).count.keys == %w[completed]
"The bulk upload has successfully completed."
else
"The bulk upload status is unknown."
end
end
private
def validator_class(bulk_upload)
case bulk_upload.log_type
when "lettings"
BulkUpload::Lettings::Validator
when "sales"
BulkUpload::Sales::Validator
else
raise "Validator not found for #{bulk_upload.log_type}"
end
end
end end

1
app/helpers/filters_helper.rb

@ -21,6 +21,7 @@ module FiltersHelper
return true if (selected_filters["uploading_organisation"].present? || selected_filters["uploading_organisation_text_search"].present?) && filter == "uploading_organisation_select" && value == :specific_org return true if (selected_filters["uploading_organisation"].present? || selected_filters["uploading_organisation_text_search"].present?) && filter == "uploading_organisation_select" && value == :specific_org
return false if selected_filters[filter].blank? return false if selected_filters[filter].blank?
selected_filters[filter].include?(value.to_s) selected_filters[filter].include?(value.to_s)
end end

2
app/models/bulk_upload.rb

@ -34,7 +34,7 @@ class BulkUpload < ApplicationRecord
scope :filter_by_uploaded_by, ->(user_id, _user = nil) { where(user_id:) } scope :filter_by_uploaded_by, ->(user_id, _user = nil) { where(user_id:) }
scope :filter_by_user_text_search, ->(param, _user = nil) { where(user_id: User.search_by(param).select(:id)) } scope :filter_by_user_text_search, ->(param, _user = nil) { where(user_id: User.search_by(param).select(:id)) }
scope :filter_by_user, ->(user_id, _user = nil) { user_id.present? ? where(user_id:) : all } scope :filter_by_user, ->(user_id, _user = nil) { user_id.present? ? where(user_id:) : all }
scope :filter_by_uploading_organisation , ->(organisation_id, _user = nil) { where(user_id: User.where(organisation_id: organisation_id).select(:id)) } scope :filter_by_uploading_organisation, ->(organisation_id, _user = nil) { where(user_id: User.where(organisation_id:).select(:id)) }
def completed? def completed?
incomplete_logs = logs.where.not(status: "completed") incomplete_logs = logs.where.not(status: "completed")

Loading…
Cancel
Save