mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
Data: controller, table, form - ipl adjustments
This commit is contained in:
parent
373d01ad64
commit
0c7e3eee41
@ -2,59 +2,67 @@
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Forms\DirectorDatalistentryForm;
|
||||
use Icinga\Module\Director\Forms\DirectorDatalistForm;
|
||||
use Icinga\Module\Director\Objects\DirectorDatalist;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Web\Table\DatafieldTable;
|
||||
use Icinga\Module\Director\Web\Table\DatalistEntryTable;
|
||||
use Icinga\Module\Director\Web\Table\DatalistTable;
|
||||
use ipl\Html\Link;
|
||||
|
||||
class DataController extends ActionController
|
||||
{
|
||||
public function listsAction()
|
||||
{
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('Add'),
|
||||
'director/data/list',
|
||||
null,
|
||||
array('class' => 'icon-plus')
|
||||
);
|
||||
['class' => 'icon-plus']
|
||||
));
|
||||
|
||||
$this->setDataTabs()->activate('datalist');
|
||||
$this->view->title = $this->translate('Data lists');
|
||||
$this->prepareAndRenderTable('datalist');
|
||||
$this->provideFilterEditorForTable($this->view->table);
|
||||
$this->addTitle($this->translate('Data lists'));
|
||||
$table = new DatalistTable($this->db());
|
||||
$table->renderTo($this);
|
||||
// $this->prepareAndRenderTable('datalist');
|
||||
// $this->provideFilterEditorForTable($this->view->table);
|
||||
}
|
||||
|
||||
public function listAction()
|
||||
{
|
||||
$this->view->stayHere = true;
|
||||
// TODO: check this
|
||||
// $this->view->stayHere = true;
|
||||
|
||||
$form = $this->view->form = $this->loadForm('directorDatalist')
|
||||
$form = DirectorDatalistForm::load()
|
||||
->setSuccessUrl('director/data/lists')
|
||||
->setDb($this->db());
|
||||
$this->content()->add($form);
|
||||
|
||||
if ($id = $this->getRequest()->getUrl()->shift('id')) {
|
||||
if ($id = $this->url()->shift('id')) {
|
||||
$form->loadObject($id);
|
||||
$this->view->title = sprintf(
|
||||
$this->addTitle(
|
||||
$this->translate('Data list: %s'),
|
||||
$form->getObject()->list_name
|
||||
);
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('back'),
|
||||
'director/data/list',
|
||||
null,
|
||||
array('class' => 'icon-left-big')
|
||||
);
|
||||
|
||||
$this->view->addLink .= $this->view->qlink(
|
||||
['class' => 'icon-left-big']
|
||||
))->add(Link::create(
|
||||
$this->translate('Entries'),
|
||||
'director/data/listentry',
|
||||
array('list_id' => $id),
|
||||
array(
|
||||
['list_id' => $id],
|
||||
[
|
||||
'class' => 'icon-doc-text',
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
);
|
||||
]
|
||||
));
|
||||
|
||||
$this->getTabs()->add('editlist', array(
|
||||
$this->tabs()->add('editlist', array(
|
||||
'url' => 'director/data/list' . '?id=' . $id,
|
||||
'label' => $this->translate('Edit list'),
|
||||
))->add('entries', array(
|
||||
@ -62,16 +70,15 @@ class DataController extends ActionController
|
||||
'label' => $this->translate('List entries'),
|
||||
))->activate('editlist');
|
||||
} else {
|
||||
$this->view->title = $this->translate('Add');
|
||||
$this->addTitle($title = $this->translate('Add'));
|
||||
|
||||
$this->getTabs()->add('addlist', array(
|
||||
$this->tabs()->add('addlist', array(
|
||||
'url' => 'director/data/list',
|
||||
'label' => $this->view->title,
|
||||
'label' => $title,
|
||||
))->activate('addlist');
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
$this->setViewScript('object/form');
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
@ -83,23 +90,24 @@ class DataController extends ActionController
|
||||
}
|
||||
|
||||
if ($edit) {
|
||||
$this->view->title = $this->translate('Edit list');
|
||||
$this->addTitle($title = $this->translate('Edit list'));
|
||||
|
||||
$this->getTabs()->add('editlist', array(
|
||||
'url' => 'director/datalist/edit' . '?id=' . $id,
|
||||
'label' => $this->view->title,
|
||||
'label' => $title,
|
||||
))->add('entries', array(
|
||||
'url' => 'director/data/listentry' . '?list_id=' . $id,
|
||||
'label' => $this->translate('List entries'),
|
||||
))->activate('editlist');
|
||||
} else {
|
||||
$this->view->title = $this->translate('Add list');
|
||||
$this->addTitle($title = $this->translate('Add list'));
|
||||
$this->getTabs()->add('addlist', array(
|
||||
'url' => 'director/datalist/add',
|
||||
'label' => $this->view->title,
|
||||
'label' => $title,
|
||||
))->activate('addlist');
|
||||
}
|
||||
|
||||
$form = $this->view->form = $this->loadForm('directorDatalist')
|
||||
$form = DirectorDatalistForm::load()
|
||||
->setSuccessUrl('director/data/lists')
|
||||
->setDb($this->db());
|
||||
|
||||
@ -108,68 +116,80 @@ class DataController extends ActionController
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
|
||||
$this->render('object/form', null, true);
|
||||
}
|
||||
|
||||
|
||||
public function fieldsAction()
|
||||
{
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('Add'),
|
||||
'director/datafield/add',
|
||||
null,
|
||||
array('class' => 'icon-plus')
|
||||
);
|
||||
['class' => 'icon-plus']
|
||||
));
|
||||
|
||||
$this->setDataTabs()->activate('datafield');
|
||||
$this->view->title = $this->translate('Data fields');
|
||||
$this->prepareAndRenderTable('datafield');
|
||||
$this->provideFilterEditorForTable($this->view->table);
|
||||
$this->addTitle($this->translate('Data fields'));
|
||||
$this->content()->add(new DatafieldTable($this->db()));
|
||||
// $this->prepareAndRenderTable('datafield');
|
||||
// $this->provideFilterEditorForTable($this->view->table);
|
||||
}
|
||||
|
||||
public function listentryAction()
|
||||
{
|
||||
$this->view->stayHere = true;
|
||||
// $this->view->stayHere = true;
|
||||
|
||||
$url = $this->getRequest()->getUrl();
|
||||
$url = $this->url();
|
||||
$entryName = $url->shift('entry_name');
|
||||
$list = DirectorDatalist::load($url->shift('list_id'), $this->db());
|
||||
$listId = $list->id;
|
||||
|
||||
$form = $this->view->form = $this->loadForm('directorDatalistentry')
|
||||
$form = DirectorDatalistentryForm::load()
|
||||
->setSuccessUrl('director/data/listentry?list_id=' . $listId)
|
||||
->setList($list)
|
||||
->setDb($this->db());
|
||||
|
||||
if ($entryName) {
|
||||
$form->loadObject(array(
|
||||
$form->loadObject([
|
||||
'list_id' => $listId,
|
||||
'entry_name' => $entryName
|
||||
));
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
]);
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('back'),
|
||||
'director/data/listentry' . '?list_id=' . $listId,
|
||||
null,
|
||||
array('class' => 'icon-left-big')
|
||||
);
|
||||
'director/data/listentry',
|
||||
['list_id' => $listId],
|
||||
['class' => 'icon-left-big']
|
||||
));
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
|
||||
$this->content()->add($form);
|
||||
|
||||
$this->view->title = $this->translate('List entries')
|
||||
. ': ' . $list->list_name;
|
||||
$this->getTabs()->add('editlist', array(
|
||||
$this->addTitle($title = $this->translate('List entries')
|
||||
. ': ' . $list->list_name);
|
||||
$this->tabs()->add('editlist', [
|
||||
'url' => 'director/data/list' . '?id=' . $listId,
|
||||
'label' => $this->translate('Edit list'),
|
||||
))->add('datalistentry', array(
|
||||
])->add('datalistentry', [
|
||||
'url' => 'director/data/listentry' . '?list_id=' . $listId,
|
||||
'label' => $this->view->title,
|
||||
))->activate('datalistentry');
|
||||
'label' => $title,
|
||||
])->activate('datalistentry');
|
||||
|
||||
$this->prepareTable('datalistEntry')->setList($list);
|
||||
$this->setViewScript('objects/table');
|
||||
$table = new DatalistEntryTable($this->db());
|
||||
$table->attributes()->set('data-base-target', '_self');
|
||||
$table->setList($list);
|
||||
$this->content()->add($table);
|
||||
}
|
||||
|
||||
protected function setDataTabs()
|
||||
{
|
||||
return $this->tabs()->add('datafield', [
|
||||
'label' => $this->translate('Data fields'),
|
||||
'url' => 'director/data/fields'
|
||||
])->add('datalist', [
|
||||
'label' => $this->translate('Data lists'),
|
||||
'url' => 'director/data/lists'
|
||||
]);
|
||||
}
|
||||
|
||||
protected function prepareTable($name)
|
||||
|
@ -22,7 +22,7 @@ class DirectorDatalistEntryForm extends DirectorObjectForm
|
||||
));
|
||||
|
||||
$this->addElement('text', 'entry_value', array(
|
||||
'label' => $this->translate('Value'),
|
||||
'label' => $this->translate('Label'),
|
||||
'required' => true,
|
||||
'description' => $this->translate(
|
||||
'This will be the visible caption for this entry'
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class DatalistTable extends QuickTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'list_name',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'l.id',
|
||||
'list_name' => 'l.list_name',
|
||||
'owner' => 'l.owner',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url(
|
||||
'director/data/listentry',
|
||||
array('list_id' => $row->id)
|
||||
);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'list_name' => $view->translate('List name'),
|
||||
// 'owner' => $view->translate('Owner'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('l' => 'director_datalist'),
|
||||
array()
|
||||
)->order('list_name ASC');
|
||||
}
|
||||
}
|
@ -161,24 +161,6 @@ abstract class ActionController extends Controller implements ControlsAndContent
|
||||
return $this->view->tabs;
|
||||
}
|
||||
|
||||
protected function setDataTabs()
|
||||
{
|
||||
$this->view->tabs = Widget::create('tabs')->add(
|
||||
'datafield',
|
||||
array(
|
||||
'label' => $this->translate('Data fields'),
|
||||
'url' => 'director/data/fields'
|
||||
)
|
||||
)->add(
|
||||
'datalist',
|
||||
array(
|
||||
'label' => $this->translate('Data lists'),
|
||||
'url' => 'director/data/lists'
|
||||
)
|
||||
);
|
||||
return $this->view->tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $permission
|
||||
* @return $this
|
||||
|
@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
use Zend_Db_Adapter_Abstract as ZfDbAdapter;
|
||||
use Zend_Db_Select as ZfDbSelect;
|
||||
|
||||
class DatafieldTable extends QuickTable
|
||||
class DatafieldTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'varname',
|
||||
@ -26,23 +27,31 @@ class DatafieldTable extends QuickTable
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this->url('director/datafield/edit', array('id' => $row->id));
|
||||
return $this::tr([
|
||||
$this::td(Link::create(
|
||||
$row->caption,
|
||||
'director/datafield/edit',
|
||||
['id' => $row->id]
|
||||
)),
|
||||
$this::td($row->varname),
|
||||
$this::td($row->assigned_fields),
|
||||
$this::td($row->assigned_vars)
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'caption' => $view->translate('Label'),
|
||||
'varname' => $view->translate('Field name'),
|
||||
'assigned_fields' => $view->translate('# Used'),
|
||||
'assigned_vars' => $view->translate('# Vars'),
|
||||
$this->translate('Label'),
|
||||
$this->translate('Field name'),
|
||||
$this->translate('# Used'),
|
||||
$this->translate('# Vars'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
public function prepareQuery()
|
||||
{
|
||||
$db = $this->db();
|
||||
$fieldTypes = array('command', 'host', 'notification', 'service', 'user');
|
||||
@ -60,7 +69,7 @@ class DatafieldTable extends QuickTable
|
||||
|
||||
return $db->select()->from(
|
||||
array('df' => 'director_datafield'),
|
||||
array()
|
||||
$this->getColumns()
|
||||
)->joinLeft(
|
||||
array('used_fields' => $db->select()->union($fieldsQueries, ZfDbSelect::SQL_UNION_ALL)),
|
||||
'used_fields.datafield_id = df.id',
|
||||
@ -72,17 +81,6 @@ class DatafieldTable extends QuickTable
|
||||
)->group('df.id')->group('df.varname')->order('caption ASC');
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
$db = $this->db();
|
||||
return $db->fetchOne(
|
||||
$db->select()->from(
|
||||
array('sub' => $this->getBaseQuery()->columns($this->getColumns())),
|
||||
'COUNT(*)'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param ZfDbAdapter $db
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\DirectorDatalist;
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class DatalistEntryTable extends QuickTable
|
||||
class DatalistEntryTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $datalist;
|
||||
|
||||
@ -34,28 +35,30 @@ class DatalistEntryTable extends QuickTable
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this->url('director/data/listentry/edit', array(
|
||||
'list_id' => $row->list_id,
|
||||
'entry_name' => $row->entry_name,
|
||||
));
|
||||
return $this::tr([
|
||||
$this::td(Link::create($row->entry_name, 'director/data/listentry/edit', [
|
||||
'list_id' => $row->list_id,
|
||||
'entry_name' => $row->entry_name,
|
||||
])),
|
||||
$this::td($row->entry_value)
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'entry_name' => $view->translate('Key'),
|
||||
'entry_value' => $view->translate('Label'),
|
||||
'entry_name' => $this->translate('Key'),
|
||||
'entry_value' => $this->translate('Label'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('l' => 'director_datalist_entry'),
|
||||
array()
|
||||
$this->getColumns()
|
||||
)->where(
|
||||
'l.list_id = ?',
|
||||
$this->getList()->id
|
41
library/Director/Web/Table/DatalistTable.php
Normal file
41
library/Director/Web/Table/DatalistTable.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class DatalistTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = ['list_name'];
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return [
|
||||
'id' => 'l.id',
|
||||
'list_name' => 'l.list_name',
|
||||
];
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::tr($this::td(Link::create(
|
||||
$row->list_name,
|
||||
'director/data/listentry',
|
||||
array('list_id' => $row->id)
|
||||
)));
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [$this->translate('List name')];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['l' => 'director_datalist'],
|
||||
$this->getColumns()
|
||||
)->order('list_name ASC');
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ use Icinga\Exception\QueryException;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\PlainObjectRenderer;
|
||||
use Icinga\Web\Request;
|
||||
use Icinga\Web\Url;
|
||||
use ipl\Web\Url;
|
||||
use Icinga\Web\View;
|
||||
use Icinga\Web\Widget;
|
||||
use Icinga\Web\Widget\Paginator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user