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 --- application/controllers/HostsController.php | 30 ++++ application/controllers/IndexController.php | 15 ++ application/controllers/ServicesController.php | 30 ++++ application/forms/DimensionsForm.php | 206 +++++++++++++++++++++++++ application/views/scripts/cube-details.phtml | 10 ++ application/views/scripts/cube-index.phtml | 20 +++ 6 files changed, 311 insertions(+) create mode 100644 application/controllers/HostsController.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..c3e5374 --- /dev/null +++ b/application/controllers/HostsController.php @@ -0,0 +1,30 @@ +createTabs()->activate('cube/hosts'); + + $this->renderCube(); + } + + protected function getCube() + { + if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { + return new IcingaDbHostStatusCube(); + } + + return new IdoHostStatusCube(); + } +} 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..ec08bbb --- /dev/null +++ b/application/controllers/ServicesController.php @@ -0,0 +1,30 @@ +createTabs()->activate('cube/services'); + + $this->renderCube(); + } + + protected function getCube() + { + if (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) { + return new IcingaDbServiceStatusCube(); + } + + return new IdoServiceStatusCube(); + } +} diff --git a/application/forms/DimensionsForm.php b/application/forms/DimensionsForm.php new file mode 100644 index 0000000..c4fcf73 --- /dev/null +++ b/application/forms/DimensionsForm.php @@ -0,0 +1,206 @@ +cube = $cube; + return $this; + } + + public function createElements(array $formData) + { + $cube = $this->cube; + $dimensions = $cube->listDimensions(); + $cnt = count($dimensions); + + if ($cnt < 3) { + $allDimensions = $cube->listAdditionalDimensions(); + + $this->addElement('select', 'addDimension', [ + 'multiOptions' => [null => $this->translate('+ Add a dimension')] + $allDimensions, + 'decorators' => ['ViewHelper'], + 'class' => 'autosubmit' + ]); + } + + $pos = 0; + foreach ($dimensions as $dimension) { + $this->addDimensionButtons($dimension, $pos++, $cnt); + } + + foreach ($cube->getSlices() as $key => $value) { + $this->addSlice($this->cube->getDimension($key), $value); + } + + $this->addAttribs(['class' => 'icinga-controls']); + } + + protected function addSlice(Dimension $dimension, $value) + { + $view = $this->getView(); + + $sliceId = sha1($dimension->getName()); + $this->addElement('button', 'removeSlice_' . $sliceId, [ + 'label' => $view->icon('cancel'), + 'decorators' => ['ViewHelper'], + 'value' => $dimension->getName(), + 'type' => 'submit', + 'escape' => false, + 'class' => 'dimension-control' + ]); + + $label = $view->escape( + sprintf( + '%s: %s = %s', + $view->translate('Slice/Filter'), + $dimension->getLabel(), + $value + ) + ); + + $this->addElement('note', 'slice_' . $sliceId, [ + 'class' => 'dimension-name', + 'value' => '' . $label . '', + 'decorators' => ['ViewHelper'] + ]); + + $this->addDisplayGroup( + [ + 'removeSlice_' . $sliceId, + 'slice_' . $sliceId, + ], + $dimension->getName(), + [ + 'class' => 'dimensions', + 'decorators' => [ + 'FormElements', + 'Fieldset' + ] + ] + ); + } + + protected function addDimensionButtons(Dimension $dimension, $pos, $total) + { + $view = $this->getView(); + $dimensionId = sha1($dimension->getName()); + + $this->addElement('note', 'dimension_' . $dimensionId, [ + 'class' => 'dimension-name', + 'value' => '' . $view->escape($dimension->getLabel()) . '', + 'decorators' => ['ViewHelper'] + ]); + + $this->addElement('button', 'removeDimension_' . $dimensionId, [ + 'label' => $view->icon('cancel'), + 'decorators' => ['ViewHelper'], + 'title' => sprintf($this->translate('Remove dimension "%s"'), $dimension->getLabel()), + 'value' => $dimension->getName(), + 'type' => 'submit', + 'escape' => false, + 'class' => 'dimension-control' + ]); + + if ($pos > 0) { + $this->addElement('button', 'moveDimensionUp_' . $dimensionId, [ + 'label' => $view->icon('angle-double-up'), + 'decorators' => ['ViewHelper'], + 'title' => sprintf($this->translate('Move dimension "%s" up'), $dimension->getLabel()), + 'value' => $dimension->getName(), + 'type' => 'submit', + 'escape' => false, + 'class' => 'dimension-control' + ]); + } + + if ($pos + 1 !== $total) { + $this->addElement('button', 'moveDimensionDown_' . $dimensionId, [ + 'label' => $view->icon('angle-double-down'), + 'decorators' => ['ViewHelper'], + 'title' => sprintf($this->translate('Move dimension "%s" down'), $dimension->getLabel()), + 'value' => $dimension->getName(), + 'type' => 'submit', + 'escape' => false, + 'class' => 'dimension-control' + ]); + } + + $this->addDisplayGroup( + [ + 'removeDimension_' . $dimensionId, + 'moveDimensionUp_' . $dimensionId, + 'moveDimensionDown_' . $dimensionId, + 'dimension_' . $dimensionId, + ], + $dimensionId, + [ + 'class' => 'dimensions', + 'decorators' => [ + 'FormElements', + 'Fieldset' + ] + ] + ); + } + + public function onSuccess() + { + $url = $this->getRequest()->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; + foreach ($this->cube->listDimensions() as $name => $_) { + $dimensionId = sha1($name); + + switch (true) { + case ($el = $this->getElement('removeDimension_' . $dimensionId)) && $el->isChecked(): + $this->cube->removeDimension($name); + $updateDimensions = true; + break 2; + case ($el = $this->getElement('moveDimensionUp_' . $dimensionId)) && $el->isChecked(): + $this->cube->moveDimensionUp($name); + $updateDimensions = true; + break 2; + case ($el = $this->getElement('moveDimensionDown_' . $dimensionId)) && $el->isChecked(): + $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) { + $sliceId = sha1($slice); + + if (($el = $this->getElement('removeSlice_' . $sliceId)) && $el->isChecked()) { + $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..b47bf9b --- /dev/null +++ b/application/views/scripts/cube-details.phtml @@ -0,0 +1,10 @@ +
+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..e45bcde --- /dev/null +++ b/application/views/scripts/cube-index.phtml @@ -0,0 +1,20 @@ +
+ 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