From e1d766f11272ef5a2f46a39708887ae41d541798 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 29 Jul 2017 00:13:20 +0200 Subject: [PATCH] ServiceController: improve ObjectTabs handling --- application/controllers/ServiceController.php | 74 +++++++++++-------- library/Director/Web/Tabs/ObjectTabs.php | 13 ++-- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 756f65c7..766f03bd 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -10,6 +10,7 @@ use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Web\Table\IcingaAppliedServiceTable; use ipl\Html\Link; +use ipl\Web\Widget\Tabs; class ServiceController extends ObjectController { @@ -20,17 +21,6 @@ class ServiceController extends ObjectController protected $apply; - protected function beforeTabs() - { - if ($this->host) { - $this->getTabs()->add('host', array( - 'url' => 'director/host', - 'urlParams' => array('name' => $this->host->object_name), - 'label' => $this->translate('Host'), - )); - } - } - protected function checkDirectorPermissions() { $this->assertPermission('director/hosts'); @@ -41,43 +31,65 @@ class ServiceController extends ObjectController if ($host = $this->params->get('host')) { $this->host = IcingaHost::load($host, $this->db()); } elseif ($set = $this->params->get('set')) { - $this->set = IcingaServiceSet::load(array('object_name' => $set), $this->db()); + $this->set = IcingaServiceSet::load(['object_name' => $set], $this->db()); } elseif ($apply = $this->params->get('apply')) { $this->apply = IcingaService::load( - array('object_name' => $apply, 'object_type' => 'template'), + ['object_name' => $apply, 'object_type' => 'template'], $this->db() ); } - parent::init(); - if ($this->object) { - if ($this->host) { - foreach ($this->getTabs()->getTabs() as $tab) { - $tab->getUrl()->setParam('host', $this->host->object_name); - } - } + if ($this->host) { + $hostname = $this->host->getObjectName(); + $tabs = new Tabs(); + $tabs->add('host', [ + 'url' => 'director/host', + 'urlParams' => ['name' => $hostname], + 'label' => $this->translate('Host'), + ])->add('services', [ + 'url' => 'director/host/services', + 'urlParams' => ['name' => $hostname], + 'label' => $this->translate('Services'), + ]); - if (! $this->set && $this->object->service_set_id) { + $this->addParamToTabs('host', $hostname); + $this->controls()->prependTabs($tabs); + } + + if ($this->object) { + if (! $this->set && $this->object->get('service_set_id')) { $this->set = $this->object->getRelated('service_set'); } } - if ($this->host) { - $this->getTabs()->add('services', array( - 'url' => 'director/host/services', - 'urlParams' => array('name' => $this->host->object_name), - 'label' => $this->translate('Services'), - )); - } elseif ($this->set) { - $this->getTabs()->add('services', array( + if ($this->set) { + $setName = $this->set->getObjectName(); + $tabs = new Tabs(); + $tabs->add('set', [ + 'url' => 'director/serviceset', + 'urlParams' => ['name' => $setName], + 'label' => $this->translate('Serviceset'), + ])->add('services', [ 'url' => 'director/serviceset/services', - 'urlParams' => array('name' => $this->set->object_name), + 'urlParams' => ['name' => $setName], 'label' => $this->translate('Services'), - )); + ]); + + $this->addParamToTabs('serviceset', $setName); + $this->controls()->prependTabs($tabs); } } + protected function addParamToTabs($name, $value) + { + foreach ($this->tabs()->getTabs() as $tab) { + $tab->getUrl()->setParam($name, $value); + } + + return $this; + } + public function addAction() { parent::addAction(); diff --git a/library/Director/Web/Tabs/ObjectTabs.php b/library/Director/Web/Tabs/ObjectTabs.php index 73d82288..ceb49770 100644 --- a/library/Director/Web/Tabs/ObjectTabs.php +++ b/library/Director/Web/Tabs/ObjectTabs.php @@ -68,6 +68,13 @@ class ObjectTabs extends Tabs 'label' => $this->translate(ucfirst($type)) )); } + if ($object->getShortTableName() === 'host') { + $this->add('services', [ + 'url' => 'director/host/services', + 'urlParams' => $params, + 'label' => $this->translate('Services') + ]); + } if ($auth->hasPermission('director/showconfig')) { $this->add('render', array( @@ -119,11 +126,7 @@ class ObjectTabs extends Tabs } if ($object->getShortTableName() === 'host') { - $this->add('services', [ - 'url' => 'director/host/services', - 'urlParams' => $params, - 'label' => $this->translate('Services') - ])->add('agent', [ + $this->add('agent', [ 'url' => 'director/host/agent', 'urlParams' => $params, 'label' => $this->translate('Agent')