IcingaServiceSetServiceTable: support inherited...

...sets. They should be shown and link to the related parent. Variable overrides
should be possible, deleting the set should not.

fixes #740
This commit is contained in:
Thomas Gelf 2017-02-16 11:45:45 +01:00
parent 13918f7337
commit ac3ea09133
2 changed files with 47 additions and 18 deletions

View File

@ -133,7 +133,7 @@ class HostController extends ObjectController
$this->addHostServiceSetTables($host, $tables);
foreach ($parents as $parent) {
$this->addHostServiceSetTables($host, $tables);
$this->addHostServiceSetTables($parent, $tables, $host);
}
$title = $this->translate('Applied services');
@ -149,9 +149,12 @@ class HostController extends ObjectController
$this->view->tables = $tables;
}
protected function addHostServiceSetTables(IcingaHost $host, & $tables)
protected function addHostServiceSetTables(IcingaHost $host, & $tables, IcingaHost $affectedHost = null)
{
$db = $this->db();
if ($affectedHost === null) {
$affectedHost = $host;
}
$query = $db->getDbAdapter()->select()
->from(
@ -168,12 +171,12 @@ class HostController extends ObjectController
)->where('hs.host_id = ?', $host->id);
$sets = IcingaServiceSet::loadAll($db, $query, 'object_name');
foreach ($sets as $name => $set) {
$title = sprintf($this->translate('%s (Service set)'), $name);
$table = $this->loadTable('IcingaServiceSetService')
->setServiceSet($set)
->setHost($host)
->setAffectedHost($affectedHost)
->setTitle($title)
->setConnection($db);

View File

@ -15,6 +15,8 @@ class IcingaServiceSetServiceTable extends QuickTable
/** @var IcingaHost */
protected $host;
protected $affectedHost;
protected $searchColumns = array(
'service',
);
@ -43,6 +45,12 @@ class IcingaServiceSetServiceTable extends QuickTable
return $this;
}
public function setAffectedHost(IcingaHost $host)
{
$this->affectedHost = $host;
return $this;
}
public function setServiceSet(IcingaServiceSet $set)
{
$this->set = $set;
@ -62,7 +70,7 @@ class IcingaServiceSetServiceTable extends QuickTable
{
if ($this->host) {
$params = array(
'name' => $this->host->getObjectName(),
'name' => $this->affectedHost->getObjectName(),
'service' => $row->service,
'set' => $row->service_set
);
@ -93,7 +101,24 @@ class IcingaServiceSetServiceTable extends QuickTable
$title = $view->escape(array_shift($row));
$htm = "<thead>\n <tr>\n";
if ($this->affectedHost->id !== $this->host->id) {
$deleteLink = $view->qlink(
$this->host->getObjectName(),
'director/host/services',
array(
'name' => $this->host->getObjectName(),
),
array(
'class' => 'icon-paste',
'style' => 'float: right; font-weight: normal',
'data-base-target' => '_next',
'title' => sprintf(
$view->translate('This set has been inherited from %s'),
$this->host->getObjectName()
)
)
);
} else {
$deleteLink = $view->qlink(
$view->translate('Remove'),
'director/host/removeset',
@ -107,6 +132,7 @@ class IcingaServiceSetServiceTable extends QuickTable
'title' => $view->translate('Remove this set from this host')
)
);
}
$htm .= ' <th>' . $view->escape($title) . "$deleteLink</th>\n";