ServiceController: rework controller for hosts
This commit is contained in:
parent
89ac089677
commit
c6ecb14d7c
|
@ -8,19 +8,37 @@ use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
|
||||||
class ServiceController extends ObjectController
|
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()
|
public function init()
|
||||||
{
|
{
|
||||||
|
if ($host = $this->params->get('host')) {
|
||||||
|
$this->host = IcingaHost::load($host, $this->db());
|
||||||
|
}
|
||||||
|
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
if ($this->object && $this->object->object_type === 'apply') {
|
if ($this->object && $this->object->object_type === 'apply') {
|
||||||
$this->getTabs()->add('assign', array(
|
$this->getTabs()->add('assign', array(
|
||||||
'url' => 'director/service/assign',
|
'url' => 'director/service/assign',
|
||||||
'urlParams' => $this->object->getUrlParams(),
|
'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) {
|
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()
|
public function assignAction()
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate('assign');
|
$this->getTabs()->activate('assign');
|
||||||
$this->view->form = $form = $this->loadForm('icingaAssignServiceToHost');
|
$this->view->form = $form = $this->loadForm('icingaServiceAssignment');
|
||||||
$form
|
$form
|
||||||
->setIcingaObject($this->object)
|
->setIcingaObject($this->object)
|
||||||
->setDb($this->db())
|
->setDb($this->db());
|
||||||
->handleRequest();
|
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->table = $this->loadTable('icingaObjectAssignment')
|
||||||
->setObject($this->object);
|
->setObject($this->object);
|
||||||
|
|
||||||
$this->view->title = 'Assign service to host';
|
$this->view->title = 'Assign service to host';
|
||||||
$this->render('object/fields', null, true); // TODO: render table
|
$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()
|
protected function loadObject()
|
||||||
{
|
{
|
||||||
if ($this->object === null) {
|
if ($this->object === null) {
|
||||||
|
@ -48,9 +86,9 @@ class ServiceController extends ObjectController
|
||||||
$params = array('object_name' => $name);
|
$params = array('object_name' => $name);
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
|
|
||||||
if ($hostname = $this->params->get('host')) {
|
if ($this->host) {
|
||||||
$this->view->host = IcingaHost::load($hostname, $db);
|
$this->view->host = $this->host;
|
||||||
$params['host_id'] = $this->view->host->id;
|
$params['host_id'] = $this->host->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->object = IcingaService::load($params, $db);
|
$this->object = IcingaService::load($params, $db);
|
||||||
|
|
Loading…
Reference in New Issue