Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 140 additions & 1 deletion application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ public function historyAction(): Generator
);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);

$preserveParams = [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam(),
'name'
];

$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
$searchBar = $this->createSearchBar($history, $preserveParams)
->setEditorUrl(
Url::fromPath('icingadb/host/history-search-editor')
->setParams($requestParams)
)->setSuggestionUrl(
Url::fromPath('icingadb/host/history-complete')
->setParams(clone $requestParams)
);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}

$history->peekAhead();

$page = $paginationControl->getCurrentPageNumber();
Expand All @@ -160,17 +189,19 @@ public function historyAction(): Generator
}

$history->filter(Filter::lessThanOrEqual('event_time', $before));
$this->filter($history, $filter);

yield $this->export($history);

$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);

$historyList = (new LoadMoreObjectList($history->execute()))
->setViewMode($viewModeSwitcher->getViewMode())
->setPageSize($limitControl->getLimit())
->setLoadMoreUrl($url->setParam('before', $before));
->setLoadMoreUrl($url->setParam('before', $before)->setFilter($filter));

if ($compact) {
$historyList->setPageNumber($page);
Expand All @@ -181,6 +212,10 @@ public function historyAction(): Generator
} else {
$this->addContent($historyList);
}

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
}

public function servicesAction(): Generator
Expand Down Expand Up @@ -218,6 +253,37 @@ public function servicesAction(): Generator
['service.state.severity DESC', 'service.state.last_state_change DESC']
);

$preserveParams = [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam(),
'name'
];

$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
$searchBar = $this->createSearchBar($services, $preserveParams)
->setEditorUrl(
Url::fromPath('icingadb/host/services-search-editor')
->setParams($requestParams)
)->setSuggestionUrl(
Url::fromPath('icingadb/host/services-complete')
->setParams(clone $requestParams)
);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}

$services->filter($filter);

yield $this->export($services);

$serviceList = (new ObjectList($services))
Expand All @@ -228,9 +294,18 @@ public function servicesAction(): Generator
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);
$continueWith = $this->createContinueWith(
Links::servicesDetails()->setFilter(Filter::equal('host.name', $this->host->name)),
$searchBar
);

$this->addContent($serviceList);

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate($continueWith);
}

$this->setAutorefreshInterval(10);
}

Expand Down Expand Up @@ -391,6 +466,26 @@ public function childrenCompleteAction(): void
$this->getDocument()->add($suggestions);
}

public function historyCompleteAction(): void
{
$suggestions = (new ObjectSuggestions())
->setModel(History::class)
->setBaseFilter(Filter::equal('host.id', $this->host->id))
->forRequest($this->getServerRequest());

$this->getDocument()->addHtml($suggestions);
}

public function servicesCompleteAction(): void
{
$suggestions = (new ObjectSuggestions())
->setModel(Service::class)
->setBaseFilter(Filter::equal('host.id', $this->host->id))
->forRequest($this->getServerRequest());

$this->getDocument()->addHtml($suggestions);
}

public function searchEditorAction(): void
{
$editor = $this->createSearchEditor(
Expand Down Expand Up @@ -432,6 +527,50 @@ public function childrenSearchEditorAction(): void
$this->setTitle($this->translate('Adjust Filter'));
}

public function historySearchEditorAction(): void
{
$preserveParams = [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
'name'
];
$editor = $this->createSearchEditor(
History::on($this->getDb()),
Url::fromPath('icingadb/host/history', ['name' => $this->host->name]),
$preserveParams
);
$editor->setSuggestionUrl(
Url::fromPath('icingadb/host/history-complete')
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
);

$this->getDocument()->addHtml($editor);
$this->setTitle($this->translate('Adjust Filter'));
}

public function servicesSearchEditorAction(): void
{
$preserveParams = [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
'name'
];
$editor = $this->createSearchEditor(
Service::on($this->getDb()),
Url::fromPath('icingadb/host/services', ['name' => $this->host->name]),
$preserveParams
);
$editor->setSuggestionUrl(
Url::fromPath('icingadb/host/services-complete')
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
);

$this->getDocument()->addHtml($editor);
$this->setTitle($this->translate('Adjust Filter'));
}

/**
* Fetch the dependency nodes of the current host
*
Expand Down
71 changes: 70 additions & 1 deletion application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,36 @@ public function historyAction(): Generator
);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl, true);

$preserveParams = [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam(),
'name',
'host.name'
];

$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
$searchBar = $this->createSearchBar($history, $preserveParams)
->setEditorUrl(
Url::fromPath('icingadb/service/history-search-editor')
->setParams($requestParams)
)->setSuggestionUrl(
Url::fromPath('icingadb/service/history-complete')
->setParams(clone $requestParams)
);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}

$history->peekAhead();

$page = $paginationControl->getCurrentPageNumber();
Expand All @@ -310,17 +340,19 @@ public function historyAction(): Generator
}

$history->filter(Filter::lessThanOrEqual('event_time', $before));
$this->filter($history, $filter);

yield $this->export($history);

$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);

$historyList = (new LoadMoreObjectList($history->execute()))
->setViewMode($viewModeSwitcher->getViewMode())
->setPageSize($limitControl->getLimit())
->setLoadMoreUrl($url->setParam('before', $before));
->setLoadMoreUrl($url->setParam('before', $before)->setFilter($filter));

if ($compact) {
$historyList->setPageNumber($page);
Expand All @@ -331,6 +363,10 @@ public function historyAction(): Generator
} else {
$this->addContent($historyList);
}

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
}

public function completeAction(): void
Expand All @@ -355,6 +391,16 @@ public function childrenCompleteAction(): void
$this->getDocument()->add($suggestions);
}

public function historyCompleteAction(): void
{
$suggestions = (new ObjectSuggestions())
->setModel(History::class)
->setBaseFilter(Filter::equal('service.id', $this->service->id))
->forRequest($this->getServerRequest());

$this->getDocument()->addHtml($suggestions);
}

public function searchEditorAction(): void
{
$editor = $this->createSearchEditor(
Expand Down Expand Up @@ -404,6 +450,29 @@ public function childrenSearchEditorAction(): void
$this->setTitle($this->translate('Adjust Filter'));
}

public function historySearchEditorAction(): void
{
$preserveParams = [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
'name',
'host.name'
];
$editor = $this->createSearchEditor(
History::on($this->getDb()),
Url::fromPath('icingadb/service/history', ['name' => $this->service->name]),
$preserveParams
);
$editor->setSuggestionUrl(
Url::fromPath('icingadb/service/history-complete')
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
);

$this->getDocument()->addHtml($editor);
$this->setTitle($this->translate('Adjust Filter'));
}

/**
* Fetch the dependency nodes of the current service
*
Expand Down
4 changes: 4 additions & 0 deletions library/Icingadb/Hook/ActionsHook/ObjectActionsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ final public static function loadActions(Model $object): HtmlElement
continue;
}

if ($link->getBaseTarget() === null && ! $link->hasAttribute('target')) {
$link->setBaseTarget('_next');
}

// It may be ValidHtml, but modules shouldn't be able to break our views.
// That's why it needs to be rendered instantly, as any error will then
// be caught here.
Expand Down
5 changes: 3 additions & 2 deletions library/Icingadb/Widget/Detail/HostDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Icingadb\Widget\Detail;

use Icinga\Module\Icingadb\Common\HostLinks;
use Icinga\Module\Icingadb\Hook\ExtensionHook\ObjectDetailExtensionHook;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\ServicestateSummary;
Expand All @@ -25,8 +26,8 @@ public function __construct(Host $object, ServicestateSummary $serviceSummary)
protected function createServiceStatistics(): array
{
if ($this->serviceSummary->services_total > 0) {
$services = new ServiceStatistics($this->serviceSummary);
$services->setBaseFilter(Filter::equal('host.name', $this->object->name));
$services = (new ServiceStatistics($this->serviceSummary))
->setUrl(HostLinks::services($this->object));
} else {
$services = new EmptyState(t('This host has no services'));
}
Expand Down
1 change: 0 additions & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Sql\Expression;
use ipl\Sql\Filter\Exists;
use ipl\Web\Url;
use ipl\Web\Widget\CopyToClipboard;
use ipl\Web\Widget\EmptyState;
use ipl\Web\Widget\EmptyStateBar;
Expand Down
2 changes: 2 additions & 0 deletions library/Icingadb/Widget/Detail/ObjectHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
*/
class ObjectHeader extends BaseHtmlElement
{
protected $defaultAttributes = ['data-base-target' => '_next'];

/** @var Item */
protected $object;

Expand Down
Loading
Loading