From d61b7618d9c04ff90fdf8d3b584ad5976faedad9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:16:36 +0200 Subject: Adding upstream version 1.3.2. Signed-off-by: Daniel Baumann --- application/controllers/HostsController.php | 45 +++++ application/controllers/IdoHostsController.php | 24 +++ application/controllers/IdoServicesController.php | 24 +++ application/controllers/IndexController.php | 15 ++ application/controllers/ServicesController.php | 45 +++++ application/forms/DimensionsForm.php | 211 ++++++++++++++++++++++ application/views/scripts/cube-details.phtml | 12 ++ application/views/scripts/cube-index.phtml | 22 +++ 8 files changed, 398 insertions(+) create mode 100644 application/controllers/HostsController.php create mode 100644 application/controllers/IdoHostsController.php create mode 100644 application/controllers/IdoServicesController.php create mode 100644 application/controllers/IndexController.php create mode 100644 application/controllers/ServicesController.php create mode 100644 application/forms/DimensionsForm.php create mode 100644 application/views/scripts/cube-details.phtml create mode 100644 application/views/scripts/cube-index.phtml (limited to 'application') diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php new file mode 100644 index 0000000..c41d846 --- /dev/null +++ b/application/controllers/HostsController.php @@ -0,0 +1,45 @@ +createTabs()->activate('cube/hosts'); + + $this->renderCube(); + } + + protected function getCube(): IcingaDbCube + { + return new IcingaDbHostStatusCube(); + } + + public function completeAction(): void + { + $suggestions = new ObjectSuggestions(); + $suggestions->setModel(Host::class); + $suggestions->forRequest($this->getServerRequest()); + $this->getDocument()->add($suggestions); + } + + public function searchEditorAction(): void + { + $editor = $this->createSearchEditor( + Host::on($this->getDb()), + $this->preserveParams + ); + + $this->getDocument()->add($editor); + $this->setTitle($this->translate('Adjust Filter')); + } +} diff --git a/application/controllers/IdoHostsController.php b/application/controllers/IdoHostsController.php new file mode 100644 index 0000000..8648823 --- /dev/null +++ b/application/controllers/IdoHostsController.php @@ -0,0 +1,24 @@ +createTabs()->activate('cube/hosts'); + + $this->renderCube(); + } + + protected function getCube(): IdoCube + { + return new IdoHostStatusCube(); + } +} diff --git a/application/controllers/IdoServicesController.php b/application/controllers/IdoServicesController.php new file mode 100644 index 0000000..f55e1d7 --- /dev/null +++ b/application/controllers/IdoServicesController.php @@ -0,0 +1,24 @@ +createTabs()->activate('cube/services'); + + $this->renderCube(); + } + + protected function getCube(): IdoCube + { + return new IdoServiceStatusCube(); + } +} diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php new file mode 100644 index 0000000..082fda3 --- /dev/null +++ b/application/controllers/IndexController.php @@ -0,0 +1,15 @@ +redirectNow('cube/hosts' . ($this->params->toString() === '' ? '' : '?' . $this->params->toString())); + } +} diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php new file mode 100644 index 0000000..0914aa2 --- /dev/null +++ b/application/controllers/ServicesController.php @@ -0,0 +1,45 @@ +createTabs()->activate('cube/services'); + + $this->renderCube(); + } + + protected function getCube(): IcingaDbCube + { + return new IcingaDbServiceStatusCube(); + } + + public function completeAction(): void + { + $suggestions = new ObjectSuggestions(); + $suggestions->setModel(Service::class); + $suggestions->forRequest($this->getServerRequest()); + $this->getDocument()->add($suggestions); + } + + public function searchEditorAction(): void + { + $editor = $this->createSearchEditor( + Service::on($this->getDb()), + $this->preserveParams + ); + + $this->getDocument()->add($editor); + $this->setTitle($this->translate('Adjust Filter')); + } +} diff --git a/application/forms/DimensionsForm.php b/application/forms/DimensionsForm.php new file mode 100644 index 0000000..fbfbbc7 --- /dev/null +++ b/application/forms/DimensionsForm.php @@ -0,0 +1,211 @@ + 'icinga-controls', + 'name' => 'dimensions-form' + ]; + + /** + * @var Cube + */ + private $cube; + + /** + * @var Url + */ + private $url; + + /** + * Get the url + * + * @return Url + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set the url + * + * @param mixed $url + */ + public function setUrl($url): self + { + $this->url = $url; + + return $this; + } + + public function setCube(Cube $cube) + { + $this->cube = $cube; + return $this; + } + + public function hasBeenSubmitted(): bool + { + // required to submit dimension controls and the selected dropdown option + return $this->hasBeenSent() && + ($this->getPressedSubmitElement() !== null || $this->getPopulatedValue('addDimension')); + } + + public function assemble() + { + $dimensions = $this->cube->listDimensions(); + $cnt = count($dimensions); + + if ($cnt < 3) { + $allDimensions = $this->cube->listAdditionalDimensions(); + + $this->addElement('select', 'addDimension', [ + 'options' => [null => $this->translate('+ Add a dimension')] + $allDimensions, + 'class' => 'autosubmit' + ]); + } + + $pos = 0; + foreach ($dimensions as $dimension) { + $this->addDimensionButtons($dimension, $pos++, $cnt); + } + + foreach ($this->cube->getSlices() as $key => $value) { + $this->addSlice($this->cube->getDimension($key), $value); + } + + $this->addElement($this->createUidElement()); + } + + protected function addSlice(Dimension $dimension, $value) + { + $sliceId = sha1($this->cube::SLICE_PREFIX . $dimension->getName()); + + $sliceFieldset = Html::tag('fieldset', ['class' => 'dimensions']); + + $btn = $this->createElement('submitButton', 'removeSlice_' . $sliceId, [ + 'label' => new Icon('trash'), + 'class' => 'dimension-control' + ]); + + $this->registerElement($btn); + $sliceFieldset->addHtml($btn); + + $sliceFieldset->addHtml(Html::tag( + 'span', + ['class' => 'dimension-name'], + sprintf('%s: %s = %s', $this->translate('Slice/Filter'), $dimension->getLabel(), $value) + )); + + $this->addHtml($sliceFieldset); + } + + protected function addDimensionButtons(Dimension $dimension, $pos, $total) + { + $dimensionId = sha1($dimension->getName()); + + $dimensionFieldset = Html::tag('fieldset', ['class' => 'dimensions']); + + $btn = $this->createElement('submitButton', 'removeDimension_' . $dimensionId, [ + 'label' => new Icon('trash'), + 'title' => sprintf($this->translate('Remove dimension "%s"'), $dimension->getLabel()), + 'class' => 'dimension-control' + ]); + + $this->registerElement($btn); + $dimensionFieldset->addHtml($btn); + + if ($pos > 0) { + $btn = $this->createElement('submitButton', 'moveDimensionUp_' . $dimensionId, [ + 'label' => new Icon('angle-double-up'), + 'title' => sprintf($this->translate('Move dimension "%s" up'), $dimension->getLabel()), + 'class' => 'dimension-control', + ]); + + $this->registerElement($btn); + $dimensionFieldset->addHtml($btn); + } + + if ($pos + 1 !== $total) { + $btn = $this->createElement('submitButton', 'moveDimensionDown_' . $dimensionId, [ + 'label' => new Icon('angle-double-down'), + 'title' => sprintf($this->translate('Move dimension "%s" down'), $dimension->getLabel()), + 'class' => 'dimension-control' + ]); + + $this->registerElement($btn); + $dimensionFieldset->addHtml($btn); + } + + $dimensionFieldset->addHtml(Html::tag('span', ['class' => 'dimension-name'], $dimension->getLabel())); + + $this->addHtml($dimensionFieldset); + } + + public function onSuccess() + { + $url = $this->getUrl(); + + if ($dimension = $this->getValue('addDimension')) { + $url->setParam('dimensions', DimensionParams::fromUrl($url)->add($dimension)->getParams()); + Notification::success($this->translate('New dimension has been added')); + } else { + $updateDimensions = false; + $pressedButtonName = $this->getPressedSubmitElement()->getName(); + + foreach ($this->cube->listDimensions() as $name => $_) { + $dimensionId = sha1($name); + + switch (true) { + case ($pressedButtonName === 'removeDimension_' . $dimensionId): + $this->cube->removeDimension($name); + $updateDimensions = true; + break 2; + case ($pressedButtonName === 'moveDimensionUp_' . $dimensionId): + $this->cube->moveDimensionUp($name); + $updateDimensions = true; + break 2; + case ($pressedButtonName === 'moveDimensionDown_' . $dimensionId): + $this->cube->moveDimensionDown($name); + $updateDimensions = true; + break 2; + } + } + + if ($updateDimensions) { + $dimensions = array_merge(array_keys($this->cube->listDimensions()), $this->cube->listSlices()); + $url->setParam('dimensions', DimensionParams::update($dimensions)->getParams()); + } else { + foreach ($this->cube->listSlices() as $slice) { + $slice = $this->cube::SLICE_PREFIX . $slice; + $sliceId = sha1($slice); + + if ($pressedButtonName === 'removeSlice_' . $sliceId) { + $url->getParams()->remove(rawurlencode($slice)); + } + } + } + } + + $this->setRedirectUrl($url); + } +} diff --git a/application/views/scripts/cube-details.phtml b/application/views/scripts/cube-details.phtml new file mode 100644 index 0000000..8e0611f --- /dev/null +++ b/application/views/scripts/cube-details.phtml @@ -0,0 +1,12 @@ +
+ + tabs ?> + +

escape($this->title) ?>

+
+ +
+ +
diff --git a/application/views/scripts/cube-index.phtml b/application/views/scripts/cube-index.phtml new file mode 100644 index 0000000..f46d74a --- /dev/null +++ b/application/views/scripts/cube-index.phtml @@ -0,0 +1,22 @@ +
+ compact): ?> + + tabs ?> + +

escape($this->title) ?>

+ form && ! $this->compact): ?> + qlink('Hide settings', $this->url->without('showSettings'), null, ['icon' => 'wrench']) ?> + + qlink('Show settings', $this->url->with('showSettings', true), null, ['icon' => 'wrench']) ?> + + +
+ +
+ form && ! $this->compact): ?> + form ?> + + cube): ?> + cube->render($this) ?> + +
-- cgit v1.2.3