IcingaServiceSet*: Improve Table and view
Add filter and pagination, and some nice display features. refs #12891
This commit is contained in:
parent
c50b1b09a2
commit
b08f3df882
|
@ -6,35 +6,50 @@ use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
|||
|
||||
class IcingaServiceSetTable extends IcingaObjectTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'name',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'sset.id',
|
||||
'name' => 'sset.object_name',
|
||||
'object_type' => 'sset.object_type',
|
||||
'assign_filter' => 'sset.assign_filter',
|
||||
'description' => 'sset.description',
|
||||
'host_name' => 'h.object_name',
|
||||
'count_hosts' => 'count(ssetobj.id)',
|
||||
'count_services' => 'count(s.id)',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
$class = parent::getRowClasses($row);
|
||||
|
||||
if ($row->object_type === 'template' && $row->assign_filter !== null) {
|
||||
$class = 'icinga-apply';
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'name' => $view->translate('Service set'),
|
||||
'name' => $view->translate('Service set'),
|
||||
'count_services' => $view->translate('# Services'),
|
||||
'count_hosts' => $view->translate('# Hosts'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
// TODO: Remove once we got a separate apply table
|
||||
if ($row->object_type === 'apply') {
|
||||
$params['id'] = $row->id;
|
||||
} else {
|
||||
$params = array('name' => $row->name);
|
||||
if ($row->host_name) {
|
||||
$params['host'] = $row->host_name;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->url('director/serviceset', $params);
|
||||
|
@ -46,10 +61,33 @@ class IcingaServiceSetTable extends IcingaObjectTable
|
|||
array('sset' => 'icinga_service_set'),
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('h' => 'icinga_host'),
|
||||
'h.id = sset.host_id',
|
||||
array('ssih' => 'icinga_service_set_inheritance'),
|
||||
'ssih.parent_service_set_id = sset.id',
|
||||
array()
|
||||
)->where('sset.object_type = ?', 'template')->order('sset.object_name');
|
||||
)->joinLeft(
|
||||
array('ssetobj' => 'icinga_service_set'),
|
||||
'ssetobj.id = ssih.service_set_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('s' => 'icinga_service'),
|
||||
's.service_set_id = sset.id',
|
||||
array()
|
||||
)->group('sset.id')
|
||||
->where('sset.object_type = ?', 'template')->order('sset.object_name');
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
$db = $this->db();
|
||||
$sub = clone($this->getBaseQuery());
|
||||
$sub->columns($this->getColumns());
|
||||
$this->applyFiltersToQuery($sub);
|
||||
$query = $db->select()->from(
|
||||
array('sub' => $sub),
|
||||
'COUNT(*)'
|
||||
);
|
||||
|
||||
return $db->fetchOne($query);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
|
|
|
@ -8,6 +8,8 @@ use Icinga\Exception\NotFoundError;
|
|||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Icinga\Web\Widget\FilterEditor;
|
||||
|
||||
abstract class ObjectsController extends ActionController
|
||||
{
|
||||
|
@ -218,9 +220,7 @@ abstract class ObjectsController extends ActionController
|
|||
}
|
||||
|
||||
$this->view->title = $this->translate('Icinga ' . $Type . ' Sets');
|
||||
$this->view->table = $this
|
||||
->loadTable('Icinga' . $Type . 'Set')
|
||||
->setConnection($this->db());
|
||||
$table = $this->loadTable('Icinga' . $Type . 'Set')->setConnection($this->db());
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('Add'),
|
||||
|
@ -232,6 +232,7 @@ abstract class ObjectsController extends ActionController
|
|||
)
|
||||
);
|
||||
|
||||
$this->provideFilterEditorForTable($table);
|
||||
$this->getTabs()->activate('sets');
|
||||
$this->setViewScript('objects/table');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue