summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:42:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:42:52 +0000
commitda0f8427204ad57aad08059906df0ea10a7ccf31 (patch)
treeccda92692e296a50dac104945f62b4402d5e4447 /application
parentInitial commit. (diff)
downloadicingaweb2-module-cube-da0f8427204ad57aad08059906df0ea10a7ccf31.tar.xz
icingaweb2-module-cube-da0f8427204ad57aad08059906df0ea10a7ccf31.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/HostsController.php30
-rw-r--r--application/controllers/IndexController.php15
-rw-r--r--application/controllers/ServicesController.php30
-rw-r--r--application/forms/DimensionsForm.php206
-rw-r--r--application/views/scripts/cube-details.phtml10
-rw-r--r--application/views/scripts/cube-index.phtml20
6 files changed, 311 insertions, 0 deletions
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 @@
+<?php
+
+// Icinga Web 2 Cube Module | (c) 2019 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Cube\Controllers;
+
+use Icinga\Application\Modules\Module;
+use Icinga\Module\Cube\IcingaDb\IcingaDbHostStatusCube;
+use Icinga\Module\Cube\Ido\IdoHostStatusCube;
+use Icinga\Module\Cube\ProvidedHook\Icingadb\IcingadbSupport;
+use Icinga\Module\Cube\Web\IdoController;
+
+class HostsController extends IdoController
+{
+ public function indexAction()
+ {
+ $this->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 @@
+<?php
+
+// Icinga Web 2 Cube Module | (c) 2016 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Cube\Controllers;
+
+use Icinga\Web\Controller;
+
+class IndexController extends Controller
+{
+ public function indexAction()
+ {
+ $this->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 @@
+<?php
+
+// Icinga Web 2 Cube Module | (c) 2019 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Cube\Controllers;
+
+use Icinga\Application\Modules\Module;
+use Icinga\Module\Cube\IcingaDb\IcingaDbServiceStatusCube;
+use Icinga\Module\Cube\Ido\IdoServiceStatusCube;
+use Icinga\Module\Cube\ProvidedHook\Icingadb\IcingadbSupport;
+use Icinga\Module\Cube\Web\IdoController;
+
+class ServicesController extends IdoController
+{
+ public function indexAction()
+ {
+ $this->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 @@
+<?php
+
+// Icinga Web 2 Cube Module | (c) 2016 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Cube\Forms;
+
+use Icinga\Module\Cube\Cube;
+use Icinga\Module\Cube\Dimension;
+use Icinga\Module\Cube\DimensionParams;
+use Icinga\Web\Form;
+use Icinga\Web\Notification;
+
+class DimensionsForm extends Form
+{
+ /**
+ * @var Cube
+ */
+ private $cube;
+
+ public function setCube(Cube $cube)
+ {
+ $this->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' => '<span class="dimension-name">' . $label . '</span>',
+ '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' => '<span class="dimension-name">' . $view->escape($dimension->getLabel()) . '</span>',
+ '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 @@
+<div class="controls">
+<?= $this->tabs ?>
+<h1><?= $this->escape($this->title) ?></h1>
+</div>
+
+<div class="content">
+ <ul class="action-links">
+ <?= $this->links ?>
+ </ul>
+</div>
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 @@
+<div class="controls">
+ <?php if (! $this->compact): ?>
+ <?= $this->tabs ?>
+ <h1><?= $this->escape($this->title) ?></h1>
+ <?php if ($this->form && ! $this->compact): ?>
+ <?= $this->qlink('Hide settings', $this->url()->without('showSettings'), null, ['icon' => 'wrench']) ?>
+ <?php else: ?>
+ <?= $this->qlink('Show settings', $this->url()->with('showSettings', true), null, ['icon' => 'wrench']) ?>
+ <?php endif ?>
+ <?php endif ?>
+</div>
+
+<div class="content">
+ <?php if ($this->form && ! $this->compact): ?>
+ <?= $this->form ?>
+ <?php endif ?>
+ <?php if ($this->cube): ?>
+ <?= $this->cube->render($this) ?>
+ <?php endif ?>
+</div>