IcingaHostTable: no more imports, show address...

...and related actions for templates
This commit is contained in:
Thomas Gelf 2016-10-24 21:43:52 +00:00
parent 698d523c88
commit b23a2437e6
2 changed files with 102 additions and 46 deletions

View File

@ -2,30 +2,25 @@
namespace Icinga\Module\Director\Tables;
use Icinga\Data\Limitable;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaHostTable extends IcingaObjectTable
class IcingaHostTable extends QuickTable
{
protected $searchColumns = array(
'host',
'address',
'display_name'
);
public function getColumns()
{
if ($this->connection()->isPgsql()) {
$parents = "ARRAY_TO_STRING(ARRAY_AGG(ih.object_name ORDER BY hi.weight), ', ')";
} else {
$parents = "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')";
}
return array(
'id' => 'h.id',
'host' => 'h.object_name',
'object_type' => 'h.object_type',
'address' => 'h.address',
'zone' => 'z.object_name',
'parents' => $parents,
'disabled' => 'h.disabled',
'display_name' => 'h.address',
);
}
@ -43,12 +38,21 @@ class IcingaHostTable extends IcingaObjectTable
);
}
protected function getRowClasses($row)
{
if ($row->disabled === 'y') {
return 'disabled';
} else {
return null;
}
}
public function getTitles()
{
$view = $this->view();
return array(
'host' => $view->translate('Hostname'),
'parents' => $view->translate('Imports'),
'address' => $view->translate('Address'),
);
}
@ -57,35 +61,7 @@ class IcingaHostTable extends IcingaObjectTable
return $this->db()->select()->from(
array('h' => 'icinga_host'),
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'h.zone_id = z.id',
array()
)->joinLeft(
array('hi' => 'icinga_host_inheritance'),
'hi.host_id = h.id',
array()
)->joinLeft(
array('ih' => 'icinga_host'),
'hi.parent_host_id = ih.id',
array()
)->group('h.id')
->group('z.id')
->order('h.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);
)->order('h.object_name');
}
public function getBaseQuery()

View File

@ -4,8 +4,88 @@ namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Tables\IcingaHostTable;
require_once __DIR__ . '/IcingaHostTable.php';
class IcingaHostTemplateTable extends IcingaHostTable
{
protected $searchColumns = array(
'host',
'display_name'
);
public function getTitles()
{
$view = $this->view();
return array(
'host' => $view->translate('Template name'),
);
}
protected function renderAdditionalActions($row)
{
$htm = '';
$view = $this->view();
if ($row->object_type === 'template') {
$htm .= $view->qlink(
'',
'director/host/add?type=object',
array('imports' => $row->host),
array(
'class' => 'icon-plus',
'title' => $view->translate(
'Create a new host based on this template'
)
)
);
if ($cnt = $row->cnt_child_templates) {
if ((int) $cnt === 1) {
$title = $view->translate('Show one host template using this template');
} else {
$title = sprintf(
$view->translate('Show %d host templates using this template'),
$cnt
);
}
$htm .= $view->qlink(
'',
'director/hosts/bytemplate',
array('name' => $row->host),
array(
'class' => 'icon-sitemap',
'title' => $title
)
);
}
if ($cnt = $row->cnt_child_hosts) {
if ((int) $cnt === 1) {
$title = $view->translate('Show one host using this template');
} else {
$title = sprintf(
$view->translate('Show %d hosts using this template'),
$cnt
);
}
$htm .= $view->qlink(
'',
'director/hosts/bytemplate',
array('name' => $row->host),
array(
'class' => 'icon-host',
'title' => $title
)
);
}
}
return $htm;
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template');