mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
Add DataFieldCategoryController, Tabs and Table
This commit is contained in:
parent
5e81f0c88c
commit
90c7bf0dc1
@ -7,6 +7,7 @@ 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\CustomvarTable;
|
||||
use Icinga\Module\Director\Web\Table\DatafieldCategoryTable;
|
||||
use Icinga\Module\Director\Web\Table\DatafieldTable;
|
||||
use Icinga\Module\Director\Web\Table\DatalistEntryTable;
|
||||
use Icinga\Module\Director\Web\Table\DatalistTable;
|
||||
@ -74,6 +75,24 @@ class DataController extends ActionController
|
||||
(new DatafieldTable($this->db()))->renderTo($this);
|
||||
}
|
||||
|
||||
public function fieldcategoriesAction()
|
||||
{
|
||||
$this->setAutorefreshInterval(10);
|
||||
$this->tabs(new DataTabs())->activate('datafieldcategory');
|
||||
$this->addTitle($this->translate('Data Field Categories'));
|
||||
$this->actions()->add(Link::create(
|
||||
$this->translate('Add'),
|
||||
'director/datafieldcategory/add',
|
||||
null,
|
||||
[
|
||||
'class' => 'icon-plus',
|
||||
'data-base-target' => '_next',
|
||||
]
|
||||
));
|
||||
|
||||
(new DatafieldCategoryTable($this->db()))->renderTo($this);
|
||||
}
|
||||
|
||||
public function varsAction()
|
||||
{
|
||||
$this->tabs(new DataTabs())->activate('customvars');
|
||||
|
46
application/controllers/DatafieldcategoryController.php
Normal file
46
application/controllers/DatafieldcategoryController.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Forms\DirectorDatafieldCategoryForm;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
|
||||
class DatafieldcategoryController extends ActionController
|
||||
{
|
||||
public function addAction()
|
||||
{
|
||||
$this->indexAction();
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
$this->indexAction();
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$edit = false;
|
||||
|
||||
if ($name = $this->params->get('name')) {
|
||||
$edit = true;
|
||||
}
|
||||
|
||||
$form = DirectorDatafieldCategoryForm::load()
|
||||
->setDb($this->db());
|
||||
|
||||
if ($edit) {
|
||||
$form->loadObject($name);
|
||||
$this->addTitle(
|
||||
$this->translate('Modify %s'),
|
||||
$form->getObject()->category_name
|
||||
);
|
||||
$this->addSingleTab($this->translate('Edit a Category'));
|
||||
} else {
|
||||
$this->addTitle($this->translate('Add a new Data Field Category'));
|
||||
$this->addSingleTab($this->translate('New Category'));
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
$this->content()->add($form);
|
||||
}
|
||||
}
|
66
library/Director/Web/Table/DatafieldCategoryTable.php
Normal file
66
library/Director/Web/Table/DatafieldCategoryTable.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use gipfl\IcingaWeb2\Link;
|
||||
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
|
||||
use ipl\Html\Html;
|
||||
use Zend_Db_Adapter_Abstract as ZfDbAdapter;
|
||||
use Zend_Db_Select as ZfDbSelect;
|
||||
|
||||
class DatafieldCategoryTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'dfc.varname',
|
||||
'dfc.caption',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'dfc.id',
|
||||
'category_name' => 'dfc.category_name',
|
||||
'description' => 'dfc.description',
|
||||
'assigned_fields' => 'COUNT(df.id)',
|
||||
);
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$main = [Link::create(
|
||||
$row->category_name,
|
||||
'director/datafieldcategory/edit',
|
||||
['name' => $row->category_name]
|
||||
)];
|
||||
|
||||
if (strlen($row->description)) {
|
||||
$main[] = Html::tag('br');
|
||||
$main[] = Html::tag('small', $row->description);
|
||||
}
|
||||
return $this::tr([
|
||||
$this::td($main),
|
||||
$this::td($row->assigned_fields)
|
||||
]);
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return array(
|
||||
$this->translate('Category Name'),
|
||||
$this->translate('# Used'),
|
||||
);
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
$db = $this->db();
|
||||
return $db->select()->from(
|
||||
['dfc' => 'director_datafield_category'],
|
||||
$this->getColumns()
|
||||
)->joinLeft(
|
||||
['df' => 'director_datafield'],
|
||||
'df.category_id = dfc.id',
|
||||
[]
|
||||
)->group('dfc.id')->group('dfc.category_name')->order('category_name ASC');
|
||||
}
|
||||
}
|
@ -20,6 +20,9 @@ class DataTabs extends Tabs
|
||||
$this->add('datafield', [
|
||||
'label' => $this->translate('Data fields'),
|
||||
'url' => 'director/data/fields'
|
||||
])->add('datafieldcategory', [
|
||||
'label' => $this->translate('Data field categories'),
|
||||
'url' => 'director/data/fieldcategories'
|
||||
])->add('datalist', [
|
||||
'label' => $this->translate('Data lists'),
|
||||
'url' => 'director/data/lists'
|
||||
|
Loading…
x
Reference in New Issue
Block a user