diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index ba58c4d113..9b40c428c9 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -54,7 +54,7 @@ class ImportController extends Controller if (!$this->jobInCorrectStep($job, 'complete')) { return $this->redirectToCorrectStep($job); } - $subTitle = trans('firefy.import_complete'); + $subTitle = trans('firefly.import_complete'); $subTitleIcon = 'fa-star'; return view('import.complete', compact('job', 'subTitle', 'subTitleIcon')); @@ -120,6 +120,19 @@ class ImportController extends Controller } + /** + * @param ImportJob $job + * + * @return View + */ + public function finished(ImportJob $job) + { + $subTitle = trans('firefly.import_finished'); + $subTitleIcon = 'fa-star'; + + return view('import.finished', compact('job', 'subTitle', 'subTitleIcon')); + } + /** * This is step 1. Upload a file. * @@ -154,6 +167,7 @@ class ImportController extends Controller 'started' => false, 'completed' => false, 'running' => false, + 'errors' => $job->extended_status['errors'], 'percentage' => 0, 'steps' => $job->extended_status['total_steps'], 'stepsDone' => $job->extended_status['steps_done'], @@ -290,7 +304,7 @@ class ImportController extends Controller if (!$this->jobInCorrectStep($job, 'status')) { return $this->redirectToCorrectStep($job); } - $subTitle = trans('firefy.import_status'); + $subTitle = trans('firefly.import_status'); $subTitleIcon = 'fa-star'; return view('import.status', compact('job', 'subTitle', 'subTitleIcon')); @@ -414,6 +428,8 @@ class ImportController extends Controller Log::debug('Will redirect to complete()'); return redirect(route('import.complete', [$job->key])); + case 'import_complete': + return redirect(route('import.finished', [$job->key])); } throw new FireflyException('Cannot redirect for job state ' . $job->status); diff --git a/app/Http/routes.php b/app/Http/routes.php index a29f331a7f..0fe44e5fec 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -234,8 +234,9 @@ Route::group( Route::get('/import/status/{importJob}', ['uses' => 'ImportController@status', 'as' => 'import.status']); Route::get('/import/json/{importJob}', ['uses' => 'ImportController@json', 'as' => 'import.json']); - Route::post('/import/start/{importJob}', ['uses' => 'ImportController@start', 'as' => 'import.start']); + Route::post('/import/start/{importJob}', ['uses' => 'ImportController@start', 'as' => 'import.start']); + Route::get('/import/finished/{importJob}', ['uses' => 'ImportController@finished', 'as' => 'import.finished']); /** * Help Controller diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.php index 5a2f37a03e..db06eb5251 100644 --- a/app/Import/ImportStorage.php +++ b/app/Import/ImportStorage.php @@ -220,8 +220,13 @@ class ImportStorage Log::warning(sprintf('Cannot import row %d, because the entry is not valid.', $index)); $result = new ImportResult(); $result->failed(); - $errors = join(', ', $entry->errors->all()); - $result->appendError(sprintf('Row #%d: ' . $errors, $index)); + $errors = join(', ', $entry->errors->all()); + $errorText = sprintf('Row #%d: ' . $errors, $index); + $result->appendError($errorText); + $extendedStatus = $this->job->extended_status; + $extendedStatus['errors'][] = $errorText; + $this->job->extended_status = $extendedStatus; + $this->job->save(); return $result; } diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php index ae96b61115..0064cca67e 100644 --- a/app/Repositories/ImportJob/ImportJobRepository.php +++ b/app/Repositories/ImportJob/ImportJobRepository.php @@ -52,7 +52,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface $importJob->file_type = $fileType; $importJob->key = Str::random(12); $importJob->status = 'import_status_never_started'; - $importJob->extended_status = ['total_steps' => 0, 'steps_done' => 0,]; + $importJob->extended_status = ['total_steps' => 0, 'steps_done' => 0, 'errors' => [], 'import_count' => 0]; $importJob->save(); // breaks the loop: diff --git a/public/js/ff/import/status.js b/public/js/ff/import/status.js index fa7ce2d9b7..a312dd6b8c 100644 --- a/public/js/ff/import/status.js +++ b/public/js/ff/import/status.js @@ -9,12 +9,13 @@ var startedImport = false; +var startInterval = 2000; var interval = 500; $(function () { "use strict"; // check status, every 500 ms. - setTimeout(checkImportStatus, 500); + setTimeout(checkImportStatus, startInterval); }); @@ -24,54 +25,85 @@ function checkImportStatus() { $.getJSON(jobImportUrl).success(reportOnJobImport).fail(failedJobImport); } -function reportOnJobImport(data) { +function importComplete(data) { "use strict"; - console.log('Now in reportOnJobImport'); - - // update bar if it's a percentage or not: + var bar = $('#import-status-bar'); + bar.removeClass('active'); + // TODO show more completion info. +} +function updateBar(data) { + "use strict"; var bar = $('#import-status-bar'); if (data.showPercentage) { - console.log('Has percentage.'); bar.addClass('progress-bar-success').removeClass('progress-bar-info'); bar.attr('aria-valuenow', data.percentage); bar.css('width', data.percentage + '%'); $('#import-status-bar').text(data.stepsDone + '/' + data.steps); - if (data.percentage >= 100) { - console.log('Now import complete!'); - bar.removeClass('active'); + importComplete(data); return; } + return; + } + // dont show percentage: + $('#import-status-more-info').text(''); + bar.removeClass('progress-bar-success').addClass('progress-bar-info'); + bar.attr('aria-valuenow', 100); + bar.css('width', '100%'); +} - } else { - $('#import-status-more-info').text(''); - console.log('Has no percentage.'); - bar.removeClass('progress-bar-success').addClass('progress-bar-info'); - bar.attr('aria-valuenow', 100); - bar.css('width', '100%'); +function reportErrors(data) { + "use strict"; + if (data.errors.length == 1) { + $('#import-status-error-intro').text('An error has occured during the import. The import can continue, however.'); + } + if (data.errors.length > 1) { + $('#import-status-error-intro').text('Errors have occured during the import. The import can continue, however.'); } - // update the message: + // fill the list: + $('#import-status-error-list').empty(); + for (var i = 0; i < data.errors.length; i++) { + var item = $('
- {{ 'import_status_text'|_ }} -
{{ 'import_status_settings_complete'|_ }}
+ +