Commit 8efadaec by Alessandro

Add timestamp on success step + refactoring

TNL-925
parent 4c0bf161
define([ define([
'js/views/import', 'jquery', 'gettext', 'jquery.fileupload', 'jquery.cookie' 'domReady', 'js/views/import', 'jquery', 'gettext', 'jquery.fileupload', 'jquery.cookie'
], function(Import, $, gettext) { ], function(domReady, Import, $, gettext) {
'use strict'; 'use strict';
return function (feedbackUrl, library) { return function (feedbackUrl, library) {
var dbError; var dbError;
if (library) { if (library) {
dbError = gettext('There was an error while importing the new library to our database.'); dbError = gettext('There was an error while importing the new library to our database.');
} else { } else {
dbError = gettext('There was an error while importing the new course to our database.'); dbError = gettext('There was an error while importing the new course to our database.');
} }
var bar = $('.progress-bar'), var bar = $('.progress-bar'),
fill = $('.progress-fill'), fill = $('.progress-fill'),
submitBtn = $('.submit-button'), submitBtn = $('.submit-button'),
chooseBtn = $('.choose-file-button'), chooseBtn = $('.view-import .choose-file-button'),
defaults = [ defaults = [
gettext('There was an error during the upload process.') + '\n', gettext('There was an error during the upload process.') + '\n',
gettext('There was an error while unpacking the file.') + '\n', gettext('There was an error while unpacking the file.') + '\n',
gettext('There was an error while verifying the file you submitted.') + '\n', gettext('There was an error while verifying the file you submitted.') + '\n',
dbError + '\n' dbError + '\n'
], ],
// Display the status of last file upload on page load previousImport = Import.storedImport(),
lastFileUpload = $.cookie('lastfileupload'),
file; file;
if (lastFileUpload){ Import.callbacks.complete = function () {
Import.getAndStartUploadFeedback(feedbackUrl.replace('fillerName', lastFileUpload), lastFileUpload); bar.hide();
chooseBtn
.find('.copy').html(gettext("Choose new file")).end()
.show();
};
// Display the status of last file upload on page load
if (previousImport) {
$('.file-name-block')
.find('.file-name').html(previousImport.file.name).end()
.show();
if (previousImport.completed !== true) {
chooseBtn.hide();
}
Import.resume();
} }
$('#fileupload').fileupload({ $('#fileupload').fileupload({
...@@ -33,39 +52,41 @@ define([ ...@@ -33,39 +52,41 @@ define([
maxChunkSize: 20 * 1000000, // 20 MB maxChunkSize: 20 * 1000000, // 20 MB
autoUpload: false, autoUpload: false,
add: function(e, data) { add: function(e, data) {
Import.clearImportDisplay(); Import.reset();
Import.okayToNavigateAway = false;
submitBtn.unbind('click'); submitBtn.unbind('click');
file = data.files[0]; file = data.files[0];
if (file.name.match(/tar\.gz$/)) { if (file.name.match(/tar\.gz$/)) {
submitBtn.click(function(event){ submitBtn.click(function(event) {
event.preventDefault(); event.preventDefault();
$.cookie('lastfileupload', file.name);
Import.start(
file.name,
feedbackUrl.replace('fillerName', file.name)
);
submitBtn.hide(); submitBtn.hide();
Import.startUploadFeedback(); data.submit().complete(function (result, textStatus, xhr) {
data.submit().complete(function(result, textStatus, xhr) { if (xhr.status !== 200) {
window.onbeforeunload = null;
if (xhr.status != 200) {
var serverMsg, errMsg, stage; var serverMsg, errMsg, stage;
try{ try{
serverMsg = $.parseJSON(result.responseText); serverMsg = $.parseJSON(result.responseText);
} catch (e) { } catch (e) {
return; return;
} }
errMsg = serverMsg.hasOwnProperty('ErrMsg') ? serverMsg.ErrMsg : '' ;
errMsg = serverMsg.hasOwnProperty('ErrMsg') ? serverMsg.ErrMsg : '' ;
if (serverMsg.hasOwnProperty('Stage')) { if (serverMsg.hasOwnProperty('Stage')) {
stage = Math.abs(serverMsg.Stage); stage = Math.abs(serverMsg.Stage);
Import.stageError(stage, defaults[stage] + errMsg); Import.error(defaults[stage] + errMsg, stage);
} }
else { else {
alert(gettext('Your import has failed.') + '\n\n' + errMsg); alert(gettext('Your import has failed.') + '\n\n' + errMsg);
} }
chooseBtn.html(gettext('Choose new file')).show();
bar.hide();
} }
Import.stopGetStatus = true;
chooseBtn.html(gettext('Choose new file')).show();
bar.hide();
}); });
}); });
} else { } else {
...@@ -87,30 +108,42 @@ define([ ...@@ -87,30 +108,42 @@ define([
} }
if (percentInt >= doneAt) { if (percentInt >= doneAt) {
bar.hide(); bar.hide();
// Start feedback with delay so that current stage of import properly updates in session
setTimeout( // Start feedback with delay so that current stage of
function () { Import.startServerFeedback(feedbackUrl.replace('fillerName', file.name));}, // import properly updates in session
3000 setTimeout(function () { Import.pollStatus(); }, 3000);
);
} else { } else {
bar.show(); bar.show();
fill.width(percentVal).html(percentVal); fill.width(percentVal).html(percentVal);
} }
}, },
done: function(event, data){
bar.hide();
window.onbeforeunload = null;
Import.displayFinishedImport();
},
start: function(event) {
window.onbeforeunload = function() {
if (!Import.okayToNavigateAway) {
return "${_('Your import is in progress; navigating away will abort it.')}";
}
};
},
sequentialUploads: true, sequentialUploads: true,
notifyOnError: false notifyOnError: false
}); });
var showImportSubmit = function (e) {
var filepath = $(this).val();
if (filepath.substr(filepath.length - 6, 6) === 'tar.gz') {
$('.error-block').hide();
$('.file-name').html($(this).val().replace('C:\\fakepath\\', ''));
$('.file-name-block').show();
chooseBtn.hide();
submitBtn.show();
$('.progress').show();
} else {
$('.error-block').html(gettext('File format not supported. Please upload a file with a <code>tar.gz</code> extension.')).show();
}
};
domReady(function () {
// import form setup
$('.view-import .file-input').bind('change', showImportSubmit);
$('.view-import .choose-file-button, .view-import .choose-file-button-inline').bind('click', function (e) {
e.preventDefault();
$('.view-import .file-input').click();
});
});
}; };
}); });
...@@ -186,6 +186,17 @@ ...@@ -186,6 +186,17 @@
// TYPE: success // TYPE: success
&.item-progresspoint-success { &.item-progresspoint-success {
.item-progresspoint-success-date {
display: none;
margin-left: 5px;
}
&.is-complete {
.item-progresspoint-success-date {
display: inline;
}
}
} }
...@@ -217,6 +228,8 @@ ...@@ -217,6 +228,8 @@
} }
.fa-cog { .fa-cog {
@include animation(fa-spin 2s infinite linear);
visibility: visible; visibility: visible;
opacity: 1.0; opacity: 1.0;
} }
......
...@@ -115,7 +115,7 @@ else: ...@@ -115,7 +115,7 @@ else:
<li class="item-progresspoint item-progresspoint-unpack is-started"> <li class="item-progresspoint item-progresspoint-unpack is-started">
<span class="deco status-visual"> <span class="deco status-visual">
<i class="icon fa fa-cog fa-spin"></i> <i class="icon fa fa-cog"></i>
<i class="icon fa fa-warning"></i> <i class="icon fa fa-warning"></i>
</span> </span>
...@@ -167,7 +167,10 @@ else: ...@@ -167,7 +167,10 @@ else:
</span> </span>
<div class="status-detail"> <div class="status-detail">
<h3 class="title">${_("Success")}</h3> <h3 class="title">
${_("Success")}
<span class="item-progresspoint-success-date"></span>
</h3>
<p class="copy"> <p class="copy">
%if library: %if library:
${_("Your imported content has now been integrated into this library")} ${_("Your imported content has now been integrated into this library")}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment