host/services: allow to delete sets

fixes #724
This commit is contained in:
Thomas Gelf 2017-01-18 15:09:57 +01:00
parent 7b776956e3
commit a1ed3f4be5
2 changed files with 59 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Util; use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ObjectController; use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Web\Url;
class HostController extends ObjectController class HostController extends ObjectController
{ {
@ -253,6 +254,28 @@ class HostController extends ObjectController
$this->commonForServices(); $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() public function servicesetserviceAction()
{ {
$db = $this->db(); $db = $this->db();

View File

@ -49,6 +49,15 @@ class IcingaServiceSetServiceTable extends QuickTable
return $this; return $this;
} }
protected function renderTitles($row)
{
if ($this->host) {
return $this->renderHostTitles($row);
} else {
return parent::renderTitles($row);
}
}
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
if ($this->host) { 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 = "<thead>\n <tr>\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 .= ' <th>' . $view->escape($title) . "$deleteLink</th>\n";
return $htm . " </tr>\n</thead>\n";
}
public function getUnfilteredQuery() public function getUnfilteredQuery()
{ {
return $this->db()->select()->from( return $this->db()->select()->from(