From c6ecb14d7ccbf83df4a0690de39ff5c10c67a72d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 18 Mar 2016 13:10:08 +0100 Subject: [PATCH] ServiceController: rework controller for hosts --- application/controllers/ServiceController.php | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index efcb95e2..f211baf1 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -8,19 +8,37 @@ use Icinga\Module\Director\Objects\IcingaHost; class ServiceController extends ObjectController { + protected $host; + + 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'), + )); + } + } + public function init() { + if ($host = $this->params->get('host')) { + $this->host = IcingaHost::load($host, $this->db()); + } + parent::init(); + if ($this->object && $this->object->object_type === 'apply') { $this->getTabs()->add('assign', array( 'url' => 'director/service/assign', 'urlParams' => $this->object->getUrlParams(), - 'label' => 'Assign' + 'label' => $this->translate('Assign') )); - if ($host = $this->params->get('host')) { + if ($this->host) { foreach ($this->getTabs()->getTabs() as $tab) { - $tab->getUrl()->setParam('host', $host); + $tab->getUrl()->setParam('host', $this->host->object_name); } } } @@ -29,18 +47,38 @@ class ServiceController extends ObjectController public function assignAction() { $this->getTabs()->activate('assign'); - $this->view->form = $form = $this->loadForm('icingaAssignServiceToHost'); + $this->view->form = $form = $this->loadForm('icingaServiceAssignment'); $form ->setIcingaObject($this->object) - ->setDb($this->db()) - ->handleRequest(); + ->setDb($this->db()); + if ($id = $this->params->get('rule_id')) { + $this->view->actionLinks = $this->view->qlink( + $this->translate('back'), + $this->getRequest()->getUrl()->without('rule_id'), + null, + array('class' => 'icon-left-big') + ); + $form->loadObject($id); + } + $form->handleRequest(); $this->view->table = $this->loadTable('icingaObjectAssignment') ->setObject($this->object); + $this->view->title = 'Assign service to host'; $this->render('object/fields', null, true); // TODO: render table } + public function loadForm($name) + { + $form = parent::loadForm($name); + if ($name === 'icingaService' && $this->host) { + $form->setHost($this->host); + } + + return $form; + } + protected function loadObject() { if ($this->object === null) { @@ -48,9 +86,9 @@ class ServiceController extends ObjectController $params = array('object_name' => $name); $db = $this->db(); - if ($hostname = $this->params->get('host')) { - $this->view->host = IcingaHost::load($hostname, $db); - $params['host_id'] = $this->view->host->id; + if ($this->host) { + $this->view->host = $this->host; + $params['host_id'] = $this->host->id; } $this->object = IcingaService::load($params, $db);