Finetune user feedback during import and add a tag to collect transactions.

This commit is contained in:
James Cole 2016-08-14 11:31:09 +02:00
parent 70b63e1736
commit 98c4ac955a
8 changed files with 75 additions and 14 deletions

View File

@ -16,6 +16,7 @@ use FireflyIII\Import\ImportProcedure;
use FireflyIII\Import\Setup\SetupInterface;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\Request;
use Log;
use Response;
@ -176,13 +177,19 @@ class ImportController extends Controller
'steps' => $job->extended_status['total_steps'],
'stepsDone' => $job->extended_status['steps_done'],
'statusText' => trans('firefly.import_status_' . $job->status),
'finishedText' => '',
];
$percentage = 0;
if ($job->extended_status['total_steps'] !== 0) {
$percentage = round(($job->extended_status['steps_done'] / $job->extended_status['total_steps']) * 100, 0);
}
if ($job->status === 'import_complete') {
$result['finished'] = true;
$tagId = $job->extended_status['importTag'];
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$tag = $repository->find($tagId);
$result['finished'] = true;
$result['finishedText'] = trans('firefly.import_finished_link', ['link' => route('tags.show', [$tag->id]), 'tag' => $tag->tag]);
}
if ($job->status === 'import_running') {
@ -392,7 +399,7 @@ class ImportController extends Controller
case 'store-settings':
return $job->status === 'import_configuration_saved';
case 'finished':
return $job->status === 'import_finished';
return $job->status === 'import_complete';
case 'complete':
return $job->status === 'settings_complete';
case 'status':
@ -442,7 +449,10 @@ class ImportController extends Controller
Log::debug('Will redirect to complete()');
return redirect(route('import.complete', [$job->key]));
case 'import_complete':
case
'import_complete':
Log::debug('Will redirect to finished()');
return redirect(route('import.finished', [$job->key]));
}

View File

@ -68,7 +68,11 @@ class ImportProcedure
// and run store routine:
$result = $storage->store();
$job->status = 'import_complete';
// grab import tag:
$status = $job->extended_status;
$status['importTag'] = $storage->importTag->id;
$job->extended_status = $status;
$job->status = 'import_complete';
$job->save();
return $result;

View File

@ -13,10 +13,12 @@ namespace FireflyIII\Import;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
@ -31,6 +33,8 @@ class ImportStorage
/** @var Collection */
public $entries;
/** @var Tag */
public $importTag;
/** @var ImportJob */
public $job;
/** @var User */
@ -68,13 +72,14 @@ class ImportStorage
*/
public function store(): Collection
{
$collection = new Collection;
// create a tag to join the transactions.
$this->importTag = $this->createImportTag();
$collection = new Collection;
Log::notice(sprintf('Started storing %d entry(ies).', $this->entries->count()));
foreach ($this->entries as $index => $entry) {
Log::debug(sprintf('--- import store start for row %d ---', $index));
$result = $this->storeSingle($index, $entry);
$this->job->addStepsDone(1);
sleep(1);
$collection->put($index, $result);
}
Log::notice(sprintf('Finished storing %d entry(ies).', $collection->count()));
@ -98,6 +103,27 @@ class ImportStorage
return new TransactionJournal;
}
/**
* @return Tag
*/
private function createImportTag(): Tag
{
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$data = [
'tag' => trans('firefly.import_with_key', ['key' => $this->job->key]),
'date' => null,
'description' => null,
'latitude' => null,
'longitude' => null,
'zoomLevel' => null,
'tagMode' => 'nothing',
];
$tag = $repository->store($data);
return $tag;
}
/**
* @param float $amount
*
@ -303,6 +329,9 @@ class ImportStorage
$journal->completed = 1;
$journal->save();
// attach import tag.
$journal->tags()->save($this->importTag);
// now attach budget and so on.
$this->storeBudget($journal, $entry);
$this->storeCategory($journal, $entry);

View File

@ -52,7 +52,13 @@ 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, 'errors' => [], 'import_count' => 0];
$importJob->extended_status = [
'total_steps' => 0,
'steps_done' => 0,
'import_count' => 0,
'importTag' => 0,
'errors' => [],
];
$importJob->save();
// breaks the loop:

View File

@ -17,6 +17,9 @@ var stepCount = 0;
$(function () {
"use strict";
$('#import-status-intro').hide();
$('#import-status-more-info').hide();
// check status, every 500 ms.
setTimeout(checkImportStatus, startInterval);
@ -53,7 +56,6 @@ function updateBar(data) {
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%');
@ -123,7 +125,7 @@ function importJobFinished(data) {
return data.finished;
}
function finishedJob() {
function finishedJob(data) {
"use strict";
console.log('finishedJob()');
// "There was an error during the import routine. Please check the log files. The error seems to be: '"
@ -131,6 +133,11 @@ function finishedJob() {
// remove progress bar.
$('#import-status-holder').hide();
// show info:
$('#import-status-intro').show();
$('#import-status-more-info').html(data.finishedText).show();
}
function reportOnJobImport(data) {
@ -142,7 +149,7 @@ function reportOnJobImport(data) {
updateTimeout(data);
if (importJobFinished(data)) {
finishedJob();
finishedJob(data);
return;
}

View File

@ -791,5 +791,8 @@ return [
'import_error_fatal' => 'There was an error during the import routine. Please check the log files. The error seems to be:',
'import_error_timeout' => 'The import seems to have timed out. If this error persists, please import your data using the console command.',
'import_double' => 'Row #:row: This row has been imported before, and is stored in <a href=":link">:description</a>.',
'import_finished_all' => 'The import has finished. Please check out the result below.',
'import_finished_all' => 'The import has finished. Please check out the results below.',
'import_with_key' => 'Import with key \':key\'',
'import_finished_report' => 'The import has finished. Please note any errors in the block above this line. All transactions imported during this particular session have been tagged, and you can check them out below. ',
'import_finished_link' => 'The transactions imported can be found in tag <a href=":link" class="label label-success" style="font-size:100%;font-weight:normal;">:tag</a>.',
];

View File

@ -46,9 +46,10 @@
<h3 class="box-title">{{ 'import_status_report'|_ }}</h3>
</div>
<div class="box-body">
<p id="import-status-more-info">
Nothing to report so far
<p id="import-status-intro">
{{ 'import_finished_report'|_ }}
</p>
<p id="import-status-more-info"></p>
</div>
</div>
</div>

View File

@ -100,7 +100,8 @@
"steps_done": 0,
"total_steps": 0,
"errors": [],
"import_count": 0
"import_count": 0,
"importTag": 0
},
"configuration": {
"has-headers": false,