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
This commit is contained in:
parent
83faa66167
commit
151f058286
|
@ -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,8 +142,15 @@ class DashboardController extends ActionController
|
|||
$pane = $this->_getParam('pane');
|
||||
$dashboard->activate($pane);
|
||||
}
|
||||
|
||||
$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',
|
||||
|
@ -144,7 +160,10 @@ class DashboardController extends ActionController
|
|||
)
|
||||
);
|
||||
*/
|
||||
|
||||
$this->view->dashboard = $dashboard;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs ?>
|
||||
</div>
|
||||
<?php if ($this->dashboard): ?>
|
||||
<div class="dashboard content">
|
||||
<?= $this->dashboard ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="content">
|
||||
<h1>No dashboard configuration found!</h1>
|
||||
<p>
|
||||
We tried to load a dashboard configuration with no success.
|
||||
Please have look that the configuration does exist:
|
||||
|
||||
<code>
|
||||
<?= $this->configPath ?>.ini
|
||||
</code>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
|
@ -305,7 +305,7 @@ class Dashboard extends AbstractWidget
|
|||
$active = $this->setDefaultPane();
|
||||
}
|
||||
}
|
||||
return $this->panes[$active];
|
||||
return isset($this->panes[$active]) ? $this->panes[$active] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue