mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
IcingaHostTable: no more imports, show address...
...and related actions for templates
This commit is contained in:
parent
698d523c88
commit
b23a2437e6
@ -2,34 +2,29 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Tables;
|
namespace Icinga\Module\Director\Tables;
|
||||||
|
|
||||||
use Icinga\Data\Limitable;
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||||
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
|
||||||
|
|
||||||
class IcingaHostTable extends IcingaObjectTable
|
class IcingaHostTable extends QuickTable
|
||||||
{
|
{
|
||||||
protected $searchColumns = array(
|
protected $searchColumns = array(
|
||||||
'host',
|
'host',
|
||||||
|
'address',
|
||||||
|
'display_name'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function getColumns()
|
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(
|
return array(
|
||||||
'id' => 'h.id',
|
'id' => 'h.id',
|
||||||
'host' => 'h.object_name',
|
'host' => 'h.object_name',
|
||||||
'object_type' => 'h.object_type',
|
'object_type' => 'h.object_type',
|
||||||
'address' => 'h.address',
|
'address' => 'h.address',
|
||||||
'zone' => 'z.object_name',
|
'disabled' => 'h.disabled',
|
||||||
'parents' => $parents,
|
'display_name' => 'h.address',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getActionUrl($row)
|
protected function getActionUrl($row)
|
||||||
{
|
{
|
||||||
return $this->url('director/host', array('name' => $row->host));
|
return $this->url('director/host', array('name' => $row->host));
|
||||||
}
|
}
|
||||||
@ -43,12 +38,21 @@ class IcingaHostTable extends IcingaObjectTable
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getRowClasses($row)
|
||||||
|
{
|
||||||
|
if ($row->disabled === 'y') {
|
||||||
|
return 'disabled';
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitles()
|
public function getTitles()
|
||||||
{
|
{
|
||||||
$view = $this->view();
|
$view = $this->view();
|
||||||
return array(
|
return array(
|
||||||
'host' => $view->translate('Hostname'),
|
'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(
|
return $this->db()->select()->from(
|
||||||
array('h' => 'icinga_host'),
|
array('h' => 'icinga_host'),
|
||||||
array()
|
array()
|
||||||
)->joinLeft(
|
)->order('h.object_name');
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseQuery()
|
public function getBaseQuery()
|
||||||
|
@ -4,8 +4,88 @@ namespace Icinga\Module\Director\Tables;
|
|||||||
|
|
||||||
use Icinga\Module\Director\Tables\IcingaHostTable;
|
use Icinga\Module\Director\Tables\IcingaHostTable;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/IcingaHostTable.php';
|
||||||
class IcingaHostTemplateTable extends IcingaHostTable
|
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()
|
public function getBaseQuery()
|
||||||
{
|
{
|
||||||
return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template');
|
return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user