Fix "show all downtimes" links

refs #8565
This commit is contained in:
Matthias Jentsch 2015-04-09 11:19:13 +02:00
parent 06a44119de
commit 878ef05896
5 changed files with 24 additions and 17 deletions

View File

@ -154,15 +154,15 @@ class Monitoring_HostsController extends Controller
$this->view->problemObjects = $this->hostList->getProblemObjects(); $this->view->problemObjects = $this->hostList->getProblemObjects();
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem') $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/hosts/acknowledge-problem')
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult()); ->setQueryString($this->hostList->getUnhandledObjects()->objectsFilter());
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime') $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/hosts/schedule-downtime')
->setQueryString($this->hostList->getUnhandledObjects()->filterFromResult()); ->setQueryString($this->hostList->getUnhandledObjects()->objectsFilter());
$this->view->downtimeLink = Url::fromPath('monitoring/hosts/schedule-downtime') $this->view->downtimeLink = Url::fromPath('monitoring/hosts/schedule-downtime')
->setQueryString($this->hostList->getProblemObjects()->filterFromResult()); ->setQueryString($this->hostList->getProblemObjects()->objectsFilter());
$this->view->acknowledgedObjects = $this->hostList->getAcknowledgedObjects(); $this->view->acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
$this->view->objectsInDowntime = $this->hostList->getObjectsInDowntime(); $this->view->objectsInDowntime = $this->hostList->getObjectsInDowntime();
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes') $this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->hostList->getObjectsInDowntime()->filterFromResult()); ->setQueryString($this->hostList->getObjectsInDowntime()->objectsFilter(array('host' => 'downtime_host')));
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments'); $this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
$this->view->baseFilter = $this->hostList->getFilter(); $this->view->baseFilter = $this->hostList->getFilter();

View File

@ -191,15 +191,16 @@ class Monitoring_ServicesController extends Controller
$this->view->unhandledObjects = $this->serviceList->getUnhandledObjects(); $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects();
$this->view->problemObjects = $this->serviceList->getProblemObjects(); $this->view->problemObjects = $this->serviceList->getProblemObjects();
$this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem') $this->view->acknowledgeUnhandledLink = Url::fromPath('monitoring/services/acknowledge-problem')
->setQueryString($this->serviceList->getUnhandledObjects()->filterFromResult()->toQueryString()); ->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
$this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime') $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')
->setQueryString($this->serviceList->getUnhandledObjects()->filterFromResult()->toQueryString()); ->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
$this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime') $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')
->setQueryString($this->serviceList->getProblemObjects()->filterFromResult()->toQueryString()); ->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString());
$this->view->acknowledgedObjects = $acknowledgedObjects; $this->view->acknowledgedObjects = $acknowledgedObjects;
$this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime(); $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime();
$this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes') $this->view->inDowntimeLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->serviceList->getObjectsInDowntime()->filterFromResult()->toQueryString()); ->setQueryString($this->serviceList->getObjectsInDowntime()
->objectsFilter(array('host' => 'downtime_host', 'service' => 'downtime_service'))->toQueryString());
$this->view->commentsLink = Url::fromRequest() $this->view->commentsLink = Url::fromRequest()
->setPath('monitoring/list/comments'); ->setPath('monitoring/list/comments');
$this->view->baseFilter = $this->serviceList->getFilter(); $this->view->baseFilter = $this->serviceList->getFilter();

View File

@ -78,11 +78,11 @@ class HostList extends ObjectList
* *
* @return array An * @return array An
*/ */
public function filterFromResult() public function objectsFilter($columns = array('host' => 'host'))
{ {
$filterExpression = array(); $filterExpression = array();
foreach ($this as $host) { foreach ($this as $host) {
$filterExpression[] = Filter::where('host', $host->getName()); $filterExpression[] = Filter::where($columns['host'], $host->getName());
} }
return FilterOr::matchAny($filterExpression); return FilterOr::matchAny($filterExpression);
} }

View File

@ -194,12 +194,16 @@ abstract class ObjectList implements Countable, IteratorAggregate
$list = new $class($this->backend); $list = new $class($this->backend);
$list->objects = $objects; $list->objects = $objects;
$list->count = count($objects); $list->count = count($objects);
$list->filter = $list->filterFromResult(); $list->filter = $list->objectsFilter();
return $list; return $list;
} }
/** /**
* @return Filter * Create a filter that matches exactly the elements of this object list
*
* @param array $columns Override default column names.
*
* @return Filter
*/ */
abstract function filterFromResult(); abstract function objectsFilter($columns = array());
} }

View File

@ -119,15 +119,17 @@ class ServiceList extends ObjectList
/** /**
* Returns a Filter that matches all hosts in this HostList * Returns a Filter that matches all hosts in this HostList
* *
* @return Filter * @param array $columns Override filter column names
*
* @return Filter
*/ */
public function filterFromResult() public function objectsFilter($columns = array('host' => 'host', 'service' => 'service'))
{ {
$filterExpression = array(); $filterExpression = array();
foreach ($this as $service) { foreach ($this as $service) {
$filterExpression[] = Filter::matchAll( $filterExpression[] = Filter::matchAll(
Filter::where('host', $service->getHost()->getName()), Filter::where($columns['host'], $service->getHost()->getName()),
Filter::where('service', $service->getName()) Filter::where($columns['service'], $service->getName())
); );
} }
return FilterOr::matchAny($filterExpression); return FilterOr::matchAny($filterExpression);