From 30589830110d712a6da15ade348d6e6152c9e81e Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 8 Jun 2022 14:59:42 +0200 Subject: [PATCH] Force to refresh the menu container when removing a home & unset moved entry from the original widget --- application/controllers/DashboardsController.php | 4 ++++ .../Icinga/Web/Dashboard/Common/BaseDashboard.php | 4 ++++ .../Web/Dashboard/Common/DashboardEntries.php | 15 +++++++++++++++ .../Web/Dashboard/Common/DashboardEntry.php | 9 +++++++++ library/Icinga/Web/Dashboard/Pane.php | 4 ++-- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php index a67cfcef9..6f17a656a 100644 --- a/application/controllers/DashboardsController.php +++ b/application/controllers/DashboardsController.php @@ -93,6 +93,8 @@ class DashboardsController extends CompatController $homeForm = new HomeForm($this->dashboard); $homeForm->on(HomeForm::ON_SUCCESS, function () use ($homeForm) { + $this->getResponse()->setHeader('X-Icinga-Extra-Updates', '#menu'); + $params = ['home' => $homeForm->getPopulatedValue('title')]; $this->redirectNow(Url::fromPath(Dashboard::BASE_ROUTE . '/settings')->setParams($params)); @@ -129,6 +131,8 @@ class DashboardsController extends CompatController $homeForm = (new RemoveHomeForm($this->dashboard)) ->on(RemoveHomeForm::ON_SUCCESS, function () { + $this->getResponse()->setHeader('X-Icinga-Extra-Updates', '#menu'); + $this->redirectNow(Url::fromPath(Dashboard::BASE_ROUTE . '/settings')); }) ->handleRequest($this->getServerRequest()); diff --git a/library/Icinga/Web/Dashboard/Common/BaseDashboard.php b/library/Icinga/Web/Dashboard/Common/BaseDashboard.php index 52649b533..fb12772a4 100644 --- a/library/Icinga/Web/Dashboard/Common/BaseDashboard.php +++ b/library/Icinga/Web/Dashboard/Common/BaseDashboard.php @@ -297,4 +297,8 @@ abstract class BaseDashboard implements DashboardEntry public function rewindEntries() { } + + public function unsetEntry(BaseDashboard $dashboard) + { + } } diff --git a/library/Icinga/Web/Dashboard/Common/DashboardEntries.php b/library/Icinga/Web/Dashboard/Common/DashboardEntries.php index 254719566..bc5ddccf3 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardEntries.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardEntries.php @@ -98,6 +98,17 @@ trait DashboardEntries return reset($dashboards); } + public function unsetEntry(BaseDashboard $dashboard) + { + if (! $this->hasEntry($dashboard->getName())) { + throw new ProgrammingError('Trying to unset an invalid Dashboard entry: "%s"', $dashboard->getName()); + } + + unset($this->dashboards[$dashboard->getName()]); + + return $this; + } + public function reorderWidget(BaseDashboard $dashboard, int $position, Sortable $origin = null) { if ($origin && ! $origin instanceof $this) { @@ -125,6 +136,10 @@ trait DashboardEntries $entries[$item->getName()] = $item; $this->manageEntry($item, $dashboard->getName() === $item->getName() ? $origin : null); + + if ($dashboard->getName() === $item->getName() && $origin) { + $origin->unsetEntry($dashboard); + } } $this->setEntries($entries); diff --git a/library/Icinga/Web/Dashboard/Common/DashboardEntry.php b/library/Icinga/Web/Dashboard/Common/DashboardEntry.php index e7d766abd..37e7cb215 100644 --- a/library/Icinga/Web/Dashboard/Common/DashboardEntry.php +++ b/library/Icinga/Web/Dashboard/Common/DashboardEntry.php @@ -129,4 +129,13 @@ interface DashboardEntry * @return false|BaseDashboard */ public function rewindEntries(); + + /** + * Unset the given dashboard entry from this widget dashboard entries + * + * @param BaseDashboard $dashboard + * + * @return $this + */ + public function unsetEntry(BaseDashboard $dashboard); } diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index 9ef3281a2..c65b00fe4 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -129,7 +129,7 @@ class Pane extends BaseDashboard implements Sortable // The module from which this dashlet originates doesn't exist anymore $this->removeEntry($newDashlet); - unset($this->dashboards[$newDashlet->getName()]); + $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 @@ -144,7 +144,7 @@ class Pane extends BaseDashboard implements Sortable } if ($newDashlet->isDisabled()) { - unset($this->dashboards[$newDashlet->getName()]); + $this->unsetEntry($newDashlet); } }