Skip to content

Commit

Permalink
(Host/Service)Controller: Add separated `(searchEditor/complete)Actio…
Browse files Browse the repository at this point in the history
…n` for `parent & children tab`
  • Loading branch information
sukhwinder33445 committed Jan 17, 2025
1 parent 47b30c2 commit 0564431
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 55 deletions.
74 changes: 50 additions & 24 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -373,27 +377,29 @@ 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);
}

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,
Expand All @@ -402,9 +408,29 @@ public function searchEditorAction(): void
]
);

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'));
Expand Down
89 changes: 58 additions & 31 deletions application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -336,33 +340,32 @@ 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);
}

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,
Expand All @@ -372,9 +375,33 @@ public function searchEditorAction(): void
]
);

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'));
Expand Down

0 comments on commit 0564431

Please sign in to comment.