mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
WIP: Add templates tab for all objects
Exceptions are global types, and those who can't import.
This commit is contained in:
parent
c73be6b976
commit
f863a9b223
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Web\Controller;
|
namespace Icinga\Module\Director\Web\Controller;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
||||||
|
|
||||||
abstract class ObjectsController extends ActionController
|
abstract class ObjectsController extends ActionController
|
||||||
{
|
{
|
||||||
protected $dummy;
|
protected $dummy;
|
||||||
@ -37,15 +41,22 @@ abstract class ObjectsController extends ActionController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var IcingaObject $object */
|
||||||
$object = $this->dummyObject();
|
$object = $this->dummyObject();
|
||||||
if ($object->isGroup()) {
|
if ($object->isGroup()) {
|
||||||
$type = substr($type, 0, -5);
|
$type = substr($type, 0, -5);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tabs = $this->getTabs()->add('objects', array(
|
$tabs->add('objects', array(
|
||||||
'url' => sprintf('director/%ss', strtolower($type)),
|
'url' => sprintf('director/%ss', strtolower($type)),
|
||||||
'label' => $this->translate(ucfirst($type) . 's'),
|
'label' => $this->translate(ucfirst($type) . 's'),
|
||||||
));
|
));
|
||||||
|
if ($object->supportsImports()) {
|
||||||
|
$tabs->add('templates', array(
|
||||||
|
'url' => sprintf('director/%ss/templates', strtolower($type)),
|
||||||
|
'label' => $this->translate('Templates'),
|
||||||
|
));
|
||||||
|
}
|
||||||
if ($object->supportsGroups() || $object->isGroup()) {
|
if ($object->supportsGroups() || $object->isGroup()) {
|
||||||
$tabs->add('objectgroups', array(
|
$tabs->add('objectgroups', array(
|
||||||
'url' => sprintf('director/%sgroups', $type),
|
'url' => sprintf('director/%sgroups', $type),
|
||||||
@ -68,12 +79,16 @@ abstract class ObjectsController extends ActionController
|
|||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
$ltype = strtolower($type);
|
$ltype = strtolower($type);
|
||||||
$this->assertPermission('director/' . $type . 's/read');
|
$this->assertPermission('director/' . $type . 's/read');
|
||||||
|
/** @var IcingaObject $dummy */
|
||||||
$dummy = $this->dummyObject();
|
$dummy = $this->dummyObject();
|
||||||
|
|
||||||
if (! in_array(ucfirst($type), $this->globalTypes)) {
|
if (! in_array(ucfirst($type), $this->globalTypes)) {
|
||||||
if ($dummy->isGroup()) {
|
if ($dummy->isGroup()) {
|
||||||
$this->getTabs()->activate('objectgroups');
|
$this->getTabs()->activate('objectgroups');
|
||||||
$table = 'icinga' . ucfirst($type);
|
$table = 'icinga' . ucfirst($type);
|
||||||
|
} else if ($dummy->isTemplate()) {
|
||||||
|
$this->getTabs()->activate('templates');
|
||||||
|
$table = 'icinga' . ucfirst($type);
|
||||||
} else {
|
} else {
|
||||||
$this->getTabs()->activate('objects');
|
$this->getTabs()->activate('objects');
|
||||||
$table = 'icinga' . ucfirst($type);
|
$table = 'icinga' . ucfirst($type);
|
||||||
@ -82,14 +97,30 @@ abstract class ObjectsController extends ActionController
|
|||||||
$table = 'icinga' . ucfirst($type);
|
$table = 'icinga' . ucfirst($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var IcingaObjectTable $table */
|
||||||
|
$table = $this->loadTable($table)->setConnection($this->db());
|
||||||
|
|
||||||
if ($dummy->isTemplate()) {
|
if ($dummy->isTemplate()) {
|
||||||
$addParams = array('type' => 'template');
|
$addParams = array('type' => 'template');
|
||||||
|
$this->getTabs()->activate('templates');
|
||||||
|
$title = $this->translate('Icinga ' . ucfirst($ltype) . ' Templates');
|
||||||
$addTitle = $this->translate('Add %s template');
|
$addTitle = $this->translate('Add %s template');
|
||||||
|
$table->enforceFilter(Filter::expression('object_type', '=', 'template'));
|
||||||
} else {
|
} else {
|
||||||
$addParams = array();
|
$addParams = array('type' => 'object');
|
||||||
|
$title = $this->translate('Icinga ' . ucfirst($ltype) . 's');
|
||||||
$addTitle = $this->translate('Add %s');
|
$addTitle = $this->translate('Add %s');
|
||||||
|
if (
|
||||||
|
$dummy->supportsImports()
|
||||||
|
&& array_key_exists('object_type', $table->getColumns())
|
||||||
|
&& ! in_array(ucfirst($type), $this->globalTypes)
|
||||||
|
) {
|
||||||
|
$table->enforceFilter(Filter::expression('object_type', '!=', 'template'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->view->title = $title;
|
||||||
|
|
||||||
$this->view->addLink = $this->view->qlink(
|
$this->view->addLink = $this->view->qlink(
|
||||||
sprintf($addTitle, $this->translate(ucfirst($ltype))),
|
sprintf($addTitle, $this->translate(ucfirst($ltype))),
|
||||||
'director/' . $ltype .'/add',
|
'director/' . $ltype .'/add',
|
||||||
@ -97,8 +128,6 @@ abstract class ObjectsController extends ActionController
|
|||||||
array('class' => 'icon-plus')
|
array('class' => 'icon-plus')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->view->title = $this->translate('Icinga ' . ucfirst($ltype) . 's');
|
|
||||||
$table = $this->loadTable($table)->setConnection($this->db());
|
|
||||||
$filterEditor = $table->getFilterEditor($this->getRequest());
|
$filterEditor = $table->getFilterEditor($this->getRequest());
|
||||||
$filter = $filterEditor->getFilter();
|
$filter = $filterEditor->getFilter();
|
||||||
|
|
||||||
@ -168,6 +197,11 @@ abstract class ObjectsController extends ActionController
|
|||||||
$this->setViewScript('objects/table');
|
$this->setViewScript('objects/table');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function templatesAction()
|
||||||
|
{
|
||||||
|
$this->indexAction();
|
||||||
|
}
|
||||||
|
|
||||||
public function templatetreeAction()
|
public function templatetreeAction()
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate('tree');
|
$this->getTabs()->activate('tree');
|
||||||
@ -182,10 +216,13 @@ abstract class ObjectsController extends ActionController
|
|||||||
$class = $this->getObjectClassname();
|
$class = $this->getObjectClassname();
|
||||||
$this->dummy = $class::create(array());
|
$this->dummy = $class::create(array());
|
||||||
if ($this->dummy->hasProperty('object_type')) {
|
if ($this->dummy->hasProperty('object_type')) {
|
||||||
if (false === strpos($this->getRequest()->getControllerName(), 'template')) {
|
if (
|
||||||
$this->dummy->object_type = 'object';
|
strpos($this->getRequest()->getControllerName(), 'template') !== false
|
||||||
} else {
|
|| strpos($this->getRequest()->getActionName(), 'templates') !== false
|
||||||
|
) {
|
||||||
$this->dummy->object_type = 'template';
|
$this->dummy->object_type = 'template';
|
||||||
|
} else {
|
||||||
|
$this->dummy->object_type = 'object';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user