Hostgroup: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-02 10:49:31 +02:00
parent f1c0e3cb2f
commit 0459ec95f9
6 changed files with 129 additions and 0 deletions

View File

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

View File

@ -20,6 +20,22 @@ class Director_ObjectController extends ActionController
$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 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 IcingaHostgroupForm 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' => 'Hostgroup object',
'template' => 'Hostgroup template',
)
));
if ($isTemplate) {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Hostgroup template name'),
'required' => true,
'description' => $this->translate('Hostgroup for the Icinga hostgroup template you are going to create')
));
} else {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Hostgroup'),
'required' => true,
'description' => $this->translate('Hostgroup for the Icinga hostgroup 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 IcingaHostgroupTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => 'hg.id',
'hostgroup' => 'hg.object_name',
'display_name' => 'hg.display_name'
);
}
protected function getActionUrl($row)
{
return $this->url('director/object/hostgroup', array('id' => $row->id));
}
public function getTitles()
{
$view = $this->view();
return array(
'hostgroup' => $view->translate('Hostgroup'),
'display_name' => $view->translate('Display Name'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('hg' => 'icinga_hostgroup'),
$this->getColumns()
);
return $db->fetchAll($query);
}
}

View File

@ -11,6 +11,8 @@ $section->add($this->translate('Command Arguments'))
->setUrl('director/list/commandarguments');
$section->add($this->translate('Hosts'))
->setUrl('director/list/hosts');
$section->add($this->translate('Hostgroups'))
->setUrl('director/list/hostgroups');
$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 IcingaHostgroup extends IcingaObject
{
protected $table = 'icinga_hostgroup';
protected $defaultProperties = array(
'id' => null,
'object_name' => null,
'display_name' => null,
'object_type' => null,
);
}