From 1ff5c35de5dbd70a782875a91dd2232fd01b002b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:38:04 +0200 Subject: Adding upstream version 0.10.1. Signed-off-by: Daniel Baumann --- vendor/ipl/web/src/Widget/ActionBar.php | 51 ++++++ vendor/ipl/web/src/Widget/ActionLink.php | 31 ++++ vendor/ipl/web/src/Widget/ButtonLink.php | 14 ++ vendor/ipl/web/src/Widget/ContinueWith.php | 72 +++++++++ vendor/ipl/web/src/Widget/Dropdown.php | 63 ++++++++ vendor/ipl/web/src/Widget/HorizontalKeyValue.php | 31 ++++ vendor/ipl/web/src/Widget/IcingaIcon.php | 26 ++++ vendor/ipl/web/src/Widget/Icon.php | 32 ++++ vendor/ipl/web/src/Widget/Link.php | 83 ++++++++++ vendor/ipl/web/src/Widget/StateBadge.php | 47 ++++++ vendor/ipl/web/src/Widget/StateBall.php | 43 +++++ vendor/ipl/web/src/Widget/Tabs.php | 190 +++++++++++++++++++++++ vendor/ipl/web/src/Widget/TimeAgo.php | 33 ++++ vendor/ipl/web/src/Widget/TimeSince.php | 33 ++++ vendor/ipl/web/src/Widget/TimeUntil.php | 33 ++++ vendor/ipl/web/src/Widget/VerticalKeyValue.php | 32 ++++ 16 files changed, 814 insertions(+) create mode 100644 vendor/ipl/web/src/Widget/ActionBar.php create mode 100644 vendor/ipl/web/src/Widget/ActionLink.php create mode 100644 vendor/ipl/web/src/Widget/ButtonLink.php create mode 100644 vendor/ipl/web/src/Widget/ContinueWith.php create mode 100644 vendor/ipl/web/src/Widget/Dropdown.php create mode 100644 vendor/ipl/web/src/Widget/HorizontalKeyValue.php create mode 100644 vendor/ipl/web/src/Widget/IcingaIcon.php create mode 100644 vendor/ipl/web/src/Widget/Icon.php create mode 100644 vendor/ipl/web/src/Widget/Link.php create mode 100644 vendor/ipl/web/src/Widget/StateBadge.php create mode 100644 vendor/ipl/web/src/Widget/StateBall.php create mode 100644 vendor/ipl/web/src/Widget/Tabs.php create mode 100644 vendor/ipl/web/src/Widget/TimeAgo.php create mode 100644 vendor/ipl/web/src/Widget/TimeSince.php create mode 100644 vendor/ipl/web/src/Widget/TimeUntil.php create mode 100644 vendor/ipl/web/src/Widget/VerticalKeyValue.php (limited to 'vendor/ipl/web/src/Widget') diff --git a/vendor/ipl/web/src/Widget/ActionBar.php b/vendor/ipl/web/src/Widget/ActionBar.php new file mode 100644 index 0000000..bf31845 --- /dev/null +++ b/vendor/ipl/web/src/Widget/ActionBar.php @@ -0,0 +1,51 @@ + 'action-bar', + 'data-base-target' => '_self' + ]; + + protected $tag = 'div'; + + /** + * Create a action bar + * + * @param Attributes|array $attributes + */ + public function __construct($attributes = null) + { + $this->getAttributes()->add($attributes); + } + + /** + * Add a link to the action bar + * + * @param mixed $content + * @param Url|string $url + * @param string $icon + * + * @return $this + */ + public function addLink($content, $url, $icon = null) + { + $this->add(new ActionLink($content, $url, $icon)); + + return $this; + } +} diff --git a/vendor/ipl/web/src/Widget/ActionLink.php b/vendor/ipl/web/src/Widget/ActionLink.php new file mode 100644 index 0000000..289d700 --- /dev/null +++ b/vendor/ipl/web/src/Widget/ActionLink.php @@ -0,0 +1,31 @@ + 'action-link']; + + /** + * Create a action link + * + * @param mixed $content + * @param Url|string $url + * @param string $icon + * @param Attributes|array $attributes + */ + public function __construct($content, $url, $icon = null, $attributes = null) + { + parent::__construct($content, $url, $attributes); + + if ($icon !== null) { + $this->prepend(new Icon($icon)); + } + } +} diff --git a/vendor/ipl/web/src/Widget/ButtonLink.php b/vendor/ipl/web/src/Widget/ButtonLink.php new file mode 100644 index 0000000..2da5dfd --- /dev/null +++ b/vendor/ipl/web/src/Widget/ButtonLink.php @@ -0,0 +1,14 @@ + 'button-link', + 'data-base-target' => '_main' + ]; +} diff --git a/vendor/ipl/web/src/Widget/ContinueWith.php b/vendor/ipl/web/src/Widget/ContinueWith.php new file mode 100644 index 0000000..4aaf52e --- /dev/null +++ b/vendor/ipl/web/src/Widget/ContinueWith.php @@ -0,0 +1,72 @@ + 'continue-with']; + + /** @var Url */ + protected $url; + + /** @var Filter\Rule|callable */ + protected $filter; + + /** @var string */ + protected $title; + + public function __construct(Url $url, $filter) + { + $this->url = $url; + $this->filter = $filter; + } + + /** + * Set title for the anchor + * + * @param string $title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + public function assemble() + { + $filter = $this->filter; + if (is_callable($filter)) { + $filter = $filter(); /** @var Filter\Rule $filter */ + } + + if ($filter instanceof Filter\Chain && $filter->isEmpty()) { + $this->addHtml(new HtmlElement( + 'span', + Attributes::create(['class' => ['control-button', 'disabled']]), + new Icon('share') + )); + } else { + $this->addHtml(new ActionLink( + null, + $this->url->setQueryString(QueryString::render($filter)), + 'share', + ['class' => 'control-button', 'title' => $this->title] + )); + } + } +} diff --git a/vendor/ipl/web/src/Widget/Dropdown.php b/vendor/ipl/web/src/Widget/Dropdown.php new file mode 100644 index 0000000..b6eb20d --- /dev/null +++ b/vendor/ipl/web/src/Widget/Dropdown.php @@ -0,0 +1,63 @@ + 'dropdown']; + + protected $tag = 'div'; + + /** + * Create a dropdown element + * + * @param mixed $content + * @param Attributes|array $attributes + */ + public function __construct($content, $attributes = null) + { + $toggle = new ActionLink($content, '#', null, [ + 'aria-expanded' => false, + 'aria-haspopup' => true, + 'class' => 'dropdown-toggle', + 'role' => 'button' + ]); + + $this + ->setContent($toggle) + ->getAttributes() + ->add($attributes); + } + + /** + * Add a link to the dropdown + * + * @param mixed $content + * @param Url|string $url + * @param string $icon + * + * @return $this + */ + public function addLink($content, $url, $icon = null) + { + $this->links[] = new ActionLink($content, $url, $icon, ['class' => 'dropdown-item']); + + return $this; + } + + protected function assemble() + { + $this->add(Html::tag('div', ['class' => 'dropdown-menu'], $this->links)); + } +} diff --git a/vendor/ipl/web/src/Widget/HorizontalKeyValue.php b/vendor/ipl/web/src/Widget/HorizontalKeyValue.php new file mode 100644 index 0000000..1d1195e --- /dev/null +++ b/vendor/ipl/web/src/Widget/HorizontalKeyValue.php @@ -0,0 +1,31 @@ + 'horizontal-key-value']; + + protected $tag = 'div'; + + public function __construct($key, $value) + { + $this->key = $key; + $this->value = $value; + } + + protected function assemble() + { + $this->add([ + Html::tag('div', ['class' => 'key'], $this->key), + Html::tag('div', ['class' => 'value'], $this->value) + ]); + } +} diff --git a/vendor/ipl/web/src/Widget/IcingaIcon.php b/vendor/ipl/web/src/Widget/IcingaIcon.php new file mode 100644 index 0000000..8002dcc --- /dev/null +++ b/vendor/ipl/web/src/Widget/IcingaIcon.php @@ -0,0 +1,26 @@ +. The given + * name will be used as automatically added CSS class for the icon element in the format 'iicon-$name'. In addition, + * the CSS class 'icon' will be automatically added too. + * + * @param string $name The name of the icon + * @param Attributes|array $attributes The HTML attributes for the element + */ + public function __construct($name, $attributes = null) + { + $this + ->getAttributes() + ->add('class', ['icon', "iicon-$name"]) + ->add($attributes); + } +} diff --git a/vendor/ipl/web/src/Widget/Icon.php b/vendor/ipl/web/src/Widget/Icon.php new file mode 100644 index 0000000..2198c87 --- /dev/null +++ b/vendor/ipl/web/src/Widget/Icon.php @@ -0,0 +1,32 @@ +. The given + * name will be used as automatically added CSS class for the icon element in the format 'icon-$name'. In addition, + * the CSS class 'icon' will be automatically added too. + * + * @param string $name The name of the icon + * @param Attributes|array $attributes The HTML attributes for the element + */ + public function __construct($name, $attributes = null) + { + $this + ->getAttributes() + ->add('class', ['icon', 'fa', "fa-$name"]) + ->add($attributes); + } +} diff --git a/vendor/ipl/web/src/Widget/Link.php b/vendor/ipl/web/src/Widget/Link.php new file mode 100644 index 0000000..2d7c9f5 --- /dev/null +++ b/vendor/ipl/web/src/Widget/Link.php @@ -0,0 +1,83 @@ +setContent($content) + ->setUrl($url) + ->getAttributes() + ->add($attributes) + ->registerAttributeCallback('href', [$this, 'createHrefAttribute']); + } + + /** + * Get the URL of the link + * + * @return Url + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set the URL of the link + * + * @param Url|string $url + * + * @return $this + */ + public function setUrl($url) + { + if (! $url instanceof Url) { + try { + $url = Url::fromPath($url); + } catch (\Exception $e) { + $url = 'invalid'; + } + } + + $this->url = $url; + + return $this; + } + + /** + * Create and return the href attribute + * + * Used as attribute callback for the href attribute. + * + * @return Attribute + */ + public function createHrefAttribute() + { + return new Attribute('href', (string) $this->getUrl()); + } +} diff --git a/vendor/ipl/web/src/Widget/StateBadge.php b/vendor/ipl/web/src/Widget/StateBadge.php new file mode 100644 index 0000000..908a348 --- /dev/null +++ b/vendor/ipl/web/src/Widget/StateBadge.php @@ -0,0 +1,47 @@ + 'state-badge']; + + /** @var mixed Badge content */ + protected $content; + + /** @var bool Whether the state is handled */ + protected $isHandled; + + /** @var string Textual representation of a state */ + protected $state; + + /** + * Create a new state badge + * + * @param mixed $content Content of the badge + * @param string $state Textual representation of a state + * @param bool $isHandled True if state is handled + */ + public function __construct($content, string $state, bool $isHandled = false) + { + $this->content = $content; + $this->isHandled = $isHandled; + $this->state = $state; + } + + protected function assemble() + { + $this->setTag('span'); + + $class = "state-{$this->state}"; + if ($this->isHandled) { + $class .= ' handled'; + } + + $this->addAttributes(['class' => $class]); + + $this->add($this->content); + } +} diff --git a/vendor/ipl/web/src/Widget/StateBall.php b/vendor/ipl/web/src/Widget/StateBall.php new file mode 100644 index 0000000..5a1216d --- /dev/null +++ b/vendor/ipl/web/src/Widget/StateBall.php @@ -0,0 +1,43 @@ +defaultAttributes = ['class' => "state-ball state-$state ball-size-$size"]; + } +} diff --git a/vendor/ipl/web/src/Widget/Tabs.php b/vendor/ipl/web/src/Widget/Tabs.php new file mode 100644 index 0000000..32ba8e9 --- /dev/null +++ b/vendor/ipl/web/src/Widget/Tabs.php @@ -0,0 +1,190 @@ + 'tabs primary-nav nav']; + + /** @var \Icinga\Web\Widget\Tabs */ + protected $tabs; + + /** @var bool Whether data exports are enabled */ + protected $dataExportsEnabled = false; + + /** @var bool Whether the legacy extensions should be shown by default */ + protected $legacyExtensionsEnabled = true; + + /** @var Url */ + protected $refreshUrl; + + public function __construct() + { + $this->tabs = new \Icinga\Web\Widget\Tabs(); + } + + /** + * Don't show legacy extensions by default + */ + public function disableLegacyExtensions() + { + $this->legacyExtensionsEnabled = false; + } + + /** + * Show export actions for JSON and CSV + */ + public function enableDataExports() + { + $this->dataExportsEnabled = true; + } + + /** + * Set the url for the refresh button + * + * @param Url $url + * + * @return $this + */ + public function setRefreshUrl(Url $url) + { + $this->refreshUrl = $url; + + return $this; + } + + protected function assemble() + { + if ($this->legacyExtensionsEnabled) { + $this->tabs->extend(new OutputFormat( + $this->dataExportsEnabled + ? [] + : [OutputFormat::TYPE_CSV, OutputFormat::TYPE_JSON] + )) + ->extend(new DashboardAction()) + ->extend(new MenuAction()); + } + + $tabHtml = substr($this->tabs->render(), 34, -5); + if ($this->refreshUrl !== null) { + $tabHtml = preg_replace( + '/(?<=class="refresh-container-control spinner" href=")([^"]*)/', + $this->refreshUrl->getAbsoluteUrl(), + $tabHtml + ); + } + + parent::add(HtmlString::create($tabHtml)); + } + + /** + * Activate the tab with the given name + * + * @param string $name + * + * @return $this + * + * @throws InvalidArgumentException + */ + public function activate($name) + { + try { + $this->tabs->activate($name); + } catch (Exception $e) { + throw new InvalidArgumentException($e->getMessage()); + } + + return $this; + } + + /** + * Get active tab + * + * @return \Icinga\Web\Widget\Tab + */ + public function getActiveTab() + { + return $this->tabs->get($this->tabs->getActiveName()); + } + + /** + * Add the given tab + * + * @param string $name + * @param mixed $tab + * + * @return $this + * + * @throws InvalidArgumentException + */ + public function add($name, $tab = null) + { + if ($tab === null) { + throw new InvalidArgumentException('Argument $tab is required'); + } + + try { + $this->tabs->add($name, $tab); + } catch (Exception $e) { + throw new InvalidArgumentException($e->getMessage()); + } + + if (is_array($tab) && isset($tab['active']) && $tab['active']) { + // Otherwise Tabs::getActiveName() returns null + $this->tabs->activate($name); + } + + return $this; + } + + /** + * Get a tab + * + * @param string $name + * + * @return \Icinga\Web\Widget\Tab|null + */ + public function get($name) + { + return $this->tabs->get($name); + } + + /** + * Count tabs + * + * @return int + */ + public function count(): int + { + return $this->tabs->count(); + } + + /** + * Apply a Tabextension on $this->tabs object not on this class + * + * @param Tabextension $extension + * + * @return $this + */ + public function extend(Tabextension $extension) + { + $this->tabs->extend($extension); + + return $this; + } +} diff --git a/vendor/ipl/web/src/Widget/TimeAgo.php b/vendor/ipl/web/src/Widget/TimeAgo.php new file mode 100644 index 0000000..cbd0dad --- /dev/null +++ b/vendor/ipl/web/src/Widget/TimeAgo.php @@ -0,0 +1,33 @@ + 'time-ago']; + + public function __construct($ago) + { + $this->ago = (int) $ago; + } + + protected function assemble() + { + $dateTime = DateFormatter::formatDateTime($this->ago); + + $this->addAttributes([ + 'datetime' => $dateTime, + 'title' => $dateTime + ]); + + $this->add(DateFormatter::timeAgo($this->ago)); + } +} diff --git a/vendor/ipl/web/src/Widget/TimeSince.php b/vendor/ipl/web/src/Widget/TimeSince.php new file mode 100644 index 0000000..308e358 --- /dev/null +++ b/vendor/ipl/web/src/Widget/TimeSince.php @@ -0,0 +1,33 @@ + 'time-since']; + + public function __construct($since) + { + $this->since = (int) $since; + } + + protected function assemble() + { + $dateTime = DateFormatter::formatDateTime($this->since); + + $this->addAttributes([ + 'datetime' => $dateTime, + 'title' => $dateTime + ]); + + $this->add(DateFormatter::timeSince($this->since)); + } +} diff --git a/vendor/ipl/web/src/Widget/TimeUntil.php b/vendor/ipl/web/src/Widget/TimeUntil.php new file mode 100644 index 0000000..ba1f527 --- /dev/null +++ b/vendor/ipl/web/src/Widget/TimeUntil.php @@ -0,0 +1,33 @@ + 'time-until']; + + public function __construct($until) + { + $this->until = (int) $until; + } + + protected function assemble() + { + $dateTime = DateFormatter::formatDateTime($this->until); + + $this->addAttributes([ + 'datetime' => $dateTime, + 'title' => $dateTime + ]); + + $this->add(DateFormatter::timeUntil($this->until)); + } +} diff --git a/vendor/ipl/web/src/Widget/VerticalKeyValue.php b/vendor/ipl/web/src/Widget/VerticalKeyValue.php new file mode 100644 index 0000000..388c740 --- /dev/null +++ b/vendor/ipl/web/src/Widget/VerticalKeyValue.php @@ -0,0 +1,32 @@ + 'vertical-key-value']; + + public function __construct($key, $value) + { + $this->key = $key; + $this->value = $value; + } + + protected function assemble() + { + $this->add([ + Html::tag('span', ['class' => 'value'], $this->value), + Html::tag('br'), + Html::tag('span', ['class' => 'key'], $this->key), + ]); + } +} -- cgit v1.2.3