mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-19 05:13:00 +08:00
Spinner now doesn't hide prematurally on file uploading. Some recently introduced bugs quickfixes (report images not showing, locale missplealing, client-side blank tables deletion deleted all tables, error if no asset present in a step).
This commit is contained in:
parent
04d9163ff6
commit
782d384e26
8 changed files with 49 additions and 29 deletions
app
assets/javascripts
controllers
helpers
|
@ -139,12 +139,12 @@
|
|||
}
|
||||
|
||||
/*
|
||||
* Validates files on server and uploads them to S3 server.
|
||||
* Spoof checks files on server and uploads them to S3 server.
|
||||
*
|
||||
* First we asyncronously validate files on server and generate post requests
|
||||
* (fetchUploadSignature), if OK the post requests are used to uplaod files
|
||||
* asyncronously to S3 (uploadFile), and if successful the form is submitted,
|
||||
* otherwise no file is saved and errors are shown.
|
||||
* First we asyncronously spoof check files on server and generate post
|
||||
* requests (fetchUploadSignature), if OK the post requests are used to uplaod
|
||||
* files asyncronously to S3 (uploadFile), and if successful the form is
|
||||
* submitted, otherwise no file is saved and errors are shown.
|
||||
* If any post fails, the user is allowed to leave the page, but other files
|
||||
* are still being uploaded because of asynchronous behaviour, so that errors
|
||||
* for other files can still show afterwards.
|
||||
|
@ -171,7 +171,7 @@
|
|||
preventLeavingPage(true, I18n.t("general.file.uploading"));
|
||||
ev.preventDefault();
|
||||
|
||||
// Validates files and if OK gets upload post requests
|
||||
// Spoof checks files and, if OK, gets upload post requests
|
||||
_.each($fileInputs, function (fileInput) {
|
||||
var file = fileInput.files[0];
|
||||
if (!_.isUndefined(file)) {
|
||||
|
@ -182,7 +182,7 @@
|
|||
});
|
||||
|
||||
$.when.apply($, signRequests).then(function () {
|
||||
// After successful file validation and posts fetching
|
||||
// After successful file spoof check and upload post requests fetching
|
||||
if (signRequests.length) {
|
||||
var fileRequests = [];
|
||||
|
||||
|
@ -196,16 +196,21 @@
|
|||
processPosts(ev, $fileInput, data.posts, fileRequests);
|
||||
});
|
||||
|
||||
$.when.apply($, fileRequests).always(function () {
|
||||
$.when.apply($, fileRequests).then(function () {
|
||||
// After successful posts processing and file uploading
|
||||
$form.onAjaxComplete(function () {
|
||||
animateSpinner(null, false);
|
||||
preventLeavingPage(false);
|
||||
});
|
||||
$form.submit();
|
||||
}, function() {
|
||||
// After unsuccessful posts processing and file uploading
|
||||
animateSpinner(null, false);
|
||||
preventLeavingPage(false);
|
||||
}).then(function () {
|
||||
// After successful posts processing and file uploading
|
||||
$form.submit();
|
||||
});
|
||||
}
|
||||
}, function () {
|
||||
// After unsuccessful file validation and posts fetching
|
||||
// After unsuccessful file spoof check and posts fetching
|
||||
animateSpinner(null, false);
|
||||
preventLeavingPage(false);
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ $.fn.removeBlankFileForms = function () {
|
|||
*/
|
||||
$.fn.removeBlankExcelTables = function (editMode) {
|
||||
if(editMode) {
|
||||
$tables = $(this).find(".handsontable");
|
||||
$tables = $(this).find("[data-role='editable-table']");
|
||||
// In edit mode, tables can't be blank
|
||||
$tables.each(function () {
|
||||
if (!$(this).find("td:not(:empty)").length) {
|
||||
|
@ -35,4 +35,4 @@ $.fn.removeBlankExcelTables = function (editMode) {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ function filesValidator(ev, fileInputs, fileTypeEnum) {
|
|||
if (fileInputs.length) {
|
||||
var filesPresentValid = filesPresentValidator(ev, fileInputs);
|
||||
var filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum);
|
||||
// TODO File content check
|
||||
// File spoof check is done on server-side only
|
||||
filesValid = filesPresentValid && filesSizeValid;
|
||||
}
|
||||
return filesValid;
|
||||
|
@ -129,7 +129,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
|||
});
|
||||
if(filesSizeValid) {
|
||||
// Check if there is enough free space for the files
|
||||
filesSizeValid = enaughSpaceValidator(ev, fileInputs);
|
||||
filesSizeValid = enoughSpaceValidator(ev, fileInputs);
|
||||
}
|
||||
return filesSizeValid;
|
||||
}
|
||||
|
@ -138,6 +138,6 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
|||
* Overriden in billing module for checking whether enough
|
||||
* organization space is free.
|
||||
*/
|
||||
function enaughSpaceValidator(ev, fileInputs) {
|
||||
function enoughSpaceValidator(ev, fileInputs) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,4 +13,4 @@ function goToFormElement(input) {
|
|||
"slow",
|
||||
function() { $(input).focus(); }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* Converts JSON data received from the server to flat array
|
||||
* of values.
|
||||
* Converts JSON data received from the server to flat array of values.
|
||||
*/
|
||||
function jsonToValuesArray(jsonData) {
|
||||
errMsgs =[];
|
||||
|
@ -12,3 +11,17 @@ function jsonToValuesArray(jsonData) {
|
|||
}
|
||||
return errMsgs;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls callback function on AJAX success (because built-in functions don't
|
||||
* work!)
|
||||
*/
|
||||
$.fn.onAjaxComplete = function (cb) {
|
||||
$(this)
|
||||
.on("ajax:success", function() {
|
||||
cb();
|
||||
})
|
||||
.on("ajax:error", function() {
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,14 +35,16 @@ class StepsController < ApplicationController
|
|||
step_assets = step_params.slice(:assets_attributes)
|
||||
@step = Step.new(step_data)
|
||||
|
||||
step_assets[:assets_attributes].each do |_i, data|
|
||||
# Ignore destroy requests on create
|
||||
next if data[:_destroy].present?
|
||||
unless step_assets[:assets_attributes].nil?
|
||||
step_assets[:assets_attributes].each do |_i, data|
|
||||
# Ignore destroy requests on create
|
||||
next if data[:_destroy].present?
|
||||
|
||||
asset = Asset.new(data)
|
||||
asset.created_by = current_user
|
||||
asset.last_modified_by = current_user
|
||||
new_assets << asset
|
||||
asset = Asset.new(data)
|
||||
asset.created_by = current_user
|
||||
asset.last_modified_by = current_user
|
||||
new_assets << asset
|
||||
end
|
||||
end
|
||||
@step.assets << new_assets
|
||||
else
|
||||
|
|
|
@ -11,7 +11,7 @@ module AssetsHelper
|
|||
data-download-url='#{download_asset_path(asset)}'
|
||||
>
|
||||
<span class='asset-loading-spinner' id='asset-loading-spinner-#{asset.id}'></span>
|
||||
#{t('general.file.loading', fileName: asset.file_file_name)}
|
||||
#{t('general.file.uploading', fileName: asset.file_file_name)}
|
||||
</span>
|
||||
<script type='text/javascript'>
|
||||
$('#asset-loading-spinner-#{asset.id}').spin(
|
||||
|
|
|
@ -81,7 +81,7 @@ end
|
|||
def report_image_asset_url(asset)
|
||||
prefix = (ENV["PAPERCLIP_STORAGE"].present? && ENV["MAIL_SERVER_URL"].present? && ENV["PAPERCLIP_STORAGE"] == "filesystem") ? ENV["MAIL_SERVER_URL"] : ""
|
||||
prefix = (!prefix.empty? && !prefix.include?("http://") && !prefix.include?("https://")) ? "http://#{prefix}" : prefix
|
||||
url = prefix + asset.file.url(:medium)
|
||||
url = prefix + asset.presigned_url(:medium, time: 86_400)
|
||||
image_tag(url)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue