Reorganize action controllers

* Removed 'list' and 'object' from urls
* IcingaObject: added isGroup helper
* Adjusted and abstracted tabs and tables
* Show endpoints in zone list
* Remove obsolete code
* Allow to filter activity log for objects
* Improve general look and feel
This commit is contained in:
Thomas Gelf 2015-06-30 11:19:31 +02:00
parent 195a30773c
commit 8f841d28ae
45 changed files with 483 additions and 341 deletions

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_CommandController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_CommandargumentController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_CommandargumentsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_CommandsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_EndpointController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_EndpointsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_HostController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_HostgroupController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_HostgroupsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_HostsController extends ObjectsController
{
}

View File

@ -4,138 +4,6 @@ use Icinga\Module\Director\ActionController;
class Director_ListController extends ActionController class Director_ListController extends ActionController
{ {
public function hostsAction()
{
$this->setHostTabs()->activate('hosts');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Host'),
'director/object/host'
);
$this->view->title = $this->translate('Icinga Hosts');
$this->view->table = $this->loadTable('icingaHost')->setConnection($this->db());
$this->render('table');
}
public function hostgroupsAction()
{
$this->setHostTabs()->activate('hostgroups');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Hostgroup'),
'director/object/hostgroup'
);
$this->view->title = $this->translate('Icinga Hostgroups');
$this->view->table = $this->loadTable('icingaHostGroup')->setConnection($this->db());
$this->render('table');
}
public function timeperiodsAction()
{
$this->setGlobalTabs()->activate('timeperiods');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Timeperiod'),
'director/object/timeperiod'
);
$this->view->title = $this->translate('Icinga Timeperiods');
$this->view->table = $this->loadTable('icingaTimePeriod')->setConnection($this->db());
$this->render('table');
}
public function servicesAction()
{
$this->setServiceTabs()->activate('services');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Service'),
'director/object/service'
);
$this->view->title = $this->translate('Icinga Services');
$this->view->table = $this->loadTable('icingaService')->setConnection($this->db());
$this->render('table');
}
public function servicegroupsAction()
{
$this->setServiceTabs()->activate('servicegroups');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Servicegroup'),
'director/object/servicegroup'
);
$this->view->title = $this->translate('Icinga Servicegroups');
$this->view->table = $this->loadTable('icingaServiceGroup')->setConnection($this->db());
$this->render('table');
}
public function commandsAction()
{
$this->setGlobalTabs()->activate('commands');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Command'),
'director/object/command'
);
$this->view->title = $this->translate('Icinga Commands');
$this->view->table = $this->loadTable('icingaCommand')->setConnection($this->db());
$this->render('table');
}
public function commandargumentsAction()
{
$this->setGlobalTabs()->activate('commandarguments');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Command Argument'),
'director/object/commandargument'
);
$this->view->title = $this->translate('Icinga Command Arguments');
$this->view->table = $this->loadTable('icingaCommandArgument')->setConnection($this->db());
$this->render('table');
}
public function usersAction()
{
$this->setUserTabs()->activate('users');
$this->view->addLink = $this->view->qlink(
$this->translate('Add User'),
'director/object/user'
);
$this->view->title = $this->translate('Icinga Users');
$this->view->table = $this->loadTable('icingaUser')->setConnection($this->db());
$this->render('table');
}
public function usergroupsAction()
{
$this->setUserTabs()->activate('usergroups');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Usergroup'),
'director/object/usergroup'
);
$this->view->title = $this->translate('Icinga Usergroups');
$this->view->table = $this->loadTable('icingaUserGroup')->setConnection($this->db());
$this->render('table');
}
public function endpointsAction()
{
$this->setGlobalTabs()->activate('endpoints');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Endpoint'),
'director/object/endpoint'
);
$this->view->title = $this->translate('Icinga Endpoints');
$this->view->table = $this->loadTable('icingaEndpoint')->setConnection($this->db());
$this->render('table');
}
public function zonesAction()
{
$this->setGlobalTabs()->activate('zones');
$this->view->addLink = $this->view->qlink(
$this->translate('Add Zone'),
'director/object/zone'
);
$this->view->title = $this->translate('Icinga Zones');
$this->view->table = $this->loadTable('icingaZone')->setConnection($this->db());
$this->render('table');
}
public function activitylogAction() public function activitylogAction()
{ {
$this->setConfigTabs()->activate('activitylog'); $this->setConfigTabs()->activate('activitylog');

View File

@ -1,182 +0,0 @@
<?php
use Icinga\Module\Director\ActionController;
class Director_ObjectController extends ActionController
{
public function hostAction()
{
$this->view->form = $this->loadForm('icingaHost')
->setDb($this->db())
->setSuccessUrl('director/list/hosts');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Host');
} else {
$this->view->title = $this->translate('Add new Icinga Host');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function hostgroupAction()
{
$this->view->form = $this->loadForm('icingaHostGroup')
->setDb($this->db())
->setSuccessUrl('director/list/hostgroups');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Hostgroup');
} else {
$this->view->title = $this->translate('Add new Icinga Hostgroup');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function serviceAction()
{
$this->view->form = $this->loadForm('icingaService')
->setDb($this->db())
->setSuccessUrl('director/list/services');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Service');
} else {
$this->view->title = $this->translate('Add new Icinga Service');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function servicegroupAction()
{
$this->view->form = $this->loadForm('icingaServiceGroup')
->setDb($this->db())
->setSuccessUrl('director/list/servicegroups');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Servicegroup');
} else {
$this->view->title = $this->translate('Add new Icinga Servicegroup');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function commandAction()
{
$this->view->form = $this->loadForm('icingaCommand')
->setDb($this->db())
->setSuccessUrl('director/list/commands');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Command');
} else {
$this->view->title = $this->translate('Add new Icinga Command');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function commandargumentAction()
{
$this->view->form = $this->loadForm('icingaCommandArgument')
->setDb($this->db())
->setSuccessUrl('director/list/commandarguments');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Command Argument');
} else {
$this->view->title = $this->translate('Add new Icinga Command Argument');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function userAction()
{
$this->view->form = $this->loadForm('icingaUser')
->setDb($this->db())
->setSuccessUrl('director/list/users');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga User');
} else {
$this->view->title = $this->translate('Add new Icinga User');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function usergroupAction()
{
$this->view->form = $this->loadForm('icingaUserGroup')
->setDb($this->db())
->setSuccessUrl('director/list/usergroups');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Usergroup');
} else {
$this->view->title = $this->translate('Add new Icinga Usergroup');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function endpointAction()
{
$this->view->form = $this->loadForm('icingaEndpoint')
->setDb($this->db())
->setSuccessUrl('director/list/endpoints');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Endpoint');
} else {
$this->view->title = $this->translate('Add new Icinga Endpoint');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function timeperiodAction()
{
$this->view->form = $this->loadForm('icingaTimePeriod')
->setDb($this->db())
->setSuccessUrl('director/list/timeperiods');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga Timeperiod');
} else {
$this->view->title = $this->translate('Add new Icinga Timeperiod');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function zoneAction()
{
$this->view->form = $this->loadForm('icingaZone')
->setDb($this->db())
->setSuccessUrl('director/list/zones');
if ($id = $this->params->get('id')) {
$this->view->title = $this->translate('Modify Icinga Zone');
$this->view->form->loadObject($id);
} else {
$this->view->title = $this->translate('Add new Icinga Zone');
}
$this->view->form->handleRequest();
$this->render('form');
}
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_ServiceController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_ServicegroupController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_ServicegroupsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_ServicesController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_TimeperiodController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_TimeperiodsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_UserController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_UsergroupController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_UsergroupsController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_UsersController extends ObjectsController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectController;
class Director_ZoneController extends ObjectController
{
}

View File

@ -0,0 +1,7 @@
<?php
use Icinga\Module\Director\Web\Controller\ObjectsController;
class Director_ZonesController extends ObjectsController
{
}

View File

@ -6,6 +6,8 @@ use Icinga\Module\Director\Web\Table\QuickTable;
class ActivityLogTable extends QuickTable class ActivityLogTable extends QuickTable
{ {
protected $filters = array();
public function getColumns() public function getColumns()
{ {
return array( return array(
@ -31,6 +33,14 @@ class ActivityLogTable extends QuickTable
); );
} }
public function filterObject($type, $name)
{
$this->filters[] = array('l.object_type = ?', $type);
$this->filters[] = array('l.object_name = ?', $name);
return $this;
}
public function fetchData() public function fetchData()
{ {
$db = $this->connection()->getConnection(); $db = $this->connection()->getConnection();
@ -40,6 +50,10 @@ class ActivityLogTable extends QuickTable
$this->getColumns() $this->getColumns()
)->order('change_time DESC'); )->order('change_time DESC');
foreach ($this->filters as $filter) {
$query->where($filter[0], $filter[1]);
}
return $db->fetchAll($query); return $db->fetchAll($query);
} }
} }

View File

@ -19,7 +19,7 @@ class IcingaCommandArgumentTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/commandargument', array('id' => $row->id)); return $this->url('director/commandargument', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -18,7 +18,7 @@ class IcingaCommandTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/command', array('id' => $row->id)); return $this->url('director/command', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -18,7 +18,7 @@ class IcingaEndpointTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/endpoint', array('id' => $row->id)); return $this->url('director/endpoint', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -17,7 +17,7 @@ class IcingaHostGroupTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/hostgroup', array('id' => $row->id)); return $this->url('director/hostgroup', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -18,7 +18,7 @@ class IcingaHostTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/host', array('id' => $row->id)); return $this->url('director/host', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -17,7 +17,7 @@ class IcingaServiceGroupTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/servicegroup', array('id' => $row->id)); return $this->url('director/servicegroup', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -17,7 +17,7 @@ class IcingaServiceTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/service', array('id' => $row->id)); return $this->url('director/service', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -18,7 +18,7 @@ class IcingaTimePeriodTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/timeperiod', array('id' => $row->id)); return $this->url('director/timeperiod', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -18,7 +18,7 @@ class IcingaUserGroupTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/usergroup', array('id' => $row->id)); return $this->url('director/usergroup', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -22,7 +22,7 @@ class IcingaUserTable extends QuickTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/user', array('id' => $row->id)); return $this->url('director/user', array('id' => $row->id));
} }
public function getTitles() public function getTitles()

View File

@ -8,15 +8,22 @@ class IcingaZoneTable extends QuickTable
{ {
public function getColumns() public function getColumns()
{ {
if ($this->connection()->getDbType() === 'pgsql') {
$endpoints = "ARRAY_TO_STRING(ARRAY_AGG(e.object_name), ', ')";
} else {
$endpoints = "GROUP_CONCAT(e.object_name ORDER BY e.object_name SEPARATOR ', ')";
}
return array( return array(
'id' => 'z.id', 'id' => 'z.id',
'zone' => 'z.object_name', 'zone' => 'z.object_name',
'endpoints' => $endpoints,
); );
} }
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
return $this->url('director/object/zone', array('id' => $row->id)); return $this->url('director/zone', array('id' => $row->id));
} }
public function getTitles() public function getTitles()
@ -24,6 +31,7 @@ class IcingaZoneTable extends QuickTable
$view = $this->view(); $view = $this->view();
return array( return array(
'zone' => $view->translate('Zone'), 'zone' => $view->translate('Zone'),
'endpoints' => $view->translate('Endpoints'),
); );
} }
@ -33,7 +41,11 @@ class IcingaZoneTable extends QuickTable
$query = $db->select()->from( $query = $db->select()->from(
array('z' => 'icinga_zone'), array('z' => 'icinga_zone'),
$this->getColumns() $this->getColumns()
); )->joinLeft(
array('e' => 'icinga_endpoint'),
'z.id = e.zone_id',
array()
)->group('z.id');
return $db->fetchAll($query); return $db->fetchAll($query);
} }

View File

@ -1,13 +1,8 @@
<div class="controls"> <div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1> <h1><?= $this->escape($this->title) ?></h1>
</div> </div>
<div class="content"> <div class="content">
<?= $this->form ?> <?= $this->form ?>
<?php
$object = $form->getObject();
if ($object->hasBeenLoadedFromDb()) {
echo '<pre>' . $this->escape($object) . '</pre>';
}
?>
</div> </div>

View File

@ -0,0 +1,8 @@
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>
<div class="content" data-base-target="_next">
<?= $this->table->render() ?>
</div>

View File

@ -0,0 +1,8 @@
<div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>
<div class="content">
<pre><?= $this->escape($object) ?></pre>
</div>

View File

@ -12,10 +12,10 @@ $section = $this->menuSection(
$this->translate('Icinga Director') $this->translate('Icinga Director')
)->setIcon('cubes'); )->setIcon('cubes');
$section->add($this->translate('Global'))->setUrl('director/list/commands'); $section->add($this->translate('Global'))->setUrl('director/commands');
$section->add($this->translate('Hosts'))->setUrl('director/list/hosts'); $section->add($this->translate('Hosts'))->setUrl('director/hosts');
$section->add($this->translate('Services'))->setUrl('director/list/services'); $section->add($this->translate('Services'))->setUrl('director/services');
$section->add($this->translate('Users'))->setUrl('director/list/users'); $section->add($this->translate('Users'))->setUrl('director/users');
$section->add($this->translate('Config')) $section->add($this->translate('Config'))
->setUrl('director/list/generatedconfig') ->setUrl('director/list/generatedconfig')
->setPriority(902); ->setPriority(902);

View File

@ -17,6 +17,7 @@ abstract class ActionController extends Controller
public function init() public function init()
{ {
// TODO: this is obsolete I guess
$m = Icinga::app()->getModuleManager(); $m = Icinga::app()->getModuleManager();
if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) { if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) {
$m->loadModule('monitoring'); $m->loadModule('monitoring');

View File

@ -323,6 +323,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
)); ));
} }
public function isGroup()
{
return substr($this->getType(), -5) === 'Group';
}
protected function getType() protected function getType()
{ {
if ($this->type === null) { if ($this->type === null) {

View File

@ -0,0 +1,143 @@
<?php
namespace Icinga\Module\Director\Web\Controller;
use Icinga\Module\Director\ActionController;
use Icinga\Web\Url;
abstract class ObjectController extends ActionController
{
protected $object;
public function init()
{
$type = $this->getType();
$ltype = strtolower($type);
$params = array();
if ($id = $this->params->get('id')) {
$params['id'] = $id;
$this->getTabs()->add($type, array(
'url' => sprintf('director/%s', $ltype),
'urlParams' => $params,
'label' => $this->translate(ucfirst($ltype)),
))->add('modify', array(
'url' => sprintf('director/%s/edit', $ltype),
'urlParams' => $params,
'label' => $this->translate('Modify')
))->add('history', array(
'url' => sprintf('director/%s/history', $ltype),
'urlParams' => $params,
'label' => $this->translate('History')
));
} else {
$this->getTabs()->add('add', array(
'url' => sprintf('director/%s', $type),
'label' => sprintf($this->translate('Add %s'), ucfirst($type)),
));
}
}
public function indexAction()
{
$type = $this->getType();
$this->getTabs()->activate($type);
$this->view->object = $this->object();
$this->render('object/show', null, true);
}
public function editAction()
{
$this->getTabs()->activate('modify');
$type = $this->getType();
$ltype = strtolower($type);
$this->view->form = $form = $this->loadForm(
'icinga' . ucfirst($type)
)->setDb($this->db());
$form->loadObject($this->params->get('id'));
$url = Url::fromPath(
sprintf('director/%s', $ltype),
array('id' => $form->getObject()->id)
);
$form->setSuccessUrl($url);
$this->view->title = sprintf(
$this->translate('Modify Icinga %s'),
ucfirst($ltype)
);
$this->view->form->handleRequest();
$this->render('object/form', null, true);
}
public function addAction()
{
$this->getTabs()->activate('add');
$type = $this->getType();
$ltype = strtolower($type);
$url = sprintf('director/%ss', $ltype);
$this->view->form = $this->loadForm('icinga' . ucfirst($type))
->setDb($this->db())
->setSuccessUrl($url);
$this->view->title = sprintf(
$this->translate('Add new Icinga %s'),
ucfirst($ltype)
);
$this->view->form->handleRequest();
$this->render('object/form', null, true);
}
public function historyAction()
{
$type = $this->getType();
$this->getTabs()->activate('history');
$object = $this->object();
$this->view->title = $this->translate('Activity Log');
$this->view->table = $this->loadTable('activityLog')
->setConnection($this->db())
->filterObject('icinga_' . $type, $object->object_name)
;
$this->render('object/history', null, true);
}
protected function getType()
{
// Strip final 's' and upcase an eventual 'group'
return preg_replace(
array('/group$/', '/period$/', '/argument$/'),
array('Group', 'Period', 'Argument'),
$this->getRequest()->getControllerName()
);
}
protected function object()
{
if ($id = $this->params->get('id')) {
$this->object = $this->loadObject($id);
}
return $this->object;
}
protected function getObjectClassname()
{
return 'Icinga\\Module\\Director\\Objects\\Icinga'
. ucfirst($this->getType());
}
protected function loadObject($id)
{
$class = $this->getObjectClassname();
$object = $class::load($id, $this->db());
$this->view->title = sprintf(
'%s "%s"',
$this->translate(ucfirst(strtolower($this->getType()))),
$object->object_name
);
return $object;
}
}

View File

@ -0,0 +1,116 @@
<?php
namespace Icinga\Module\Director\Web\Controller;
use Icinga\Module\Director\ActionController;
abstract class ObjectsController extends ActionController
{
protected $dummy;
protected $globalTypes = array(
'Command',
'CommandArgument',
'TimePeriod',
'Zone',
'Endpoint'
);
public function init()
{
$type = $this->getType();
$ltype = strtolower($type);
$object = $this->dummyObject();
if (in_array(ucfirst($type), $this->globalTypes)) {
$tabs = $this->getTabs();
foreach ($this->globalTypes as $tabType) {
$ltabType = strtolower($tabType);
$tabs->add($ltabType, array(
'label' => $this->translate(ucfirst($ltabType) . 's'),
'url' => sprintf('director/%ss', $ltabType)
));
}
$tabs->activate($ltype);
} elseif ($object->isGroup()) {
$singleType = substr($type, 0, -5);
$tabs = $this->getTabs()->add('objects', array(
'url' => sprintf('director/%ss', $singleType),
'label' => $this->translate(ucfirst($singleType) . 's'),
));
$tabs->add('objectgroups', array(
'url' => sprintf('director/%ss', strtolower($type)),
'label' => $this->translate(ucfirst(strtolower($type)) . 's')
));
} else {
$tabs = $this->getTabs()->add('objects', array(
'url' => sprintf('director/%ss', strtolower($type)),
'label' => $this->translate(ucfirst($type) . 's'),
));
if ($object->supportsGroups()) {
$tabs->add('objectgroups', array(
'url' => sprintf('director/%sgroups', $type),
'label' => $this->translate(ucfirst($type) . 'groups')
));
}
}
}
public function indexAction()
{
$type = $this->getType();
$ltype = strtolower($type);
if (! in_array($type, $this->globalTypes)) {
if ($this->dummyObject()->isGroup()) {
$this->getTabs()->activate('objectgroups');
} else {
$this->getTabs()->activate('objects');
}
}
$this->view->addLink = $this->view->qlink(
$this->translate('Add ' . ucfirst($ltype)),
'director/' . $ltype . '/add'
);
$this->view->title = $this->translate('Icinga ' . ucfirst($ltype));
$this->view->table = $this->loadTable('icinga' . ucfirst($type))
->setConnection($this->db());
$this->render('objects/table', null, true);
}
protected function dummyObject()
{
if ($this->dummy === null) {
$class = $this->getObjectClassname();
$this->dummy = $class::create(array());
}
return $this->dummy;
}
protected function getType()
{
// Strip final 's' and upcase an eventual 'group'
return preg_replace(
array('/group$/', '/period$/', '/argument$/'),
array('Group', 'Period', 'Argument'),
substr($this->getRequest()->getControllerName(), 0, -1)
);
}
protected function getObjectClassname()
{
return 'Icinga\\Module\\Director\\Objects\\Icinga'
. ucfirst($this->getType());
}
}