mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 15:54:03 +02:00
ScheduledDowntimes: a bunch of url-related changes
This commit is contained in:
parent
f5a5a9c741
commit
c72b51c538
@ -6,6 +6,13 @@ use Icinga\Module\Director\Web\Controller\ObjectsController;
|
|||||||
|
|
||||||
class ScheduledDowntimesController extends ObjectsController
|
class ScheduledDowntimesController extends ObjectsController
|
||||||
{
|
{
|
||||||
|
protected function addObjectsTabs()
|
||||||
|
{
|
||||||
|
$res = parent::addObjectsTabs();
|
||||||
|
$this->tabs()->remove('index');
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return 'scheduledDowntime';
|
return 'scheduledDowntime';
|
||||||
|
@ -188,6 +188,12 @@ class SuggestController extends ActionController
|
|||||||
return $this->fetchTemplateNames('icinga_user');
|
return $this->fetchTemplateNames('icinga_user');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function suggestScheduled_downtimetemplates()
|
||||||
|
{
|
||||||
|
$this->assertPermission('director/scheduled-downtimes');
|
||||||
|
return $this->fetchTemplateNames('icinga_scheduled_downtime');
|
||||||
|
}
|
||||||
|
|
||||||
protected function suggestCheckcommandnames()
|
protected function suggestCheckcommandnames()
|
||||||
{
|
{
|
||||||
$db = $this->db()->getDbAdapter();
|
$db = $this->db()->getDbAdapter();
|
||||||
@ -199,7 +205,7 @@ class SuggestController extends ActionController
|
|||||||
return $db->fetchCol($query);
|
return $db->fetchCol($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fetchTemplateNames($table, $where)
|
protected function fetchTemplateNames($table, $where = null)
|
||||||
{
|
{
|
||||||
$db = $this->db()->getDbAdapter();
|
$db = $this->db()->getDbAdapter();
|
||||||
$query = $db->select()
|
$query = $db->select()
|
||||||
|
@ -11,18 +11,7 @@ class IcingaScheduledDowntimeForm extends DirectorObjectForm
|
|||||||
*/
|
*/
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
|
if ($this->isTemplate()) {
|
||||||
$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) {
|
|
||||||
$this->addElement('text', 'object_name', [
|
$this->addElement('text', 'object_name', [
|
||||||
'label' => $this->translate('Template name'),
|
'label' => $this->translate('Template name'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -15,6 +15,6 @@ class ScheduledDowntimeApplyDashlet extends Dashlet
|
|||||||
|
|
||||||
public function getUrl()
|
public function getUrl()
|
||||||
{
|
{
|
||||||
return 'director/scheduled_downtimes/applyrules';
|
return 'director/scheduled-downtimes/applyrules';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,15 @@ class IcingaScheduledDowntime extends IcingaObject
|
|||||||
'comment' => null,
|
'comment' => null,
|
||||||
'fixed' => null,
|
'fixed' => null,
|
||||||
'duration' => null,
|
'duration' => null,
|
||||||
|
'assign_filter' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $supportsImports = true;
|
protected $supportsImports = true;
|
||||||
|
|
||||||
protected $supportsRanges = true;
|
protected $supportsRanges = true;
|
||||||
|
|
||||||
|
protected $supportsApplyRules = true;
|
||||||
|
|
||||||
protected $relations = [
|
protected $relations = [
|
||||||
'zone' => 'IcingaZone',
|
'zone' => 'IcingaZone',
|
||||||
];
|
];
|
||||||
|
@ -8,7 +8,7 @@ class TemplateActionBar extends DirectorBaseActionBar
|
|||||||
{
|
{
|
||||||
protected function assemble()
|
protected function assemble()
|
||||||
{
|
{
|
||||||
$type = $this->type;
|
$type = str_replace('_', '-', $this->type);
|
||||||
$plType = preg_replace('/cys$/', 'cies', $type . 's');
|
$plType = preg_replace('/cys$/', 'cies', $type . 's');
|
||||||
$renderTree = $this->url->getParam('render') === 'tree';
|
$renderTree = $this->url->getParam('render') === 'tree';
|
||||||
$renderParams = $renderTree ? null : ['render' => 'tree'];
|
$renderParams = $renderTree ? null : ['render' => 'tree'];
|
||||||
|
@ -79,7 +79,11 @@ abstract class ObjectController extends ActionController
|
|||||||
'add'
|
'add'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->tabs(new ObjectTabs($this->getType(), $this->getAuth(), $this->object));
|
$this->tabs(new ObjectTabs(
|
||||||
|
$this->getRequest()->getControllerName(),
|
||||||
|
$this->getAuth(),
|
||||||
|
$this->object
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,11 @@ abstract class ObjectsController extends ActionController
|
|||||||
if (substr($this->getType(), -5) === 'Group') {
|
if (substr($this->getType(), -5) === 'Group') {
|
||||||
$tabName = 'groups';
|
$tabName = 'groups';
|
||||||
}
|
}
|
||||||
$this->tabs(new ObjectsTabs($this->getBaseType(), $this->Auth()))
|
$this->tabs(new ObjectsTabs(
|
||||||
->activate($tabName);
|
$this->getBaseType(),
|
||||||
|
$this->Auth(),
|
||||||
|
$this->getBaseObjectUrl()
|
||||||
|
))->activate($tabName);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -126,7 +129,8 @@ abstract class ObjectsController extends ActionController
|
|||||||
protected function getTable()
|
protected function getTable()
|
||||||
{
|
{
|
||||||
return ObjectsTable::create($this->getType(), $this->db())
|
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'),
|
$this->translate('All your %s Apply Rules'),
|
||||||
$tType
|
$tType
|
||||||
);
|
);
|
||||||
|
$baseUrl = 'director/' . $this->getBaseObjectUrl();
|
||||||
$this->actions()
|
$this->actions()
|
||||||
//->add($this->getBackToDashboardLink())
|
//->add($this->getBackToDashboardLink())
|
||||||
->add(
|
->add(
|
||||||
Link::create(
|
Link::create(
|
||||||
$this->translate('Add'),
|
$this->translate('Add'),
|
||||||
"director/$type/add",
|
"${baseUrl}/add",
|
||||||
['type' => 'apply'],
|
['type' => 'apply'],
|
||||||
[
|
[
|
||||||
'title' => sprintf(
|
'title' => sprintf(
|
||||||
@ -259,7 +264,8 @@ abstract class ObjectsController extends ActionController
|
|||||||
);
|
);
|
||||||
|
|
||||||
$table = new ApplyRulesTable($this->db());
|
$table = new ApplyRulesTable($this->db());
|
||||||
$table->setType($this->getType());
|
$table->setType($this->getType())
|
||||||
|
->setBaseObjectUrl($this->getBaseObjectUrl());
|
||||||
$this->eventuallyFilterCommand($table);
|
$this->eventuallyFilterCommand($table);
|
||||||
$table->renderTo($this);
|
$table->renderTo($this);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
private $type;
|
private $type;
|
||||||
|
|
||||||
|
/** @var IcingaObject */
|
||||||
|
protected $dummyObject;
|
||||||
|
|
||||||
|
protected $baseObjectUrl;
|
||||||
|
|
||||||
public static function create($type, Db $db)
|
public static function create($type, Db $db)
|
||||||
{
|
{
|
||||||
$table = new static($db);
|
$table = new static($db);
|
||||||
@ -35,6 +40,14 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
|||||||
public function setType($type)
|
public function setType($type)
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBaseObjectUrl($url)
|
||||||
|
{
|
||||||
|
$this->baseObjectUrl = $url;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,32 +112,32 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
public function createActionLinks($row)
|
public function createActionLinks($row)
|
||||||
{
|
{
|
||||||
$type = $this->type;
|
$baseUrl = 'director/' . $this->baseObjectUrl;
|
||||||
$links = [];
|
$links = [];
|
||||||
$links[] = Link::create(
|
$links[] = Link::create(
|
||||||
Icon::create('sitemap'),
|
Icon::create('sitemap'),
|
||||||
"director/${type}template/applytargets",
|
"${baseUrl}template/applytargets",
|
||||||
['id' => $row->id],
|
['id' => $row->id],
|
||||||
['title' => $this->translate('Show affected Objects')]
|
['title' => $this->translate('Show affected Objects')]
|
||||||
);
|
);
|
||||||
|
|
||||||
$links[] = Link::create(
|
$links[] = Link::create(
|
||||||
Icon::create('edit'),
|
Icon::create('edit'),
|
||||||
"director/$type/edit",
|
"$baseUrl/edit",
|
||||||
['id' => $row->id],
|
['id' => $row->id],
|
||||||
['title' => $this->translate('Modify this Apply Rule')]
|
['title' => $this->translate('Modify this Apply Rule')]
|
||||||
);
|
);
|
||||||
|
|
||||||
$links[] = Link::create(
|
$links[] = Link::create(
|
||||||
Icon::create('doc-text'),
|
Icon::create('doc-text'),
|
||||||
"director/$type/render",
|
"$baseUrl/render",
|
||||||
['id' => $row->id],
|
['id' => $row->id],
|
||||||
['title' => $this->translate('Apply Rule rendering preview')]
|
['title' => $this->translate('Apply Rule rendering preview')]
|
||||||
);
|
);
|
||||||
|
|
||||||
$links[] = Link::create(
|
$links[] = Link::create(
|
||||||
Icon::create('history'),
|
Icon::create('history'),
|
||||||
"director/$type/history",
|
"$baseUrl/history",
|
||||||
['id' => $row->id],
|
['id' => $row->id],
|
||||||
['title' => $this->translate('Apply rule history')]
|
['title' => $this->translate('Apply rule history')]
|
||||||
);
|
);
|
||||||
@ -149,9 +162,22 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
|||||||
return FilterRenderer::applyToQuery($filter, $query);
|
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()
|
public function prepareQuery()
|
||||||
{
|
{
|
||||||
$type = $this->type;
|
$table = $this->getDummyObject()->getTableName();
|
||||||
$columns = [
|
$columns = [
|
||||||
'id' => 'o.id',
|
'id' => 'o.id',
|
||||||
'object_name' => 'o.object_name',
|
'object_name' => 'o.object_name',
|
||||||
@ -159,13 +185,13 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
|||||||
'assign_filter' => 'o.assign_filter',
|
'assign_filter' => 'o.assign_filter',
|
||||||
];
|
];
|
||||||
$query = $this->db()->select()->from(
|
$query = $this->db()->select()->from(
|
||||||
['o' => "icinga_$type"],
|
['o' => $table],
|
||||||
$columns
|
$columns
|
||||||
)->where(
|
)->where(
|
||||||
"object_type = 'apply'"
|
"object_type = 'apply'"
|
||||||
)->order('o.object_name');
|
)->order('o.object_name');
|
||||||
|
|
||||||
if ($type === 'service') {
|
if ($this->type === 'service') {
|
||||||
$query->where('service_set_id IS NULL');
|
$query->where('service_set_id IS NULL');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ class ObjectsTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
protected $type;
|
protected $type;
|
||||||
|
|
||||||
|
protected $baseObjectUrl;
|
||||||
|
|
||||||
/** @var IcingaObject */
|
/** @var IcingaObject */
|
||||||
protected $dummyObject;
|
protected $dummyObject;
|
||||||
|
|
||||||
@ -62,6 +64,17 @@ class ObjectsTable extends ZfQueryBasedTable
|
|||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setBaseObjectUrl($url)
|
||||||
|
{
|
||||||
|
$this->baseObjectUrl = $url;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Auth
|
* @return Auth
|
||||||
*/
|
*/
|
||||||
@ -119,7 +132,7 @@ class ObjectsTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
protected function renderObjectNameColumn($row)
|
protected function renderObjectNameColumn($row)
|
||||||
{
|
{
|
||||||
$type = $this->getType();
|
$type = $this->baseObjectUrl;
|
||||||
$url = Url::fromPath("director/${type}", [
|
$url = Url::fromPath("director/${type}", [
|
||||||
'name' => $row->object_name
|
'name' => $row->object_name
|
||||||
]);
|
]);
|
||||||
|
@ -117,7 +117,7 @@ class ObjectTabs extends Tabs
|
|||||||
|
|
||||||
if ($object->supportsRanges()) {
|
if ($object->supportsRanges()) {
|
||||||
$this->add('ranges', [
|
$this->add('ranges', [
|
||||||
'url' => 'director/timeperiod/ranges',
|
'url' => "director/${type}/ranges",
|
||||||
'urlParams' => $params,
|
'urlParams' => $params,
|
||||||
'label' => $this->translate('Ranges')
|
'label' => $this->translate('Ranges')
|
||||||
]);
|
]);
|
||||||
|
@ -11,14 +11,14 @@ class ObjectsTabs extends Tabs
|
|||||||
{
|
{
|
||||||
use TranslationHelper;
|
use TranslationHelper;
|
||||||
|
|
||||||
public function __construct($type, Auth $auth)
|
public function __construct($type, Auth $auth, $typeUrl)
|
||||||
{
|
{
|
||||||
$object = IcingaObject::createByType($type);
|
$object = IcingaObject::createByType($type);
|
||||||
if ($object->isGroup()) {
|
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}")) {
|
if ($auth->hasPermission("director/${plType}")) {
|
||||||
$this->add('index', array(
|
$this->add('index', array(
|
||||||
'url' => sprintf('director/%s', $plType),
|
'url' => sprintf('director/%s', $plType),
|
||||||
@ -56,7 +56,7 @@ class ObjectsTabs extends Tabs
|
|||||||
|
|
||||||
if ($object->supportsGroups()) {
|
if ($object->supportsGroups()) {
|
||||||
$this->add('groups', array(
|
$this->add('groups', array(
|
||||||
'url' => sprintf('director/%sgroups', $type),
|
'url' => sprintf('director/%sgroups', $typeUrl),
|
||||||
'label' => $this->translate('Groups')
|
'label' => $this->translate('Groups')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -65,12 +65,12 @@ class ObjectsTabs extends Tabs
|
|||||||
if ($auth->hasPermission('director/admin')) {
|
if ($auth->hasPermission('director/admin')) {
|
||||||
if ($object->supportsChoices()) {
|
if ($object->supportsChoices()) {
|
||||||
$this->add('choices', array(
|
$this->add('choices', array(
|
||||||
'url' => sprintf('director/templatechoices/%s', $type),
|
'url' => sprintf('director/templatechoices/%s', $typeUrl),
|
||||||
'label' => $this->translate('Choices')
|
'label' => $this->translate('Choices')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($object->supportsSets() && $auth->hasPermission("director/${type}sets")) {
|
if ($object->supportsSets() && $auth->hasPermission("director/${typeUrl}sets")) {
|
||||||
$this->add('sets', array(
|
$this->add('sets', array(
|
||||||
'url' => sprintf('director/%s/sets', $plType),
|
'url' => sprintf('director/%s/sets', $plType),
|
||||||
'label' => $this->translate('Sets')
|
'label' => $this->translate('Sets')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user