Skip to content

Commit

Permalink
Controller::createColumnControl(): Make columns mandatory in `tabular…
Browse files Browse the repository at this point in the history
…` view mode
  • Loading branch information
sukhwinder33445 authored and nilmerg committed Aug 11, 2023
1 parent ee7fa6e commit ba26dbe
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions library/Icingadb/Web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Icinga\Data\ConfigObject;
use Icinga\Date\DateFormatter;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\Http\HttpBadRequestException;
use Icinga\Exception\Json\JsonDecodeException;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\BaseItemTable;
Expand Down Expand Up @@ -72,12 +73,27 @@ public function getFilter(): Filter\Rule
return $this->filter;
}

public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwitcher)
/**
* Create column control
*
* @param Query $query
* @param ViewModeSwitcher $viewModeSwitcher
*
* @return array provided columns
*
* @throws HttpBadRequestException
*/
public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwitcher): array
{
// All of that is essentially what `ColumnControl::apply()` should do
$viewMode = $this->getRequest()->getUrl()->getParam($viewModeSwitcher->getViewModeParam());
$columnsDef = $this->params->shift('columns');
if (! $columnsDef) {
return null;
if ($viewMode === 'tabular') {
$this->httpBadRequest('Missing parameter "columns"');
}

return [];
}

$columns = [];
Expand All @@ -89,7 +105,7 @@ public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwit

$query->withColumns($columns);

if (! $this->getRequest()->getUrl()->hasParam($viewModeSwitcher->getViewModeParam())) {
if (! $viewMode) {
$viewModeSwitcher->setViewMode('tabular');
}

Expand Down

0 comments on commit ba26dbe

Please sign in to comment.