summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/icingaweb2/src/Controller
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
commita1ec78bf0dc93d0e05e5f066f1949dc3baecea06 (patch)
treeee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/icingaweb2/src/Controller
parentInitial commit. (diff)
downloadicingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.tar.xz
icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.zip
Adding upstream version 0.20.0.upstream/0.20.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/icingaweb2/src/Controller')
-rw-r--r--vendor/gipfl/icingaweb2/src/Controller/Extension/AutoRefreshHelper.php30
-rw-r--r--vendor/gipfl/icingaweb2/src/Controller/Extension/ConfigHelper.php46
-rw-r--r--vendor/gipfl/icingaweb2/src/Controller/Extension/ControlsAndContentHelper.php173
3 files changed, 249 insertions, 0 deletions
diff --git a/vendor/gipfl/icingaweb2/src/Controller/Extension/AutoRefreshHelper.php b/vendor/gipfl/icingaweb2/src/Controller/Extension/AutoRefreshHelper.php
new file mode 100644
index 0000000..5b899ba
--- /dev/null
+++ b/vendor/gipfl/icingaweb2/src/Controller/Extension/AutoRefreshHelper.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace gipfl\IcingaWeb2\Controller\Extension;
+
+use InvalidArgumentException;
+
+trait AutoRefreshHelper
+{
+ /** @var int|null */
+ private $autorefreshInterval;
+
+ public function setAutorefreshInterval($interval)
+ {
+ if (! is_int($interval) || $interval < 1) {
+ throw new InvalidArgumentException(
+ 'Setting autorefresh interval smaller than 1 second is not allowed'
+ );
+ }
+ $this->autorefreshInterval = $interval;
+ $this->layout->autorefreshInterval = $interval;
+ return $this;
+ }
+
+ public function disableAutoRefresh()
+ {
+ $this->autorefreshInterval = null;
+ $this->layout->autorefreshInterval = null;
+ return $this;
+ }
+}
diff --git a/vendor/gipfl/icingaweb2/src/Controller/Extension/ConfigHelper.php b/vendor/gipfl/icingaweb2/src/Controller/Extension/ConfigHelper.php
new file mode 100644
index 0000000..72cefa7
--- /dev/null
+++ b/vendor/gipfl/icingaweb2/src/Controller/Extension/ConfigHelper.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace gipfl\IcingaWeb2\Controller\Extension;
+
+use Icinga\Application\Config;
+
+trait ConfigHelper
+{
+ private $config;
+
+ private $configs = [];
+
+ /**
+ * @param null $file
+ * @return Config
+ * @codingStandardsIgnoreStart
+ */
+ public function Config($file = null)
+ {
+ // @codingStandardsIgnoreEnd
+ if ($this->moduleName === null) {
+ if ($file === null) {
+ return Config::app();
+ } else {
+ return Config::app($file);
+ }
+ } else {
+ return $this->getModuleConfig($file);
+ }
+ }
+
+ public function getModuleConfig($file = null)
+ {
+ if ($file === null) {
+ if ($this->config === null) {
+ $this->config = Config::module($this->getModuleName());
+ }
+ return $this->config;
+ } else {
+ if (! array_key_exists($file, $this->configs)) {
+ $this->configs[$file] = Config::module($this->getModuleName(), $file);
+ }
+ return $this->configs[$file];
+ }
+ }
+}
diff --git a/vendor/gipfl/icingaweb2/src/Controller/Extension/ControlsAndContentHelper.php b/vendor/gipfl/icingaweb2/src/Controller/Extension/ControlsAndContentHelper.php
new file mode 100644
index 0000000..00ef389
--- /dev/null
+++ b/vendor/gipfl/icingaweb2/src/Controller/Extension/ControlsAndContentHelper.php
@@ -0,0 +1,173 @@
+<?php
+
+namespace gipfl\IcingaWeb2\Controller\Extension;
+
+use gipfl\IcingaWeb2\Url;
+use gipfl\IcingaWeb2\Widget\Content;
+use gipfl\IcingaWeb2\Widget\Controls;
+use gipfl\IcingaWeb2\Widget\Tabs;
+use ipl\Html\HtmlDocument;
+
+trait ControlsAndContentHelper
+{
+ /** @var Controls */
+ private $controls;
+
+ /** @var Content */
+ private $content;
+
+ protected $title;
+
+ /** @var Url */
+ private $url;
+
+ /** @var Url */
+ private $originalUrl;
+
+ /**
+ * TODO: Not sure whether we need dedicated Content/Controls classes,
+ * a simple Container with a class name might suffice here
+ *
+ * @return Controls
+ */
+ public function controls()
+ {
+ if ($this->controls === null) {
+ $this->view->controls = $this->controls = new Controls();
+ }
+
+ return $this->controls;
+ }
+
+ /**
+ * @param Tabs|null $tabs
+ * @return Tabs
+ */
+ public function tabs(Tabs $tabs = null)
+ {
+ if ($tabs === null) {
+ return $this->controls()->getTabs();
+ } else {
+ $this->controls()->setTabs($tabs);
+ return $tabs;
+ }
+ }
+
+ /**
+ * @param HtmlDocument|null $actionBar
+ * @return HtmlDocument
+ */
+ public function actions(HtmlDocument $actionBar = null)
+ {
+ if ($actionBar === null) {
+ return $this->controls()->getActionBar();
+ } else {
+ $this->controls()->setActionBar($actionBar);
+ return $actionBar;
+ }
+ }
+
+ /**
+ * @return Content
+ */
+ public function content()
+ {
+ if ($this->content === null) {
+ $this->view->content = $this->content = new Content();
+ }
+
+ return $this->content;
+ }
+
+ /**
+ * @param $title
+ * @return $this
+ */
+ public function setTitle($title)
+ {
+ $this->title = $this->makeTitle(func_get_args());
+ return $this;
+ }
+
+ /**
+ * @param $title
+ * @return $this
+ */
+ public function addTitle($title)
+ {
+ $title = $this->makeTitle(func_get_args());
+ $this->title = $title;
+ $this->controls()->addTitle($title);
+
+ return $this;
+ }
+
+ private function makeTitle($args)
+ {
+ $title = array_shift($args);
+
+ if (empty($args)) {
+ return $title;
+ } else {
+ return vsprintf($title, $args);
+ }
+ }
+
+ /**
+ * @param string $title
+ * @param mixed $url
+ * @param string $name
+ * @return $this
+ */
+ public function addSingleTab($title, $url = null, $name = 'main')
+ {
+ if ($url === null) {
+ $url = $this->url();
+ }
+
+ $this->tabs()->add($name, [
+ 'label' => $title,
+ 'url' => $url,
+ ])->activate($name);
+
+ return $this;
+ }
+
+ /**
+ * @return Url
+ */
+ public function url()
+ {
+ if ($this->url === null) {
+ $this->url = $this->getOriginalUrl();
+ }
+
+ return $this->url;
+ }
+
+ /**
+ * @return Url
+ */
+ public function getOriginalUrl()
+ {
+ if ($this->originalUrl === null) {
+ $this->originalUrl = clone($this->getUrlFromRequest());
+ }
+
+ return clone($this->originalUrl);
+ }
+
+ /**
+ * @return Url
+ */
+ protected function getUrlFromRequest()
+ {
+ /** @var \Icinga\Web\Request $request */
+ $request = $this->getRequest();
+ $webUrl = $request->getUrl();
+
+ return Url::fromPath(
+ $webUrl->getPath()
+ )->setParams($webUrl->getParams());
+ }
+}