Pagination: Add pagination suppport for all tables

fixes #9691
This commit is contained in:
Alexander Fuhr 2015-07-23 16:19:22 +02:00
parent 08ec28345e
commit ec6974b9c5
27 changed files with 107 additions and 76 deletions

View File

@ -8,7 +8,9 @@ class Director_ListController extends ActionController
{
$this->setConfigTabs()->activate('activitylog');
$this->view->title = $this->translate('Activity Log');
$this->view->table = $this->loadTable('activityLog')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('activityLog')->setConnection($this->db())
);
$this->render('table');
}
@ -21,7 +23,9 @@ class Director_ListController extends ActionController
$this->setConfigTabs()->activate('datalist');
$this->view->title = $this->translate('Data lists');
$this->view->table = $this->loadTable('datalist')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('datalist')->setConnection($this->db())
);
$this->render('table');
}
@ -34,7 +38,9 @@ class Director_ListController extends ActionController
$this->setImportTabs()->activate('importsource');
$this->view->title = $this->translate('Import source');
$this->view->table = $this->loadTable('importsource')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('importsource')->setConnection($this->db())
);
$this->render('table');
}
@ -42,7 +48,9 @@ class Director_ListController extends ActionController
{
$this->setImportTabs()->activate('importrun');
$this->view->title = $this->translate('Import runs');
$this->view->table = $this->loadTable('importrun')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('importrun')->setConnection($this->db())
);
$this->render('table');
}
@ -65,7 +73,9 @@ class Director_ListController extends ActionController
'label' => $this->view->title,
))->activate('datalistentry');
$this->view->table = $this->loadTable('datalistEntry')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('datalistEntry')->setConnection($this->db())
);
$this->render('table');
}
@ -78,7 +88,9 @@ class Director_ListController extends ActionController
$this->setConfigTabs()->activate('datafield');
$this->view->title = $this->translate('Data fields');
$this->view->table = $this->loadTable('datafield')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('datafield')->setConnection($this->db())
);
$this->render('table');
}
@ -91,7 +103,9 @@ class Director_ListController extends ActionController
$this->setConfigTabs()->activate('generatedconfig');
$this->view->title = $this->translate('Generated Configs');
$this->view->table = $this->loadTable('generatedConfig')->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('generatedConfig')->setConnection($this->db())
);
$this->render('table');
}
}

View File

@ -41,19 +41,19 @@ class ActivityLogTable extends QuickTable
return $this;
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('l' => 'director_activity_log'),
$this->getColumns()
array()
)->order('change_time DESC');
foreach ($this->filters as $filter) {
$query->where($filter[0], $filter[1]);
}
return $db->fetchAll($query);
return $query;
}
}

View File

@ -29,15 +29,15 @@ class DatafieldTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('f' => 'director_datafield'),
$this->getColumns()
array()
)->order('varname ASC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -37,15 +37,15 @@ class DatalistEntryTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('l' => 'director_datalist_entry'),
$this->getColumns()
array()
)->where('l.list_id = ?', $this->getListId())->order('l.entry_name ASC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -29,15 +29,15 @@ class DatalistTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('l' => 'director_datalist'),
$this->getColumns()
array()
)->order('list_name ASC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -38,13 +38,13 @@ class GeneratedConfigTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('l' => 'director_activity_log'),
$this->getColumns()
array()
)->joinRight(
array('c' => 'director_generated_config'),
'c.last_activity_checksum = l.checksum',
@ -55,6 +55,6 @@ class GeneratedConfigTable extends QuickTable
array()
)->group('c.checksum')->group('l.id')->order('l.change_time DESC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -32,18 +32,18 @@ class IcingaCommandArgumentTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('ca' => 'icinga_command_argument'),
$this->getColumns()
array()
)->joinLeft(
array('c' => 'icinga_command'),
'ca.command_id = c.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -31,18 +31,18 @@ class IcingaCommandTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('c' => 'icinga_command'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'c.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -31,18 +31,18 @@ class IcingaEndpointTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('e' => 'icinga_endpoint'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'e.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -29,14 +29,14 @@ class IcingaHostGroupTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('hg' => 'icinga_hostgroup'),
$this->getColumns()
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -2,10 +2,12 @@
namespace Icinga\Module\Director\Tables;
use Icinga\Data\Limitable;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaHostTable extends QuickTable
{
public function getColumns()
{
return array(
@ -31,18 +33,18 @@ class IcingaHostTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('h' => 'icinga_host'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'h.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -35,18 +35,16 @@ class IcingaHostVarTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
return $db->select()->from(
array('hv' => 'icinga_host_var'),
$this->getColumns()
array()
)->join(
array('h' => 'icinga_host'),
'hv.host_id = h.id',
array()
);
return $db->fetchAll($query);
}
}

View File

@ -29,14 +29,14 @@ class IcingaServiceGroupTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sg' => 'icinga_servicegroup'),
$this->getColumns()
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -29,18 +29,18 @@ class IcingaServiceTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'icinga_service'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
's.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -35,18 +35,18 @@ class IcingaServiceVarTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sv' => 'icinga_service_var'),
$this->getColumns()
array()
)->join(
array('h' => 'icinga_service'),
'sv.service_id = h.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -31,18 +31,18 @@ class IcingaTimePeriodTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('t' => 'icinga_timeperiod'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
't.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -31,18 +31,18 @@ class IcingaUserGroupTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('ug' => 'icinga_usergroup'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'ug.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -35,18 +35,18 @@ class IcingaUserTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('u' => 'icinga_user'),
$this->getColumns()
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'u.zone_id = z.id',
array()
);
return $db->fetchAll($query);
return $query;
}
}

View File

@ -35,18 +35,18 @@ class IcingaZoneTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('z' => 'icinga_zone'),
$this->getColumns()
array()
)->joinLeft(
array('e' => 'icinga_endpoint'),
'z.id = e.zone_id',
array()
)->group('z.id');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -33,13 +33,13 @@ class ImportrunTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'import_source'),
$this->getColumns()
array()
)->join(
array('r' => 'import_run'),
'r.source_id = s.id',
@ -54,6 +54,6 @@ class ImportrunTable extends QuickTable
array()
)->group('r.id')->order('r.start_time DESC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -38,15 +38,15 @@ class ImportsourceTable extends QuickTable
);
}
public function fetchData()
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'import_source'),
$this->getColumns()
array()
)->order('source_name ASC');
return $db->fetchAll($query);
return $query;
}
}

View File

@ -3,7 +3,8 @@
<h1><?= $this->escape($this->title) ?></h1>
<span data-base-target="_next">
<?= $this->addLink ?>
</span>
</span><br />
<?= $this->table->getPaginator() ?>
</div>
<div class="content" data-base-target="_next">

View File

@ -1,6 +1,8 @@
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
<br />
<?= $this->table->getPaginator() ?>
</div>
<div class="content" data-base-target="_next">

View File

@ -3,7 +3,8 @@
<h1><?= $this->escape($this->title) ?></h1>
<span data-base-target="_next">
<?= $this->addLink ?>
</span>
</span><br />
<?= $this->table->getPaginator() ?>
</div>
<div class="content" data-base-target="_next">

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Web\Controller;
use Icinga\Application\Icinga;
use Icinga\Data\Paginatable;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Web\Form\FormLoader;
use Icinga\Module\Director\Web\Table\TableLoader;
@ -24,6 +25,16 @@ abstract class ActionController extends Controller
}
}
protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
{
$limit = $this->params->get('limit', $limit);
$page = $this->params->get('page', $offset);
$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
return $paginatable;
}
public function loadForm($name)
{
return FormLoader::load($name, $this->Module());

View File

@ -95,10 +95,10 @@ abstract class ObjectController extends ActionController
$this->getTabs()->activate('history');
$object = $this->object();
$this->view->title = $this->translate('Activity Log');
$this->view->table = $this->loadTable('activityLog')
->setConnection($this->db())
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('activityLog')->setConnection($this->db())
->filterObject('icinga_' . $type, $object->object_name)
;
);
$this->render('object/history', null, true);
}

View File

@ -81,8 +81,10 @@ abstract class ObjectsController extends ActionController
'director/' . $ltype . '/add'
);
$this->view->title = $this->translate('Icinga ' . ucfirst($ltype));
$this->view->table = $this->loadTable('icinga' . ucfirst($type))
->setConnection($this->db());
$this->view->table = $this->applyPaginationLimits(
$this->loadTable('icinga' . ucfirst($type))->setConnection($this->db())
);
$this->render('objects/table', null, true);
}