Correct row numbers displayed in the import result form (#3136)

* Add support for a source index offset

Improves the reporting of errors in the importing process by getting the correct offset for the displayed row where the error took place.

* Add the source index offset to the row number

Refs ce6df84b04
This commit is contained in:
Luke Towers 2017-10-15 13:45:35 -06:00 committed by GitHub
parent 46205298df
commit 8a5d0c3b13
2 changed files with 14 additions and 1 deletions

View File

@ -210,6 +210,8 @@ class ImportExportController extends ControllerBehavior
catch (Exception $ex) {
$this->controller->handleError($ex);
}
$this->vars['sourceIndexOffset'] = $this->getImportSourceIndexOffset($importOptions['firstRowTitles']);
return $this->importExportMakePartial('import_result_form');
}
@ -332,6 +334,17 @@ class ImportExportController extends ControllerBehavior
return $firstRow;
}
/**
* Get the index offset to add to the reported row number in status messages
*
* @param bool $firstRowTitles Whether or not the first row contains column titles
* @return int $offset
*/
protected function getImportSourceIndexOffset($firstRowTitles)
{
return $firstRowTitles ? 2 : 1;
}
protected function makeImportUploadFormWidget()
{

View File

@ -61,7 +61,7 @@
<ul>
<?php foreach ($importResults->{$code} as $row => $message): ?>
<li>
<strong>Row <?= $row ?></strong>
<strong>Row <?= $row + $sourceIndexOffset ?></strong>
- <?= e($message) ?>
</li>
<?php endforeach ?>