mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
ObjectController: allow for graceful tabs
This commit is contained in:
parent
d01194a7b4
commit
d1af897114
@ -21,7 +21,7 @@ class CommandController extends ObjectController
|
|||||||
|
|
||||||
public function argumentsAction()
|
public function argumentsAction()
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate('arguments');
|
$this->gracefullyActivateTab('arguments');
|
||||||
$this->view->title = sprintf(
|
$this->view->title = sprintf(
|
||||||
$this->translate('Command arguments: %s'),
|
$this->translate('Command arguments: %s'),
|
||||||
$this->object->object_name
|
$this->object->object_name
|
||||||
|
@ -75,7 +75,7 @@ class HostController extends ObjectController
|
|||||||
|
|
||||||
public function agentAction()
|
public function agentAction()
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate('agent');
|
$this->gracefullyActivateTab('agent');
|
||||||
$this->view->title = 'Agent deployment instructions';
|
$this->view->title = 'Agent deployment instructions';
|
||||||
// TODO: Fail when no ticket
|
// TODO: Fail when no ticket
|
||||||
$this->view->certname = $this->object->object_name;
|
$this->view->certname = $this->object->object_name;
|
||||||
|
@ -53,16 +53,14 @@ abstract class ObjectController extends ActionController
|
|||||||
'label' => $this->translate('History')
|
'label' => $this->translate('History')
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($object->hasBeenLoadedFromDb()
|
if ($this->hasFields()) {
|
||||||
&& $object->supportsFields()
|
|
||||||
&& ($object->isTemplate() || $type === 'command')
|
|
||||||
) {
|
|
||||||
$tabs->add('fields', array(
|
$tabs->add('fields', array(
|
||||||
'url' => sprintf('director/%s/fields', $type),
|
'url' => sprintf('director/%s/fields', $type),
|
||||||
'urlParams' => $params,
|
'urlParams' => $params,
|
||||||
'label' => $this->translate('Fields')
|
'label' => $this->translate('Fields')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->beforeTabs();
|
$this->beforeTabs();
|
||||||
$this->getTabs()->add('add', array(
|
$this->getTabs()->add('add', array(
|
||||||
@ -337,6 +335,17 @@ abstract class ObjectController extends ActionController
|
|||||||
return $this->object;
|
return $this->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function hasFields()
|
||||||
|
{
|
||||||
|
if (! ($object = $this->object)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object->hasBeenLoadedFromDb()
|
||||||
|
&& $object->supportsFields()
|
||||||
|
&& ($object->isTemplate() || $this->getType() === 'command');
|
||||||
|
}
|
||||||
|
|
||||||
protected function handleApiRequest()
|
protected function handleApiRequest()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
@ -434,6 +443,20 @@ abstract class ObjectController extends ActionController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function gracefullyActivateTab($name)
|
||||||
|
{
|
||||||
|
$tabs = $this->getTabs();
|
||||||
|
|
||||||
|
if ($tabs->has($name)) {
|
||||||
|
return $tabs->activate($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
$req = $this->getRequest();
|
||||||
|
$this->redirectNow(
|
||||||
|
$req->getUrl()->setPath('director/' . $req->getControllerName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function beforeTabs()
|
protected function beforeTabs()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user