mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-28 00:57:11 +00:00
Towards managing mapping for file imports.
This commit is contained in:
@@ -27,6 +27,8 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigurationInterface;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigureMappingHandler;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigureRolesHandler;
|
||||
use FireflyIII\Support\Import\Configuration\File\ConfigureUploadHandler;
|
||||
use FireflyIII\Support\Import\Configuration\File\NewFileJobHandler;
|
||||
use Illuminate\Support\MessageBag;
|
||||
@@ -48,6 +50,20 @@ class FileJobConfiguration implements JobConfigurationInterface
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
if ($this->importJob->stage === 'ready_to_run') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store any data from the $data array into the job. Anything in the message bag will be flashed
|
||||
* as an error to the user, regardless of its content.
|
||||
@@ -79,6 +95,45 @@ class FileJobConfiguration implements JobConfigurationInterface
|
||||
return $configurator->getNextData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
return 'import.file.new';
|
||||
case 'configure-upload':
|
||||
return 'import.file.configure-upload';
|
||||
break;
|
||||
case 'roles':
|
||||
return 'import.file.roles';
|
||||
break;
|
||||
case 'map':
|
||||
return 'import.file.map';
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
sprintf('FileJobConfiguration::getNextView() cannot handle stage "%s"', $this->importJob->stage)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*/
|
||||
public function setJob(ImportJob $job): void
|
||||
{
|
||||
$this->importJob = $job;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($job->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration handler for this specific stage.
|
||||
*
|
||||
@@ -95,6 +150,12 @@ class FileJobConfiguration implements JobConfigurationInterface
|
||||
case 'configure-upload':
|
||||
$class = ConfigureUploadHandler::class;
|
||||
break;
|
||||
case 'roles':
|
||||
$class = ConfigureRolesHandler::class;
|
||||
break;
|
||||
case 'map':
|
||||
$class = ConfigureMappingHandler::class;
|
||||
break;
|
||||
// case 'upload-config': // has file, needs file config.
|
||||
// $class = UploadConfig::class;
|
||||
// break;
|
||||
@@ -113,51 +174,4 @@ class FileJobConfiguration implements JobConfigurationInterface
|
||||
|
||||
return app($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view of the next step in the job configuration.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return string
|
||||
*/
|
||||
public function getNextView(): string
|
||||
{
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
return 'import.file.new';
|
||||
case 'configure-upload':
|
||||
return 'import.file.configure-upload';
|
||||
break;
|
||||
default:
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new FireflyException(
|
||||
sprintf('FileJobConfiguration::getNextView() cannot handle stage "%s"', $this->importJob->stage)
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the initial configuration for this job is complete.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function configurationComplete(): bool
|
||||
{
|
||||
if ($this->importJob->stage === 'ready_to run') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*/
|
||||
public function setJob(ImportJob $job): void
|
||||
{
|
||||
$this->importJob = $job;
|
||||
$this->repository = app(ImportJobRepositoryInterface::class);
|
||||
$this->repository->setUser($job->user);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user