Better import feedback.

This commit is contained in:
James Cole 2015-07-09 18:38:15 +02:00
parent 9c9fc2b5dc
commit f15267c1ab
3 changed files with 27 additions and 6 deletions

View File

@ -12,6 +12,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
@ -44,6 +45,9 @@ class Importer
/** @var array */
protected $specifix = [];
/** @var Collection */
protected $journals;
/**
* Used by CsvController.
*
@ -74,6 +78,15 @@ class Importer
return $this->rows;
}
/**
* @return Collection
*/
public function getJournals()
{
return $this->journals;
}
/**
* @throws FireflyException
*/
@ -81,6 +94,7 @@ class Importer
{
set_time_limit(0);
$this->journals = new Collection;
$this->map = $this->data->getMap();
$this->roles = $this->data->getRoles();
$this->mapped = $this->data->getMapped();
@ -91,11 +105,12 @@ class Importer
Log::debug('--- Importing row ' . $index);
$this->rows++;
$result = $this->importRow($row);
if (!($result === true)) {
if (!($result instanceof TransactionJournal)) {
Log::error('Caught error at row #' . $index . ': ' . $result);
$this->errors[$index] = $result;
} else {
$this->imported++;
$this->journals->push($result);
}
Log::debug('---');
}
@ -151,9 +166,6 @@ class Importer
return $result; // return error.
}
$journal = $this->createTransactionJournal();
if ($journal instanceof TransactionJournal) {
return true;
}
return $journal;
}

View File

@ -57,7 +57,7 @@ class CsvController extends Controller
public function columnRoles()
{
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers','csv-import-account'];
$fields = ['csv-file', 'csv-date-format', 'csv-has-headers', 'csv-import-account'];
if (!$this->wizard->sessionHasValues($fields)) {
Session::flash('warning', 'Could not recover upload.');
@ -302,12 +302,13 @@ class CsvController extends Controller
$rows = $importer->getRows();
$errors = $importer->getErrors();
$imported = $importer->getImported();
$journals = $importer->getJournals();
Preferences::mark();
$subTitle = trans('firefly.csv_process_title');
return view('csv.process', compact('rows', 'errors', 'imported', 'subTitle'));
return view('csv.process', compact('rows', 'errors', 'imported', 'subTitle', 'journals'));
}

View File

@ -42,6 +42,14 @@
{{ trans('firefly.csv_process_new_entries',{imported: imported}) }}
</p>
{% if journals|length > 0 %}
<ul>
{% for journal in journals %}
<li>#{{ journal.id }}: <a href="{{ route('transactions.show', [journal.id]) }}">{{ journal.description }}</a></li>
{% endfor %}
</ul>
{% endif %}
<p>
<a href="{{ route('csv.index') }}" class="btn btn-warning">{{ 'csv_start_over'|_ }}</a>
<a href="{{ route('index') }}" class="btn btn-success">{{ 'csv_to_index'|_ }}</a>