Fix that filters are not preserved on timeline element urls

refs #4190
This commit is contained in:
Johannes Meyer 2014-04-01 14:26:10 +02:00
parent 19b2a94777
commit 21b9c1f4af
4 changed files with 60 additions and 13 deletions

View File

@ -58,6 +58,13 @@ class Url
*/
private $params = array();
/**
* An array to map aliases to valid parameters
*
* @var array
*/
private $aliases = array();
/**
* The site anchor after the '#'
*
@ -197,6 +204,31 @@ class Url
return preg_replace('/#.*$/', '', $url);
}
/**
* Set the array to be used to map aliases to valid parameters
*
* @param array $aliases The array to be used (alias => param)
*
* @return self
*/
public function setAliases(array $aliases)
{
$this->aliases = $aliases;
return $this;
}
/**
* Return the parameter for the given alias
*
* @param string $alias The alias to translate
*
* @return string The parameter name
*/
public function translateAlias($alias)
{
return array_key_exists($alias, $this->aliases) ? $this->aliases[$alias] : $alias;
}
/**
* Overwrite the baseUrl.
*
@ -256,7 +288,11 @@ class Url
if (empty($this->params)) {
return ltrim($this->path, '/') . $this->anchor;
}
return ltrim($this->path, '/') . '?' . http_build_query($this->params, '', '&') . $this->anchor;
$params = array();
foreach ($this->params as $param => $value) {
$params[$this->translateAlias($param)] = $value;
}
return ltrim($this->path, '/') . '?' . http_build_query($params, '', '&') . $this->anchor;
}
/**

View File

@ -5,6 +5,7 @@
use \DateTime;
use \DateInterval;
use \Zend_Config;
use Icinga\Web\Url;
use Icinga\Application\Config;
use Icinga\Web\Controller\ActionController;
use Icinga\Module\Monitoring\Timeline\TimeLine;
@ -20,7 +21,17 @@ class Monitoring_TimelineController extends ActionController
$this->setupIntervalBox();
list($displayRange, $forecastRange) = $this->buildTimeRanges();
$detailUrl = '/monitoring/list/eventhistory?raw_timestamp<=%s&raw_timestamp>=%s&type=%s';
$detailUrl = Url::fromPath(
'/monitoring/list/eventhistory',
Url::fromRequest()->getParams()
)->setAliases(
array(
'name' => 'type',
'end' => 'raw_timestamp>',
'start' => 'raw_timestamp<'
)
)->remove(array('start', 'end', 'extend', 'interval'));
$timeline = new TimeLine(
EventHistoryView::fromRequest(
$this->getRequest(),

View File

@ -67,12 +67,11 @@ $extrapolatedCircleWidth = $timeline->getExtrapolatedCircleWidth($timeInfo[1][$g
((float) substr($circleWidth, 0, -2) / 2) . 'em',
$timeInfo[1][$groupName]->getColor(),
$circleWidth
); ?>" href="<?= $this->href(
sprintf(
$timeInfo[1][$groupName]->getDetailUrl(),
$timeInfo[0]->start->getTimestamp(),
$timeInfo[0]->end->getTimestamp(),
$groupName
); ?>" href="<?= $timeInfo[1][$groupName]->getDetailUrl()->overwriteParams(
array(
'start' => $timeInfo[0]->start->getTimestamp(),
'end' => $timeInfo[0]->end->getTimestamp(),
'name' => $groupName
)
); ?>" title="<?= $timeInfo[1][$groupName]->getValue(); ?> <?= $labelAndColor['label']; ?>"></a>
</div>
@ -82,7 +81,7 @@ $extrapolatedCircleWidth = $timeline->getExtrapolatedCircleWidth($timeInfo[1][$g
</div>
<?php $firstRow = false; ?>
<?php endforeach ?>
<a id="end" href="<?= Url::fromRequest()->getUrlWithout(
<a id="end" href="<?= Url::fromRequest()->remove(
array(
'raw_timestamp<',
'raw_timestamp>'

View File

@ -5,6 +5,7 @@
namespace Icinga\Module\Monitoring\Timeline;
use \DateTime;
use Icinga\Web\Url;
use Icinga\Exception\ProgrammingError;
/**
@ -36,7 +37,7 @@ class TimeEntry
/**
* The url to this group's detail view
*
* @var string
* @var Url
*/
protected $detailUrl;
@ -149,9 +150,9 @@ class TimeEntry
/**
* Set the url to this group's detail view
*
* @param string $detailUrl The url to set
* @param Url $detailUrl The url to set
*/
public function setDetailUrl($detailUrl)
public function setDetailUrl(Url $detailUrl)
{
$this->detailUrl = $detailUrl;
}
@ -159,7 +160,7 @@ class TimeEntry
/**
* Return the url to this group's detail view
*
* @return string
* @return Url
*/
public function getDetailUrl()
{