From 151f058286261a82ab538ef322778f9801c05eea Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 5 Jun 2014 15:20:54 +0200 Subject: [PATCH] Dashboard: Display error message on failure When no (default) configuration is available for dashboards application dies not very gracefully. Display error message and guid the user to the solution is a better way. fixes #6412 --- .../controllers/DashboardController.php | 45 +++++++++++++------ .../views/scripts/dashboard/index.phtml | 20 +++++++-- library/Icinga/Web/Widget/Dashboard.php | 2 +- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 7b917e2e7..1f86fd2ce 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -46,6 +46,11 @@ use Icinga\Web\Controller\ActionController; */ class DashboardController extends ActionController { + /** + * Default configuration + */ + const DEFAULT_CONFIG = 'dashboard/dashboard'; + /** * Retrieve a dashboard from the provided config * @@ -53,14 +58,18 @@ class DashboardController extends ActionController * * @return \Icinga\Web\Widget\Dashboard */ - private function getDashboard($config = 'dashboard/dashboard') + private function getDashboard($config = self::DEFAULT_CONFIG) { $dashboard = new Dashboard(); try { $dashboardConfig = IcingaConfig::app($config); + if (count($dashboardConfig) === 0) { + return null; + } $dashboard->readConfig($dashboardConfig); } catch (NotReadableError $e) { Logger::error(new Exception('Cannot load dashboard configuration. An exception was thrown:', 0, $e)); + return null; } return $dashboard; } @@ -133,18 +142,28 @@ class DashboardController extends ActionController $pane = $this->_getParam('pane'); $dashboard->activate($pane); } - $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; - $this->view->tabs = $dashboard->getTabs(); - /* Temporarily removed - $this->view->tabs->add( - 'Add', - array( - 'title' => '+', - 'url' => Url::fromPath('dashboard/addurl') - ) - ); - */ - $this->view->dashboard = $dashboard; + + $this->view->configPath = IcingaConfig::$configDir . DIRECTORY_SEPARATOR . self::DEFAULT_CONFIG; + + if ($dashboard === null) { + $this->view->title = 'Dashboard'; + } else { + $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; + $this->view->tabs = $dashboard->getTabs(); + + /* Temporarily removed + $this->view->tabs->add( + 'Add', + array( + 'title' => '+', + 'url' => Url::fromPath('dashboard/addurl') + ) + ); + */ + + $this->view->dashboard = $dashboard; + + } } /** diff --git a/application/views/scripts/dashboard/index.phtml b/application/views/scripts/dashboard/index.phtml index 8ec851e11..92e8771e2 100644 --- a/application/views/scripts/dashboard/index.phtml +++ b/application/views/scripts/dashboard/index.phtml @@ -1,6 +1,20 @@
tabs ?>
-
-dashboard ?> -
+dashboard): ?> +
+ dashboard ?> +
+ +
+

No dashboard configuration found!

+

+ We tried to load a dashboard configuration with no success. + Please have look that the configuration does exist: + + + configPath ?>.ini + +

+
+ \ No newline at end of file diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index 107e4c0a6..5e5180a9b 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -305,7 +305,7 @@ class Dashboard extends AbstractWidget $active = $this->setDefaultPane(); } } - return $this->panes[$active]; + return isset($this->panes[$active]) ? $this->panes[$active] : null; } /**