From da0f8427204ad57aad08059906df0ea10a7ccf31 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:42:52 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- library/Cube/Web/ActionLink.php | 103 +++++++++++++++++++++++++++++++++ library/Cube/Web/ActionLinks.php | 115 +++++++++++++++++++++++++++++++++++++ library/Cube/Web/Controller.php | 115 +++++++++++++++++++++++++++++++++++++ library/Cube/Web/IdoController.php | 24 ++++++++ 4 files changed, 357 insertions(+) create mode 100644 library/Cube/Web/ActionLink.php create mode 100644 library/Cube/Web/ActionLinks.php create mode 100644 library/Cube/Web/Controller.php create mode 100644 library/Cube/Web/IdoController.php (limited to 'library/Cube/Web') diff --git a/library/Cube/Web/ActionLink.php b/library/Cube/Web/ActionLink.php new file mode 100644 index 0000000..c9ad87b --- /dev/null +++ b/library/Cube/Web/ActionLink.php @@ -0,0 +1,103 @@ +url = $url; + $this->title = $title; + $this->description = $description; + $this->icon = $icon; + } + + /** + * @return Url + */ + public function getUrl() + { + return $this->url; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @return string + */ + public function getIcon() + { + return $this->icon; + } + + /** + * Render our icon + * + * @param View $view + * @return string + */ + protected function renderIcon(View $view) + { + return $view->icon($this->getIcon()); + } + + /** + * @param View $view + * @return string + */ + public function render(View $view) + { + return sprintf( + '%s%s

%s

', + $this->getUrl(), + $this->renderIcon($view), + $view->escape($this->getTitle()), + $view->escape($this->getDescription()) + ); + } +} diff --git a/library/Cube/Web/ActionLinks.php b/library/Cube/Web/ActionLinks.php new file mode 100644 index 0000000..0c6cba4 --- /dev/null +++ b/library/Cube/Web/ActionLinks.php @@ -0,0 +1,115 @@ +prepareActionLinks($cube, $view); + } catch (Exception $e) { + $html[] = static::renderErrorItem($e, $view); + } + + foreach ($hook->getActionLinks()->getLinks() as $link) { + $html[] = '
  • ' . $link->render($view) . '
  • '; + } + } + + if (empty($html)) { + $html[] = static::renderErrorItem( + $view->translate('No action links have been provided for this cube'), + $view + ); + } + + return implode("\n", $html) . "\n"; + } + + /** + * @param Exception|string $error + * @param View $view + * @return string + */ + private static function renderErrorItem($error, View $view) + { + if ($error instanceof Exception) { + $error = $error->getMessage(); + } + return '
  • ' . $view->escape($error) . '
  • '; + } + + /** + * Add an ActionLink to this set of actions + * + * @param ActionLink $link + * @return $this + */ + public function add(ActionLink $link) + { + $this->links[] = $link; + return $this; + } + + /** + * @return ActionLink[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * @param View $view + * + * @return string + */ + public function render(View $view) + { + $links = $this->getLinks(); + if (empty($links)) { + return ''; + } + + $html = ''; + + return $html; + } +} diff --git a/library/Cube/Web/Controller.php b/library/Cube/Web/Controller.php new file mode 100644 index 0000000..b7405f9 --- /dev/null +++ b/library/Cube/Web/Controller.php @@ -0,0 +1,115 @@ +cube = $this->getCube(); + } + + public function detailsAction() + { + $this->getTabs()->add('details', [ + 'label' => $this->translate('Cube details'), + 'url' => $this->getRequest()->getUrl() + ])->activate('details'); + + $this->cube->chooseFacts(array_keys($this->cube->getAvailableFactColumns())); + $vars = DimensionParams::fromString($this->params->shift('dimensions', ''))->getDimensions(); + $wantNull = $this->params->shift('wantNull'); + + foreach ($vars as $var) { + $this->cube->addDimensionByName($var); + if ($wantNull) { + $this->cube->getDimension($var)->wantNull(); + } + } + + foreach (['renderLayout', 'showFullscreen', 'showCompact', 'view'] as $p) { + $this->params->shift($p); + } + + foreach ($this->params->toArray() as $param) { + $this->cube->slice(rawurldecode($param[0]), rawurldecode($param[1])); + } + + $this->view->title = $this->cube->getSlicesLabel(); + if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { + $this->view->links = IcingaDbActionsHook::renderAll($this->cube); + } else { + $this->view->links = ActionLinks::renderAll($this->cube, $this->view); + } + + $this->render('cube-details', null, true); + } + + protected function renderCube() + { + // Hint: order matters, we are shifting! + $showSettings = $this->params->shift('showSettings'); + + $this->cube->chooseFacts(array_keys($this->cube->getAvailableFactColumns())); + $vars = DimensionParams::fromString($this->params->shift('dimensions', ''))->getDimensions(); + $wantNull = $this->params->shift('wantNull'); + + foreach ($vars as $var) { + $this->cube->addDimensionByName($var); + if ($wantNull) { + $this->cube->getDimension($var)->wantNull(); + } + } + + foreach (['renderLayout', 'showFullscreen', 'showCompact', 'view'] as $p) { + $this->params->shift($p); + } + + foreach ($this->params->toArray() as $param) { + $this->cube->slice(rawurldecode($param[0]), rawurldecode($param[1])); + } + + $this->view->title = sprintf( + $this->translate('Cube: %s'), + $this->cube->getPathLabel() + ); + + if (count($this->cube->listDimensions()) > 0) { + $this->view->cube = $this->cube; + } else { + $showSettings = true; + } + + if ($showSettings) { + $this->view->form = (new DimensionsForm())->setCube($this->cube); + $this->view->form->handleRequest(); + } else { + $this->setAutorefreshInterval(15); + } + + $this->render('cube-index', null, true); + } +} diff --git a/library/Cube/Web/IdoController.php b/library/Cube/Web/IdoController.php new file mode 100644 index 0000000..2a024ae --- /dev/null +++ b/library/Cube/Web/IdoController.php @@ -0,0 +1,24 @@ +getTabs() + ->add('cube/hosts', [ + 'label' => $this->translate('Hosts'), + 'url' => 'cube/hosts' . ($this->params->toString() === '' ? '' : '?' . $this->params->toString()) + ]) + ->add('cube/services', [ + 'label' => $this->translate('Services'), + 'url' => 'cube/services' . ($this->params->toString() === '' ? '' : '?' . $this->params->toString()) + ]) + ->extend(new DashboardAction()); + } +} -- cgit v1.2.3