From 1ac4a2050c8076eb96e07e83721ebc9db864db94 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:47:21 +0200 Subject: Adding upstream version 0.3.3. Signed-off-by: Daniel Baumann --- application/controllers/EditController.php | 92 ++++++++++++++++++++++++++++ application/controllers/IndexController.php | 24 ++++++++ application/controllers/ShowController.php | 93 +++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 application/controllers/EditController.php create mode 100644 application/controllers/IndexController.php create mode 100644 application/controllers/ShowController.php (limited to 'application/controllers') diff --git a/application/controllers/EditController.php b/application/controllers/EditController.php new file mode 100644 index 0000000..b91255c --- /dev/null +++ b/application/controllers/EditController.php @@ -0,0 +1,92 @@ +assertPermission('toplevelview/edit'); + + $tabs = $this->getTabs(); + + if ($name = $this->getParam('name')) { + $tabs->add( + 'tiles', + array( + 'title' => $this->translate('Tiles'), + 'url' => Url::fromPath('toplevelview/show', array( + 'name' => $name + )) + ) + ); + + $tabs->add( + 'index', + array( + 'title' => $this->translate('Edit'), + 'url' => Url::fromPath('toplevelview/edit', array( + 'name' => $name + )) + ) + ); + } + + + $action = $this->getRequest()->getActionName(); + if ($tab = $tabs->get($action)) { + $tab->setActive(); + } + } + + public function indexAction() + { + $action = $this->getRequest()->getActionName(); + if ($action === 'add') { + $this->view->title = sprintf( + '%s Top Level View', + $this->translate('Add') + ); + $view = new ViewConfig(); + $view->setConfigDir(); + } elseif ($action === 'clone') { + $name = $this->params->getRequired('name'); + $this->view->title = sprintf( + '%s Top Level View', + $this->translate('Clone') + ); + $view = clone ViewConfig::loadByName($name); + } else { + $this->view->name = $name = $this->params->getRequired('name'); + $this->view->title = sprintf( + '%s Top Level View: %s', + $this->translate('Edit'), + $this->params->getRequired('name') + ); + $view = ViewConfig::loadByName($name); + } + + $this->view->form = $form = new EditForm(); + $view->setFormat(ViewConfig::FORMAT_YAML); + $form->setViewConfig($view); + $form->handleRequest(); + + $this->setViewScript('edit/index'); + } + + public function addAction() + { + $this->indexAction(); + } + + public function cloneAction() + { + $this->indexAction(); + } +} diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php new file mode 100644 index 0000000..e1353f3 --- /dev/null +++ b/application/controllers/IndexController.php @@ -0,0 +1,24 @@ + */ + +namespace Icinga\Module\Toplevelview\Controllers; + +use Icinga\Module\Toplevelview\ViewConfig; +use Icinga\Module\Toplevelview\Web\Controller; + +class IndexController extends Controller +{ + public function indexAction() + { + $this->getTabs()->add( + 'index', + array( + 'title' => 'Top Level View', + 'url' => 'toplevelview', + ) + )->activate('index'); + $this->view->views = ViewConfig::loadAll(); + + $this->setAutorefreshInterval(30); + } +} diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php new file mode 100644 index 0000000..d0560f2 --- /dev/null +++ b/application/controllers/ShowController.php @@ -0,0 +1,93 @@ +getTabs(); + + $tiles = Url::fromPath('toplevelview/show', array( + 'name' => $this->params->getRequired('name') + )); + + $tabs->add( + 'index', + array( + 'title' => $this->translate('Tiles'), + 'url' => $tiles + ) + ); + + if (($id = $this->getParam('id')) !== null) { + $tabs->add( + 'tree', + array( + 'title' => $this->translate('Tree'), + 'url' => Url::fromPath('toplevelview/show/tree', array( + 'name' => $this->params->getRequired('name'), + 'id' => $id + )) + ) + ); + } + + $fullscreen = new Tab(array( + 'title' => $this->translate('Go Fullscreen'), + 'icon' => 'dashboard', + 'url' => ((string) $tiles) . '&view=compact&showFullscreen' + )); + $fullscreen->setTargetBlank(); + $tabs->addAsDropdown('fullscreen', $fullscreen); + + $action = $this->getRequest()->getActionName(); + if ($tab = $tabs->get($action)) { + $tab->setActive(); + } + } + + public function indexAction() + { + $this->view->name = $name = $this->params->getRequired('name'); + $this->view->view = $view = ViewConfig::loadByName($name); + $tree = $view->getTree(); + $tree->setBackend($this->monitoringBackend()); + + if (($lifetime = $this->getParam('cache')) !== null) { + $tree->setCacheLifetime($lifetime); + } + + $this->setAutorefreshInterval(30); + } + + public function treeAction() + { + $this->view->name = $name = $this->params->getRequired('name'); + $this->view->view = $view = ViewConfig::loadByName($name); + $tree = $view->getTree(); + $this->view->node = $tree->getById($this->params->getRequired('id')); + $tree->setBackend($this->monitoringBackend()); + + if (($lifetime = $this->getParam('cache')) !== null) { + $tree->setCacheLifetime($lifetime); + } + + $this->setAutorefreshInterval(30); + } + + public function sourceAction() + { + $this->view->name = $name = $this->params->getRequired('name'); + $this->view->view = $view = ViewConfig::loadByName($name); + + $this->view->text = $view->getText(); + $this->setViewScript('index', 'text'); + } +} -- cgit v1.2.3