New code for import routine, part 3

This commit is contained in:
James Cole
2017-12-16 19:47:14 +01:00
parent 9086259a65
commit 8176356509
11 changed files with 428 additions and 90 deletions

View File

@@ -18,7 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: jobImportUrl, langImportSingleError, langImportMultiError, jobStartUrl, langImportTimeOutError, langImportFinished, langImportFatalError */
/** global: langImportSingleError, langImportMultiError, jobStartUrl, langImportTimeOutError, langImportFinished, langImportFatalError */
var timeOutId;
var startInterval = 1000;
@@ -34,9 +34,10 @@ var knownErrors = 0;
$(function () {
"use strict";
timeOutId = setTimeout(checkImportStatus, startInterval);
timeOutId = setTimeout(checkJobStatus, startInterval);
$('.start-job').click(startJob);
if(autoStart) {
if (job.configuration['auto-start']) {
startJob();
}
});
@@ -44,14 +45,14 @@ $(function () {
/**
* Downloads some JSON and responds to its content to see what the status is of the current import.
*/
function checkImportStatus() {
$.getJSON(jobImportUrl).done(reportOnJobImport).fail(failedJobImport);
function checkJobStatus() {
$.getJSON(jobStatusUri).done(reportOnJobStatus).fail(reportFailedJob);
}
/**
* This method is called when the JSON query returns an error. If possible, this error is relayed to the user.
*/
function failedJobImport(jqxhr, textStatus, error) {
function reportFailedJob(jqxhr, textStatus, error) {
// hide all possible boxes:
$('.statusbox').hide();
@@ -70,13 +71,15 @@ function failedJobImport(jqxhr, textStatus, error) {
*
* @param data
*/
function reportOnJobImport(data) {
function reportOnJobStatus(data) {
switch (data.status) {
case "configured":
// job is ready. Do not check again, just show the start-box. Hide the rest.
$('.statusbox').hide();
$('.status_configured').show();
if (!job.configuration['auto-start']) {
$('.statusbox').hide();
$('.status_configured').show();
}
break;
case "running":
// job is running! Show the running box:
@@ -97,7 +100,7 @@ function reportOnJobImport(data) {
showStalledBox();
} else {
// check again in 500ms
timeOutId = setTimeout(checkImportStatus, interval);
timeOutId = setTimeout(checkJobStatus, interval);
}
break;
case "finished":
@@ -106,6 +109,19 @@ function reportOnJobImport(data) {
// show text:
$('#import-status-more-info').html(data.finishedText);
break;
case "errored":
// TODO this view is not yet used.
// hide all possible boxes:
$('.statusbox').hide();
// fill in some details:
var errorMessage = data.error_message;
$('.fatal_error_txt').text(errorMessage);
// show the fatal error box:
$('.fatal_error').show();
break;
default:
break;
@@ -147,13 +163,16 @@ function jobIsStalled(data) {
function startJob() {
// disable the button, add loading thing.
$('.start-job').prop('disabled', true).text('...');
$.post(jobStartUrl).fail(reportOnSubmitError);
$.post(jobStartUri).fail(reportOnSubmitError);
// check status, every 500 ms.
timeOutId = setTimeout(checkImportStatus, startInterval);
timeOutId = setTimeout(checkJobStatus, startInterval);
}
function reportOnSubmitError() {
/**
* When the start button fails (returns error code) this function reports. It assumes a time out.
*/
function reportOnSubmitError(jqxhr, textStatus, error) {
// stop the refresh thing
clearTimeout(timeOutId);
@@ -161,7 +180,7 @@ function reportOnSubmitError() {
$('.statusbox').hide();
// fill in some details:
var errorMessage = "Time out while waiting for job to finish.";
var errorMessage = "Submitting the job returned an error: " + textStatus + ' ' + error;
$('.fatal_error_txt').text(errorMessage);