Monitoring/ListController: Operate on the `hostStatus' view instead of the query

The monitoring module's ListController should only operate on data views instead of queries.
Thus the applyRestrictions() method now expects a data view instead of a query. Further since
filters are subject to change the applyRestrictions() method now does nothing.

The `hostsAction()' no longer uses `DataView::fromRequest()' but selects the data view from
a monitoring backend. `DataView::fromRequest()' orders the underlying query which must be reworked
in the current scenario.
This commit is contained in:
Eric Lippmann 2014-05-07 09:40:23 +02:00
parent cfdb695c94
commit 068e07109b

View File

@ -114,8 +114,8 @@ class Monitoring_ListController extends Controller
$this->view->query = $this->_request->getQuery(); $this->view->query = $this->_request->getQuery();
$this->view->title = 'Host Status'; $this->view->title = 'Host Status';
$this->compactView = 'hosts-compact'; $this->compactView = 'hosts-compact';
$dataview = HostStatusView::fromRequest( $dataView = $this->backend->select()->from(
$this->_request, 'hostStatus',
array( array(
'host_icon_image', 'host_icon_image',
'host_name', 'host_name',
@ -141,10 +141,10 @@ class Monitoring_ListController extends Controller
'host_max_check_attempts' 'host_max_check_attempts'
) )
); );
$query = $dataview->getQuery(); $query = $dataView->getQuery();
$this->applyRestrictions($query); $this->applyRestrictions($dataView);
$this->setupFilterControl($dataview, 'host'); $this->setupFilterControl($dataView, 'host');
$this->setupSortControl(array( $this->setupSortControl(array(
'host_last_check' => 'Last Host Check', 'host_last_check' => 'Last Host Check',
@ -155,7 +155,7 @@ class Monitoring_ListController extends Controller
'host_state' => 'Hard State' 'host_state' => 'Hard State'
)); ));
$this->handleFormatRequest($query); $this->handleFormatRequest($query);
$this->view->hosts = $query->paginate(); $this->view->hosts = $dataView->paginate();
} }
@ -499,24 +499,18 @@ class Monitoring_ListController extends Controller
} }
/** /**
* Apply current users monitoring/filter restrictions to the given query * Apply current user's `monitoring/filter' restrictions on the given data view
* *
* @param $query Filterable Query that should be filtered * @param DataView $dataView
* @return Filterable *
* @return DataView
*/ */
protected function applyRestrictions(Filterable $query) protected function applyRestrictions(DataView $dataView)
{ {
foreach ($this->getRestrictions('monitoring/filter') as $restriction) { foreach ($this->getRestrictions('monitoring/filter') as $restriction) {
parse_str($restriction, $filter); // TODO(el): Apply restrictions
foreach ($filter as $k => $v) {
if ($query->isValidFilterTarget($k)) {
// TODO: This is NOT enough. We need to fix filters and get
// applyAuthFilters back.
$query->where($k, $v);
}
}
} }
return $query; return $dataView;
} }
/** /**