From e525e673a8aeabe9ec2874f97d07a62746157b2b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 Jun 2017 06:57:24 +0200 Subject: [PATCH] Import routine cleanup. --- app/Http/Controllers/ImportController.php | 45 ++++----- app/Http/breadcrumbs.php | 14 +-- app/Import/Converter/Amount.php | 11 +-- app/Import/Converter/BasicConverter.php | 85 ---------------- app/Import/Converter/ConverterInterface.php | 28 ------ app/Import/Converter/INGDebetCredit.php | 4 +- app/Import/Converter/RabobankDebetCredit.php | 4 +- app/Import/Converter/TagSplit.php | 86 ----------------- app/Import/Converter/TagsComma.php | 48 ---------- app/Import/Converter/TagsSpace.php | 49 ---------- app/Import/FileProcessor/CsvProcessor.php | 1 + app/Import/Mapper/AssetAccountIbans.php | 2 +- app/Import/Mapper/AssetAccounts.php | 2 +- app/Import/Mapper/Bills.php | 2 +- app/Import/Mapper/Budgets.php | 2 +- app/Import/Mapper/Categories.php | 2 +- app/Import/Mapper/OpposingAccountIbans.php | 2 +- app/Import/Mapper/OpposingAccounts.php | 2 +- app/Import/Mapper/Tags.php | 2 +- app/Import/Mapper/TransactionCurrencies.php | 2 +- app/Import/Object/ImportJournal.php | 2 +- app/Import/Routine/ImportRoutine.php | 96 +++++++++++++++---- app/Import/Storage/ImportStorage.php | 2 +- .../ImportJob/ImportJobRepository.php | 8 +- public/js/ff/import/status.js | 23 ++--- resources/lang/en_US/csv.php | 51 +++++----- resources/lang/en_US/firefly.php | 88 +++++++++-------- resources/views/import/complete.twig | 44 --------- resources/views/import/csv/initial.twig | 8 +- resources/views/import/csv/map.twig | 47 +-------- resources/views/import/csv/roles.twig | 2 +- resources/views/import/index.twig | 15 ++- resources/views/import/status.twig | 49 +++++----- 33 files changed, 245 insertions(+), 583 deletions(-) delete mode 100644 app/Import/Converter/BasicConverter.php delete mode 100644 app/Import/Converter/TagSplit.php delete mode 100644 app/Import/Converter/TagsComma.php delete mode 100644 app/Import/Converter/TagsSpace.php delete mode 100644 resources/views/import/complete.twig diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index c1e2b718a9..07e4418e99 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -17,8 +17,8 @@ use FireflyIII\Http\Requests\ImportUploadRequest; use FireflyIII\Import\Configurator\ConfiguratorInterface; use FireflyIII\Import\Routine\ImportRoutine; use FireflyIII\Models\ImportJob; -use FireflyIII\Models\Tag; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Http\Response as LaravelResponse; use Log; @@ -45,7 +45,7 @@ class ImportController extends Controller $this->middleware( function ($request, $next) { View::share('mainTitleIcon', 'fa-archive'); - View::share('title', trans('firefly.import_data_full')); + View::share('title', trans('firefly.import_index_title')); $this->repository = app(ImportJobRepositoryInterface::class); return $next($request); @@ -74,7 +74,7 @@ class ImportController extends Controller } $view = $configurator->getNextView(); $data = $configurator->getNextData(); - $subTitle = trans('firefly.configure_import'); + $subTitle = trans('firefly.import_config_bread_crumb'); $subTitleIcon = 'fa-wrench'; return view($view, compact('data', 'job', 'subTitle', 'subTitleIcon')); @@ -124,7 +124,7 @@ class ImportController extends Controller */ public function index() { - $subTitle = trans('firefly.import_data_index'); + $subTitle = trans('firefly.import_index_sub_title'); $subTitleIcon = 'fa-home'; $importFileTypes = []; $defaultImportType = config('firefly.default_import_format'); @@ -176,30 +176,31 @@ class ImportController extends Controller public function json(ImportJob $job) { $result = [ - 'started' => false, - 'finished' => false, - 'running' => false, - 'errors' => array_values($job->extended_status['errors']), - 'percentage' => 0, - 'steps' => $job->extended_status['steps'], - 'done' => $job->extended_status['done'], - 'statusText' => trans('firefly.import_status_' . $job->status), - 'status' => $job->status, - 'finishedText' => '', + 'started' => false, + 'finished' => false, + 'running' => false, + 'errors' => array_values($job->extended_status['errors']), + 'percentage' => 0, + 'show_percentage' => false, + 'steps' => $job->extended_status['steps'], + 'done' => $job->extended_status['done'], + 'statusText' => trans('firefly.import_status_job_' . $job->status), + 'status' => $job->status, + 'finishedText' => '', ]; if ($job->extended_status['steps'] !== 0) { - $result['percentage'] = round(($job->extended_status['done'] / $job->extended_status['steps']) * 100, 0); + $result['percentage'] = round(($job->extended_status['done'] / $job->extended_status['steps']) * 100, 0); + $result['show_percentage'] = true; } if ($job->status === 'finished') { - // $tagId = $job->extended_status['importTag']; - // /** @var TagRepositoryInterface $repository */ - // $repository = app(TagRepositoryInterface::class); - // $tag = $repository->find($tagId); - $tag = new Tag; + $tagId = $job->extended_status['tag']; + /** @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]); + $result['finishedText'] = trans('firefly.import_status_finished_job', ['link' => route('tags.show', [$tag->id, 'all']), 'tag' => $tag->tag]); } if ($job->status === 'running') { @@ -262,7 +263,7 @@ class ImportController extends Controller if (!in_array($job->status, $statuses)) { return redirect(route('import.configure', [$job->key])); } - $subTitle = trans('firefly.import_status'); + $subTitle = trans('firefly.import_status_sub_title'); $subTitleIcon = 'fa-star'; return view('import.status', compact('job', 'subTitle', 'subTitleIcon')); diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 5668c16162..7bd76f3d9e 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -469,26 +469,20 @@ Breadcrumbs::register( $breadcrumbs->push(trans('firefly.import'), route('import.index')); } ); -Breadcrumbs::register( - 'import.complete', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) { - $breadcrumbs->parent('import.index'); - $breadcrumbs->push(trans('firefly.bread_crumb_import_complete', ['key' => $job->key]), route('import.complete', [$job->key])); -} -); + Breadcrumbs::register( 'import.configure', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) { $breadcrumbs->parent('import.index'); - $breadcrumbs->push(trans('firefly.bread_crumb_configure_import', ['key' => $job->key]), route('import.configure', [$job->key])); + $breadcrumbs->push(trans('firefly.import_config_sub_title', ['key' => $job->key]), route('import.configure', [$job->key])); } ); Breadcrumbs::register( - 'import.finished', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) { + 'import.status', function (BreadCrumbGenerator $breadcrumbs, ImportJob $job) { $breadcrumbs->parent('import.index'); - $breadcrumbs->push(trans('firefly.bread_crumb_import_finished', ['key' => $job->key]), route('import.finished', [$job->key])); + $breadcrumbs->push(trans('firefly.import_status_bread_crumb', ['key' => $job->key]), route('import.status', [$job->key])); } ); - /** * PREFERENCES */ diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php index c7840e397c..4cd861e25d 100644 --- a/app/Import/Converter/Amount.php +++ b/app/Import/Converter/Amount.php @@ -18,7 +18,7 @@ namespace FireflyIII\Import\Converter; * * @package FireflyIII\Import\Converter */ -class Amount extends BasicConverter implements ConverterInterface +class Amount implements ConverterInterface { /** @@ -28,9 +28,9 @@ class Amount extends BasicConverter implements ConverterInterface * * @param $value * - * @return float + * @return string */ - public function convert($value): float + public function convert($value): string { $len = strlen($value); $decimalPosition = $len - 3; @@ -59,10 +59,7 @@ class Amount extends BasicConverter implements ConverterInterface $value = str_replace($search, '', $value); } - $this->setCertainty(90); - - - return round(floatval($value), 12); + return strval(round(floatval($value), 12)); } } diff --git a/app/Import/Converter/BasicConverter.php b/app/Import/Converter/BasicConverter.php deleted file mode 100644 index 49fba30f0d..0000000000 --- a/app/Import/Converter/BasicConverter.php +++ /dev/null @@ -1,85 +0,0 @@ -certainty; - } - - /** - * @param int $certainty - */ - protected function setCertainty(int $certainty) - { - $this->certainty = $certainty; - } - - /** - * @param array $config - */ - public function setConfig(array $config) - { - $this->config = $config; - } - - /** - * @param mixed $doMap - */ - public function setDoMap(bool $doMap) - { - $this->doMap = $doMap; - } - - /** - * @param array $mapping - * - */ - public function setMapping(array $mapping) - { - $this->mapping = $mapping; - } - - /** - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } -} diff --git a/app/Import/Converter/ConverterInterface.php b/app/Import/Converter/ConverterInterface.php index f5c27a2746..010d06e4ca 100644 --- a/app/Import/Converter/ConverterInterface.php +++ b/app/Import/Converter/ConverterInterface.php @@ -13,8 +13,6 @@ declare(strict_types=1); namespace FireflyIII\Import\Converter; -use FireflyIII\User; - /** * Interface ConverterInterface * @@ -27,30 +25,4 @@ interface ConverterInterface * */ public function convert($value); - - /** - * @return int - */ - public function getCertainty(): int; - - /** - * @param array $config - */ - public function setConfig(array $config); - - /** - * @param bool $doMap - */ - public function setDoMap(bool $doMap); - - /** - * @param array $mapping - * - */ - public function setMapping(array $mapping); - - /** - * @param User $user - */ - public function setUser(User $user); } diff --git a/app/Import/Converter/INGDebetCredit.php b/app/Import/Converter/INGDebetCredit.php index 80650257ae..7fa82f2cf6 100644 --- a/app/Import/Converter/INGDebetCredit.php +++ b/app/Import/Converter/INGDebetCredit.php @@ -20,7 +20,7 @@ use Log; * * @package FireflyIII\Import\Converter */ -class INGDebetCredit extends BasicConverter implements ConverterInterface +class INGDebetCredit implements ConverterInterface { /** @@ -34,12 +34,10 @@ class INGDebetCredit extends BasicConverter implements ConverterInterface if ($value === 'Af') { Log::debug('Return -1'); - $this->setCertainty(100); return -1; } - $this->setCertainty(100); Log::debug('Return 1'); return 1; diff --git a/app/Import/Converter/RabobankDebetCredit.php b/app/Import/Converter/RabobankDebetCredit.php index 9b3e89314d..cef1a55607 100644 --- a/app/Import/Converter/RabobankDebetCredit.php +++ b/app/Import/Converter/RabobankDebetCredit.php @@ -20,7 +20,7 @@ use Log; * * @package FireflyIII\Import\Converter */ -class RabobankDebetCredit extends BasicConverter implements ConverterInterface +class RabobankDebetCredit implements ConverterInterface { /** @@ -34,13 +34,11 @@ class RabobankDebetCredit extends BasicConverter implements ConverterInterface if ($value === 'D') { Log::debug('Return -1'); - $this->setCertainty(100); return -1; } Log::debug('Return 1'); - $this->setCertainty(100); return 1; } diff --git a/app/Import/Converter/TagSplit.php b/app/Import/Converter/TagSplit.php deleted file mode 100644 index f5ebd034af..0000000000 --- a/app/Import/Converter/TagSplit.php +++ /dev/null @@ -1,86 +0,0 @@ -setUser($user); - - - /** @var string $part */ - foreach ($parts as $part) { - if (isset($mapping[$part])) { - Log::debug('Found tag in mapping. Should exist.', ['value' => $part, 'map' => $mapping[$part]]); - $tag = $repository->find(intval($mapping[$part])); - if (!is_null($tag->id)) { - Log::debug('Found tag by ID', ['id' => $tag->id]); - - $set->push($tag); - continue; - } - } - // not mapped? Still try to find it first: - $tag = $repository->findByTag($part); - if (!is_null($tag->id)) { - Log::debug('Found tag by name ', ['id' => $tag->id]); - - $set->push($tag); - } - if (is_null($tag->id)) { - // create new tag - $tag = $repository->store( - [ - 'tag' => $part, - 'date' => null, - 'description' => $part, - 'latitude' => null, - 'longitude' => null, - 'zoomLevel' => null, - 'tagMode' => 'nothing', - ] - ); - Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]); - $set->push($tag); - } - } - - return $set; - } - -} diff --git a/app/Import/Converter/TagsComma.php b/app/Import/Converter/TagsComma.php deleted file mode 100644 index 93e13698f0..0000000000 --- a/app/Import/Converter/TagsComma.php +++ /dev/null @@ -1,48 +0,0 @@ - $value]); - - if (strlen($value) === 0) { - $this->setCertainty(0); - - return new Collection; - } - $parts = array_unique(explode(',', $value)); - $set = TagSplit::createSetFromSplits($this->user, $this->mapping, $parts); - $this->setCertainty(100); - - return $set; - } -} diff --git a/app/Import/Converter/TagsSpace.php b/app/Import/Converter/TagsSpace.php deleted file mode 100644 index ae9635a8b7..0000000000 --- a/app/Import/Converter/TagsSpace.php +++ /dev/null @@ -1,49 +0,0 @@ - $value]); - - if (strlen($value) === 0) { - $this->setCertainty(0); - - return new Collection; - } - $parts = array_unique(explode(' ', $value)); - $set = TagSplit::createSetFromSplits($this->user, $this->mapping, $parts); - $this->setCertainty(100); - - return $set; - - } -} diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.php index 010a0580d9..4efe046c33 100644 --- a/app/Import/FileProcessor/CsvProcessor.php +++ b/app/Import/FileProcessor/CsvProcessor.php @@ -70,6 +70,7 @@ class CsvProcessor implements FileProcessorInterface $index = 0; Log::notice('Building importable objects from CSV file.'); foreach ($entries as $index => $row) { + sleep(1); // verify if not exists already: if ($this->rowAlreadyImported($row)) { $message = sprintf('Row #%d has already been imported.', $index); diff --git a/app/Import/Mapper/AssetAccountIbans.php b/app/Import/Mapper/AssetAccountIbans.php index e94f502cbb..9f6d58ac5b 100644 --- a/app/Import/Mapper/AssetAccountIbans.php +++ b/app/Import/Mapper/AssetAccountIbans.php @@ -50,7 +50,7 @@ class AssetAccountIbans implements MapperInterface asort($list); $list = $topList + $list; - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/AssetAccounts.php b/app/Import/Mapper/AssetAccounts.php index 8335bea7e4..2679334fe3 100644 --- a/app/Import/Mapper/AssetAccounts.php +++ b/app/Import/Mapper/AssetAccounts.php @@ -47,7 +47,7 @@ class AssetAccounts implements MapperInterface asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/Bills.php b/app/Import/Mapper/Bills.php index 57d60b3013..a12ee950ea 100644 --- a/app/Import/Mapper/Bills.php +++ b/app/Import/Mapper/Bills.php @@ -40,7 +40,7 @@ class Bills implements MapperInterface } asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/Budgets.php b/app/Import/Mapper/Budgets.php index 37276ddcc0..88ca1e0d5e 100644 --- a/app/Import/Mapper/Budgets.php +++ b/app/Import/Mapper/Budgets.php @@ -41,7 +41,7 @@ class Budgets implements MapperInterface } asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/Categories.php b/app/Import/Mapper/Categories.php index 5144a06a41..30c81dfada 100644 --- a/app/Import/Mapper/Categories.php +++ b/app/Import/Mapper/Categories.php @@ -41,7 +41,7 @@ class Categories implements MapperInterface } asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/OpposingAccountIbans.php b/app/Import/Mapper/OpposingAccountIbans.php index bcf3372e10..3a4299c26a 100644 --- a/app/Import/Mapper/OpposingAccountIbans.php +++ b/app/Import/Mapper/OpposingAccountIbans.php @@ -56,7 +56,7 @@ class OpposingAccountIbans implements MapperInterface asort($list); $list = $topList + $list; - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/OpposingAccounts.php b/app/Import/Mapper/OpposingAccounts.php index fd2d86a5bb..bd95610504 100644 --- a/app/Import/Mapper/OpposingAccounts.php +++ b/app/Import/Mapper/OpposingAccounts.php @@ -53,7 +53,7 @@ class OpposingAccounts implements MapperInterface asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; } diff --git a/app/Import/Mapper/Tags.php b/app/Import/Mapper/Tags.php index e549fd90ef..c1b7f324e0 100644 --- a/app/Import/Mapper/Tags.php +++ b/app/Import/Mapper/Tags.php @@ -40,7 +40,7 @@ class Tags implements MapperInterface } asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Mapper/TransactionCurrencies.php b/app/Import/Mapper/TransactionCurrencies.php index d24f083b0f..286f275214 100644 --- a/app/Import/Mapper/TransactionCurrencies.php +++ b/app/Import/Mapper/TransactionCurrencies.php @@ -36,7 +36,7 @@ class TransactionCurrencies implements MapperInterface asort($list); - $list = [0 => trans('csv.do_not_map')] + $list; + $list = [0 => trans('csv.map_do_not_map')] + $list; return $list; diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.php index 6359852111..60d9edb2f9 100644 --- a/app/Import/Object/ImportJournal.php +++ b/app/Import/Object/ImportJournal.php @@ -104,7 +104,7 @@ class ImportJournal /** @var ConverterInterface $amountConverter */ $amountConverter = app(Amount::class); - $this->amount = strval($amountConverter->convert($this->amount)); + $this->amount = $amountConverter->convert($this->amount); // modify foreach ($this->modifiers as $modifier) { $class = sprintf('FireflyIII\Import\Converter\%s', config(sprintf('csv.import_roles.%s.converter', $modifier['role']))); diff --git a/app/Import/Routine/ImportRoutine.php b/app/Import/Routine/ImportRoutine.php index 9a71e79348..2978ecbf71 100644 --- a/app/Import/Routine/ImportRoutine.php +++ b/app/Import/Routine/ImportRoutine.php @@ -12,9 +12,13 @@ declare(strict_types=1); namespace FireflyIII\Import\Routine; +use Carbon\Carbon; use FireflyIII\Import\FileProcessor\FileProcessorInterface; use FireflyIII\Import\Storage\ImportStorage; use FireflyIII\Models\ImportJob; +use FireflyIII\Models\Tag; +use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Support\Collection; use Log; @@ -53,8 +57,37 @@ class ImportRoutine return false; } - + set_time_limit(0); Log::debug(sprintf('Start with import job %s', $this->job->key)); + + $importObjects = $this->getImportObjects(); + $this->lines = $importObjects->count(); + + // once done, use storage thing to actually store them: + Log::debug(sprintf('Returned %d valid objects from file processor', $this->lines)); + + $storage = $this->storeObjects($importObjects); + + // update job: + $this->job->status = 'finished'; + $this->job->save(); + + $this->journals = $storage->journals; + $this->errors = $storage->errors; + + // create tag, link tag to all journals: + $this->createImportTag(); + + Log::debug(sprintf('Done with import job %s', $this->job->key)); + + return true; + } + + /** + * @return Collection + */ + protected function getImportObjects(): Collection + { $objects = new Collection; $type = $this->job->file_type; $class = config(sprintf('firefly.import_processors.%s', $type)); @@ -62,7 +95,6 @@ class ImportRoutine $processor = app($class); $processor->setJob($this->job); - set_time_limit(0); if ($this->job->status == 'configured') { // set job as "running"... @@ -73,28 +105,56 @@ class ImportRoutine $processor->run(); $objects = $processor->getObjects(); } - $this->lines = $objects->count(); - // once done, use storage thing to actually store them: - Log::debug(sprintf('Returned %d valid objects from file processor', $this->lines)); + return $objects; + } + + /** + * + */ + private function createImportTag(): Tag + { + /** @var TagRepositoryInterface $repository */ + $repository = app(TagRepositoryInterface::class); + $repository->setUser($this->job->user); + $data = [ + 'tag' => trans('firefly.import_with_key', ['key' => $this->job->key]), + 'date' => new Carbon, + 'description' => null, + 'latitude' => null, + 'longitude' => null, + 'zoomLevel' => null, + 'tagMode' => 'nothing', + ]; + $tag = $repository->store($data); + $extended = $this->job->extended_status; + $extended['tag'] = $tag->id; + $this->job->extended_status = $extended; + $this->job->save(); + + $this->journals->each( + function (TransactionJournal $journal) use ($tag) { + $journal->tags()->save($tag); + } + ); + + return $tag; + + } + + /** + * @param Collection $objects + * + * @return ImportStorage + */ + private function storeObjects(Collection $objects): ImportStorage + { $storage = new ImportStorage; $storage->setJob($this->job); $storage->setDateFormat($this->job->configuration['date-format']); $storage->setObjects($objects); $storage->store(); - // update job: - $this->job->status = 'finished'; - $this->job->save(); - - $this->journals = $storage->journals; - $this->errors = $storage->errors; - - // run rules: - - - Log::debug(sprintf('Done with import job %s', $this->job->key)); - - return true; + return $storage; } } \ No newline at end of file diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index bb20d2ad89..929f5c5cb8 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -99,7 +99,7 @@ class ImportStorage * @var ImportJournal $object */ foreach ($this->objects as $index => $object) { - sleep(4); + sleep(1); Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $object->description)); $errors = new MessageBag; diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php index bc54f07503..36bd597406 100644 --- a/app/Repositories/ImportJob/ImportJobRepository.php +++ b/app/Repositories/ImportJob/ImportJobRepository.php @@ -60,10 +60,10 @@ class ImportJobRepository implements ImportJobRepositoryInterface $importJob->status = 'new'; $importJob->configuration = []; $importJob->extended_status = [ - 'steps' => 0, - 'done' => 0, - 'importTag' => 0, - 'errors' => [], + 'steps' => 0, + 'done' => 0, + 'tag' => 0, + 'errors' => [], ]; $importJob->save(); diff --git a/public/js/ff/import/status.js b/public/js/ff/import/status.js index 68150eb85d..9c4487c8d2 100644 --- a/public/js/ff/import/status.js +++ b/public/js/ff/import/status.js @@ -50,10 +50,10 @@ function failedJobImport(jqxhr, textStatus, error) { // fill in some details: var errorMessage = textStatus + " " + error; - $('.import_error_txt').text(errorMessage); + $('.fatal_error_txt').text(errorMessage); - // show the error box: - $('.errorbox').show(); + // show the fatal error box: + $('.fatal_error').show(); } /** @@ -98,6 +98,7 @@ function reportOnJobImport(data) { $('.statusbox').hide(); $('.status_finished').show(); // show text: + $('#import-status-more-info').html(data.finishedText); break; @@ -105,12 +106,12 @@ function reportOnJobImport(data) { } /** - * Shows an error when the job seems to be stalled. + * Shows a fatal error when the job seems to be stalled. */ function showStalledBox() { $('.statusbox').hide(); - $('.errorbox').show(); - $('.import_error_txt').text(langImportTimeOutError); + $('.fatal_error').show(); + $('.fatal_error_txt').text(langImportTimeOutError); } /** @@ -156,12 +157,12 @@ function reportOnSubmitError() { $('.statusbox').hide(); // fill in some details: - var errorMessage = "Time out."; + var errorMessage = "Time out while waiting for job to finish."; - $('.import_error_txt').text(errorMessage); + $('.fatal_error_txt').text(errorMessage); - // show the error box: - $('.errorbox').show(); + // show the fatal error box: + $('.fatal_error').show(); jobFailed = true; } @@ -172,7 +173,7 @@ function reportOnSubmitError() { function updateBar(data) { console.log('updateBar()'); var bar = $('#import-status-bar'); - if (data.percentage > 0) { + if (data.show_percentage) { console.log('Going to update bar with percentage.'); bar.addClass('progress-bar-success').removeClass('progress-bar-info'); bar.attr('aria-valuenow', data.percentage); diff --git a/resources/lang/en_US/csv.php b/resources/lang/en_US/csv.php index 837616a801..f262f83b10 100644 --- a/resources/lang/en_US/csv.php +++ b/resources/lang/en_US/csv.php @@ -14,39 +14,36 @@ declare(strict_types=1); return [ // initial config - 'initial_config_title' => 'Import configuration (1/3)', - 'initial_config_text' => 'To be able to import your file correctly, please validate the options below.', - 'initial_config_box' => 'Basic CSV import configuration', - 'initial_header_help' => 'Check this box if the first row of your CSV file are the column titles.', - 'initial_date_help' => 'Date time format in your CSV. Follow the format like this page indicates. The default value will parse dates that look like this: :dateExample.', - 'initial_delimiter_help' => 'Choose the field delimiter that is used in your input file. If not sure, comma is the safest option.', - 'initial_import_account_help' => 'If your CSV file does NOT contain information about your asset account(s), use this dropdown to select to which account the transactions in the CSV belong to.', + 'initial_title' => 'Import setup (1/3) - Basic CSV import setup', + 'initial_text' => 'To be able to import your file correctly, please validate the options below.', + 'initial_box' => 'Basic CSV import setup', + 'initial_header_help' => 'Check this box if the first row of your CSV file are the column titles.', + 'initial_date_help' => 'Date time format in your CSV. Follow the format like this page indicates. The default value will parse dates that look like this: :dateExample.', + 'initial_delimiter_help' => 'Choose the field delimiter that is used in your input file. If not sure, comma is the safest option.', + 'initial_import_account_help' => 'If your CSV file does NOT contain information about your asset account(s), use this dropdown to select to which account the transactions in the CSV belong to.', + 'initial_submit' => 'Continue with step 2/3', // roles config - 'roles_title' => 'Define each column\'s role', - 'roles_text' => 'Each column in your CSV file contains certain data. Please indicate what kind of data the importer should expect. The option to "map" data means that you will link each entry found in the column to a value in your database. An often mapped column is the column that contains the IBAN of the opposing account. That can be easily matched to IBAN\'s present in your database already.', - 'roles_table' => 'Table', - 'roles_column_name' => 'Name of column', - 'roles_column_example' => 'Column example data', - 'roles_column_role' => 'Column data meaning', - 'roles_do_map_value' => 'Map these values', - 'roles_column' => 'Column', - 'roles_no_example_data' => 'No example data available', - - 'roles_store' => 'Continue import', - 'roles_do_not_map' => '(do not map)', + 'roles_title' => 'Import setup (2/3) - Define each column\'s role', + 'roles_text' => 'Each column in your CSV file contains certain data. Please indicate what kind of data the importer should expect. The option to "map" data means that you will link each entry found in the column to a value in your database. An often mapped column is the column that contains the IBAN of the opposing account. That can be easily matched to IBAN\'s present in your database already.', + 'roles_table' => 'Table', + 'roles_column_name' => 'Name of column', + 'roles_column_example' => 'Column example data', + 'roles_column_role' => 'Column data meaning', + 'roles_do_map_value' => 'Map these values', + 'roles_column' => 'Column', + 'roles_no_example_data' => 'No example data available', + 'roles_submit' => 'Continue with step 3/3', // map data - 'map_title' => 'Connect import data to Firefly III data', - 'map_text' => 'In the following tables, the left value shows you information found in your uploaded CSV file. It is your task to map this value, if possible, to a value already present in your database. Firefly will stick to this mapping. If there is no value to map to, or you do not wish to map the specific value, select nothing.', - - 'field_value' => 'Field value', - 'field_mapped_to' => 'Mapped to', - 'store_column_mapping' => 'Store mapping', + 'map_title' => 'Import setup (3/3) - Connect import data to Firefly III data', + 'map_text' => 'In the following tables, the left value shows you information found in your uploaded CSV file. It is your task to map this value, if possible, to a value already present in your database. Firefly will stick to this mapping. If there is no value to map to, or you do not wish to map the specific value, select nothing.', + 'map_field_value' => 'Field value', + 'map_field_mapped_to' => 'Mapped to', + 'map_do_not_map' => '(do not map)', + 'map_submit' => 'Start the import', // map things. - - 'column__ignore' => '(ignore this column)', 'column_account-iban' => 'Asset account (IBAN)', 'column_account-id' => 'Asset account ID (matching Firefly)', diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 8e13a610b1..4c1e536382 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -966,53 +966,51 @@ return [ 'cannot_edit_opening_balance' => 'You cannot edit the opening balance of an account.', 'no_edit_multiple_left' => 'You have selected no valid transactions to edit.', - // import - 'configuration_file_help' => 'If you have previously imported data into Firefly III, you may have a configuration file, which will pre-set configuration values for you. For some banks, other users have kindly provided their configuration file.', - 'import_data_index' => 'Index', - 'import_file_type_csv' => 'CSV (comma separated values)', - 'import_file_type_help' => 'Select the type of file you will upload', - 'import_start' => 'Start the import', - 'configure_import' => 'Further configure your import', - 'import_finish_configuration' => 'Finish configuration', - 'settings_for_import' => 'Settings', - 'import_status' => 'Import status', - 'import_status_text' => 'The import is currently running, or will start momentarily.', - 'import_complete' => 'Import configuration complete!', - 'import_complete_text' => 'The import is ready to start. All the configuration you needed to do has been done. Please download the configuration file. It will help you with the import should it not go as planned. To actually run the import, you can either execute the following command in your console, or run the web-based import. Depending on your configuration, the console import will give you more feedback.', - 'import_download_config' => 'Download configuration', - 'import_start_import' => 'Start import', - 'import_data' => 'Import data', - 'import_data_full' => 'Import data into Firefly III', + // import bread crumbs and titles: 'import' => 'Import', - 'import_file_help' => 'Select your file', - 'import_status_settings_complete' => 'The import is ready to start.', - 'import_status_import_complete' => 'The import has completed.', - 'import_status_running' => 'The import is currently running. Please be patient.', - 'import_status_header' => 'Import status and progress', - 'import_status_errors' => 'Import errors', - 'import_status_report' => 'Import report', - 'import_finished' => 'Import has finished', - 'import_error_single' => 'An error has occured during the import.', - 'import_error_multi' => 'Some errors occured during the import.', - '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 :description.', - 'import_finished_all' => 'The import has finished. Please check out the results below.', + 'import_data' => 'Import data', + + // import index page: + 'import_index_title' => 'Import data into Firefly III', + 'import_index_sub_title' => 'Index', + 'import_index_intro' => 'Welcome to Firefly\'s import routine. These pages can help you import data from your bank into Firefly III. Please check out the help pages in the top right corner.', + 'import_index_file' => 'Select your file', + 'import_index_config' => 'If you have previously imported data into Firefly III, you may have a configuration file, which will pre-set configuration values for you. For some banks, other users have kindly provided their configuration file.', + 'import_index_type' => 'Select the type of file you will upload', + 'import_index_start' => 'Start importing', + + // supported file types: + 'import_file_type_csv' => 'CSV (comma separated values)', + + // import configuration routine: + 'import_config_sub_title' => 'Set up your import file', + 'import_config_bread_crumb' => 'Set up your import file', + + // import status page: + 'import_status_bread_crumb' => 'Import status', + 'import_status_sub_title' => 'Import status', + 'import_status_wait_title' => 'Please hold...', + 'import_status_wait_text' => 'This box will disappear in a moment.', + 'import_status_ready_title' => 'Import is ready to start', + 'import_status_ready_text' => 'The import is ready to start. All the configuration you needed to do has been done. Please download the configuration file. It will help you with the import should it not go as planned. To actually run the import, you can either execute the following command in your console, or run the web-based import. Depending on your configuration, the console import will give you more feedback.', + 'import_status_ready_config' => 'Download configuration', + 'import_status_ready_start' => 'Start the import', + 'import_status_ready_share' => 'Please consider downloading your configuration and sharing it at the import configuration center. This will allow other users of Firefly III to import their files more easily.', + 'import_status_running_title' => 'The import is running', + 'import_status_running_placeholder' => 'Please hold for an update...', + 'import_status_errors_title' => 'Errors during the import', + 'import_status_errors_single' => 'An error has occured during the import. It does not appear to be fatal.', + 'import_status_errors_multi' => 'Some errors occured during the import. These do not appear to be fatal.', + 'import_status_fatal_title' => 'A fatal error occurred', + 'import_status_fatal_text' => 'A fatal error occurred, which the import-routine cannot recover from. Please see the explanation in red below.', + 'import_status_fatal_more' => 'If the error is a time-out, the import will have stopped half-way. For some server configurations, it is merely the server that stopped while the import keeps running in the background. To verify this, check out the log files. If the problem persists, consider importing over the command line instead.', + 'import_status_finished_title' => 'Import routine finished', + 'import_status_finished_text' => 'The import routine has imported your file.', + 'import_status_finished_job' => 'The transactions imported can be found in tag :tag.', 'import_with_key' => 'Import with key \':key\'', - 'import_share_configuration' => 'Please consider downloading your configuration and sharing it at the import configuration center. This will allow other users of Firefly III to import their files more easily.', - '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 :tag.', - 'need_at_least_one_account' => 'You need at least one asset account to be able to create piggy banks', - 'bread_crumb_import_complete' => 'Import ":key" complete', - 'bread_crumb_configure_import' => 'Configure import ":key"', - 'bread_crumb_import_finished' => 'Import ":key" finished', - 'import_finished_intro' => 'The import has finished! You can now see the new transactions in Firefly.', - 'import_finished_text_without_link' => 'It seems there is no tag that points to all your imported transactions. Please look for your imported data in the menu on the left, under "Transactions".', - 'import_finished_text_with_link' => 'You can find a list of your imported transactions on the page of the tag that was created for this import.', - 'please_wait_for_status' => 'Please wait for Firefly III to check on your import', - 'box_will_refresh' => 'This box will auto-refresh...', - 'import_job_status' => 'Import routine status..', - 'see_help_top_right' => 'Welcome to Firefly\'s import routine. Please check out the help pages in the top right corner.', + + // different states: + 'import_status_job_running' => 'The import is underway. Please be patient...', // sandstorm.io errors and messages: 'sandstorm_not_available' => 'This function is not available when you are using Firefly III within a Sandstorm.io environment.', diff --git a/resources/views/import/complete.twig b/resources/views/import/complete.twig deleted file mode 100644 index 932dbe2caa..0000000000 --- a/resources/views/import/complete.twig +++ /dev/null @@ -1,44 +0,0 @@ -{% extends "./layout/default" %} - -{% block breadcrumbs %} - {{ Breadcrumbs.renderIfExists }} -{% endblock %} -{% block content %} -
-
-
-
-

{{ 'import_complete'|_ }}

-
-
-

- {{ 'import_complete_text'|_ }} -

-

- php artisan firefly:start-import {{ job.key }} -

- -

-   -

-

- {{ 'import_share_configuration'|_ }} -

-
-
-
-
-{% endblock %} -{% block scripts %} -{% endblock %} -{% block styles %} -{% endblock %} diff --git a/resources/views/import/csv/initial.twig b/resources/views/import/csv/initial.twig index 2af4c072b8..bbfbc52d95 100644 --- a/resources/views/import/csv/initial.twig +++ b/resources/views/import/csv/initial.twig @@ -10,11 +10,11 @@
-

{{ trans('csv.initial_config_title') }}

+

{{ trans('csv.initial_title') }}

- {{ trans('csv.initial_config_text') }} + {{ trans('csv.initial_text') }}

@@ -29,7 +29,7 @@
-

{{ trans('csv.initial_config_box') }}

+

{{ trans('csv.initial_box_title') }}

@@ -67,7 +67,7 @@
diff --git a/resources/views/import/csv/map.twig b/resources/views/import/csv/map.twig index 3fd6f31d57..0d58cfcf51 100644 --- a/resources/views/import/csv/map.twig +++ b/resources/views/import/csv/map.twig @@ -36,8 +36,8 @@ - - + + @@ -62,53 +62,12 @@ {% endfor %} - {# - - {% for index,columnName in map %} - -
-
-
-
-

{{ Config.get('csv.roles.'~columnName~'.name') }}

-
-
-
{{ trans('csv.field_value') }}{{ trans('csv.field_mapped_to') }}{{ trans('csv.map_field_value') }}{{ trans('csv.map_field_mapped_to') }}
- - - - - - - - {% for value in values[index] %} - - - - - {% endfor %} - - - -
{{ 'csv_field_value'|_ }}{{ 'csv_field_mapped_to'|_ }}
{{ value }} - {{ Form.select('mapping['~index~']['~value~']',options[index], mapped[index][value], {class: 'form-control'}) }} -
- - -
-
-
-
- {% endfor %} - #} - -
diff --git a/resources/views/import/csv/roles.twig b/resources/views/import/csv/roles.twig index 307498f52c..4513b1b7dd 100644 --- a/resources/views/import/csv/roles.twig +++ b/resources/views/import/csv/roles.twig @@ -91,7 +91,7 @@
diff --git a/resources/views/import/index.twig b/resources/views/import/index.twig index 2f8ff89345..c48d31ea6d 100644 --- a/resources/views/import/index.twig +++ b/resources/views/import/index.twig @@ -8,16 +8,13 @@
-

{{ 'import'|_ }}

+

{{ 'import_index_title'|_ }}

-

- {{ 'import_data_full'|_ }} -

- {{ 'see_help_top_right'|_ }} + {{ 'import_index_intro'|_ }}

@@ -30,15 +27,15 @@
- {{ ExpandedForm.file('import_file', {helpText: 'import_file_help'|_}) }} - {{ ExpandedForm.file('configuration_file', {helpText: 'configuration_file_help'|_|raw}) }} - {{ ExpandedForm.select('import_file_type', importFileTypes, defaultImportType, {'helpText' : 'import_file_type_help'|_}) }} + {{ ExpandedForm.file('import_file', {helpText: 'import_index_file'|_}) }} + {{ ExpandedForm.file('configuration_file', {helpText: 'import_index_config'|_|raw}) }} + {{ ExpandedForm.select('import_file_type', importFileTypes, defaultImportType, {'helpText' : 'import_index_type'|_}) }}
diff --git a/resources/views/import/status.twig b/resources/views/import/status.twig index 1f1412a818..487293de8e 100644 --- a/resources/views/import/status.twig +++ b/resources/views/import/status.twig @@ -11,33 +11,33 @@
-

{{ 'please_wait_for_status'|_ }}

+

{{ 'import_status_wait_title'|_ }}

- {{ 'box_will_refresh'|_ }} + {{ 'import_status_wait_text'|_ }}

- {# Error display. Will be shown (duh) when something goes horribly wrong. #} -