diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/controllers/ServicesetController.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/ServicesetController.php')
-rw-r--r-- | application/controllers/ServicesetController.php | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/application/controllers/ServicesetController.php b/application/controllers/ServicesetController.php new file mode 100644 index 0000000..684d2fc --- /dev/null +++ b/application/controllers/ServicesetController.php @@ -0,0 +1,141 @@ +<?php + +namespace Icinga\Module\Director\Controllers; + +use Icinga\Data\Filter\Filter; +use Icinga\Module\Director\Forms\IcingaServiceSetForm; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Objects\IcingaServiceSet; +use Icinga\Module\Director\Web\Controller\ObjectController; +use Icinga\Module\Director\Web\Form\DirectorObjectForm; +use Icinga\Module\Director\Web\Table\IcingaHostsMatchingFilterTable; +use Icinga\Module\Director\Web\Table\IcingaServiceSetHostTable; +use Icinga\Module\Director\Web\Table\IcingaServiceSetServiceTable; +use gipfl\IcingaWeb2\Link; + +class ServicesetController extends ObjectController +{ + /** @var IcingaHost */ + protected $host; + + protected function checkDirectorPermissions() + { + $this->assertPermission('director/servicesets'); + } + + public function init() + { + if (null !== ($host = $this->params->get('host'))) { + $this->host = IcingaHost::load($host, $this->db()); + } + + parent::init(); + if ($this->object) { + $this->addServiceSetTabs(); + } + } + + protected function onObjectFormLoaded(DirectorObjectForm $form) + { + if ($this->host) { + /** @var IcingaServiceSetForm $form */ + $form->setHost($this->host); + } + } + + public function addAction() + { + parent::addAction(); + if ($this->host) { + $this->addTitle( + $this->translate('Add a service set to "%s"'), + $this->host->getObjectName() + ); + } + } + + public function servicesAction() + { + /** @var IcingaServiceSet $set */ + $set = $this->object; + $name = $set->getObjectName(); + $this->tabs()->activate('services'); + $this->addTitle( + $this->translate('Services in this set: %s'), + $name + ); + $this->actions()->add(Link::create( + $this->translate('Add service'), + 'director/service/add', + ['set' => $name], + ['class' => 'icon-plus'] + )); + + IcingaServiceSetServiceTable::load($set) + ->setBranch($this->getBranch()) + ->renderTo($this); + } + + public function hostsAction() + { + /** @var IcingaServiceSet $set */ + $set = $this->object; + $this->tabs()->activate('hosts'); + $this->addTitle( + $this->translate('Hosts using this set: %s'), + $set->getObjectName() + ); + + $table = IcingaServiceSetHostTable::load($set); + if ($table->count()) { + $table->renderTo($this); + } + $filter = $set->get('assign_filter'); + if ($filter !== null && \strlen($filter) > 0) { + $this->content()->add( + IcingaHostsMatchingFilterTable::load(Filter::fromQueryString($filter), $this->db()) + ); + } + } + + protected function addServiceSetTabs() + { + $hexUuid = $this->object->getUniqueId()->toString(); + $tabs = $this->tabs(); + $tabs->add('services', [ + 'url' => 'director/serviceset/services', + 'urlParams' => ['uuid' => $hexUuid], + 'label' => 'Services' + ]); + if ($this->branch->isBranch()) { + return $this; + } + $tabs->add('hosts', [ + 'url' => 'director/serviceset/hosts', + 'urlParams' => ['uuid' => $hexUuid], + 'label' => 'Hosts' + ]); + + return $this; + } + + protected function loadObject() + { + if ($this->object === null) { + if (null !== ($name = $this->params->get('name'))) { + $params = ['object_name' => $name]; + $db = $this->db(); + + if ($this->host) { + $params['host_id'] = $this->host->get('id'); + } + + $this->object = IcingaServiceSet::load($params, $db); + } else { + parent::loadObject(); + } + } + + return $this->object; + } +} |