Dashboards: allow to ship tabs, use them to...

...improve usability
This commit is contained in:
Thomas Gelf 2017-07-19 18:37:19 +02:00
parent 7db89d2656
commit 44f1ddc891
9 changed files with 96 additions and 7 deletions

View File

@ -17,19 +17,26 @@ class DashboardController extends ActionController
$this->setAutorefreshInterval(10);
}
$mainDashlets = ['Objects', 'Alerts', 'Automation', 'Deployment', 'Data'];
$mainDashboards = ['Objects', 'Alerts', 'Automation', 'Deployment', 'Data'];
$this->setTitle($this->translate('Icinga Director - Main Dashboard'));
$names = $this->params->getValues('name', $mainDashlets);
$names = $this->params->getValues('name', $mainDashboards);
if (count($names) === 1) {
// TODO: Find a better way for this
$this->addSingleTab($this->translate(ucfirst($names[0])));
$name = $names[0];
$dashboard = Dashboard::loadByName($name, $this->db());
$this->tabs($dashboard->getTabs())->activate($name);
// $this->addSingleTab($this->translate(ucfirst($name)));
} else {
$this->addSingleTab($this->translate('Overview'));
}
$cntDashboards = 0;
foreach ($names as $name) {
$dashboard = Dashboard::loadByName($name, $this->db());
if ($name instanceof Dashboard) {
$dashboard = $name;
} else {
$dashboard = Dashboard::loadByName($name, $this->db());
}
if ($dashboard->isAvailable()) {
$cntDashboards++;
$this->content()->add($dashboard);

View File

@ -25,4 +25,11 @@ class CommandsDashboard extends Dashboard
. ' plugins on your Monitoring (or monitored) systems'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['hosts', 'services', 'commands']
);
}
}

View File

@ -7,15 +7,14 @@ use Exception;
use Icinga\Authentication\Auth;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Restriction\HostgroupRestriction;
use Icinga\Web\View;
use Icinga\Module\Director\Dashboard\Dashlet\Dashlet;
use Icinga\Module\Director\Db;
use ipl\Html\BaseElement;
use Icinga\Web\Widget\Tab;
use ipl\Html\Html;
use ipl\Html\HtmlString;
use ipl\Html\Util;
use ipl\Html\ValidHtml;
use ipl\Translation\TranslationHelper;
use ipl\Web\Component\Tabs;
use Zend_Db_Select as ZfSelect;
abstract class Dashboard extends Html implements Countable
@ -107,6 +106,40 @@ abstract class Dashboard extends Html implements Countable
return null;
}
public function getTabs()
{
$lName = $this->getName();
$tabs = new Tabs();
$tabs->add($lName, new Tab([
'label' => $this->translate(ucfirst($this->getName())),
'url' => 'director/dashboard',
'urlParams' => ['name' => $lName]
]));
return $tabs;
}
protected function createTabsForDashboards($names)
{
$tabs = new Tabs();
foreach ($names as $name) {
$dashboard = Dashboard::loadByName($name, $this->getDb());
$tabs->add($name, $this->createTabForDashboard($dashboard));
}
return $tabs;
}
protected function createTabForDashboard(Dashboard $dashboard)
{
$name = $dashboard->getName();
return new Tab([
'label' => $this->translate(ucfirst($name)),
'url' => 'director/dashboard',
'urlParams' => ['name' => $name]
]);
}
public function count()
{
return count($this->dashlets());

View File

@ -25,4 +25,11 @@ class HostsDashboard extends Dashboard
. ' preconfigured templates.'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['hosts', 'services', 'commands']
);
}
}

View File

@ -2,6 +2,8 @@
namespace Icinga\Module\Director\Dashboard;
use Icinga\Module\Director\Web\Tabs\InfraTabs;
class InfrastructureDashboard extends Dashboard
{
protected $dashletNames = array(
@ -31,4 +33,9 @@ class InfrastructureDashboard extends Dashboard
. ' clean up the whole mess afterwards.'
);
}
public function getTabs()
{
return new InfraTabs($this->getAuth());
}
}

View File

@ -34,4 +34,11 @@ class NotificationsDashboard extends Dashboard
. ' define as many custom notification commands as you want'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['notifications', 'users', 'timePeriods']
);
}
}

View File

@ -29,4 +29,11 @@ class ServicesDashboard extends Dashboard
. ' to still modify (or delete) many of them at once.'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['hosts', 'services', 'commands']
);
}
}

View File

@ -23,4 +23,11 @@ class TimePeriodsDashboard extends Dashboard
. ' you to tackle those and similar requirements.'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['notifications', 'users', 'timePeriods']
);
}
}

View File

@ -26,4 +26,11 @@ class UsersDashboard extends Dashboard
. ' to automate all the things with Imports and related Sync Rules!'
);
}
public function getTabs()
{
return $this->createTabsForDashboards(
['notifications', 'users', 'timePeriods']
);
}
}