From 75ca51e85b4823f79564248ef7ef01c448b374f9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 27 Jul 2017 11:01:10 +0200 Subject: [PATCH] TimeperiodtemplateController: initial import fixes #1028 --- .../TimeperiodtemplateController.php | 147 ++++++++++++++++++ library/Director/Db.php | 1 - 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 application/controllers/TimeperiodtemplateController.php diff --git a/application/controllers/TimeperiodtemplateController.php b/application/controllers/TimeperiodtemplateController.php new file mode 100644 index 00000000..649431de --- /dev/null +++ b/application/controllers/TimeperiodtemplateController.php @@ -0,0 +1,147 @@ +requireTemplate(); + $type = $template->getShortTableName(); + $this + ->addSingleTab($this->translate('Timeperiods')) + ->setAutorefreshInterval(10) + ->addTitle( + $this->translate('Timeperiods based on %s'), + $template->getObjectName() + )->addBackToUsageLink($template); + + ObjectsTable::create($type, $this->db()) + ->setAuth($this->Auth()) + ->filterTemplate($template, $this->params->get('inheritance', 'direct')) + ->renderTo($this); + } + + public function templatesAction() + { + $template = $this->requireTemplate(); + $type = $template->getShortTableName(); + $this + ->addSingleTab($this->translate('Timeperiod Templates')) + ->setAutorefreshInterval(10) + ->addTitle( + $this->translate('Timeperiod templates based on %s'), + $template->getObjectName() + )->addBackToUsageLink($template); + + $table = TemplatesTable::create($type, $this->db()); + $table->filterTemplate($template, $this->params->get('inheritance', 'direct')); + $table->renderTo($this); + } + + protected function addBackToUsageLink(IcingaObject $template) + { + $this->actions()->add( + Link::create( + $this->translate('Back'), + 'director/timeperiodtemplate/usage', + ['name' => $template->getObjectName()], + ['class' => 'icon-left-big'] + ) + ); + + return $this; + } + + public function usageAction() + { + $template = $this->requireTemplate(); + $templateName = $template->getObjectName(); + + $this + ->addSingleTab($this->translate('Timeperiod Template Usage')) + ->addTitle($this->translate('Template: %s'), $templateName) + ->setAutorefreshInterval(10); + + $type = $template->getShortTableName(); + $this->actions()->add([ + Link::create( + $this->translate('Modify'), + "director/$type/edit", + ['name' => $templateName], + ['class' => 'icon-edit'] + ), + Link::create( + $this->translate('Preview'), + "director/$type/render", + ['name' => $templateName], + [ + 'title' => $this->translate('Template rendering preview'), + 'class' => 'icon-doc-text' + ] + ), + Link::create( + $this->translate('History'), + "director/$type/history", + ['name' => $templateName], + [ + 'title' => $this->translate('Template history'), + 'class' => 'icon-history' + ] + ) + ]); + + $this->content()->addPrintf( + $this->translate( + 'This is the "%s" Timeperiod Template. Based on this, you might want to:' + ), + $templateName + )->add( + new UnorderedList([ + new FormattedString($this->translate('Create a new %s inheriting from this one'), [ + Link::create( + $this->translate('Object'), + 'director/timeperiod/add', + ['import' => $templateName] + ) + ]), + new FormattedString($this->translate('Create a new %s inheriting from this one'), [ + Link::create( + $this->translate('Template'), + 'director/timeperiod/add', + ['import' => $templateName, 'type' => 'template'] + ) + ]) + ], [ + 'class' => 'vertical-action-list' + ]) + )->add( + Html::tag('h2', null, $this->translate('Current Template Usage')) + ); + + $this->content()->add( + TemplateUsageTable::forTemplate($template) + ); + } + + protected function requireTemplate() + { + return IcingaTimePeriod::load([ + 'object_name' => $this->params->get('name') + ], $this->db()); + } +} diff --git a/library/Director/Db.php b/library/Director/Db.php index 914f2c40..1196d9f1 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -3,7 +3,6 @@ namespace Icinga\Module\Director; use Icinga\Module\Director\Data\Db\DbConnection; -use Icinga\Module\Director\Objects\DirectorDeploymentLog; use Icinga\Module\Director\Objects\IcingaEndpoint; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Exception\ConfigurationError;