From e623bea016a47e7ba09937e1d6c972389a8dabf3 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 17 Jan 2025 12:00:38 +0100 Subject: [PATCH] (Host/Service)Controller: Add separated `(searchEditor/complete)Action` for `parent & children tab` --- application/controllers/HostController.php | 86 ++++++++++------ application/controllers/ServiceController.php | 99 ++++++++++++------- 2 files changed, 121 insertions(+), 64 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index d835cd915..4990b9a30 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -323,18 +323,22 @@ public function childrenAction(): Generator $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar( - $nodesQuery, - [ - $limitControl->getLimitParam(), - $sortControl->getSortParam(), - $viewModeSwitcher->getViewModeParam(), - 'name' - ] - ); - - $searchBar->getSuggestionUrl()->setParam('isChildrenTab'); - $searchBar->getEditorUrl()->setParam('isChildrenTab'); + $preserveParams = [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam(), + 'name' + ]; + + $requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams(); + $searchBar = $this->createSearchBar($nodesQuery, $preserveParams) + ->setEditorUrl( + Url::fromPath('icingadb/host/children-search-editor') + ->setParams($requestParams) + )->setSuggestionUrl( + Url::fromPath('icingadb/host/children-complete') + ->setParams($requestParams) + ); if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { if ($searchBar->hasBeenSubmitted()) { @@ -373,12 +377,19 @@ public function childrenAction(): Generator public function completeAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $relation = $isChildrenTab ? 'parent' : 'child'; + $suggestions = (new ObjectSuggestions()) + ->setModel(DependencyNode::class) + ->setBaseFilter(Filter::equal("child.host.id", $this->host->id)) + ->forRequest($this->getServerRequest()); + + $this->getDocument()->add($suggestions); + } + public function childrenCompleteAction(): void + { $suggestions = (new ObjectSuggestions()) ->setModel(DependencyNode::class) - ->setBaseFilter(Filter::equal("$relation.host.id", $this->host->id)) + ->setBaseFilter(Filter::equal("parent.host.id", $this->host->id)) ->forRequest($this->getServerRequest()); $this->getDocument()->add($suggestions); @@ -386,25 +397,42 @@ public function completeAction(): void public function searchEditorAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $redirectUrl = $isChildrenTab - ? Url::fromPath('icingadb/host/children', ['name' => $this->host->name]) - : Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]); + $preserveParams = [ + LimitControl::DEFAULT_LIMIT_PARAM, + SortControl::DEFAULT_SORT_PARAM, + ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, + 'name' + ]; $editor = $this->createSearchEditor( DependencyNode::on($this->getDb()), - $redirectUrl, - [ - LimitControl::DEFAULT_LIMIT_PARAM, - SortControl::DEFAULT_SORT_PARAM, - ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, - 'name' - ] + Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]), + $preserveParams ); - if ($isChildrenTab) { - $editor->getSuggestionUrl()->setParam('isChildrenTab'); - } + $this->getDocument()->add($editor); + $this->setTitle($this->translate('Adjust Filter')); + } + + public function childrenSearchEditorAction(): void + { + $preserveParams = [ + LimitControl::DEFAULT_LIMIT_PARAM, + SortControl::DEFAULT_SORT_PARAM, + ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, + 'name' + ]; + + $editor = $this->createSearchEditor( + DependencyNode::on($this->getDb()), + Url::fromPath('icingadb/host/children', ['name' => $this->host->name]), + $preserveParams + ); + + $editor->setSuggestionUrl( + Url::fromPath('icingadb/host/children-complete') + ->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams()) + ); $this->getDocument()->add($editor); $this->setTitle($this->translate('Adjust Filter')); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index d8269412c..fbd98599a 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -194,19 +194,23 @@ public function childrenAction(): Generator $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar( - $nodesQuery, - [ - $limitControl->getLimitParam(), - $sortControl->getSortParam(), - $viewModeSwitcher->getViewModeParam(), - 'name', - 'host.name' - ] - ); - - $searchBar->getSuggestionUrl()->setParam('isChildrenTab'); - $searchBar->getEditorUrl()->setParam('isChildrenTab'); + $preserveParams = [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam(), + 'name', + 'host.name' + ]; + + $requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams(); + $searchBar = $this->createSearchBar($nodesQuery, $preserveParams) + ->setEditorUrl( + Url::fromPath('icingadb/service/children-search-editor') + ->setParams($requestParams) + )->setSuggestionUrl( + Url::fromPath('icingadb/service/children-complete') + ->setParams($requestParams) + ); if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { if ($searchBar->hasBeenSubmitted()) { @@ -336,12 +340,19 @@ public function historyAction(): Generator public function completeAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $relation = $isChildrenTab ? 'parent' : 'child'; + $suggestions = (new ObjectSuggestions()) + ->setModel(DependencyNode::class) + ->setBaseFilter(Filter::equal("child.service.id", $this->service->id)) + ->forRequest($this->getServerRequest()); + $this->getDocument()->add($suggestions); + } + + public function childrenCompleteAction(): void + { $suggestions = (new ObjectSuggestions()) ->setModel(DependencyNode::class) - ->setBaseFilter(Filter::equal("$relation.service.id", $this->service->id)) + ->setBaseFilter(Filter::equal("parent.service.id", $this->service->id)) ->forRequest($this->getServerRequest()); $this->getDocument()->add($suggestions); @@ -349,32 +360,50 @@ public function completeAction(): void public function searchEditorAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $redirectUrl = $isChildrenTab - ? Url::fromPath( - 'icingadb/service/children', - ['name' => $this->service->name, 'host.name' => $this->service->host->name] - ) - : Url::fromPath( + $preserveParams = [ + LimitControl::DEFAULT_LIMIT_PARAM, + SortControl::DEFAULT_SORT_PARAM, + ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, + 'name', + 'host.name' + ]; + + $editor = $this->createSearchEditor( + DependencyNode::on($this->getDb()), + Url::fromPath( 'icingadb/service/parents', ['name' => $this->service->name, 'host.name' => $this->service->host->name] - ); + ), + $preserveParams + ); + + $this->getDocument()->add($editor); + $this->setTitle($this->translate('Adjust Filter')); + } + + public function childrenSearchEditorAction(): void + { + $preserveParams = [ + LimitControl::DEFAULT_LIMIT_PARAM, + SortControl::DEFAULT_SORT_PARAM, + ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, + 'name', + 'host.name' + ]; $editor = $this->createSearchEditor( DependencyNode::on($this->getDb()), - $redirectUrl, - [ - LimitControl::DEFAULT_LIMIT_PARAM, - SortControl::DEFAULT_SORT_PARAM, - ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM, - 'name', - 'host.name' - ] + Url::fromPath( + 'icingadb/service/children', + ['name' => $this->service->name, 'host.name' => $this->service->host->name] + ), + $preserveParams ); - if ($isChildrenTab) { - $editor->getSuggestionUrl()->setParam('isChildrenTab'); - } + $editor->setSuggestionUrl( + Url::fromPath('icingadb/host/children-complete') + ->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams()) + ); $this->getDocument()->add($editor); $this->setTitle($this->translate('Adjust Filter'));