ServiceController: rework controller for hosts

This commit is contained in:
Thomas Gelf 2016-03-18 13:10:08 +01:00
parent 89ac089677
commit c6ecb14d7c
1 changed files with 47 additions and 9 deletions

View File

@ -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);