2016-10-27 19:58:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Controllers;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Dashboard\Dashboard;
|
|
|
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
2018-06-07 23:50:31 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DbSelectorForm;
|
2016-10-27 19:58:31 +02:00
|
|
|
|
|
|
|
class DashboardController extends ActionController
|
|
|
|
{
|
2016-11-03 16:06:18 +01:00
|
|
|
protected function checkDirectorPermissions()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-06-07 23:50:31 +02:00
|
|
|
protected function addDbSelection()
|
|
|
|
{
|
|
|
|
$form = new DbSelectorForm($this->Window(), $this->listAllowedDbResourceNames());
|
|
|
|
$this->content()->add($form);
|
|
|
|
$form->handleRequest($this->getRequest());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Icinga\Exception\ConfigurationError
|
|
|
|
* @throws \Icinga\Exception\Http\HttpNotFoundException
|
|
|
|
*/
|
2016-10-27 19:58:31 +02:00
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
if ($this->getRequest()->isGet()) {
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
}
|
|
|
|
|
2017-07-19 18:37:19 +02:00
|
|
|
$mainDashboards = ['Objects', 'Alerts', 'Automation', 'Deployment', 'Data'];
|
2017-07-14 11:02:44 +02:00
|
|
|
$this->setTitle($this->translate('Icinga Director - Main Dashboard'));
|
2017-07-19 18:37:19 +02:00
|
|
|
$names = $this->params->getValues('name', $mainDashboards);
|
2018-06-07 23:50:31 +02:00
|
|
|
if (! $this->params->has('name')) {
|
|
|
|
$this->addDbSelection();
|
|
|
|
}
|
2016-12-14 14:58:51 +01:00
|
|
|
if (count($names) === 1) {
|
2017-07-19 18:37:19 +02:00
|
|
|
$name = $names[0];
|
|
|
|
$dashboard = Dashboard::loadByName($name, $this->db());
|
|
|
|
$this->tabs($dashboard->getTabs())->activate($name);
|
2016-12-14 14:58:51 +01:00
|
|
|
} else {
|
2017-06-14 18:20:39 +02:00
|
|
|
$this->addSingleTab($this->translate('Overview'));
|
2016-12-14 14:58:51 +01:00
|
|
|
}
|
2017-06-14 18:20:39 +02:00
|
|
|
|
2017-07-03 15:19:43 +02:00
|
|
|
$cntDashboards = 0;
|
2016-12-14 14:58:51 +01:00
|
|
|
foreach ($names as $name) {
|
2017-07-19 18:37:19 +02:00
|
|
|
if ($name instanceof Dashboard) {
|
|
|
|
$dashboard = $name;
|
|
|
|
} else {
|
|
|
|
$dashboard = Dashboard::loadByName($name, $this->db());
|
|
|
|
}
|
2016-10-27 19:58:31 +02:00
|
|
|
if ($dashboard->isAvailable()) {
|
2017-07-03 15:19:43 +02:00
|
|
|
$cntDashboards++;
|
2017-06-14 18:20:39 +02:00
|
|
|
$this->content()->add($dashboard);
|
2016-10-27 19:58:31 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 15:19:43 +02:00
|
|
|
|
|
|
|
if ($cntDashboards === 0) {
|
|
|
|
$msg = $this->translate(
|
|
|
|
'No dashboard available, you might have not enough permissions'
|
|
|
|
);
|
|
|
|
$this->content()->add($msg);
|
|
|
|
}
|
2016-10-27 19:58:31 +02:00
|
|
|
}
|
|
|
|
}
|