Importrun, imported rows: move and refactor...

...table and refactor the controller
This commit is contained in:
Thomas Gelf 2017-08-16 14:55:34 +02:00
parent cea6baa331
commit d5ccb1edb5
2 changed files with 23 additions and 48 deletions

View File

@ -4,33 +4,21 @@ namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Objects\ImportRun;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Web\Table\ImportedrowsTable;
class ImportrunController extends ActionController
{
public function indexAction()
{
$db = $this->db();
$id = $this->getRequest()->getUrl()->getParams()->shift('id');
$importRun = ImportRun::load($id, $db);
$url = clone($this->getRequest()->getUrl());
$chosenColumns = $this->getRequest()->getUrl()->shift('chosenColumns');
$importRun = ImportRun::load($this->params->getRequired('id'), $this->db());
$this->addTitle($this->translate('Import run'));
$this->addSingleTab($this->translate('Import run'));
$this->view->title = $this->translate('Import run');
$this->getTabs()->add('importrun', array(
'label' => $this->view->title,
'url' => $url
))->activate('importrun');
$table = $this
->loadTable('importedrows')
->setConnection($db)
->setImportRun($importRun);
if ($chosenColumns) {
$table->setColumns(preg_split('/,/', $chosenColumns, -1, PREG_SPLIT_NO_EMPTY));
$table = ImportedrowsTable::load($importRun);
if ($chosen = $this->params->get('chosenColumns')) {
$table->setColumns(preg_split('/,/', $chosen, -1, PREG_SPLIT_NO_EMPTY));
}
$this->view->table = $this->applyPaginationLimits($table);
$this->view->filterEditor = $table->getFilterEditor($this->getRequest());
$table->renderTo($this);
}
}

View File

@ -1,18 +1,25 @@
<?php
namespace Icinga\Module\Director\Tables;
namespace Icinga\Module\Director\Web\Table;
use Icinga\Data\DataArray\ArrayDatasource;
use Icinga\Module\Director\Objects\ImportRun;
use Icinga\Module\Director\Web\Table\QuickTable;
use Icinga\Module\Director\Objects\ImportRun;
use ipl\Web\Table\SimpleQueryBasedTable;
class ImportedrowsTable extends QuickTable
class ImportedrowsTable extends SimpleQueryBasedTable
{
protected $columns;
/** @var ImportRun */
protected $importRun;
public static function load(ImportRun $run)
{
$table = new static();
$table->setImportRun($run);
return $table;
}
public function setImportRun(ImportRun $run)
{
$this->importRun = $run;
@ -42,35 +49,15 @@ class ImportedrowsTable extends QuickTable
return array_combine($cols, $cols);
}
public function getTitles()
public function getColumnsToBeRendered()
{
$cols = $this->getColumns();
// TODO: replace key column with object name!?
// $view = $this->view();
// 'object_name' => $view->translate('Object name')
return array_combine($cols, $cols);
return $this->getColumns();
}
public function fetchData()
{
$query = $this->getBaseQuery()->columns($this->getColumns());
if ($this->hasLimit() || $this->hasOffset()) {
$query->limit($this->getLimit(), $this->getOffset());
}
return $query->fetchAll();
}
public function count()
{
return $this->getBaseQuery()->count();
}
public function getBaseQuery()
public function prepareQuery()
{
$ds = new ArrayDatasource(
$this->importRun->fetchRows($this->columns, $this->filter)
$this->importRun->fetchRows($this->columns)
);
return $ds->select()->order('object_name');