monitoring: Add DataView::$requiresFilter

refs #9606
This commit is contained in:
Eric Lippmann 2015-08-24 16:01:07 +02:00
parent ec390d7a8b
commit e9c7a5894a

View File

@ -11,6 +11,7 @@ use Icinga\Data\FilterColumns;
use Icinga\Data\PivotTable; use Icinga\Data\PivotTable;
use Icinga\Data\QueryInterface; use Icinga\Data\QueryInterface;
use Icinga\Data\SortRules; use Icinga\Data\SortRules;
use Icinga\Exception\Http\HttpBadRequestException;
use Icinga\Exception\QueryException; use Icinga\Exception\QueryException;
use Icinga\Module\Monitoring\Backend\Ido\Query\IdoQuery; use Icinga\Module\Monitoring\Backend\Ido\Query\IdoQuery;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
@ -40,6 +41,13 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
*/ */
protected $filterColumns; protected $filterColumns;
/**
* Whether the data view requires a filter
*
* @var bool
*/
protected $requiresFilter = false;
/** /**
* Create a new view * Create a new view
* *
@ -188,6 +196,29 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
return in_array($column, $this->getFilterColumns()); return in_array($column, $this->getFilterColumns());
} }
/**
* Get whether the data view requires a filter
*
* @return bool
*/
public function getRequiresFilter()
{
return $this->requiresFilter;
}
/**
* Set whether the data view requires a filter
*
* @param bool $requiresFilter
*
* @return $this
*/
public function setRequiresFilter($requiresFilter = true)
{
$this->requiresFilter = (bool) $requiresFilter;
return $this;
}
/** /**
* Return all filter columns with their optional label as key * Return all filter columns with their optional label as key
* *
@ -638,7 +669,12 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
public function handleRequest(Request $request) public function handleRequest(Request $request)
{ {
$params = $request->getUrl()->getParams(); $params = $request->getUrl()->getParams();
$this->applyFilter(Filter::fromQuerystring((string) $params)); $filter = Filter::fromQuerystring((string) $params);
/** @var Filter $filter */
if ($this->getRequiresFilter() && $filter->isEmpty()) {
throw new HttpBadRequestException('Filter must not be empty');
}
$this->applyFilter($filter);
return $this; return $this;
} }
} }