From a726348718f3592c7312400f92acf64bc22c6b13 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 13 Jun 2022 08:56:20 +0200 Subject: [PATCH] Drop all dashboards related legacy codes --- application/forms/Navigation/DashletForm.php | 35 -- .../views/scripts/dashboard/error.phtml | 13 - .../views/scripts/dashboard/index.phtml | 26 - .../views/scripts/dashboard/new-dashlet.phtml | 6 - .../scripts/dashboard/remove-dashlet.phtml | 6 - .../views/scripts/dashboard/remove-pane.phtml | 6 - .../views/scripts/dashboard/rename-pane.phtml | 6 - .../views/scripts/dashboard/settings.phtml | 91 ---- .../scripts/dashboard/update-dashlet.phtml | 6 - library/Icinga/Application/Web.php | 48 +- library/Icinga/Legacy/DashboardConfig.php | 137 ----- library/Icinga/User.php | 25 +- .../Icinga/Web/Navigation/DashboardPane.php | 84 ---- library/Icinga/Web/Navigation/Navigation.php | 18 +- library/Icinga/Web/Widget/Dashboard.php | 475 ------------------ .../Icinga/Web/Widget/Dashboard/Dashlet.php | 315 ------------ library/Icinga/Web/Widget/Dashboard/Pane.php | 335 ------------ .../Web/Widget/Dashboard/UserWidget.php | 36 -- 18 files changed, 19 insertions(+), 1649 deletions(-) delete mode 100644 application/forms/Navigation/DashletForm.php delete mode 100644 application/views/scripts/dashboard/error.phtml delete mode 100644 application/views/scripts/dashboard/index.phtml delete mode 100644 application/views/scripts/dashboard/new-dashlet.phtml delete mode 100644 application/views/scripts/dashboard/remove-dashlet.phtml delete mode 100644 application/views/scripts/dashboard/remove-pane.phtml delete mode 100644 application/views/scripts/dashboard/rename-pane.phtml delete mode 100644 application/views/scripts/dashboard/settings.phtml delete mode 100644 application/views/scripts/dashboard/update-dashlet.phtml delete mode 100644 library/Icinga/Legacy/DashboardConfig.php delete mode 100644 library/Icinga/Web/Navigation/DashboardPane.php delete mode 100644 library/Icinga/Web/Widget/Dashboard.php delete mode 100644 library/Icinga/Web/Widget/Dashboard/Dashlet.php delete mode 100644 library/Icinga/Web/Widget/Dashboard/Pane.php delete mode 100644 library/Icinga/Web/Widget/Dashboard/UserWidget.php diff --git a/application/forms/Navigation/DashletForm.php b/application/forms/Navigation/DashletForm.php deleted file mode 100644 index 6575fd789..000000000 --- a/application/forms/Navigation/DashletForm.php +++ /dev/null @@ -1,35 +0,0 @@ -addElement( - 'text', - 'pane', - array( - 'required' => true, - 'label' => $this->translate('Pane'), - 'description' => $this->translate('The name of the dashboard pane in which to display this dashlet') - ) - ); - $this->addElement( - 'text', - 'url', - array( - 'required' => true, - 'label' => $this->translate('Url'), - 'description' => $this->translate( - 'The url to load in the dashlet. For external urls, make sure to prepend' - . ' an appropriate protocol identifier (e.g. http://example.tld)' - ) - ) - ); - } -} diff --git a/application/views/scripts/dashboard/error.phtml b/application/views/scripts/dashboard/error.phtml deleted file mode 100644 index 9396b490e..000000000 --- a/application/views/scripts/dashboard/error.phtml +++ /dev/null @@ -1,13 +0,0 @@ -
-

translate('Could not save dashboard'); ?>

-

- translate('Please copy the following dashboard snippet to '); ?> - config->getConfigFile(); ?>;. -
- translate('Make sure that the webserver can write to this file.'); ?> -

-
config; ?>
-
-

translate('Error details'); ?>

-

error->getMessage(); ?>

-
\ No newline at end of file diff --git a/application/views/scripts/dashboard/index.phtml b/application/views/scripts/dashboard/index.phtml deleted file mode 100644 index 1d561146f..000000000 --- a/application/views/scripts/dashboard/index.phtml +++ /dev/null @@ -1,26 +0,0 @@ -
-compact): ?> -tabs ?> - -
-dashboard): ?> -
- dashboard ?> -
- -
-

escape($this->translate('Welcome to Icinga Web!')) ?>

-

- hasPermission('config/modules')) { - echo $this->escape($this->translate( - 'Currently there is no dashlet available. Please contact the administrator.' - )); - } else { - printf( - $this->escape($this->translate('Currently there is no dashlet available. This might change once you enabled some of the available %s.')), - $this->qlink($this->translate('modules'), 'config/modules') - ); - } ?> -

-
- diff --git a/application/views/scripts/dashboard/new-dashlet.phtml b/application/views/scripts/dashboard/new-dashlet.phtml deleted file mode 100644 index b265a253a..000000000 --- a/application/views/scripts/dashboard/new-dashlet.phtml +++ /dev/null @@ -1,6 +0,0 @@ -
- tabs ?> -
-
- form; ?> -
\ No newline at end of file diff --git a/application/views/scripts/dashboard/remove-dashlet.phtml b/application/views/scripts/dashboard/remove-dashlet.phtml deleted file mode 100644 index b265a253a..000000000 --- a/application/views/scripts/dashboard/remove-dashlet.phtml +++ /dev/null @@ -1,6 +0,0 @@ -
- tabs ?> -
-
- form; ?> -
\ No newline at end of file diff --git a/application/views/scripts/dashboard/remove-pane.phtml b/application/views/scripts/dashboard/remove-pane.phtml deleted file mode 100644 index b265a253a..000000000 --- a/application/views/scripts/dashboard/remove-pane.phtml +++ /dev/null @@ -1,6 +0,0 @@ -
- tabs ?> -
-
- form; ?> -
\ No newline at end of file diff --git a/application/views/scripts/dashboard/rename-pane.phtml b/application/views/scripts/dashboard/rename-pane.phtml deleted file mode 100644 index b265a253a..000000000 --- a/application/views/scripts/dashboard/rename-pane.phtml +++ /dev/null @@ -1,6 +0,0 @@ -
- tabs ?> -
-
- form; ?> -
\ No newline at end of file diff --git a/application/views/scripts/dashboard/settings.phtml b/application/views/scripts/dashboard/settings.phtml deleted file mode 100644 index a6cfe83d1..000000000 --- a/application/views/scripts/dashboard/settings.phtml +++ /dev/null @@ -1,91 +0,0 @@ -
- tabs ?> -
-
-

- - - - - - - - - - - dashboard->getPanes() as $pane): ?> - getDisabled()) continue; ?> - - - - - getDashlets(); ?> - - - - - - - getDisabled()) continue; ?> - - - - - - - - - -
- - - -  
- isUserWidget()): ?> - qlink( - $pane->getName(), - 'dashboard/rename-pane', - array('pane' => $pane->getName()), - array('title' => sprintf($this->translate('Edit pane %s'), $pane->getName())) - ) ?> - - escape($pane->getName()) ?> - - - qlink( - '', - 'dashboard/remove-pane', - array('pane' => $pane->getName()), - array( - 'icon' => 'trash', - 'title' => sprintf($this->translate('Remove pane %s'), $pane->getName()) - ) - ); ?> -
- translate('No dashlets added to dashboard') ?>. -
- qlink( - $dashlet->getTitle(), - 'dashboard/update-dashlet', - array('pane' => $pane->getName(), 'dashlet' => $dashlet->getName()), - array('title' => sprintf($this->translate('Edit dashlet %s'), $dashlet->getTitle())) - ); ?> - - qlink( - $dashlet->getUrl()->getRelativeUrl(), - $dashlet->getUrl()->getRelativeUrl(), - null, - array('title' => sprintf($this->translate('Show dashlet %s'), $dashlet->getTitle())) - ); ?> - - qlink( - '', - 'dashboard/remove-dashlet', - array('pane' => $pane->getName(), 'dashlet' => $dashlet->getName()), - array( - 'icon' => 'trash', - 'title' => sprintf($this->translate('Remove dashlet %s from pane %s'), $dashlet->getTitle(), $pane->getTitle()) - ) - ); ?> -
-
diff --git a/application/views/scripts/dashboard/update-dashlet.phtml b/application/views/scripts/dashboard/update-dashlet.phtml deleted file mode 100644 index b265a253a..000000000 --- a/application/views/scripts/dashboard/update-dashlet.phtml +++ /dev/null @@ -1,6 +0,0 @@ -
- tabs ?> -
-
- form; ?> -
\ No newline at end of file diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 4ce9b45a6..6106291d4 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -238,48 +238,24 @@ class Web extends EmbeddedWeb */ public function getSharedNavigation($type) { - $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type); - - if ($type === 'dashboard-pane') { - $panes = array(); - foreach ($config as $dashletName => $dashletConfig) { - if ($this->hasAccessToSharedNavigationItem($dashletConfig)) { - // TODO: Throw ConfigurationError if pane or url is missing - $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; + $config = Config::navigation($type); + $items = array(); + foreach ($config as $name => $typeConfig) { + if (isset($this->accessibleMenuItems[$name])) { + if ($this->accessibleMenuItems[$name]) { + $items[$name] = $typeConfig; } - } - - $navigation = new Navigation(); - foreach ($panes as $paneName => $dashlets) { - $navigation->addItem( - $paneName, - array( - 'type' => 'dashboard-pane', - 'dashlets' => $dashlets - ) - ); - } - } else { - $items = array(); - foreach ($config as $name => $typeConfig) { - if (isset($this->accessibleMenuItems[$name])) { - if ($this->accessibleMenuItems[$name]) { - $items[$name] = $typeConfig; - } + } else { + if ($this->hasAccessToSharedNavigationItem($typeConfig, $config)) { + $this->accessibleMenuItems[$name] = true; + $items[$name] = $typeConfig; } else { - if ($this->hasAccessToSharedNavigationItem($typeConfig, $config)) { - $this->accessibleMenuItems[$name] = true; - $items[$name] = $typeConfig; - } else { - $this->accessibleMenuItems[$name] = false; - } + $this->accessibleMenuItems[$name] = false; } } - - $navigation = Navigation::fromConfig($items); } - return $navigation; + return Navigation::fromConfig($items); } /** diff --git a/library/Icinga/Legacy/DashboardConfig.php b/library/Icinga/Legacy/DashboardConfig.php deleted file mode 100644 index 3fb5c2fc2..000000000 --- a/library/Icinga/Legacy/DashboardConfig.php +++ /dev/null @@ -1,137 +0,0 @@ -user; - } - - /** - * Set the user - * - * @param User $user - * - * @return $this - */ - public function setUser($user) - { - $this->user = $user; - return $this; - } - - - /** - * List all dashboard configuration files that match the given user - * - * @param User $user - * - * @return string[] - */ - public static function listConfigFilesForUser(User $user) - { - $files = array(); - $dashboards = static::resolvePath('dashboards'); - if ($handle = @opendir($dashboards)) { - while (false !== ($entry = readdir($handle))) { - if ($entry[0] === '.' || ! is_dir($dashboards . '/' . $entry)) { - continue; - } - if (strtolower($entry) === strtolower($user->getUsername())) { - $files[] = $dashboards . '/' . $entry . '/dashboard.ini'; - } - } - closedir($handle); - } - return $files; - } - - /** - * {@inheritdoc} - */ - public function saveIni($filePath = null, $fileMode = 0660) - { - // Preprocessing start, ensures that the non-translated names are used to save module dashboard changes - // TODO: This MUST NOT survive the new dashboard implementation (yes, it's still a thing..) - $dashboardNavigation = new Navigation(); - $dashboardNavigation->load('dashboard-pane'); - $getDashboardPane = function ($label) use ($dashboardNavigation) { - foreach ($dashboardNavigation as $dashboardPane) { - /** @var DashboardPane $dashboardPane */ - if ($dashboardPane->getLabel() === $label) { - return $dashboardPane; - } - - foreach ($dashboardPane->getChildren() as $dashlet) { - /** @var NavigationItem $dashlet */ - if ($dashlet->getLabel() === $label) { - return $dashlet; - } - } - } - }; - - foreach (clone $this->config as $name => $options) { - if (strpos($name, '.') !== false) { - list($dashboardLabel, $dashletLabel) = explode('.', $name, 2); - } else { - $dashboardLabel = $name; - $dashletLabel = null; - } - - $dashboardPane = $getDashboardPane($dashboardLabel); - if ($dashboardPane !== null) { - $dashboardLabel = $dashboardPane->getName(); - } - - if ($dashletLabel !== null) { - $dashletItem = $getDashboardPane($dashletLabel); - if ($dashletItem !== null) { - $dashletLabel = $dashletItem->getName(); - } - } - - unset($this->config[$name]); - $this->config[$dashboardLabel . ($dashletLabel ? '.' . $dashletLabel : '')] = $options; - } - // Preprocessing end - - parent::saveIni($filePath, $fileMode); - if ($filePath === null) { - $filePath = $this->configFile; - } - foreach (static::listConfigFilesForUser($this->user) as $file) { - if ($file !== $filePath) { - @unlink($file); - } - } - } -} diff --git a/library/Icinga/User.php b/library/Icinga/User.php index 8610dd0fe..d568ff4a7 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -621,29 +621,8 @@ class User */ public function getNavigation($type) { - $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type, $this->getUsername()); + $config = Config::navigation($type, $this->getUsername()); - if ($type === 'dashboard-pane') { - $panes = array(); - foreach ($config as $dashletName => $dashletConfig) { - // TODO: Throw ConfigurationError if pane or url is missing - $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; - } - - $navigation = new Navigation(); - foreach ($panes as $paneName => $dashlets) { - $navigation->addItem( - $paneName, - array( - 'type' => 'dashboard-pane', - 'dashlets' => $dashlets - ) - ); - } - } else { - $navigation = Navigation::fromConfig($config); - } - - return $navigation; + return Navigation::fromConfig($config); } } diff --git a/library/Icinga/Web/Navigation/DashboardPane.php b/library/Icinga/Web/Navigation/DashboardPane.php deleted file mode 100644 index 71b3215cf..000000000 --- a/library/Icinga/Web/Navigation/DashboardPane.php +++ /dev/null @@ -1,84 +0,0 @@ -dashlets = $dashlets; - return $this; - } - - /** - * Return this pane's dashlets - * - * @param bool $ordered Whether to order the dashlets first - * - * @return array - */ - public function getDashlets($ordered = true) - { - if ($this->dashlets === null) { - return array(); - } - - if ($ordered) { - $dashlets = $this->dashlets; - ksort($dashlets); - return $dashlets; - } - - return $this->dashlets; - } - - /** - * {@inheritdoc} - */ - public function init() - { - $this->setUrl(Url::fromPath('dashboard', array('pane' => $this->getName()))); - } - - /** - * Set disabled state for pane - * - * @param bool $disabled - */ - public function setDisabled($disabled = true) - { - $this->disabled = (bool) $disabled; - } - - /** - * Get disabled state for pane - * - * @return bool - */ - public function getDisabled() - { - return $this->disabled; - } -} diff --git a/library/Icinga/Web/Navigation/Navigation.php b/library/Icinga/Web/Navigation/Navigation.php index 8cf3f6845..6765f1c83 100644 --- a/library/Icinga/Web/Navigation/Navigation.php +++ b/library/Icinga/Web/Navigation/Navigation.php @@ -414,13 +414,11 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate public function load($type) { $user = Auth::getInstance()->getUser(); - if ($type !== 'dashboard-pane') { - // Shareables - $this->merge(Icinga::app()->getSharedNavigation($type)); + // Shareables + $this->merge(Icinga::app()->getSharedNavigation($type)); - // User Preferences - $this->merge($user->getNavigation($type)); - } + // User Preferences + $this->merge($user->getNavigation($type)); // Modules $moduleManager = Icinga::app()->getModuleManager(); @@ -428,8 +426,6 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate if ($user->can($moduleManager::MODULE_PERMISSION_NS . $module->getName())) { if ($type === 'menu-item') { $this->merge($module->getMenu()); - } elseif ($type === 'dashboard-pane') { - $this->merge($module->getDashboard()); } } } @@ -448,11 +444,7 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate 'menu-item' => array( 'label' => t('Menu Entry'), 'config' => 'menu' - )/*, // Disabled, until it is able to fully replace the old implementation - 'dashlet' => array( - 'label' => 'Dashlet', - 'config' => 'dashboard' - )*/ + ) ); $moduleItemTypes = array(); diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php deleted file mode 100644 index 5a8796d27..000000000 --- a/library/Icinga/Web/Widget/Dashboard.php +++ /dev/null @@ -1,475 +0,0 @@ -getTabs()->activate($name); - } - - /** - * Load Pane items provided by all enabled modules - * - * @return $this - */ - public function load() - { - $navigation = new Navigation(); - $navigation->load('dashboard-pane'); - - $panes = array(); - foreach ($navigation as $dashboardPane) { - /** @var DashboardPane $dashboardPane */ - $pane = new Pane($dashboardPane->getLabel()); - foreach ($dashboardPane->getChildren() as $dashlet) { - $pane->addDashlet($dashlet->getLabel(), $dashlet->getUrl()); - } - - $panes[] = $pane; - } - - $this->mergePanes($panes); - $this->loadUserDashboards($navigation); - return $this; - } - - /** - * Create and return a Config object for this dashboard - * - * @return Config - */ - public function getConfig() - { - $output = array(); - foreach ($this->panes as $pane) { - if ($pane->isUserWidget()) { - $output[$pane->getName()] = $pane->toArray(); - } - foreach ($pane->getDashlets() as $dashlet) { - if ($dashlet->isUserWidget()) { - $output[$pane->getName() . '.' . $dashlet->getName()] = $dashlet->toArray(); - } - } - } - - return DashboardConfig::fromArray($output)->setConfigFile($this->getConfigFile())->setUser($this->user); - } - - /** - * Load user dashboards from all config files that match the username - */ - protected function loadUserDashboards(Navigation $navigation) - { - foreach (DashboardConfig::listConfigFilesForUser($this->user) as $file) { - $this->loadUserDashboardsFromFile($file, $navigation); - } - } - - /** - * Load user dashboards from the given config file - * - * @param string $file - * - * @return bool - */ - protected function loadUserDashboardsFromFile($file, Navigation $dashboardNavigation) - { - try { - $config = Config::fromIni($file); - } catch (NotReadableError $e) { - return false; - } - - if (! count($config)) { - return false; - } - $panes = array(); - $dashlets = array(); - foreach ($config as $key => $part) { - if (strpos($key, '.') === false) { - $dashboardPane = $dashboardNavigation->getItem($key); - if ($dashboardPane !== null) { - $key = $dashboardPane->getLabel(); - } - if ($this->hasPane($key)) { - $panes[$key] = $this->getPane($key); - } else { - $panes[$key] = new Pane($key); - $panes[$key]->setTitle($part->title); - } - $panes[$key]->setUserWidget(); - if ((bool) $part->get('disabled', false) === true) { - $panes[$key]->setDisabled(); - } - } else { - list($paneName, $dashletName) = explode('.', $key, 2); - $dashboardPane = $dashboardNavigation->getItem($paneName); - if ($dashboardPane !== null) { - $paneName = $dashboardPane->getLabel(); - $dashletItem = $dashboardPane->getChildren()->getItem($dashletName); - if ($dashletItem !== null) { - $dashletName = $dashletItem->getLabel(); - } - } - $part->pane = $paneName; - $part->dashlet = $dashletName; - $dashlets[] = $part; - } - } - foreach ($dashlets as $dashletData) { - $pane = null; - - if (array_key_exists($dashletData->pane, $panes) === true) { - $pane = $panes[$dashletData->pane]; - } elseif (array_key_exists($dashletData->pane, $this->panes) === true) { - $pane = $this->panes[$dashletData->pane]; - } else { - continue; - } - $dashlet = new DashboardDashlet( - $dashletData->title, - $dashletData->url, - $pane - ); - $dashlet->setName($dashletData->dashlet); - - if ((bool) $dashletData->get('disabled', false) === true) { - $dashlet->setDisabled(true); - } - - $dashlet->setUserWidget(); - $pane->addDashlet($dashlet); - } - - $this->mergePanes($panes); - - return true; - } - - /** - * Merge panes with existing panes - * - * @param array $panes - * - * @return $this - */ - public function mergePanes(array $panes) - { - /** @var $pane Pane */ - foreach ($panes as $pane) { - if ($this->hasPane($pane->getName()) === true) { - /** @var $current Pane */ - $current = $this->panes[$pane->getName()]; - $current->addDashlets($pane->getDashlets()); - } else { - $this->panes[$pane->getName()] = $pane; - } - } - - return $this; - } - - /** - * Return the tab object used to navigate through this dashboard - * - * @return Tabs - */ - public function getTabs() - { - $url = Url::fromPath('dashboard')->getUrlWithout($this->tabParam); - if ($this->tabs === null) { - $this->tabs = new Tabs(); - - foreach ($this->panes as $key => $pane) { - if ($pane->getDisabled()) { - continue; - } - $this->tabs->add( - $key, - array( - 'title' => sprintf( - t('Show %s', 'dashboard.pane.tooltip'), - $pane->getTitle() - ), - 'label' => $pane->getTitle(), - 'url' => clone($url), - 'urlParams' => array($this->tabParam => $key) - ) - ); - } - } - return $this->tabs; - } - - /** - * Return all panes of this dashboard - * - * @return array - */ - public function getPanes() - { - return $this->panes; - } - - - /** - * Creates a new empty pane with the given title - * - * @param string $title - * - * @return $this - */ - public function createPane($title) - { - $pane = new Pane($title); - $pane->setTitle($title); - $this->addPane($pane); - - return $this; - } - - /** - * Checks if the current dashboard has any panes - * - * @return bool - */ - public function hasPanes() - { - return ! empty($this->panes); - } - - /** - * Check if a panel exist - * - * @param string $pane - * @return bool - */ - public function hasPane($pane) - { - return $pane && array_key_exists($pane, $this->panes); - } - - /** - * Add a pane object to this dashboard - * - * @param Pane $pane The pane to add - * - * @return $this - */ - public function addPane(Pane $pane) - { - $this->panes[$pane->getName()] = $pane; - return $this; - } - - public function removePane($title) - { - if ($this->hasPane($title) === true) { - $pane = $this->getPane($title); - if ($pane->isUserWidget() === true) { - unset($this->panes[$pane->getName()]); - } else { - $pane->setDisabled(); - $pane->setUserWidget(); - } - } else { - throw new ProgrammingError('Pane not found: ' . $title); - } - } - - /** - * Return the pane with the provided name - * - * @param string $name The name of the pane to return - * - * @return Pane The pane or null if no pane with the given name exists - * @throws ProgrammingError - */ - public function getPane($name) - { - if (! array_key_exists($name, $this->panes)) { - throw new ProgrammingError( - 'Trying to retrieve invalid dashboard pane "%s"', - $name - ); - } - return $this->panes[$name]; - } - - /** - * Return an array with pane name=>title format used for comboboxes - * - * @return array - */ - public function getPaneKeyTitleArray() - { - $list = array(); - foreach ($this->panes as $name => $pane) { - $list[$name] = $pane->getTitle(); - } - return $list; - } - - /** - * @see Icinga\Web\Widget::render - */ - public function render() - { - if (empty($this->panes)) { - return ''; - } - - return $this->determineActivePane()->render(); - } - - /** - * Activates the default pane of this dashboard and returns its name - * - * @return mixed - */ - private function setDefaultPane() - { - $active = null; - - foreach ($this->panes as $key => $pane) { - if ($pane->getDisabled() === false) { - $active = $key; - break; - } - } - - if ($active !== null) { - $this->activate($active); - } - return $active; - } - - /** - * @see determineActivePane() - */ - public function getActivePane() - { - return $this->determineActivePane(); - } - - /** - * Determine the active pane either by the selected tab or the current request - * - * @throws \Icinga\Exception\ConfigurationError - * @throws \Icinga\Exception\ProgrammingError - * - * @return Pane The currently active pane - */ - public function determineActivePane() - { - $active = $this->getTabs()->getActiveName(); - if (! $active) { - if ($active = Url::fromRequest()->getParam($this->tabParam)) { - if ($this->hasPane($active)) { - $this->activate($active); - } else { - throw new ProgrammingError( - 'Try to get an inexistent pane.' - ); - } - } else { - $active = $this->setDefaultPane(); - } - } - - if (isset($this->panes[$active])) { - return $this->panes[$active]; - } - - throw new ConfigurationError('Could not determine active pane'); - } - - /** - * Setter for user object - * - * @param User $user - */ - public function setUser(User $user) - { - $this->user = $user; - } - - /** - * Getter for user object - * - * @return User - */ - public function getUser() - { - return $this->user; - } - - /** - * Get config file - * - * @return string - */ - public function getConfigFile() - { - if ($this->user === null) { - throw new ProgrammingError('Can\'t load dashboards. User is not set'); - } - return Config::resolvePath('dashboards/' . strtolower($this->user->getUsername()) . '/dashboard.ini'); - } -} diff --git a/library/Icinga/Web/Widget/Dashboard/Dashlet.php b/library/Icinga/Web/Widget/Dashboard/Dashlet.php deleted file mode 100644 index 2ba26dfff..000000000 --- a/library/Icinga/Web/Widget/Dashboard/Dashlet.php +++ /dev/null @@ -1,315 +0,0 @@ - -

{TITLE}

-

{PROGRESS_LABEL}...

- - -EOD; - - /** - * The template string used for rendering this widget in case of an error - * - * @var string - */ - private $errorTemplate = <<<'EOD' - -
-

{TITLE}

-

{ERROR_MESSAGE}

-
-EOD; - - /** - * Create a new dashlet displaying the given url in the provided pane - * - * @param string $title The title to use for this dashlet - * @param Url|string $url The url this dashlet uses for displaying information - * @param Pane $pane The pane this Dashlet will be added to - */ - public function __construct($title, $url, Pane $pane) - { - $this->name = $title; - $this->title = $title; - $this->pane = $pane; - $this->url = $url; - } - - public function setName($name) - { - $this->name = $name; - return $this; - } - - public function getName() - { - return $this->name; - } - - /** - * Retrieve the dashlets title - * - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * Retrieve the dashlets url - * - * @return Url|null - */ - public function getUrl() - { - if ($this->url !== null && ! $this->url instanceof Url) { - $this->url = Url::fromPath($this->url); - } - return $this->url; - } - - /** - * Set the dashlets URL - * - * @param string|Url $url The url to use, either as an Url object or as a path - * - * @return $this - */ - public function setUrl($url) - { - $this->url = $url; - return $this; - } - - /** - * Set the disabled property - * - * @param boolean $disabled - */ - public function setDisabled($disabled) - { - $this->disabled = $disabled; - } - - /** - * Get the disabled property - * - * @return boolean - */ - public function getDisabled() - { - return $this->disabled; - } - - /** - * Set the progress label to use - * - * @param string $label - * - * @return $this - */ - public function setProgressLabel($label) - { - $this->progressLabel = $label; - return $this; - } - - /** - * Return the progress label to use - * - * @return string - */ - public function getProgressLabe() - { - if ($this->progressLabel === null) { - return $this->view()->translate('Loading'); - } - - return $this->progressLabel; - } - - /** - * Return this dashlet's structure as array - * - * @return array - */ - public function toArray() - { - $array = array( - 'url' => $this->getUrl()->getRelativeUrl(), - 'title' => $this->getTitle() - ); - if ($this->getDisabled() === true) { - $array['disabled'] = 1; - } - return $array; - } - - /** - * @see Widget::render() - */ - public function render() - { - if ($this->disabled === true) { - return ''; - } - - $view = $this->view(); - - if (! $this->url) { - $searchTokens = array( - '{TOOLTIP}', - '{TITLE}', - '{ERROR_MESSAGE}' - ); - - $replaceTokens = array( - sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())), - $view->escape($this->getTitle()), - $view->escape( - sprintf($view->translate('Cannot create dashboard dashlet "%s" without valid URL'), $this->title) - ) - ); - - return str_replace($searchTokens, $replaceTokens, $this->errorTemplate); - } - - $url = $this->getUrl(); - $url->setParam('showCompact', true); - $iframeUrl = clone $url; - $iframeUrl->setParam('isIframe'); - - $searchTokens = array( - '{URL}', - '{IFRAME_URL}', - '{FULL_URL}', - '{TOOLTIP}', - '{TITLE}', - '{TITLE_PREFIX}', - '{PROGRESS_LABEL}' - ); - - $replaceTokens = array( - $url, - $iframeUrl, - $url->getUrlWithout(['showCompact', 'limit', 'view']), - sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())), - $view->escape($this->getTitle()), - $view->translate('Dashlet') . ': ', - $this->getProgressLabe() - ); - - return str_replace($searchTokens, $replaceTokens, $this->template); - } - - /** - * Create a @see Dashlet instance from the given Zend config, using the provided title - * - * @param $title The title for this dashlet - * @param ConfigObject $config The configuration defining url, parameters, height, width, etc. - * @param Pane $pane The pane this dashlet belongs to - * - * @return Dashlet A newly created Dashlet for use in the Dashboard - */ - public static function fromIni($title, ConfigObject $config, Pane $pane) - { - $height = null; - $width = null; - $url = $config->get('url'); - $parameters = $config->toArray(); - unset($parameters['url']); // otherwise there's an url = parameter in the Url - - $cmp = new Dashlet($title, Url::fromPath($url, $parameters), $pane); - return $cmp; - } - - /** - * @param \Icinga\Web\Widget\Dashboard\Pane $pane - */ - public function setPane(Pane $pane) - { - $this->pane = $pane; - } - - /** - * @return \Icinga\Web\Widget\Dashboard\Pane - */ - public function getPane() - { - return $this->pane; - } -} diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php deleted file mode 100644 index c8b14c5a1..000000000 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ /dev/null @@ -1,335 +0,0 @@ -name = $name; - $this->title = $name; - } - - /** - * Set the name of this pane - * - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Returns the name of this pane - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Returns the title of this pane - * - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * Overwrite the title of this pane - * - * @param string $title The new title to use for this pane - * - * @return $this - */ - public function setTitle($title) - { - $this->title = $title; - return $this; - } - - /** - * Return true if a dashlet with the given title exists in this pane - * - * @param string $title The title of the dashlet to check for existence - * - * @return bool - */ - public function hasDashlet($title) - { - return array_key_exists($title, $this->dashlets); - } - - /** - * Checks if the current pane has any dashlets - * - * @return bool - */ - public function hasDashlets() - { - return ! empty($this->dashlets); - } - - /** - * Return a dashlet with the given name if existing - * - * @param string $title The title of the dashlet to return - * - * @return Dashlet The dashlet with the given title - * @throws ProgrammingError If the dashlet doesn't exist - */ - public function getDashlet($title) - { - if ($this->hasDashlet($title)) { - return $this->dashlets[$title]; - } - throw new ProgrammingError( - 'Trying to access invalid dashlet: %s', - $title - ); - } - - /** - * Removes the dashlet with the given title if it exists in this pane - * - * @param string $title The pane - * @return Pane $this - */ - public function removeDashlet($title) - { - if ($this->hasDashlet($title)) { - $dashlet = $this->getDashlet($title); - if ($dashlet->isUserWidget() === true) { - unset($this->dashlets[$title]); - } else { - $dashlet->setDisabled(true); - $dashlet->setUserWidget(); - } - } else { - throw new ProgrammingError('Dashlet does not exist: ' . $title); - } - return $this; - } - - /** - * Removes all or a given list of dashlets from this pane - * - * @param array $dashlets Optional list of dashlet titles - * @return Pane $this - */ - public function removeDashlets(array $dashlets = null) - { - if ($dashlets === null) { - $this->dashlets = array(); - } else { - foreach ($dashlets as $dashlet) { - $this->removeDashlet($dashlet); - } - } - return $this; - } - - /** - * Return all dashlets added at this pane - * - * @return array - */ - public function getDashlets() - { - return $this->dashlets; - } - - /** - * @see Widget::render - */ - public function render() - { - $dashlets = array_filter( - $this->dashlets, - function ($e) { - return ! $e->getDisabled(); - } - ); - return implode("\n", $dashlets) . "\n"; - } - - /** - * Create, add and return a new dashlet - * - * @param string $title - * @param string $url - * - * @return Dashlet - */ - public function createDashlet($title, $url = null) - { - $dashlet = new Dashlet($title, $url, $this); - $this->addDashlet($dashlet); - return $dashlet; - } - - /** - * Add a dashlet to this pane, optionally creating it if $dashlet is a string - * - * @param string|Dashlet $dashlet The dashlet object or title - * (if a new dashlet will be created) - * @param string|null $url An Url to be used when dashlet is a string - * - * @return $this - * @throws \Icinga\Exception\ConfigurationError - */ - public function addDashlet($dashlet, $url = null) - { - if ($dashlet instanceof Dashlet) { - $this->dashlets[$dashlet->getName()] = $dashlet; - } elseif (is_string($dashlet) && $url !== null) { - $this->createDashlet($dashlet, $url); - } else { - throw new ConfigurationError('Invalid dashlet added: %s', $dashlet); - } - return $this; - } - - /** - * Add new dashlets to existing dashlets - * - * @param array $dashlets - * @return $this - */ - public function addDashlets(array $dashlets) - { - /* @var $dashlet Dashlet */ - foreach ($dashlets as $dashlet) { - if (array_key_exists($dashlet->getName(), $this->dashlets)) { - if (preg_match('/_(\d+)$/', $dashlet->getName(), $m)) { - $name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getName()); - } else { - $name = $dashlet->getName() . '_2'; - } - $this->dashlets[$name] = $dashlet; - } else { - $this->dashlets[$dashlet->getName()] = $dashlet; - } - } - - return $this; - } - - /** - * Add a dashlet to the current pane - * - * @param $title - * @param $url - * @return Dashlet - * - * @see addDashlet() - */ - public function add($title, $url = null) - { - $this->addDashlet($title, $url); - - return $this->dashlets[$title]; - } - - /** - * Return the this pane's structure as array - * - * @return array - */ - public function toArray() - { - $pane = array( - 'title' => $this->getTitle(), - ); - - if ($this->getDisabled() === true) { - $pane['disabled'] = 1; - } - - return $pane; - } - - /** - * Create a new pane with the title $title from the given configuration - * - * @param $title The title for this pane - * @param ConfigObject $config The configuration to use for setup - * - * @return Pane - */ - public static function fromIni($title, ConfigObject $config) - { - $pane = new Pane($title); - if ($config->get('title', false)) { - $pane->setTitle($config->get('title')); - } - return $pane; - } - - /** - * Setter for disabled - * - * @param boolean $disabled - */ - public function setDisabled($disabled = true) - { - $this->disabled = (bool) $disabled; - } - - /** - * Getter for disabled - * - * @return boolean - */ - public function getDisabled() - { - return $this->disabled; - } -} diff --git a/library/Icinga/Web/Widget/Dashboard/UserWidget.php b/library/Icinga/Web/Widget/Dashboard/UserWidget.php deleted file mode 100644 index 164d58b75..000000000 --- a/library/Icinga/Web/Widget/Dashboard/UserWidget.php +++ /dev/null @@ -1,36 +0,0 @@ -userWidget = (bool) $userWidget; - } - - /** - * Getter for user widget flag - * - * @return boolean - */ - public function isUserWidget() - { - return $this->userWidget; - } -}