From 66c3dd26e54781359ea2c3bcaf8406fd33872dd4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 25 Mar 2014 14:19:50 +0100 Subject: [PATCH] Be window aware when calculating circle widths refs #4190 --- .../controllers/TimelineController.php | 1 + .../library/Monitoring/Timeline/TimeLine.php | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php index 84eb60e68..408d53f39 100644 --- a/modules/monitoring/application/controllers/TimelineController.php +++ b/modules/monitoring/application/controllers/TimelineController.php @@ -38,6 +38,7 @@ class Monitoring_TimelineController extends ActionController ); $timeline->setDisplayRange($displayRange); $timeline->setForecastRange($forecastRange); + $timeline->setSession($this->getWindowSession('timeline')); $this->view->timeline = $timeline; $this->view->intervalFormat = $this->getIntervalFormat(); diff --git a/modules/monitoring/library/Monitoring/Timeline/TimeLine.php b/modules/monitoring/library/Monitoring/Timeline/TimeLine.php index e6c275599..2122e0ada 100644 --- a/modules/monitoring/library/Monitoring/Timeline/TimeLine.php +++ b/modules/monitoring/library/Monitoring/Timeline/TimeLine.php @@ -9,6 +9,8 @@ use \Exception; use \ArrayIterator; use \IteratorAggregate; use Icinga\Web\Hook; +use Icinga\Web\Session; +use Icinga\Web\Session\SessionNamespace; use Icinga\Module\Monitoring\DataView\DataView; /** @@ -30,6 +32,13 @@ class TimeLine implements IteratorAggregate */ private $displayGroups; + /** + * The session to use + * + * @var SessionNamespace + */ + protected $session; + /** * The base that is used to calculate each circle's diameter * @@ -105,6 +114,16 @@ class TimeLine implements IteratorAggregate $this->identifiers = $identifiers; } + /** + * Set the session to use + * + * @param SessionNamespace $session The session to use + */ + public function setSession(SessionNamespace $session) + { + $this->session = $session; + } + /** * Set the range of time for which to display elements * @@ -201,12 +220,20 @@ class TimeLine implements IteratorAggregate public function getCalculationBase($create) { if ($this->calculationBase === null) { - // TODO: get base from session + if ($this->session !== null) { + // TODO: Do not use this if the interval has changed or the user did a reload + $this->calculationBase = $this->session->get('calculationBase'); + } + if ($create) { $new = $this->generateCalculationBase(); if ($new > $this->calculationBase) { - // TODO: save base in session $this->calculationBase = $new; + + if ($this->session !== null) { + $this->session->calculationBase = $new; + Session::getSession()->write(); // TODO: Should it be possible to call write() on the namespace? + } } } } @@ -242,7 +269,7 @@ class TimeLine implements IteratorAggregate } } - return pow($highestValue, 1 / 100); + return pow($highestValue, 1 / 100); // 100 == 100% } /**