From db3b822aef5d723a908313c683de0d983e3a885b Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 29 Jul 2017 08:27:39 +0200 Subject: [PATCH] Include warning for #722 --- app/Http/Controllers/ImportController.php | 8 ++++++++ .../Configurator/ConfiguratorInterface.php | 7 +++++++ app/Import/Configurator/CsvConfigurator.php | 18 +++++++++++++++++- .../Configuration/ConfigurationInterface.php | 7 +++++++ .../Import/Configuration/Csv/Initial.php | 10 ++++++++++ app/Support/Import/Configuration/Csv/Map.php | 10 ++++++++++ app/Support/Import/Configuration/Csv/Roles.php | 17 +++++++++++++++++ resources/lang/en_US/csv.php | 2 ++ 8 files changed, 78 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index d49835f280..4c6e0268c2 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -23,6 +23,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response as LaravelResponse; use Log; use Response; +use Session; use View; /** @@ -231,6 +232,13 @@ class ImportController extends Controller $data = $request->all(); $configurator->configureJob($data); + // get possible warning from configurator: + $warning = $configurator->getWarningMessage(); + + if(strlen($warning) > 0) { + Session::flash('warning', $warning); + } + // return to configure return redirect(route('import.configure', [$job->key])); } diff --git a/app/Import/Configurator/ConfiguratorInterface.php b/app/Import/Configurator/ConfiguratorInterface.php index 1f120d30d3..5e802d154d 100644 --- a/app/Import/Configurator/ConfiguratorInterface.php +++ b/app/Import/Configurator/ConfiguratorInterface.php @@ -48,6 +48,13 @@ interface ConfiguratorInterface */ public function getNextView(): string; + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string; + /** * Returns true when the initial configuration for this job is complete. * diff --git a/app/Import/Configurator/CsvConfigurator.php b/app/Import/Configurator/CsvConfigurator.php index 4e7d4ff476..5b6b7d52ef 100644 --- a/app/Import/Configurator/CsvConfigurator.php +++ b/app/Import/Configurator/CsvConfigurator.php @@ -26,8 +26,12 @@ use Log; */ class CsvConfigurator implements ConfiguratorInterface { + /** @var ImportJob */ private $job; + /** @var string */ + private $warning = ''; + /** * ConfiguratorInterface constructor. */ @@ -50,8 +54,10 @@ class CsvConfigurator implements ConfiguratorInterface /** @var ConfigurationInterface $object */ $object = new $class($this->job); $object->setJob($job); + $result = $object->storeConfiguration($data); + $this->warning = $object->getWarningMessage(); - return $object->storeConfiguration($data); + return $result; } /** @@ -91,6 +97,16 @@ class CsvConfigurator implements ConfiguratorInterface throw new FireflyException('No view for state'); } + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string + { + return $this->warning; + } + /** * @return bool */ diff --git a/app/Support/Import/Configuration/ConfigurationInterface.php b/app/Support/Import/Configuration/ConfigurationInterface.php index 7f13ebe167..83a8275021 100644 --- a/app/Support/Import/Configuration/ConfigurationInterface.php +++ b/app/Support/Import/Configuration/ConfigurationInterface.php @@ -43,4 +43,11 @@ interface ConfigurationInterface */ public function storeConfiguration(array $data): bool; + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string; + } diff --git a/app/Support/Import/Configuration/Csv/Initial.php b/app/Support/Import/Configuration/Csv/Initial.php index 7884a83f6b..6b4923f3bc 100644 --- a/app/Support/Import/Configuration/Csv/Initial.php +++ b/app/Support/Import/Configuration/Csv/Initial.php @@ -135,4 +135,14 @@ class Initial implements ConfigurationInterface return $config; } + + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string + { + return ''; + } } diff --git a/app/Support/Import/Configuration/Csv/Map.php b/app/Support/Import/Configuration/Csv/Map.php index 22016210da..b22638369b 100644 --- a/app/Support/Import/Configuration/Csv/Map.php +++ b/app/Support/Import/Configuration/Csv/Map.php @@ -268,4 +268,14 @@ class Map implements ConfigurationInterface return $column; } + + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string + { + return ''; + } } diff --git a/app/Support/Import/Configuration/Csv/Roles.php b/app/Support/Import/Configuration/Csv/Roles.php index f53a01abf7..ebb5299a9a 100644 --- a/app/Support/Import/Configuration/Csv/Roles.php +++ b/app/Support/Import/Configuration/Csv/Roles.php @@ -29,6 +29,9 @@ class Roles implements ConfigurationInterface /** @var ImportJob */ private $job; + /** @var string */ + private $warning = ''; + /** * Get the data necessary to show the configuration screen. * @@ -68,6 +71,16 @@ class Roles implements ConfigurationInterface return $this->data; } + /** + * Return possible warning to user. + * + * @return string + */ + public function getWarningMessage(): string + { + return $this->warning; + } + /** * @param ImportJob $job * @@ -246,6 +259,10 @@ class Roles implements ConfigurationInterface $config['column-roles-complete'] = true; $this->job->configuration = $config; $this->job->save(); + $this->warning = ''; + } + if ($assigned === 0 || !$hasAmount) { + $this->warning = trans('csv.roles_warning'); } return true; diff --git a/resources/lang/en_US/csv.php b/resources/lang/en_US/csv.php index f262f83b10..eb7fe230b1 100644 --- a/resources/lang/en_US/csv.php +++ b/resources/lang/en_US/csv.php @@ -17,6 +17,7 @@ return [ '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_box_title' => 'Basic CSV import setup options', '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.', @@ -34,6 +35,7 @@ return [ 'roles_column' => 'Column', 'roles_no_example_data' => 'No example data available', 'roles_submit' => 'Continue with step 3/3', + 'roles_warning' => 'At the very least, mark one column as the amount-column. It is advisable to also select a column for the description, date and the opposing account.', // map data 'map_title' => 'Import setup (3/3) - Connect import data to Firefly III data',