From a1ed3f4be57bd72fea32fea59a3a568b4b8cd191 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 18 Jan 2017 15:09:57 +0100 Subject: [PATCH] host/services: allow to delete sets fixes #724 --- application/controllers/HostController.php | 23 ++++++++++++ .../tables/IcingaServiceSetServiceTable.php | 36 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 59600af9..0b84bc51 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -11,6 +11,7 @@ use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Util; use Icinga\Module\Director\Web\Controller\ObjectController; +use Icinga\Web\Url; class HostController extends ObjectController { @@ -253,6 +254,28 @@ class HostController extends ObjectController $this->commonForServices(); } + public function removesetAction() + { + // TODO: clean this up, use POST + $db = $this->db()->getDbAdapter(); + $query = $db->select()->from( + array('ss' => 'icinga_service_set'), + array('id' => 'ss.id') + )->join( + array('si' => 'icinga_service_set_inheritance'), + 'si.service_set_id = ss.id', + array() + )->where('si.parent_service_set_id = ?', $this->params->get('setId')) + ->where('ss.host_id = ?', $this->object->id); + + IcingaServiceSet::loadWithAutoIncId($db->fetchOne($query), $this->db())->delete(); + $this->redirectNow( + Url::fromPath('director/host/services', array( + 'name' => $this->object->getObjectName() + )) + ); + } + public function servicesetserviceAction() { $db = $this->db(); diff --git a/application/tables/IcingaServiceSetServiceTable.php b/application/tables/IcingaServiceSetServiceTable.php index cc045e73..97642fb2 100644 --- a/application/tables/IcingaServiceSetServiceTable.php +++ b/application/tables/IcingaServiceSetServiceTable.php @@ -49,6 +49,15 @@ class IcingaServiceSetServiceTable extends QuickTable return $this; } + protected function renderTitles($row) + { + if ($this->host) { + return $this->renderHostTitles($row); + } else { + return parent::renderTitles($row); + } + } + protected function getActionUrl($row) { if ($this->host) { @@ -77,6 +86,33 @@ class IcingaServiceSetServiceTable extends QuickTable ); } + protected function renderHostTitles($row) + { + $view = $this->view(); + // Hint: row is an array of titles!?!?!? + $title = $view->escape(array_shift($row)); + + $htm = "\n \n"; + + $deleteLink = $view->qlink( + $view->translate('Remove'), + 'director/host/removeset', + array( + 'name' => $this->host->getObjectName(), + 'setId' => $this->set->id + ), + array( + 'class' => 'icon-cancel', + 'style' => 'float: right; font-weight: normal', + 'title' => $view->translate('Remove this set from this host') + ) + ); + + $htm .= ' ' . $view->escape($title) . "$deleteLink\n"; + + return $htm . " \n\n"; + } + public function getUnfilteredQuery() { return $this->db()->select()->from(