ScheduledDowntimes: a bunch of url-related changes

This commit is contained in:
Thomas Gelf 2018-06-15 02:08:06 +02:00
parent f5a5a9c741
commit c72b51c538
12 changed files with 91 additions and 37 deletions

View File

@ -6,6 +6,13 @@ use Icinga\Module\Director\Web\Controller\ObjectsController;
class ScheduledDowntimesController extends ObjectsController
{
protected function addObjectsTabs()
{
$res = parent::addObjectsTabs();
$this->tabs()->remove('index');
return $res;
}
public function getType()
{
return 'scheduledDowntime';

View File

@ -188,6 +188,12 @@ class SuggestController extends ActionController
return $this->fetchTemplateNames('icinga_user');
}
protected function suggestScheduled_downtimetemplates()
{
$this->assertPermission('director/scheduled-downtimes');
return $this->fetchTemplateNames('icinga_scheduled_downtime');
}
protected function suggestCheckcommandnames()
{
$db = $this->db()->getDbAdapter();
@ -199,7 +205,7 @@ class SuggestController extends ActionController
return $db->fetchCol($query);
}
protected function fetchTemplateNames($table, $where)
protected function fetchTemplateNames($table, $where = null)
{
$db = $this->db()->getDbAdapter();
$query = $db->select()

View File

@ -11,18 +11,7 @@ class IcingaScheduledDowntimeForm extends DirectorObjectForm
*/
public function setup()
{
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
$this->addElement('select', 'object_type', [
'label' => $this->translate('Object type'),
'description' => $this->translate('Whether this should be a template'),
'class' => 'autosubmit',
'multiOptions' => $this->optionalEnum([
'object' => $this->translate('Object'),
'template' => $this->translate('Template'),
])
]);
if ($isTemplate) {
if ($this->isTemplate()) {
$this->addElement('text', 'object_name', [
'label' => $this->translate('Template name'),
'required' => true,

View File

@ -15,6 +15,6 @@ class ScheduledDowntimeApplyDashlet extends Dashlet
public function getUrl()
{
return 'director/scheduled_downtimes/applyrules';
return 'director/scheduled-downtimes/applyrules';
}
}

View File

@ -17,12 +17,15 @@ class IcingaScheduledDowntime extends IcingaObject
'comment' => null,
'fixed' => null,
'duration' => null,
'assign_filter' => null,
];
protected $supportsImports = true;
protected $supportsRanges = true;
protected $supportsApplyRules = true;
protected $relations = [
'zone' => 'IcingaZone',
];

View File

@ -8,7 +8,7 @@ class TemplateActionBar extends DirectorBaseActionBar
{
protected function assemble()
{
$type = $this->type;
$type = str_replace('_', '-', $this->type);
$plType = preg_replace('/cys$/', 'cies', $type . 's');
$renderTree = $this->url->getParam('render') === 'tree';
$renderParams = $renderTree ? null : ['render' => 'tree'];

View File

@ -79,7 +79,11 @@ abstract class ObjectController extends ActionController
'add'
);
} else {
$this->tabs(new ObjectTabs($this->getType(), $this->getAuth(), $this->object));
$this->tabs(new ObjectTabs(
$this->getRequest()->getControllerName(),
$this->getAuth(),
$this->object
));
}
}
}

View File

@ -48,8 +48,11 @@ abstract class ObjectsController extends ActionController
if (substr($this->getType(), -5) === 'Group') {
$tabName = 'groups';
}
$this->tabs(new ObjectsTabs($this->getBaseType(), $this->Auth()))
->activate($tabName);
$this->tabs(new ObjectsTabs(
$this->getBaseType(),
$this->Auth(),
$this->getBaseObjectUrl()
))->activate($tabName);
return $this;
}
@ -126,7 +129,8 @@ abstract class ObjectsController extends ActionController
protected function getTable()
{
return ObjectsTable::create($this->getType(), $this->db())
->setAuth($this->getAuth());
->setAuth($this->getAuth())
->setBaseObjectUrl($this->getBaseObjectUrl());
}
/**
@ -240,12 +244,13 @@ abstract class ObjectsController extends ActionController
$this->translate('All your %s Apply Rules'),
$tType
);
$baseUrl = 'director/' . $this->getBaseObjectUrl();
$this->actions()
//->add($this->getBackToDashboardLink())
->add(
Link::create(
$this->translate('Add'),
"director/$type/add",
"${baseUrl}/add",
['type' => 'apply'],
[
'title' => sprintf(
@ -259,7 +264,8 @@ abstract class ObjectsController extends ActionController
);
$table = new ApplyRulesTable($this->db());
$table->setType($this->getType());
$table->setType($this->getType())
->setBaseObjectUrl($this->getBaseObjectUrl());
$this->eventuallyFilterCommand($table);
$table->renderTo($this);
}

View File

@ -25,6 +25,11 @@ class ApplyRulesTable extends ZfQueryBasedTable
private $type;
/** @var IcingaObject */
protected $dummyObject;
protected $baseObjectUrl;
public static function create($type, Db $db)
{
$table = new static($db);
@ -35,6 +40,14 @@ class ApplyRulesTable extends ZfQueryBasedTable
public function setType($type)
{
$this->type = $type;
return $this;
}
public function setBaseObjectUrl($url)
{
$this->baseObjectUrl = $url;
return $this;
}
@ -99,32 +112,32 @@ class ApplyRulesTable extends ZfQueryBasedTable
public function createActionLinks($row)
{
$type = $this->type;
$baseUrl = 'director/' . $this->baseObjectUrl;
$links = [];
$links[] = Link::create(
Icon::create('sitemap'),
"director/${type}template/applytargets",
"${baseUrl}template/applytargets",
['id' => $row->id],
['title' => $this->translate('Show affected Objects')]
);
$links[] = Link::create(
Icon::create('edit'),
"director/$type/edit",
"$baseUrl/edit",
['id' => $row->id],
['title' => $this->translate('Modify this Apply Rule')]
);
$links[] = Link::create(
Icon::create('doc-text'),
"director/$type/render",
"$baseUrl/render",
['id' => $row->id],
['title' => $this->translate('Apply Rule rendering preview')]
);
$links[] = Link::create(
Icon::create('history'),
"director/$type/history",
"$baseUrl/history",
['id' => $row->id],
['title' => $this->translate('Apply rule history')]
);
@ -149,9 +162,22 @@ class ApplyRulesTable extends ZfQueryBasedTable
return FilterRenderer::applyToQuery($filter, $query);
}
/**
* @return IcingaObject
*/
protected function getDummyObject()
{
if ($this->dummyObject === null) {
$type = $this->type;
$this->dummyObject = IcingaObject::createByType($type);
}
return $this->dummyObject;
}
public function prepareQuery()
{
$type = $this->type;
$table = $this->getDummyObject()->getTableName();
$columns = [
'id' => 'o.id',
'object_name' => 'o.object_name',
@ -159,13 +185,13 @@ class ApplyRulesTable extends ZfQueryBasedTable
'assign_filter' => 'o.assign_filter',
];
$query = $this->db()->select()->from(
['o' => "icinga_$type"],
['o' => $table],
$columns
)->where(
"object_type = 'apply'"
)->order('o.object_name');
if ($type === 'service') {
if ($this->type === 'service') {
$query->where('service_set_id IS NULL');
}

View File

@ -33,6 +33,8 @@ class ObjectsTable extends ZfQueryBasedTable
protected $type;
protected $baseObjectUrl;
/** @var IcingaObject */
protected $dummyObject;
@ -62,6 +64,17 @@ class ObjectsTable extends ZfQueryBasedTable
return $this->type;
}
/**
* @param string $url
* @return $this
*/
public function setBaseObjectUrl($url)
{
$this->baseObjectUrl = $url;
return $this;
}
/**
* @return Auth
*/
@ -119,7 +132,7 @@ class ObjectsTable extends ZfQueryBasedTable
protected function renderObjectNameColumn($row)
{
$type = $this->getType();
$type = $this->baseObjectUrl;
$url = Url::fromPath("director/${type}", [
'name' => $row->object_name
]);

View File

@ -117,7 +117,7 @@ class ObjectTabs extends Tabs
if ($object->supportsRanges()) {
$this->add('ranges', [
'url' => 'director/timeperiod/ranges',
'url' => "director/${type}/ranges",
'urlParams' => $params,
'label' => $this->translate('Ranges')
]);

View File

@ -11,14 +11,14 @@ class ObjectsTabs extends Tabs
{
use TranslationHelper;
public function __construct($type, Auth $auth)
public function __construct($type, Auth $auth, $typeUrl)
{
$object = IcingaObject::createByType($type);
if ($object->isGroup()) {
$object = IcingaObject::createByType(substr($type, 0, -5));
$object = IcingaObject::createByType(substr($typeUrl, 0, -5));
}
$plType = strtolower(preg_replace('/cys$/', 'cies', $type . 's'));
$plType = strtolower(preg_replace('/cys$/', 'cies', $typeUrl . 's'));
if ($auth->hasPermission("director/${plType}")) {
$this->add('index', array(
'url' => sprintf('director/%s', $plType),
@ -56,7 +56,7 @@ class ObjectsTabs extends Tabs
if ($object->supportsGroups()) {
$this->add('groups', array(
'url' => sprintf('director/%sgroups', $type),
'url' => sprintf('director/%sgroups', $typeUrl),
'label' => $this->translate('Groups')
));
}
@ -65,12 +65,12 @@ class ObjectsTabs extends Tabs
if ($auth->hasPermission('director/admin')) {
if ($object->supportsChoices()) {
$this->add('choices', array(
'url' => sprintf('director/templatechoices/%s', $type),
'url' => sprintf('director/templatechoices/%s', $typeUrl),
'label' => $this->translate('Choices')
));
}
}
if ($object->supportsSets() && $auth->hasPermission("director/${type}sets")) {
if ($object->supportsSets() && $auth->hasPermission("director/${typeUrl}sets")) {
$this->add('sets', array(
'url' => sprintf('director/%s/sets', $plType),
'label' => $this->translate('Sets')