mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-21 08:57:40 +02:00
Add activateEntry()
& getActiveEntry()
interface methods
This commit is contained in:
parent
ee829fd4dc
commit
b619dd2186
@ -58,7 +58,7 @@ class DashboardsController extends CompatController
|
||||
// If we don't load all dashboard homes here, the cog icon won't be rendered in the dashboard tabs
|
||||
$this->dashboard->load(DashboardHome::DEFAULT_HOME, $pane, true);
|
||||
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
if (! $activeHome || ! $activeHome->hasEntries()) {
|
||||
$this->addTitleTab(t('Welcome'));
|
||||
|
||||
@ -89,7 +89,7 @@ class DashboardsController extends CompatController
|
||||
|
||||
$this->dashboard->load($home, $pane);
|
||||
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
if (! $activeHome->getEntries()) {
|
||||
$this->addTitleTab($activeHome->getTitle());
|
||||
}
|
||||
@ -133,7 +133,7 @@ class DashboardsController extends CompatController
|
||||
})
|
||||
->handleRequest($this->getServerRequest());
|
||||
|
||||
$homeForm->load($this->dashboard->getActiveHome());
|
||||
$homeForm->load($this->dashboard->getActiveEntry());
|
||||
|
||||
$this->addTitleTab(t('Update Home'));
|
||||
$this->addContent($homeForm);
|
||||
@ -201,7 +201,7 @@ class DashboardsController extends CompatController
|
||||
}
|
||||
})->handleRequest($this->getServerRequest());
|
||||
|
||||
$paneForm->load($this->dashboard->getActiveHome()->getEntry($pane));
|
||||
$paneForm->load($this->dashboard->getActiveEntry()->getEntry($pane));
|
||||
|
||||
$this->addTitleTab(t('Update Pane'));
|
||||
$this->addContent($paneForm);
|
||||
@ -282,7 +282,7 @@ class DashboardsController extends CompatController
|
||||
|
||||
$this->dashboard->load($home, $pane, true);
|
||||
|
||||
$pane = $this->dashboard->getActiveHome()->getActivePane();
|
||||
$pane = $this->dashboard->getActiveEntry()->getActiveEntry();
|
||||
if (! $pane->hasEntry($dashlet)) {
|
||||
$this->httpNotFound(t('Dashlet "%s" not found'), $dashlet);
|
||||
}
|
||||
@ -311,7 +311,7 @@ class DashboardsController extends CompatController
|
||||
|
||||
$this->dashboard->load($home, $pane);
|
||||
|
||||
$pane = $this->dashboard->getActiveHome()->getActivePane();
|
||||
$pane = $this->dashboard->getActiveEntry()->getActiveEntry();
|
||||
if (! $pane->hasEntry($dashlet)) {
|
||||
$this->httpNotFound(t('Dashlet "%s" not found'), $dashlet);
|
||||
}
|
||||
@ -510,7 +510,7 @@ class DashboardsController extends CompatController
|
||||
|
||||
$this->createTabs();
|
||||
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
// We can't grant access the user to the dashboard manager if there aren't any dashboards to manage
|
||||
if (! $activeHome || (! $activeHome->hasEntries() && $this->dashboard->countEntries() === 1)) {
|
||||
$this->redirectNow(Dashboard::BASE_ROUTE);
|
||||
@ -540,7 +540,7 @@ class DashboardsController extends CompatController
|
||||
private function createTabs()
|
||||
{
|
||||
$tabs = $this->dashboard->getTabs();
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
if ($activeHome
|
||||
&& (
|
||||
! $activeHome->isDefaultHome()
|
||||
@ -553,7 +553,7 @@ class DashboardsController extends CompatController
|
||||
$params['home'] = $activeHome->getName();
|
||||
}
|
||||
|
||||
if (($activePane = $activeHome->getActivePane())) {
|
||||
if (($activePane = $activeHome->getActiveEntry())) {
|
||||
$params['pane'] = $activePane->getName();
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ abstract class BaseDashboardForm extends CompatForm
|
||||
*/
|
||||
protected function isUpdating(): bool
|
||||
{
|
||||
return substr($this->requestUrl->getPath(), 0, 16) === Dashboard::BASE_ROUTE . '/edit-';
|
||||
return strpos($this->requestUrl->getPath(), Dashboard::BASE_ROUTE . '/edit-') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ class DashletForm extends SetupNewDashboardForm
|
||||
protected function assembleNextPageDashboardPart()
|
||||
{
|
||||
$homes = $this->dashboard->getEntryKeyTitleArr();
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
$currentHome = $this->requestUrl->getParam('home', reset($homes));
|
||||
$populatedHome = $this->getPopulatedValue('home', $currentHome);
|
||||
|
||||
@ -177,16 +177,16 @@ class DashletForm extends SetupNewDashboardForm
|
||||
if ($dashboard->hasEntry($currentHome->getName())) {
|
||||
$currentHome = clone $dashboard->getEntry($currentHome->getName());
|
||||
$activatePane = $currentHome->hasEntry($selectedPane)
|
||||
&& $currentHome->getActivePane()->getName() !== $selectedPane
|
||||
&& $currentHome->getActiveEntry()->getName() !== $selectedPane
|
||||
? $selectedPane
|
||||
: null;
|
||||
|
||||
if ($currentHome->getName() !== $dashboard->getActiveHome()->getName() || $activatePane) {
|
||||
if ($currentHome->getName() !== $dashboard->getActiveEntry()->getName() || $activatePane) {
|
||||
$currentHome->loadDashboardEntries($activatePane);
|
||||
}
|
||||
|
||||
if ($currentHome->hasEntry($currentPane->getName())) {
|
||||
$currentPane = clone $currentHome->getActivePane();
|
||||
$currentPane = clone $currentHome->getActiveEntry();
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,8 +229,8 @@ class DashletForm extends SetupNewDashboardForm
|
||||
}
|
||||
|
||||
$this->dumpArbitaryDashlets(false);
|
||||
// Avoid the hassle of iterating through the module dashlets each time to check if exits,
|
||||
// even though the current pane doesn't have any entries
|
||||
// Avoid the overhead of traversing the module Dashlets each time to check if they already exist,
|
||||
// even the current Dashboard Pane doesn't contain any records
|
||||
if (! $this->getPopulatedValue('new_pane') && $currentPane->hasEntries()) {
|
||||
foreach ($this->moduleDashlets as $_ => $dashlets) {
|
||||
/** @var Dashlet $dashlet */
|
||||
@ -278,10 +278,10 @@ class DashletForm extends SetupNewDashboardForm
|
||||
} else {
|
||||
$orgHome = $dashboard->getEntry($this->getValue('org_home'));
|
||||
$orgPane = $orgHome->getEntry($this->getValue('org_pane'));
|
||||
if ($orgHome->getActivePane()->getName() !== $orgPane->getName()) {
|
||||
if ($orgHome->getActiveEntry()->getName() !== $orgPane->getName()) {
|
||||
$orgHome->loadDashboardEntries($orgPane->getName());
|
||||
|
||||
$orgPane = $orgHome->getActivePane();
|
||||
$orgPane = $orgHome->getActiveEntry();
|
||||
}
|
||||
|
||||
$orgDashlet = $orgPane->getEntry($this->getValue('org_dashlet'));
|
||||
|
@ -41,7 +41,7 @@ class HomeForm extends BaseDashboardForm
|
||||
protected function onSuccess()
|
||||
{
|
||||
if ($this->isUpdating()) {
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
if ($home->getTitle() === $this->getPopulatedValue('title')) {
|
||||
return;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class PaneForm extends BaseDashboardForm
|
||||
]);
|
||||
|
||||
$homes = $this->dashboard->getEntryKeyTitleArr();
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
$populatedHome = $this->getPopulatedValue('home', $activeHome->getName());
|
||||
|
||||
$this->addElement('select', 'home', [
|
||||
@ -90,7 +90,7 @@ class PaneForm extends BaseDashboardForm
|
||||
if ($dashboard->hasEntry($currentHome->getName())) {
|
||||
/** @var DashboardHome $currentHome */
|
||||
$currentHome = clone $dashboard->getEntry($currentHome->getName());
|
||||
if ($currentHome->getName() !== $dashboard->getActiveHome()->getName()) {
|
||||
if ($currentHome->getName() !== $dashboard->getActiveEntry()->getName()) {
|
||||
$currentHome->loadDashboardEntries();
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ class RemoveDashletForm extends BaseDashboardForm
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$dashlet = $pane->getEntry($this->requestUrl->getParam('dashlet'));
|
||||
|
||||
|
@ -20,7 +20,7 @@ class RemoveHomeForm extends BaseDashboardForm
|
||||
$this->addHtml(HtmlElement::create(
|
||||
'h2',
|
||||
null,
|
||||
sprintf(t('Please confirm removal of Dashboard Home "%s"'), $this->dashboard->getActiveHome()->getTitle())
|
||||
sprintf(t('Please confirm removal of Dashboard Home "%s"'), $this->dashboard->getActiveEntry()->getTitle())
|
||||
));
|
||||
|
||||
$this->addHtml($this->registerSubmitButton('Remove Home')->setName('btn_remove'));
|
||||
@ -28,7 +28,7 @@ class RemoveHomeForm extends BaseDashboardForm
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
try {
|
||||
$this->dashboard->removeEntry($home);
|
||||
|
@ -29,8 +29,8 @@ class RemovePaneForm extends BaseDashboardForm
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
try {
|
||||
$home->removeEntry($pane);
|
||||
|
@ -6,7 +6,7 @@ use Icinga\Web\Widget\SearchDashboard;
|
||||
$searchDashboard = new SearchDashboard();
|
||||
$searchDashboard->setUser($this->Auth()->getUser());
|
||||
|
||||
$searchPane = $searchDashboard->search('dummy')->getActiveHome()->getEntry(SearchDashboard::SEARCH_PANE);
|
||||
$searchPane = $searchDashboard->search('dummy')->getActiveEntry()->getEntry(SearchDashboard::SEARCH_PANE);
|
||||
if ($searchPane->hasEntries()): ?>
|
||||
<form action="<?= $this->href('search') ?>" method="get" role="search" class="search-control">
|
||||
<input type="text" name="q" id="search" class="search search-input" required
|
||||
|
@ -75,7 +75,6 @@ class DashletManager
|
||||
->setPriority($priority++)
|
||||
->setModule($module->getName());
|
||||
|
||||
// As we don't have a setter for labels, this might be ignored by the data extractor
|
||||
if (isset($configPart['label'])) {
|
||||
$dashlet->setTitle($configPart['label']);
|
||||
}
|
||||
|
@ -53,6 +53,20 @@ abstract class BaseDashboard
|
||||
*/
|
||||
protected $owner;
|
||||
|
||||
/**
|
||||
* A flag whether this widget is currently being loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $active = false;
|
||||
|
||||
/**
|
||||
* A flag whether this widget has been disabled (affects only default home)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $disabled = false;
|
||||
|
||||
/**
|
||||
* Create a new widget
|
||||
*
|
||||
@ -232,6 +246,57 @@ abstract class BaseDashboard
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this widget should be disabled
|
||||
*
|
||||
* @param bool $disabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisabled(bool $disabled): self
|
||||
{
|
||||
$this->disabled = $disabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this widget has been disabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this widget is currently being loaded
|
||||
*
|
||||
* @param bool $active
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setActive(bool $active = true): self
|
||||
{
|
||||
$this->active = $active;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this widget is currently being loaded
|
||||
*
|
||||
* Indicates which dashboard tab is currently open if this widget is a Dashboard Pane type
|
||||
* or whether the Dashboard Home is active/focused in the navigation bar
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this class's structure as array
|
||||
*
|
||||
|
@ -58,6 +58,36 @@ trait DashboardEntries
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function activateEntry(BaseDashboard $dashboard)
|
||||
{
|
||||
if (! $this->hasEntry($dashboard->getName())) {
|
||||
throw new ProgrammingError(
|
||||
'Trying to activate Dashboard Entry "%s" that does not exist.',
|
||||
$dashboard->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
$activeEntry = $this->getActiveEntry();
|
||||
if ($activeEntry && $activeEntry->getName() !== $dashboard->getName()) {
|
||||
$activeEntry->setActive(false);
|
||||
}
|
||||
|
||||
$dashboard->setActive();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActiveEntry()
|
||||
{
|
||||
foreach ($this->getEntries() as $entry) {
|
||||
if ($entry->isActive()) {
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addEntry(BaseDashboard $dashboard)
|
||||
{
|
||||
if ($this->hasEntry($dashboard->getName())) {
|
||||
|
@ -148,4 +148,20 @@ interface DashboardEntry
|
||||
* @return $this
|
||||
*/
|
||||
public function unsetEntry(BaseDashboard $dashboard);
|
||||
|
||||
/**
|
||||
* Activates the given dashboard entry and deactivates all other active ones
|
||||
*
|
||||
* @param BaseDashboard $dashboard
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function activateEntry(BaseDashboard $dashboard);
|
||||
|
||||
/**
|
||||
* Get the active dashboard entry currently being loaded
|
||||
*
|
||||
* @return ?DashboardEntry
|
||||
*/
|
||||
public function getActiveEntry();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ trait DashboardManager
|
||||
}
|
||||
|
||||
if ($home) {
|
||||
$this->activateHome($home);
|
||||
$this->activateEntry($home);
|
||||
$home->loadDashboardEntries($activePane);
|
||||
}
|
||||
|
||||
@ -90,49 +90,6 @@ trait DashboardManager
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the given home and deactivates all other active homes
|
||||
*
|
||||
* @param DashboardHome $home
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function activateHome(DashboardHome $home): self
|
||||
{
|
||||
if (! $this->hasEntry($home->getName())) {
|
||||
throw new ProgrammingError(
|
||||
'Trying to activate Dashboard Home "%s" that does not exist.',
|
||||
$home->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
$activeHome = $this->getActiveHome();
|
||||
if ($activeHome && $activeHome->getName() !== $home->getName()) {
|
||||
$activeHome->setActive(false);
|
||||
}
|
||||
|
||||
$home->setActive();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active home currently being loaded
|
||||
*
|
||||
* @return ?DashboardHome
|
||||
*/
|
||||
public function getActiveHome(): ?DashboardHome
|
||||
{
|
||||
/** @var DashboardHome $home */
|
||||
foreach ($this->getEntries() as $home) {
|
||||
if ($home->isActive()) {
|
||||
return $home;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function removeEntry($home)
|
||||
{
|
||||
$name = $home instanceof DashboardHome ? $home->getName() : $home;
|
||||
|
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Dashboard\Common;
|
||||
|
||||
trait WidgetState
|
||||
{
|
||||
/**
|
||||
* A flag whether this widget is currently being loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $active = false;
|
||||
|
||||
/**
|
||||
* A flag whether this widget has been disabled (affects only default home)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $disabled = false;
|
||||
|
||||
/**
|
||||
* Set whether this widget should be disabled
|
||||
*
|
||||
* @param bool $disabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisabled(bool $disabled): self
|
||||
{
|
||||
$this->disabled = $disabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this widget has been disabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this widget is currently being loaded
|
||||
*
|
||||
* @param bool $active
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setActive(bool $active = true): self
|
||||
{
|
||||
$this->active = $active;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this widget is currently being loaded
|
||||
*
|
||||
* Indicates which dashboard tab is currently open if this widget is a Dashboard Pane type
|
||||
* or whether the Dashboard Home is active/focused in the navigation bar
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
}
|
@ -113,7 +113,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
||||
*/
|
||||
public function getTabs()
|
||||
{
|
||||
$activeHome = $this->getActiveHome();
|
||||
$activeHome = $this->getActiveEntry();
|
||||
if ($activeHome && ! $activeHome->isDefaultHome()) {
|
||||
$url = Url::fromPath(self::BASE_ROUTE . '/home')->getUrlWithout(['home', $this->tabParam]);
|
||||
$url->addParams(['home' => $activeHome->getName()]);
|
||||
@ -139,7 +139,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
||||
'active' => $pane->isActive(),
|
||||
'title' => sprintf(t('Show %s', 'dashboard.pane.tooltip'), $pane->getTitle()),
|
||||
'label' => $pane->getTitle(),
|
||||
'url' => clone($url),
|
||||
'url' => clone $url,
|
||||
'urlParams' => [$this->tabParam => $pane->getName()]
|
||||
]
|
||||
);
|
||||
@ -151,7 +151,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$activeHome = $this->getActiveHome();
|
||||
$activeHome = $this->getActiveEntry();
|
||||
if (! $activeHome || (! $activeHome->hasEntries() && $activeHome->isDefaultHome())) {
|
||||
$this->setAttribute('class', 'dashboard-introduction');
|
||||
|
||||
@ -174,7 +174,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
||||
);
|
||||
$this->addHtml(HtmlElement::create('p', null, $message));
|
||||
} elseif ($activeHome->hasEntries()) {
|
||||
$activePane = $activeHome->getActivePane();
|
||||
$activePane = $activeHome->getActiveEntry();
|
||||
|
||||
if (! $activePane->hasEntries()) {
|
||||
$this->addHtml(HtmlElement::create('h1', null, t('No dashlet added to this pane.')));
|
||||
|
@ -13,7 +13,6 @@ use Icinga\Web\Dashboard\Common\DashboardEntries;
|
||||
use Icinga\Web\Dashboard\Common\DashboardEntry;
|
||||
use Icinga\Web\Dashboard\Common\Sortable;
|
||||
use Icinga\Util\DBUtils;
|
||||
use Icinga\Web\Dashboard\Common\WidgetState;
|
||||
use Icinga\Web\Navigation\NavigationItem;
|
||||
use ipl\Stdlib\Filter;
|
||||
|
||||
@ -27,7 +26,6 @@ use function ipl\Stdlib\get_php_type;
|
||||
class DashboardHome extends BaseDashboard implements DashboardEntry, Sortable
|
||||
{
|
||||
use DashboardEntries;
|
||||
use WidgetState;
|
||||
|
||||
/**
|
||||
* Name of the default home
|
||||
@ -104,49 +102,6 @@ class DashboardHome extends BaseDashboard implements DashboardEntry, Sortable
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the given pane and deactivate all the others
|
||||
*
|
||||
* @param Pane $pane
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function activatePane(Pane $pane): self
|
||||
{
|
||||
if (! $this->hasEntry($pane->getName())) {
|
||||
throw new ProgrammingError(
|
||||
'Trying to activate Dashboard Pane "%s" that does not exist.',
|
||||
$pane->getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
$active = $this->getActivePane();
|
||||
if ($active && $active->getName() !== $pane->getName()) {
|
||||
$active->setActive(false);
|
||||
}
|
||||
|
||||
$pane->setActive();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the active pane currently being loaded
|
||||
*
|
||||
* @return ?Pane
|
||||
*/
|
||||
public function getActivePane(): ?Pane
|
||||
{
|
||||
/** @var Pane $pane */
|
||||
foreach ($this->getEntries() as $pane) {
|
||||
if ($pane->isActive()) {
|
||||
return $pane;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function removeEntry($pane)
|
||||
{
|
||||
$name = $pane instanceof Pane ? $pane->getName() : $pane;
|
||||
@ -193,13 +148,13 @@ class DashboardHome extends BaseDashboard implements DashboardEntry, Sortable
|
||||
if ($this->hasEntry($name)) {
|
||||
$pane = $this->getEntry($name);
|
||||
|
||||
$this->activatePane($pane);
|
||||
$this->activateEntry($pane);
|
||||
$pane->loadDashboardEntries();
|
||||
} else {
|
||||
throw new HttpNotFoundException(t('Pane "%s" not found'), $name);
|
||||
}
|
||||
} elseif (($firstPane = $this->rewindEntries())) {
|
||||
$this->activatePane($firstPane);
|
||||
$this->activateEntry($firstPane);
|
||||
$firstPane->loadDashboardEntries();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ namespace Icinga\Web\Dashboard;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Web\Dashboard\Common\BaseDashboard;
|
||||
use Icinga\Web\Dashboard\Common\WidgetState;
|
||||
use Icinga\Web\Url;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\HtmlElement;
|
||||
@ -18,8 +17,6 @@ use ipl\Web\Widget\Link;
|
||||
*/
|
||||
class Dashlet extends BaseDashboard
|
||||
{
|
||||
use WidgetState;
|
||||
|
||||
/** @var string Database table name */
|
||||
public const TABLE = 'icingaweb_dashlet';
|
||||
|
||||
|
@ -14,7 +14,6 @@ use Icinga\Web\Dashboard\Common\DashboardEntries;
|
||||
use Icinga\Util\DBUtils;
|
||||
use Icinga\Web\Dashboard\Common\DashboardEntry;
|
||||
use Icinga\Web\Dashboard\Common\Sortable;
|
||||
use Icinga\Web\Dashboard\Common\WidgetState;
|
||||
use InvalidArgumentException;
|
||||
use ipl\Stdlib\Filter;
|
||||
use LogicException;
|
||||
@ -28,7 +27,6 @@ use function ipl\Stdlib\get_php_type;
|
||||
class Pane extends BaseDashboard implements DashboardEntry, Sortable
|
||||
{
|
||||
use DashboardEntries;
|
||||
use WidgetState;
|
||||
|
||||
public const TABLE = 'icingaweb_dashboard';
|
||||
|
||||
@ -132,11 +130,8 @@ class Pane extends BaseDashboard implements DashboardEntry, Sortable
|
||||
$newDashlet->isModuleDashlet()
|
||||
&& $dashlet->system_module_dashlet_id === null
|
||||
)
|
||||
) {
|
||||
// The module from which this dashlet originates doesn't exist anymore
|
||||
) { // The module from which this dashlet originates doesn't exist anymore
|
||||
$this->removeEntry($newDashlet);
|
||||
|
||||
$this->unsetEntry($newDashlet);
|
||||
} elseif (! $newDashlet->isDisabled() && ! Modules\DashletManager::isUsable($newDashlet)) {
|
||||
// The module from which this dashlet originates is probably disabled,
|
||||
// so don't load this dashlet anymore and disable it
|
||||
@ -250,7 +245,7 @@ class Pane extends BaseDashboard implements DashboardEntry, Sortable
|
||||
'description' => $dashlet->getDescription()
|
||||
], $filterCondition);
|
||||
} else {
|
||||
// Failed to move the pane! Should have already been handled by the caller,
|
||||
// Failed to move the dashlet! Should have already been handled by the caller,
|
||||
// though I think it's better that we raise an exception here!!
|
||||
throw new AlreadyExistsException(
|
||||
'Failed to successfully manage the Dashlet. Pane "%s" has already a Dashlet called "%s"!',
|
||||
|
@ -23,7 +23,7 @@ class Settings extends BaseHtmlElement
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
$activeHome = $this->dashboard->getActiveEntry();
|
||||
if ($this->dashboard->countEntries() === 1 && $activeHome->isDefaultHome()) {
|
||||
$this->setAttribute('data-icinga-home', DashboardHome::DEFAULT_HOME);
|
||||
$this->addFrom((new DashboardHomeList($activeHome))->setHeaderDisabled());
|
||||
|
@ -59,7 +59,7 @@ class SearchDashboard extends Dashboard
|
||||
return $this->tabs;
|
||||
}
|
||||
|
||||
public function getActiveHome(): ?DashboardHome
|
||||
public function getActiveEntry()
|
||||
{
|
||||
return $this->searchHome;
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$this->assertCount(
|
||||
2,
|
||||
@ -60,8 +60,8 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$this->assertCount(
|
||||
2,
|
||||
@ -85,16 +85,16 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
$pane->getEntry(self::TEST_DASHLET)->setTitle('Hello');
|
||||
|
||||
$pane->manageEntry($pane->getEntries());
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$this->assertEquals(
|
||||
'Hello',
|
||||
@ -120,8 +120,8 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$default = $this->dashboard->getActiveHome();
|
||||
$pane1 = $default->getActivePane();
|
||||
$default = $this->dashboard->getActiveEntry();
|
||||
$pane1 = $default->getActiveEntry();
|
||||
$pane2 = $default->getEntry('Test2');
|
||||
|
||||
// Move the dashlet from pane1 -> pane2
|
||||
@ -129,8 +129,8 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$default = $this->dashboard->getActiveHome();
|
||||
$pane1 = $default->getActivePane();
|
||||
$default = $this->dashboard->getActiveEntry();
|
||||
$pane1 = $default->getActiveEntry();
|
||||
$pane2 = $default->getEntry('Test2');
|
||||
$pane2->loadDashboardEntries();
|
||||
|
||||
@ -166,23 +166,23 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, $pane1->getName(), true);
|
||||
|
||||
$default = $this->dashboard->getActiveHome();
|
||||
$default = $this->dashboard->getActiveEntry();
|
||||
$home = $this->dashboard->getEntry($home->getName());
|
||||
$home->loadDashboardEntries();
|
||||
|
||||
$pane1 = $default->getActivePane();
|
||||
$pane2 = $home->getActivePane();
|
||||
$pane1 = $default->getActiveEntry();
|
||||
$pane2 = $home->getActiveEntry();
|
||||
|
||||
// Move the dashlet from pane1 -> pane2
|
||||
$pane2->manageEntry($pane1->getEntries(), $pane1);
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, $pane1->getName(), true);
|
||||
|
||||
//$default = $this->dashboard->getActiveHome();
|
||||
//$default = $this->dashboard->getActiveEntry();
|
||||
$home = $this->dashboard->getEntry($home->getName());
|
||||
$home->loadDashboardEntries();
|
||||
|
||||
$pane2 = $home->getActivePane();
|
||||
$pane2 = $home->getActiveEntry();
|
||||
|
||||
$this->assertCount(
|
||||
1,
|
||||
@ -218,8 +218,8 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load($default->getName());
|
||||
|
||||
$default = $this->dashboard->getActiveHome();
|
||||
$pane1 = $default->getActivePane();
|
||||
$default = $this->dashboard->getActiveEntry();
|
||||
$pane1 = $default->getActiveEntry();
|
||||
$pane2 = $default->getEntry('Test2');
|
||||
$pane2->loadDashboardEntries();
|
||||
|
||||
@ -246,17 +246,17 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, $pane->getName());
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$pane->removeEntry(self::TEST_DASHLET);
|
||||
|
||||
$this->dashboard->load();
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertFalse(
|
||||
$home->getActivePane()->hasEntry(self::TEST_DASHLET),
|
||||
$home->getActiveEntry()->hasEntry(self::TEST_DASHLET),
|
||||
'Pane::removeEntry() could not remove expected Dashlet'
|
||||
);
|
||||
}
|
||||
@ -276,17 +276,17 @@ class DashletTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, $pane->getName());
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getActivePane();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$pane = $home->getActiveEntry();
|
||||
|
||||
$pane->removeEntries();
|
||||
|
||||
$this->dashboard->load();
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertFalse(
|
||||
$home->getActivePane()->hasEntries(),
|
||||
$home->getActiveEntry()->hasEntries(),
|
||||
'Pane::removeEntries() could not remove all Dashlet Entries'
|
||||
);
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ class HomeTest extends BaseDashboardTestCase
|
||||
$this->dashboard->manageEntry($this->getTestHome());
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$home->setTitle('Hello');
|
||||
|
||||
$this->dashboard->manageEntry($home);
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertEquals(
|
||||
'Hello',
|
||||
@ -125,7 +125,7 @@ class HomeTest extends BaseDashboardTestCase
|
||||
|
||||
$this->assertEquals(
|
||||
'Second Home',
|
||||
$this->dashboard->getActiveHome()->getName(),
|
||||
$this->dashboard->getActiveEntry()->getName(),
|
||||
'Dashboard::load() could not load all expected Dashboard Homes and activate expected Dashboard Home'
|
||||
);
|
||||
}
|
||||
@ -134,7 +134,7 @@ class HomeTest extends BaseDashboardTestCase
|
||||
{
|
||||
$this->expectException(ProgrammingError::class);
|
||||
|
||||
$this->dashboard->activateHome($this->getTestHome('Activate Home'));
|
||||
$this->dashboard->activateEntry($this->getTestHome('Activate Home'));
|
||||
}
|
||||
|
||||
public function testWhetherLoadHomesActivatesFirstHome()
|
||||
@ -145,7 +145,7 @@ class HomeTest extends BaseDashboardTestCase
|
||||
|
||||
$this->assertEquals(
|
||||
self::TEST_HOME,
|
||||
$this->dashboard->getActiveHome()->getName(),
|
||||
$this->dashboard->getActiveEntry()->getName(),
|
||||
'Dashboard::load() could not activate expected Dashboard Home'
|
||||
);
|
||||
}
|
||||
@ -159,9 +159,9 @@ class HomeTest extends BaseDashboardTestCase
|
||||
$this->dashboard->load();
|
||||
|
||||
$active = $this->dashboard->getEntry('Second Home');
|
||||
$this->dashboard->activateHome($active);
|
||||
$this->dashboard->activateEntry($active);
|
||||
|
||||
$this->assertTrue($active->isActive(), 'Dashboard::activateHome() could not activate expected Dashboard Home');
|
||||
$this->assertTrue($active->isActive(), 'Dashboard::activateEntry() could not activate expected Dashboard Home');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,12 +173,12 @@ class HomeTest extends BaseDashboardTestCase
|
||||
$this->dashboard->addEntry($this->getTestHome('Second Home'));
|
||||
|
||||
$active = $this->dashboard->getEntry(self::TEST_HOME);
|
||||
$this->dashboard->activateHome($active);
|
||||
$this->dashboard->activateEntry($active);
|
||||
|
||||
$this->assertEquals(
|
||||
self::TEST_HOME,
|
||||
$this->dashboard->getActiveHome()->getName(),
|
||||
'Dashboard::getActiveHome() could not return expected Dashboard Home'
|
||||
$this->dashboard->getActiveEntry()->getName(),
|
||||
'Dashboard::getActiveEntry() could not return expected Dashboard Home'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class PaneTest extends BaseDashboardTestCase
|
||||
$this->expectException(ProgrammingError::class);
|
||||
|
||||
$home = $this->getTestHome();
|
||||
$home->activatePane(new Pane(self::TEST_PANE));
|
||||
$home->activateEntry(new Pane(self::TEST_PANE));
|
||||
}
|
||||
|
||||
public function testWhetherActivatePaneActivatesExpectedPane()
|
||||
@ -32,11 +32,11 @@ class PaneTest extends BaseDashboardTestCase
|
||||
$home = $this->getTestHome();
|
||||
$home->addEntry($this->getTestPane());
|
||||
|
||||
$home->activatePane($home->getEntry(self::TEST_PANE));
|
||||
$home->activateEntry($home->getEntry(self::TEST_PANE));
|
||||
|
||||
$this->assertEquals(
|
||||
self::TEST_PANE,
|
||||
$home->getActivePane()->getName(),
|
||||
$home->getActiveEntry()->getName(),
|
||||
'DashboardHome::activatePane() could not activate expected Pane'
|
||||
);
|
||||
}
|
||||
@ -53,11 +53,11 @@ class PaneTest extends BaseDashboardTestCase
|
||||
$home->manageEntry($this->getTestPane('Test Me'));
|
||||
|
||||
$this->dashboard->load();
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertEquals(
|
||||
self::TEST_PANE,
|
||||
$home->getActivePane()->getName(),
|
||||
$home->getActiveEntry()->getName(),
|
||||
'DashboardHome::loadDashboardEntries() could not activate expected Pane'
|
||||
);
|
||||
}
|
||||
@ -73,11 +73,11 @@ class PaneTest extends BaseDashboardTestCase
|
||||
$home->manageEntry(new Pane(self::TEST_PANE));
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, self::TEST_PANE);
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertEquals(
|
||||
self::TEST_PANE,
|
||||
$home->getActivePane()->getName(),
|
||||
$home->getActiveEntry()->getName(),
|
||||
'DashboardHome::loadDashboardEntries() could not load and activate expected Pane'
|
||||
);
|
||||
}
|
||||
@ -85,18 +85,18 @@ class PaneTest extends BaseDashboardTestCase
|
||||
/**
|
||||
* @depends testWhetherActivatePaneActivatesAPaneEntry
|
||||
*/
|
||||
public function testWhetherGetActivePaneGetsExpectedPane()
|
||||
public function testWhethergetActiveEntryGetsExpectedPane()
|
||||
{
|
||||
$home = $this->getTestHome();
|
||||
$home->addEntry($this->getTestPane());
|
||||
$home->addEntry($this->getTestPane('Test Me'));
|
||||
|
||||
$home->activatePane($home->getEntry('Test Me'));
|
||||
$home->activateEntry($home->getEntry('Test Me'));
|
||||
|
||||
$this->assertEquals(
|
||||
'Test Me',
|
||||
$home->getActivePane()->getName(),
|
||||
'DashboardHome::getActivePane() could not determine valid active pane'
|
||||
$home->getActiveEntry()->getName(),
|
||||
'DashboardHome::getActiveEntry() could not determine valid active pane'
|
||||
);
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ class PaneTest extends BaseDashboardTestCase
|
||||
$home->manageEntry($this->getTestPane());
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertCount(
|
||||
1,
|
||||
@ -132,17 +132,17 @@ class PaneTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home->getActivePane()->setTitle('Hello');
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$home->getActiveEntry()->setTitle('Hello');
|
||||
|
||||
$home->manageEntry($home->getEntries());
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertEquals(
|
||||
'Hello',
|
||||
$home->getActivePane()->getTitle(),
|
||||
$home->getActiveEntry()->getTitle(),
|
||||
'DashboardHome::manageEntry() could not update existing Pane'
|
||||
);
|
||||
}
|
||||
@ -159,14 +159,14 @@ class PaneTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load('Second Home', null, true);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
/** @var DashboardHome $default */
|
||||
$default = $this->dashboard->getEntry(self::TEST_HOME);
|
||||
|
||||
$default->manageEntry($home->getEntry(self::TEST_PANE), $home);
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$default = $this->dashboard->getActiveHome();
|
||||
$default = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertCount(
|
||||
1,
|
||||
@ -191,7 +191,7 @@ class PaneTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load();
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
$default = $this->dashboard->getEntry(self::TEST_HOME);
|
||||
$default->loadDashboardEntries();
|
||||
|
||||
@ -215,12 +215,12 @@ class PaneTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME, self::TEST_PANE);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$home->removeEntry(self::TEST_PANE);
|
||||
$this->dashboard->load();
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertFalse(
|
||||
$home->hasEntry(self::TEST_PANE),
|
||||
@ -240,12 +240,12 @@ class PaneTest extends BaseDashboardTestCase
|
||||
|
||||
$this->dashboard->load(self::TEST_HOME);
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$home->removeEntries();
|
||||
$this->dashboard->load();
|
||||
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$home = $this->dashboard->getActiveEntry();
|
||||
|
||||
$this->assertFalse(
|
||||
$home->hasEntries(),
|
||||
|
@ -28,7 +28,7 @@ class SearchDashboardTest extends BaseDashboardTestCase
|
||||
$dashboard->setUser($this->getUser());
|
||||
$dashboard->search('pending');
|
||||
|
||||
$searchHome = $dashboard->getActiveHome();
|
||||
$searchHome = $dashboard->getActiveEntry();
|
||||
$searchHome->getEntry(SearchDashboard::SEARCH_PANE)->setEntries([]);
|
||||
$dashboard->render();
|
||||
}
|
||||
@ -39,7 +39,7 @@ class SearchDashboardTest extends BaseDashboardTestCase
|
||||
$dashboard->setUser($this->getUser());
|
||||
$dashboard->search('pending');
|
||||
|
||||
$searchHome = $dashboard->getActiveHome();
|
||||
$searchHome = $dashboard->getActiveEntry();
|
||||
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Hosts: pending');
|
||||
|
||||
$this->assertTrue($result, 'SearchDashboard::search() could not load search dashlets from modules');
|
||||
@ -51,7 +51,7 @@ class SearchDashboardTest extends BaseDashboardTestCase
|
||||
$dashboard->setUser($this->getUser());
|
||||
$dashboard->search();
|
||||
|
||||
$searchHome = $dashboard->getActiveHome();
|
||||
$searchHome = $dashboard->getActiveEntry();
|
||||
$result = $searchHome->getEntry(SearchDashboard::SEARCH_PANE)->hasEntry('Ready to search');
|
||||
|
||||
$this->assertTrue($result, 'SearchDashboard::search() could not get hint for search');
|
||||
|
Loading…
x
Reference in New Issue
Block a user