ServiceVars: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-09 11:55:48 +02:00
parent 5412254d83
commit db8059c4b7
6 changed files with 148 additions and 0 deletions

View File

@ -92,6 +92,17 @@ class Director_ListController extends ActionController
$this->render('table'); $this->render('table');
} }
public function servicevarsAction()
{
$this->view->addLink = $this->view->qlink(
$this->translate('Add Service Variable'),
'director/object/servicevar'
);
$this->view->title = $this->translate('Icinga Service Variables');
$this->view->table = $this->loadTable('icingaServiceVar')->setConnection($this->db());
$this->render('table');
}
public function commandsAction() public function commandsAction()
{ {
$this->view->addLink = $this->view->qlink( $this->view->addLink = $this->view->qlink(

View File

@ -134,6 +134,26 @@ class Director_ObjectController extends ActionController
$this->render('form'); $this->render('form');
} }
public function servicevarAction()
{
$this->view->form = $this->loadForm('icingaServiceVar')
->setDb($this->db())
->setSuccessUrl('director/list/servicevars');
if (($host_id = $this->params->get('service_id'))
&& ($varname = $this->params->get('varname'))) {
$this->view->form->loadObject(array(
'service_id' => $host_id,
'varname' => $varname,
));
$this->view->title = $this->translate('Modify Icinga Service Variable');
} else {
$this->view->title = $this->translate('Add new Icinga Service Variable');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function commandAction() public function commandAction()
{ {
$this->view->form = $this->loadForm('icingaCommand') $this->view->form = $this->loadForm('icingaCommand')

View File

@ -0,0 +1,34 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaServiceVarForm extends DirectorObjectForm
{
public function setup()
{
$this->addElement('select', 'service_id', array(
'label' => $this->translate('Service'),
'description' => $this->translate('The name of the service'),
'required' => true
));
$this->addElement('text', 'varname', array(
'label' => $this->translate('Name'),
'description' => $this->translate('service var name')
));
$this->addElement('textarea', 'varvalue', array(
'label' => $this->translate('Value'),
'description' => $this->translate('service var value')
));
$this->addElement('text', 'format', array(
'label' => $this->translate('Format'),
'description' => $this->translate('value format')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaServiceVarTable extends QuickTable
{
public function getColumns()
{
return array(
'service_id' => 'sv.service_id',
'service' => 'h.object_name',
'varname' => 'sv.varname',
'varvalue' => 'sv.varvalue',
'format' => 'sv.format',
);
}
protected function getActionUrl($row)
{
return $this->url('director/object/servicevar', array(
'service_id' => $row->service_id,
'varname' => $row->varname,
));
}
public function getTitles()
{
$view = $this->view();
return array(
'service' => $view->translate('Service'),
'varname' => $view->translate('Name'),
'varvalue' => $view->translate('Value'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sv' => 'icinga_service_var'),
$this->getColumns()
)->join(
array('h' => 'icinga_service'),
'sv.service_id = h.id',
array()
);
return $db->fetchAll($query);
}
}

View File

@ -31,6 +31,8 @@ $section->add($this->translate('Servicegroups'))
->setUrl('director/list/servicegroups'); ->setUrl('director/list/servicegroups');
$section->add($this->translate('Serviceroup Members')) $section->add($this->translate('Serviceroup Members'))
->setUrl('director/list/servicegroupmembers'); ->setUrl('director/list/servicegroupmembers');
$section->add($this->translate('Service Vars'))
->setUrl('director/list/servicevars');
// USER // USER
$section->add($this->translate('Users')) $section->add($this->translate('Users'))

View File

@ -0,0 +1,29 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaServiceVar extends IcingaObject
{
protected $keyName = array('service_id', 'varname');
protected $table = 'icinga_service_var';
protected $defaultProperties = array(
'service_id' => null,
'varname' => null,
'varvalue' => null,
'format' => null,
);
public function onInsert()
{
}
public function onUpdate()
{
}
public function onDelete()
{
}
}