Move SelectBoxes into form

This commit is contained in:
Matthias Jentsch 2014-09-17 18:21:32 +02:00
parent 6f1cb6f1f3
commit 7385be06ea
2 changed files with 76 additions and 92 deletions

View File

@ -15,6 +15,7 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Web\Widget; use Icinga\Web\Widget;
use Icinga\Module\Monitoring\Web\Widget\SelectBox; use Icinga\Module\Monitoring\Web\Widget\SelectBox;
use Icinga\Module\Monitoring\Form\StatehistoryForm;
class Monitoring_ListController extends Controller class Monitoring_ListController extends Controller
{ {
@ -360,59 +361,17 @@ class Monitoring_ListController extends Controller
public function statehistorysummaryAction() public function statehistorysummaryAction()
{ {
$this->view->from = $this->params->shift('from', '3 months ago');
$this->addTitleTab('statehistorysummary', 'State Summary'); $this->addTitleTab('statehistorysummary', 'State Summary');
$selections = array(
'critical' => array(
'column' => 'cnt_critical',
'filter' => Filter::matchAll(
Filter::expression('object_type', '=', 'service'),
Filter::expression('state', '=', '2')
),
'tooltip' => t('%d critical events on %s'),
'color' => '#ff5566', 'opacity' => '0.9'
),
'warning' => array(
'column' => 'cnt_warning',
'filter' => Filter::matchAll(
Filter::expression('object_type', '=', 'service'),
Filter::expression('state', '=', '1')
),
'tooltip' => t('%d warning events on %s'),
'color' => '#ffaa44', 'opacity' => '1.0'
),
'unknown' => array(
'column' => 'cnt_unknown',
'filter' => Filter::matchAll(
Filter::expression('object_type', '=', 'service'),
Filter::expression('state', '=', '3')
),
'tooltip' => t('%d unknown events on %s'),
'color' => '#cc77ff', 'opacity' => '0.7'
),
'ok' => array(
'column' => 'cnt_ok',
'filter' => Filter::matchAll(
Filter::expression('object_type', '=', 'service'),
Filter::expression('state', '=', '0')
),
'tooltip' => t('%d ok events on %s'),
'color' => '#49DF96', 'opacity' => '0.55'
)
);
$eventBox = new SelectBox( $form = new StatehistoryForm();
'statehistoryfilter', $form->setEnctype(Zend_Form::ENCTYPE_URLENCODED);
array( $form->setMethod('get');
'critical' => t('Critical'), $form->setTokenDisabled();
'warning' => t('Warning'), $form->setRequest($this->getRequest());
'unknown' => t('Unknown'), $form->buildForm();
'ok' => t('Ok') $this->view->form = $form;
),
t('Events'), $orientation = $this->params->shift('horizontal', 0) ? 'horizontal' : 'vertical';
'event'
);
$eventBox->applyRequest($this->getRequest());
$orientationBox = new SelectBox( $orientationBox = new SelectBox(
'orientation', 'orientation',
@ -425,35 +384,20 @@ class Monitoring_ListController extends Controller
); );
$orientationBox->applyRequest($this->getRequest()); $orientationBox->applyRequest($this->getRequest());
$intervalBox = new SelectBox(
'from',
array(
'3 months ago' => t('3 Months'),
'4 months ago' => t('4 Months'),
'8 months ago' => t('8 Months'),
'12 months ago' => t('1 Year'),
'24 months ago' => t('2 Years')
),
t('Interval'),
'from'
);
$intervalBox->applyRequest($this->getRequest());
$eventtype = $this->params->shift('event', 'critical');
$orientation = $this->params->shift('horizontal', 0) ? 'horizontal' : 'vertical';
$selection = $selections[$eventtype];
$query = $this->backend->select()->from( $query = $this->backend->select()->from(
'stateHistorySummary', 'stateHistorySummary',
array('day', $selection['column']) array('day', $form->getValue('state'))
); );
$this->params->shift('objecttype');
$this->params->shift('from');
$this->params->shift('to');
$this->params->shift('state');
$this->params->shift('btn_submit');
$this->applyFilters($query); $this->applyFilters($query);
$this->view->orientationBox = $orientationBox;
$this->view->eventBox = $eventBox;
$this->view->selection = $selection;
$this->view->orientation = $orientation;
$this->view->summary = $query->getQuery()->fetchAll(); $this->view->summary = $query->getQuery()->fetchAll();
$this->view->intervalBox = $intervalBox; $this->view->column = $form->getValue('state');
$this->view->orientationBox = $orientationBox;
$this->view->orientation = $orientation;
} }
public function contactgroupsAction() public function contactgroupsAction()
@ -735,6 +679,7 @@ class Monitoring_ListController extends Controller
'hosts', 'hosts',
'services', 'services',
'eventhistory', 'eventhistory',
'statehistorysummary',
'notifications' 'notifications'
))) { ))) {
$tabs->extend(new OutputFormat())->extend(new DashboardAction()); $tabs->extend(new OutputFormat())->extend(new DashboardAction());

View File

@ -9,9 +9,7 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
<?= $this->tabs->render($this); ?> <?= $this->tabs->render($this); ?>
<div class="fake-controls"> <div class="fake-controls">
<br /> <br />
<?= $intervalBox ?> <?= $form ?>
<?= $eventBox; ?>
<?= $orientationBox; ?>
</div> </div>
</div> </div>
<? endif; ?> <? endif; ?>
@ -19,34 +17,75 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
<div class="content" data-base-target="_next"> <div class="content" data-base-target="_next">
<?php <?php
$from = strtotime($from); $settings = array(
$to = time(); 'cnt_up' => array(
'tooltip' => t('%d ok states on %s'),
'color' => '#49DF96',
'opacity' => '0.55'
),
'cnt_down_hard' => array(
'tooltip' => t('%d ok states on %s'),
'color' => '#ff5566',
'opacity' => '0.7'
),
'cnt_unreachable_hard' => array(
'tooltip' => t('%d ok states on %s'),
'color' => '#77AAFF',
'opacity' => '0.55'
),
'cnt_critical_hard' => array(
'tooltip' => t('%d critical states on %s'),
'color' => '#ff5566',
'opacity' => '0.9'
),
'cnt_warning_hard' => array(
'tooltip' => t('%d warning states on %s'),
'color' => '#ffaa44',
'opacity' => '1.0'
),
'cnt_unknown_hard' => array(
'tooltip' => t('%d unknown states on %s'),
'color' => '#cc77ff',
'opacity' => '0.7'
),
'cnt_ok' => array(
'tooltip' => t('%d ok states on %s'),
'color' => '#49DF96',
'opacity' => '0.55'
)
);
$from = intval($form->getValue('from', strtotime('3 months ago')));
$to = intval($form->getValue('to', time()));
// don't display more than ten years, or else this will get really slow
if ($to - $from > 315360000) {
$from = $to - 315360000;
}
$data = array(); $data = array();
if (count($summary) === 0) { if (count($summary) === 0) {
echo t('No events in the selected time period.'); echo t('No state changes in the selected time period.');
} }
foreach ($summary as $entry) { foreach ($summary as $entry) {
$day = $entry->day; $day = $entry->day;
$value = $entry->{$selection['column']}; $value = $entry->$column;
$caption = sprintf( $caption = sprintf(
$selection['tooltip'], $settings[$column]['tooltip'],
$value, $value,
$this->dateFormat()->formatDate(strtotime($day)) $this->dateFormat()->formatDate(strtotime($day))
); );
$filter = Filter::matchAll( $linkFilter = Filter::matchAll(
Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')), Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')),
Filter::expression('timestamp', '>', strtotime($day . ' 00:00:00')), Filter::expression('timestamp', '>', strtotime($day . ' 00:00:00')),
Filter::matchAny( $form->getFilter(),
Filter::expression('type', '=', 'hard_state'), $filter
Filter::expression('type', '=', 'hard_state')
),
$selection['filter']
); );
$data[$day] = array( $data[$day] = array(
'value' => $value, 'value' => $value,
'caption' => $caption, 'caption' => $caption,
'url' => $this->href('monitoring/list/eventhistory?' . $filter->toQueryString()) 'url' => $this->href('monitoring/list/eventhistory?' . $linkFilter->toQueryString())
); );
} }
@ -67,8 +106,8 @@ for ($i = 0; $i < $diff->days; $i += $step) {
$end->add(new DateInterval('P' . ($diff->days - $i) . 'D')); $end->add(new DateInterval('P' . ($diff->days - $i) . 'D'));
} }
$grid = new HistoryColorGrid(null, $f->getTimestamp(), $end->getTimestamp()); $grid = new HistoryColorGrid(null, $f->getTimestamp(), $end->getTimestamp());
$grid->setColor($selection['color']); $grid->setColor($settings[$column]['color']);
$grid->opacity = $selection['opacity']; $grid->opacity = $settings[$column]['opacity'];
$grid->orientation = $orientation; $grid->orientation = $orientation;
$grid->setData($data); $grid->setData($data);
$grids[] = $grid; $grids[] = $grid;