Servicegroup: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-02 11:56:42 +02:00
parent b0e666ab61
commit 8d25b84f20
6 changed files with 129 additions and 0 deletions

View File

@ -26,6 +26,17 @@ class Director_ListController extends ActionController
$this->render('table');
}
public function servicegroupsAction()
{
$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->view->addLink = $this->view->qlink(

View File

@ -36,6 +36,22 @@ class Director_ObjectController extends ActionController
$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')

View File

@ -0,0 +1,43 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaServicegroupForm extends DirectorObjectForm
{
public function setup()
{
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
$this->addElement('select', 'object_type', array(
'label' => $this->translate('Object type'),
'description' => $this->translate('Whether this should be a template'),
'multiOptions' => array(
null => '- please choose -',
'object' => 'Servicegroup object',
'template' => 'Servicegroup template',
)
));
if ($isTemplate) {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Servicegroup template name'),
'required' => true,
'description' => $this->translate('Servicegroup for the Icinga servicegroup template you are going to create')
));
} else {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Servicegroup'),
'required' => true,
'description' => $this->translate('Servicegroup for the Icinga servicegroup you are going to create')
));
}
$this->addElement('text', 'display_name', array(
'label' => $this->translate('Display Name'),
'description' => $this->translate('The name which should displayed.')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaServicegroupTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => 'sg.id',
'servicegroup' => 'sg.object_name',
'display_name' => 'sg.display_name'
);
}
protected function getActionUrl($row)
{
return $this->url('director/object/servicegroup', array('id' => $row->id));
}
public function getTitles()
{
$view = $this->view();
return array(
'servicegroup' => $view->translate('Servicegroup'),
'display_name' => $view->translate('Display Name'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sg' => 'icinga_servicegroup'),
$this->getColumns()
);
return $db->fetchAll($query);
}
}

View File

@ -13,6 +13,8 @@ $section->add($this->translate('Hosts'))
->setUrl('director/list/hosts');
$section->add($this->translate('Hostgroups'))
->setUrl('director/list/hostgroups');
$section->add($this->translate('Servicegroups'))
->setUrl('director/list/servicegroups');
$section->add($this->translate('Users'))
->setUrl('director/list/users');
$section->add($this->translate('Endpoints'))

View File

@ -0,0 +1,15 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaServicegroup extends IcingaObject
{
protected $table = 'icinga_servicegroup';
protected $defaultProperties = array(
'id' => null,
'object_name' => null,
'display_name' => null,
'object_type' => null,
);
}