From ebdb48a3f565469a8b8e21da6a4ca240ea77d18d 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 | 74 ++++++++++----- application/controllers/ServiceController.php | 89 ++++++++++++------- 2 files changed, 108 insertions(+), 55 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index b4d370c7..d30ea765 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -317,18 +317,22 @@ class HostController extends Controller $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar( - $nodesQuery, - [ - $limitControl->getLimitParam(), - $sortControl->getSortParam(), - $viewModeSwitcher->getViewModeParam(), - 'name' - ] - ); + $preserveParams = [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam(), + 'name' + ]; - $searchBar->getSuggestionUrl()->setParam('isChildrenTab'); - $searchBar->getEditorUrl()->setParam('isChildrenTab'); + $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(clone $requestParams) + ); if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { if ($searchBar->hasBeenSubmitted()) { @@ -367,12 +371,19 @@ class HostController extends Controller public function completeAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $relation = $isChildrenTab ? 'parent' : 'child'; - $suggestions = (new ObjectSuggestions()) ->setModel(DependencyNode::class) - ->setBaseFilter(Filter::equal("$relation.host.id", $this->host->id)) + ->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("parent.host.id", $this->host->id)) ->forRequest($this->getServerRequest()); $this->getDocument()->add($suggestions); @@ -380,14 +391,9 @@ class HostController extends Controller 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]); - $editor = $this->createSearchEditor( DependencyNode::on($this->getDb()), - $redirectUrl, + Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]), [ LimitControl::DEFAULT_LIMIT_PARAM, SortControl::DEFAULT_SORT_PARAM, @@ -396,9 +402,29 @@ class HostController extends Controller ] ); - 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 0a0a452b..fbfb08ef 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -188,19 +188,23 @@ class ServiceController extends Controller $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); - $searchBar = $this->createSearchBar( - $nodesQuery, - [ - $limitControl->getLimitParam(), - $sortControl->getSortParam(), - $viewModeSwitcher->getViewModeParam(), - 'name', - 'host.name' - ] - ); + $preserveParams = [ + $limitControl->getLimitParam(), + $sortControl->getSortParam(), + $viewModeSwitcher->getViewModeParam(), + 'name', + 'host.name' + ]; - $searchBar->getSuggestionUrl()->setParam('isChildrenTab'); - $searchBar->getEditorUrl()->setParam('isChildrenTab'); + $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(clone $requestParams) + ); if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) { if ($searchBar->hasBeenSubmitted()) { @@ -330,12 +334,19 @@ class ServiceController extends Controller public function completeAction(): void { - $isChildrenTab = $this->params->shift('isChildrenTab'); - $relation = $isChildrenTab ? 'parent' : 'child'; - $suggestions = (new ObjectSuggestions()) ->setModel(DependencyNode::class) - ->setBaseFilter(Filter::equal("$relation.service.id", $this->service->id)) + ->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("parent.service.id", $this->service->id)) ->forRequest($this->getServerRequest()); $this->getDocument()->add($suggestions); @@ -343,20 +354,12 @@ class ServiceController extends Controller 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( - 'icingadb/service/parents', - ['name' => $this->service->name, 'host.name' => $this->service->host->name] - ); - $editor = $this->createSearchEditor( DependencyNode::on($this->getDb()), - $redirectUrl, + Url::fromPath( + 'icingadb/service/parents', + ['name' => $this->service->name, 'host.name' => $this->service->host->name] + ), [ LimitControl::DEFAULT_LIMIT_PARAM, SortControl::DEFAULT_SORT_PARAM, @@ -366,9 +369,33 @@ class ServiceController extends Controller ] ); - 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', + 'host.name' + ]; + + $editor = $this->createSearchEditor( + DependencyNode::on($this->getDb()), + Url::fromPath( + 'icingadb/service/children', + ['name' => $this->service->name, 'host.name' => $this->service->host->name] + ), + $preserveParams + ); + + $editor->setSuggestionUrl( + Url::fromPath('icingadb/service/children-complete') + ->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams()) + ); $this->getDocument()->add($editor); $this->setTitle($this->translate('Adjust Filter'));