-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,241 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ruby 2.3.1 | ||
bundler 1.17.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 1.0.0 | ||
|
||
Site has been released for a long time, but starting at 1.0.0 for the purposes of adding a change log | ||
|
||
- use date_discovery for date filtering instead of created_at | ||
- rake task to fix non-breaking spaces and  character in database | ||
- process strings during import to prevent the above issue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
class BulkUploadsController < ApplicationController | ||
before_action :authenticate_user! | ||
load_and_authorize_resource | ||
|
||
def show | ||
end | ||
def show; end | ||
|
||
def index | ||
@bulk_uploads = BulkUpload.includes(:reports).order(:created_at).page(params[:page]) | ||
end | ||
|
||
def new | ||
end | ||
def new; end | ||
|
||
def edit | ||
@bulk_upload = BulkUpload.find(params[:id]) or raise_404 | ||
(@bulk_upload = BulkUpload.find(params[:id])) || raise_404 | ||
end | ||
|
||
def update | ||
redirect_to(:back) and return if params[:file].nil? | ||
redirect_to(:back) && return if params[:file].nil? | ||
|
||
result = CsvImporter.import(params[:file].path) | ||
@bulk_upload = BulkUpload.find(params[:id]) or raise_404 | ||
(@bulk_upload = BulkUpload.find(params[:id])) || raise_404 | ||
@bulk_upload.update(result) | ||
|
||
if result[:successful] | ||
redirect_to @bulk_upload, flash: {success: t("bulk_uploads.upload_successful")} | ||
redirect_to @bulk_upload, flash: { success: t('bulk_uploads.upload_successful') } | ||
else | ||
redirect_to @bulk_upload, flash: {error: t("bulk_uploads.upload_error")} | ||
redirect_to @bulk_upload, flash: { error: t('bulk_uploads.upload_error') } | ||
end | ||
end | ||
|
||
def create | ||
redirect_to(:back) and return if params[:file].nil? | ||
redirect_to(:back) && return unless params[:files].present? | ||
|
||
result = CsvImporter.import(params[:file].path) | ||
if result[:successful] | ||
redirect_to BulkUpload.create(result), flash: {success: t("bulk_uploads.upload_successful")} | ||
else | ||
redirect_to BulkUpload.create(result), flash: {error: t("bulk_uploads.upload_error")} | ||
results = [] # store of all this BulkUpload's reports (successful and not) | ||
blocking_files = [] # store of this BulkUpload's invalid files ( { filename:, error_messages: } ) | ||
|
||
ActiveRecord::Base.transaction do | ||
params[:files].each do |file| | ||
import = CsvImporter.import file.path | ||
results << import | ||
|
||
next if import[:successful] | ||
|
||
blocking_files.push({ | ||
filename: file.original_filename, | ||
error_messages: import[:happy_accidents].map { |hash| hash[:message] }.uniq | ||
}) | ||
end | ||
|
||
raise ActiveRecord::Rollback unless blocking_files.empty? | ||
|
||
# Only reached if no files are 'blocking' | ||
results.each { |_result| BulkUpload.create results } | ||
return redirect_to bulk_uploads_path, flash: { success: t('bulk_uploads.upload_successful') } | ||
end | ||
|
||
error_message = generate_bulk_upload_error_message(blocking_files) | ||
|
||
redirect_to bulk_uploads_path, flash: { error: error_message } | ||
end | ||
|
||
def destroy | ||
bulk_upload = BulkUpload.find(params[:id]) or raise_404 | ||
(bulk_upload = BulkUpload.find(params[:id])) || raise_404 | ||
bulk_upload.destroy | ||
|
||
redirect_to action: :index, notice: "That bulk upload has been successfully deleted from the system. Thank you!" | ||
redirect_to action: :index, notice: 'That bulk upload has been successfully deleted from the system. Thank you!' | ||
end | ||
|
||
private | ||
|
||
def generate_bulk_upload_error_message(blocking_files) | ||
error_message = t('bulk_uploads.upload_error') | ||
tab = " " * 4 | ||
|
||
|
||
blocking_files.each do |file| | ||
error_message += [ | ||
file[:filename], | ||
file[:error_messages].map { |message| tab + message }.flatten | ||
].join("<br>") | ||
end | ||
|
||
error_message | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ | |
# | ||
|
||
class BulkUpload < ActiveRecord::Base | ||
has_many :reports | ||
has_many :reports, dependent: :destroy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.