The timeline object is NOT a form

refs #4190
This commit is contained in:
Johannes Meyer 2014-03-20 16:18:11 +01:00
parent 5e945e3194
commit b22f3f6b47
3 changed files with 21 additions and 67 deletions

View File

@ -45,12 +45,8 @@ class Monitoring_TimelineController extends ActionController
{ {
$this->setupIntervalBox(); $this->setupIntervalBox();
$timeline = new TimeLine(); $timeline = new TimeLine();
$timeline->setName('Timeline');
$timeline->setRequest($this->_request);
$timeline->setConfiguration(Config::app()); $timeline->setConfiguration(Config::app());
$timeline->buildForm(); // Necessary in order to populate request parameters //$timeline->setAttrib('data-icinga-component', 'monitoring/timelineComponent');
$timeline->populate($this->_request->getParams());
$timeline->setAttrib('data-icinga-component', 'monitoring/timelineComponent');
list($displayRange, $forecastRange) = $this->buildTimeRanges($this->getTimelineInterval()); list($displayRange, $forecastRange) = $this->buildTimeRanges($this->getTimelineInterval());
$timeline->setTimeRange($displayRange); $timeline->setTimeRange($displayRange);
$timeline->setDisplayData($this->loadData($displayRange)); $timeline->setDisplayData($this->loadData($displayRange));
@ -62,7 +58,6 @@ class Monitoring_TimelineController extends ActionController
{ {
$this->setupIntervalBox(); $this->setupIntervalBox();
$timeline = new TimeLine(); $timeline = new TimeLine();
$timeline->setRequest($this->_request);
$timeline->setConfiguration(Config::app()); $timeline->setConfiguration(Config::app());
list($displayRange, $forecastRange) = $this->buildTimeRanges($this->getTimelineInterval()); list($displayRange, $forecastRange) = $this->buildTimeRanges($this->getTimelineInterval());
$timeline->setTimeRange($displayRange); $timeline->setTimeRange($displayRange);

View File

@ -5,4 +5,4 @@
</div> </div>
</div> </div>
<?php endif ?> <?php endif ?>
<?= $this->timeline; ?> <?= $this->timeline->buildTimeline(); ?>

View File

@ -29,17 +29,11 @@
namespace Icinga\Module\Monitoring\Timeline; namespace Icinga\Module\Monitoring\Timeline;
use \Zend_Config; use \Zend_Config;
use \DateInterval;
use \Zend_View_Interface;
use Icinga\Web\Form;
use Icinga\Web\Form\Element\Note;
/** /**
* Represents a set of events in a specific time range * Represents a set of events in a specific time range
*
* @see Form
*/ */
class TimeLine extends Form class TimeLine
{ {
/** /**
* The range of time represented by this timeline * The range of time represented by this timeline
@ -130,53 +124,6 @@ class TimeLine extends Form
} }
} }
/**
* Disable the CSRF token
*/
public function init()
{
$this->setTokenDisabled();
}
/**
* Render the form and timeline to HTML
*
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
$this->buildForm();
$this->postCreate();
return parent::render($view);
}
/**
* Add timeline elements
*/
private function postCreate()
{
$timeline = new Note(
'timeline',
array(
'value' => '<div id="timeline">' . $this->buildTimeline() . '</div>'
)
);
$this->addElement($timeline); // Form::addElement adjusts the element's decorators
$timeline->clearDecorators();
$timeline->addDecorator('ViewHelper');
$legend = new Note(
'legend',
array(
'value' => '<div id="timelineLegend">' . $this->buildLegend() . '</div>'
)
);
$this->addElement($legend);
$legend->clearDecorators();
$legend->addDecorator('ViewHelper');
}
/** /**
* Build the legend * Build the legend
*/ */
@ -213,7 +160,7 @@ class TimeLine extends Form
/** /**
* Build the timeline * Build the timeline
*/ */
private function buildTimeline() public function buildTimeline()
{ {
$timelineGroups = array(); $timelineGroups = array();
foreach ($this->displayData as $group) { foreach ($this->displayData as $group) {
@ -261,8 +208,8 @@ class TimeLine extends Form
} }
} }
$timeframeUrl = $this->getRequest()->getBaseUrl() . '/monitoring/list/eventhistory?timestamp<=' . $timeframeUrl = '';/*$this->getRequest()->getBaseUrl() . '/monitoring/list/eventhistory?timestamp<=' .
$timeframe->start->getTimestamp() . '&timestamp>=' . $timeframe->end->getTimestamp(); $timeframe->start->getTimestamp() . '&timestamp>=' . $timeframe->end->getTimestamp();*/
$elements[] = sprintf( $elements[] = sprintf(
'<div class="row" style="height:%3$s%2$s;">%1$s</div>', '<div class="row" style="height:%3$s%2$s;">%1$s</div>',
implode('', $elementGroups), implode('', $elementGroups),
@ -318,18 +265,18 @@ class TimeLine extends Form
) )
); );
$this->calculationBase = $this->getRequest()->getParam('calculationBase', 1); $this->calculationBase = 1;//$this->getRequest()->getParam('calculationBase', 1);
while (log($highestValue, $this->calculationBase) > 100) { while (log($highestValue, $this->calculationBase) > 100) {
$this->calculationBase += 0.01; $this->calculationBase += 0.01;
} }
$this->addElement( /*$this->addElement(
'hidden', 'hidden',
'calculationBase', 'calculationBase',
array( array(
'value' => $this->calculationBase 'value' => $this->calculationBase
) )
); );*/
} }
return intval($this->circleDiameter * (log($eventCount, $this->calculationBase) / 100)); return intval($this->circleDiameter * (log($eventCount, $this->calculationBase) / 100));
@ -395,6 +342,16 @@ class TimeLine extends Form
} }
} }
public function setConfiguration($config)
{
$this->config = $config;
}
public function getConfiguration()
{
return $this->config;
}
/** /**
* Get the application's global configuration or an empty one * Get the application's global configuration or an empty one
* *
@ -419,6 +376,7 @@ class TimeLine extends Form
*/ */
private function getTimeFormat() private function getTimeFormat()
{ {
return 'g:i A';
$globalConfig = $this->getGlobalConfiguration(); $globalConfig = $this->getGlobalConfiguration();
$preferences = $this->getUserPreferences(); $preferences = $this->getUserPreferences();
return $preferences->get('app.timeFormat', $globalConfig->get('timeFormat', 'g:i A')); return $preferences->get('app.timeFormat', $globalConfig->get('timeFormat', 'g:i A'));
@ -431,6 +389,7 @@ class TimeLine extends Form
*/ */
private function getDateFormat() private function getDateFormat()
{ {
return 'd/m/Y';
$globalConfig = $this->getGlobalConfiguration(); $globalConfig = $this->getGlobalConfiguration();
$preferences = $this->getUserPreferences(); $preferences = $this->getUserPreferences();
return $preferences->get('app.dateFormat', $globalConfig->get('dateFormat', 'd/m/Y')); return $preferences->get('app.dateFormat', $globalConfig->get('dateFormat', 'd/m/Y'));