ServiceController: adjust apply/assign handling

This commit is contained in:
Thomas Gelf 2016-03-26 16:36:10 +01:00
parent 77a78a5038
commit 311f9da850

View File

@ -10,6 +10,8 @@ class ServiceController extends ObjectController
{ {
protected $host; protected $host;
protected $apply;
protected function beforeTabs() protected function beforeTabs()
{ {
if ($this->host) { if ($this->host) {
@ -27,15 +29,16 @@ class ServiceController extends ObjectController
$this->host = IcingaHost::load($host, $this->db()); $this->host = IcingaHost::load($host, $this->db());
} }
if ($apply = $this->params->get('apply')) {
$this->apply = IcingaService::load(
array('object_name' => $apply, 'object_type' => 'template'),
$this->db()
);
}
parent::init(); parent::init();
if ($this->object && $this->object->object_type === 'apply') { if ($this->object) {
$this->getTabs()->add('assign', array(
'url' => 'director/service/assign',
'urlParams' => $this->object->getUrlParams(),
'label' => $this->translate('Assign')
));
if ($this->host) { if ($this->host) {
foreach ($this->getTabs()->getTabs() as $tab) { foreach ($this->getTabs()->getTabs() as $tab) {
$tab->getUrl()->setParam('host', $this->host->object_name); $tab->getUrl()->setParam('host', $this->host->object_name);
@ -58,31 +61,64 @@ class ServiceController extends ObjectController
if ($this->host) { if ($this->host) {
$this->view->title = $this->host->object_name . ': ' . $this->view->title; $this->view->title = $this->host->object_name . ': ' . $this->view->title;
} }
if ($this->apply) {
$this->view->title = sprintf(
$this->translate('Apply "%s"'),
$this->apply->object_name
);
$form = $this->view->form;
if (!$form->hasBeenSent()) {
$form->populate(array(
'imports' => $this->apply->object_name,
'object_name' => $this->apply->object_name,
'object_type' => 'apply',
));
}
}
}
public function editAction()
{
parent::editAction();
$object = $this->object;
if ($object->isTemplate()
&& $object->getResolvedProperty('check_command_id')
) {
$this->view->actionLinks .= ' ' . $this->view->qlink(
'Create apply-rule',
'director/service/add',
array('apply' => $object->object_name),
array('class' => 'icon-plus')
);
}
} }
public function assignAction() public function assignAction()
{ {
$this->getTabs()->activate('assign'); $service = $this->object;
$this->view->form = $form = $this->loadForm('icingaServiceAssignment'); $this->view->stayHere = true;
$form
->setIcingaObject($this->object)
->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') $this->view->actionLinks = $this->view->qlink(
->setObject($this->object); $this->translate('back'),
$this->getRequest()->getUrl()->without('rule_id'),
null,
array('class' => 'icon-left-big')
);
$this->view->title = 'Assign service to host'; $this->getTabs()->activate('applied');
$this->render('object/fields', null, true); // TODO: render table $this->view->title = sprintf(
$this->translate('Apply: %s'),
$service->object_name
);
$this->view->table = $this->loadTable('IcingaAppliedService')
->setService($service)
->setConnection($this->db());
$this->setViewScript('objects/table');
} }
public function loadForm($name) public function loadForm($name)