diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/Icinga/Web/Widget/Tabextension | |
parent | Initial commit. (diff) | |
download | icingaweb2-upstream.tar.xz icingaweb2-upstream.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
5 files changed, 248 insertions, 0 deletions
diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php new file mode 100644 index 0000000..a3e6c43 --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php @@ -0,0 +1,35 @@ +<?php +/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabs; + +/** + * Tabextension that allows to add the current URL to a dashboard + * + * Displayed as a dropdown field in the tabs + */ +class DashboardAction implements Tabextension +{ + /** + * Applies the dashboard actions to the provided tabset + * + * @param Tabs $tabs The tabs object to extend with + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown( + 'dashboard', + array( + 'icon' => 'dashboard', + 'label' => t('Add To Dashboard'), + 'url' => Url::fromPath('dashboard/new-dashlet'), + 'urlParams' => array( + 'url' => rawurlencode(Url::fromRequest()->getRelativeUrl()) + ) + ) + ); + } +} diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php new file mode 100644 index 0000000..fc7412a --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php @@ -0,0 +1,39 @@ +<?php +/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabs; + +/** + * Dashboard settings + */ +class DashboardSettings implements Tabextension +{ + /** + * Apply this tabextension to the provided tabs + * + * @param Tabs $tabs The tabbar to modify + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown( + 'dashboard_add', + array( + 'icon' => 'dashboard', + 'label' => t('Add Dashlet'), + 'url' => Url::fromPath('dashboard/new-dashlet') + ) + ); + + $tabs->addAsDropdown( + 'dashboard_settings', + array( + 'icon' => 'dashboard', + 'label' => t('Settings'), + 'url' => Url::fromPath('dashboard/settings') + ) + ); + } +} diff --git a/library/Icinga/Web/Widget/Tabextension/MenuAction.php b/library/Icinga/Web/Widget/Tabextension/MenuAction.php new file mode 100644 index 0000000..d713892 --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/MenuAction.php @@ -0,0 +1,35 @@ +<?php +/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabs; + +/** + * Tabextension that allows to add the current URL as menu entry + * + * Displayed as a dropdown field in the tabs + */ +class MenuAction implements Tabextension +{ + /** + * Applies the menu actions to the provided tabset + * + * @param Tabs $tabs The tabs object to extend with + */ + public function apply(Tabs $tabs) + { + $tabs->addAsDropdown( + 'menu-entry', + array( + 'icon' => 'menu', + 'label' => t('Add To Menu'), + 'url' => Url::fromPath('navigation/add'), + 'urlParams' => array( + 'url' => rawurlencode(Url::fromRequest()->getRelativeUrl()) + ) + ) + ); + } +} diff --git a/library/Icinga/Web/Widget/Tabextension/OutputFormat.php b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php new file mode 100644 index 0000000..d5d83af --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/OutputFormat.php @@ -0,0 +1,114 @@ +<?php +/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Application\Platform; +use Icinga\Application\Hook; +use Icinga\Web\Url; +use Icinga\Web\Widget\Tab; +use Icinga\Web\Widget\Tabs; + +/** + * Tabextension that offers different output formats for the user in the dropdown area + */ +class OutputFormat implements Tabextension +{ + /** + * PDF output type + */ + const TYPE_PDF = 'pdf'; + + /** + * JSON output type + */ + const TYPE_JSON = 'json'; + + /** + * CSV output type + */ + const TYPE_CSV = 'csv'; + + /** + * An array of tabs to be added to the dropdown area + * + * @var array + */ + private $tabs = array(); + + /** + * Create a new OutputFormat extender + * + * In general, it's assumed that all types are supported when an outputFormat extension + * is added, so this class offers to remove specific types instead of adding ones + * + * @param array $disabled An array of output types to <b>not</b> show. + */ + public function __construct(array $disabled = array()) + { + foreach ($this->getSupportedTypes() as $type => $tabConfig) { + if (!in_array($type, $disabled)) { + $tabConfig['url'] = Url::fromRequest(); + $tab = new Tab($tabConfig); + $tab->setTargetBlank(); + $this->tabs[] = $tab; + } + } + } + + /** + * Applies the format selectio to the provided tabset + * + * @param Tabs $tabs The tabs object to extend with + * + * @see Tabextension::apply() + */ + public function apply(Tabs $tabs) + { + foreach ($this->tabs as $tab) { + $tabs->addAsDropdown($tab->getName(), $tab); + } + } + + /** + * Return an array containing the tab definitions for all supported types + * + * Using array_keys on this array or isset allows to check whether a + * requested type is supported + * + * @return array + */ + public function getSupportedTypes() + { + $supportedTypes = array(); + + $pdfexport = Hook::has('Pdfexport'); + + if ($pdfexport || Platform::extensionLoaded('gd')) { + $supportedTypes[self::TYPE_PDF] = array( + 'name' => 'pdf', + 'label' => 'PDF', + 'icon' => 'file-pdf', + 'urlParams' => array('format' => 'pdf'), + ); + } + + $supportedTypes[self::TYPE_CSV] = array( + 'name' => 'csv', + 'label' => 'CSV', + 'icon' => 'file-excel', + 'urlParams' => array('format' => 'csv') + ); + + if (Platform::extensionLoaded('json')) { + $supportedTypes[self::TYPE_JSON] = array( + 'name' => 'json', + 'label' => 'JSON', + 'icon' => 'doc-text', + 'urlParams' => array('format' => 'json') + ); + } + + return $supportedTypes; + } +} diff --git a/library/Icinga/Web/Widget/Tabextension/Tabextension.php b/library/Icinga/Web/Widget/Tabextension/Tabextension.php new file mode 100644 index 0000000..ea49c4b --- /dev/null +++ b/library/Icinga/Web/Widget/Tabextension/Tabextension.php @@ -0,0 +1,25 @@ +<?php +/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */ + +namespace Icinga\Web\Widget\Tabextension; + +use Icinga\Web\Widget\Tabs; + +/** + * Tabextension interface that allows to extend a tabbar with reusable components + * + * Tabs can be either extended by creating a `Tabextension` and calling the `apply()` method + * or by calling the `\Icinga\Web\Widget\Tabs` `extend()` method and providing + * a tab extension + * + * @see \Icinga\Web\Widget\Tabs::extend() + */ +interface Tabextension +{ + /** + * Apply this tabextension to the provided tabs + * + * @param Tabs $tabs The tabbar to modify + */ + public function apply(Tabs $tabs); +} |