diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php index 20545da9b..eed71569f 100644 --- a/application/controllers/DashboardsController.php +++ b/application/controllers/DashboardsController.php @@ -34,10 +34,22 @@ class DashboardsController extends CompatController /** @var Dashboard */ protected $dashboard; + /** + * Whether the currently loaded home/pane is also loaded on the previous page + * + * @var string + */ + protected $prevActive = null; + public function init() { parent::init(); + // The "prevActive" param indicates whether this home/pane is currently being loaded in the + // DM view meanwhile rendering a modal view (update and remove actions). If it's indeed the case, + // we have to construct a proper http redirect after successfully removing this home + $this->prevActive = $this->params->shift('prevActive'); + $this->dashboard = new Dashboard(); $this->dashboard->setUser($this->Auth()->getUser()); $this->dashboard->setTabs($this->getTabs()); @@ -136,11 +148,16 @@ class DashboardsController extends CompatController $homeForm = (new RemoveHomeForm($this->dashboard)) ->on(RemoveHomeForm::ON_SUCCESS, function () { - $this->getResponse() - ->setHeader('X-Icinga-Extra-Updates', '#menu') - ->setHeader('X-Icinga-Container', 'modal-content', true); + $response = $this->getResponse(); + $response->setHeader('X-Icinga-Extra-Updates', '#menu'); - $this->redirectNow('__CLOSE__'); + if ($this->prevActive) { + $this->redirectNow(Url::fromPath(Dashboard::BASE_ROUTE . '/settings')); + } else { + $response->setHeader('X-Icinga-Container', 'modal-content', true); + + $this->redirectNow('__CLOSE__'); + } }) ->handleRequest($this->getServerRequest()); @@ -179,9 +196,13 @@ class DashboardsController extends CompatController $paneForm = (new PaneForm($this->dashboard)) ->on(PaneForm::ON_SUCCESS, function () { - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); + if ($this->prevActive) { + $this->redirectNow(Url::fromPath(Dashboard::BASE_ROUTE . '/settings')); + } else { + $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); - $this->redirectNow('__CLOSE__'); + $this->redirectNow('__CLOSE__'); + } }) ->handleRequest($this->getServerRequest()); @@ -205,9 +226,13 @@ class DashboardsController extends CompatController $paneForm = new RemovePaneForm($this->dashboard); $paneForm->populate(['org_name' => $paneParam]); $paneForm->on(RemovePaneForm::ON_SUCCESS, function () { - $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); + if ($this->prevActive) { + $this->redirectNow(Url::fromPath(Dashboard::BASE_ROUTE . '/settings')); + } else { + $this->getResponse()->setHeader('X-Icinga-Container', 'modal-content', true); - $this->redirectNow('__CLOSE__'); + $this->redirectNow('__CLOSE__'); + } })->handleRequest($this->getServerRequest()); $this->setTitle(t('Remove Pane')); diff --git a/library/Icinga/Web/Dashboard/DashboardHome.php b/library/Icinga/Web/Dashboard/DashboardHome.php index d6e256137..67cc698a4 100644 --- a/library/Icinga/Web/Dashboard/DashboardHome.php +++ b/library/Icinga/Web/Dashboard/DashboardHome.php @@ -152,6 +152,8 @@ class DashboardHome extends BaseDashboard implements Sortable 'home_id = ?' => $this->getUuid() ]); + $this->unsetEntry($pane); + return $this; } diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php index 6787f3659..8c554e5fd 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardHomeList.php @@ -78,8 +78,14 @@ class DashboardHomeList extends ItemListControl protected function createItemList(): BaseHtmlElement { if (! $this->headerDisabled) { - $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-home') - ->setParams(['home' => $this->home->getName()]); + $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-home')->setParams([ + 'home' => $this->home->getName() + ]); + + if ($this->home->isActive()) { + $url->addParams(['prevActive' => true]); + } + $this->assembleHeader($url, $this->home->getTitle()); } diff --git a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php index 03a0d9761..8d36bb9c8 100644 --- a/library/Icinga/Web/Dashboard/ItemList/DashboardList.php +++ b/library/Icinga/Web/Dashboard/ItemList/DashboardList.php @@ -43,8 +43,14 @@ class DashboardList extends ItemListControl protected function createItemList(): BaseHtmlElement { $pane = $this->pane; - $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-pane') - ->setParams(['home' => $pane->getHome()->getName(), 'pane' => $pane->getName()]); + $url = Url::fromPath(Dashboard::BASE_ROUTE . '/edit-pane')->setParams([ + 'home' => $pane->getHome()->getName(), + 'pane' => $pane->getName() + ]); + + if ($this->pane->isActive()) { + $url->addParams(['prevActive' => true]); + } $this->assembleHeader($url, $pane->getTitle()); diff --git a/library/Icinga/Web/Dashboard/Pane.php b/library/Icinga/Web/Dashboard/Pane.php index 73acfc9da..ba322a67c 100644 --- a/library/Icinga/Web/Dashboard/Pane.php +++ b/library/Icinga/Web/Dashboard/Pane.php @@ -89,6 +89,8 @@ class Pane extends BaseDashboard implements Sortable 'dashboard_id = ?' => $this->getUuid() ]); + $this->unsetEntry($dashlet); + return $this; } @@ -176,7 +178,7 @@ class Pane extends BaseDashboard implements Sortable $order = count($this->getEntries()); foreach ($dashlets as $dashlet) { if (is_array($dashlet)) { - $this->manageEntry($dashlet, $origin); + $this->manageEntry($dashlet, $origin, $manageRecursive); continue; }