Dashboard: provide space for Branch Hook dashlets

This commit is contained in:
Thomas Gelf 2021-08-24 16:13:22 +02:00
parent 31d6cfe4cd
commit b321327634
3 changed files with 46 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class DashboardController extends ActionController
$mainDashboards = [
'Objects',
'Alerts',
'Branches',
'Automation',
'Deployment',
'Director',

View File

@ -0,0 +1,34 @@
<?php
namespace Icinga\Module\Director\Dashboard;
use gipfl\IcingaWeb2\Icon;
use Icinga\Application\Hook;
use Icinga\Module\Director\Db\Branch\Branch;
use Icinga\Module\Director\Db\Branch\BranchStore;
use Icinga\Module\Director\Hook\BranchSupportHook;
use ipl\Html\Html;
class BranchesDashboard extends Dashboard
{
public function getTitle()
{
$branch = Branch::detect(new BranchStore($this->getDb()));
if ($branch->isBranch()) {
return Html::sprintf(
$this->translate('Working in a Configuration Branch: %s'),
Html::tag('span', ['class' => 'active-branch'], $branch->getName())
);
}
return $this->translate('Prepare your configuration in a safe Environment');
}
public function loadDashlets()
{
/** @var BranchSupportHook $hook */
if ($hook = Hook::first('director/BranchSupport')) {
$this->dashlets = $hook->loadDashlets($this->getDb());
}
}
}

View File

@ -3,7 +3,9 @@
namespace Icinga\Module\Director\Hook;
use Icinga\Authentication\Auth;
use Icinga\Module\Director\Dashboard\Dashlet\Dashlet;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Db\Branch\Branch;
use Icinga\Module\Director\Db\Branch\BranchSTore;
use Icinga\Web\Request;
@ -35,4 +37,13 @@ abstract class BranchSupportHook
* @return ?ValidHtml
*/
abstract public function linkToBranchedObject($label, Branch $branch, DbObject $object, Auth $auth);
/**
* @param Db $db
* @return Dashlet[]
*/
public function loadDashlets(Db $db)
{
return [];
}
}