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\Web\Widget;
use Icinga\Module\Monitoring\Web\Widget\SelectBox;
use Icinga\Module\Monitoring\Form\StatehistoryForm;
class Monitoring_ListController extends Controller
{
@ -360,59 +361,17 @@ class Monitoring_ListController extends Controller
public function statehistorysummaryAction()
{
$this->view->from = $this->params->shift('from', '3 months ago');
$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(
'statehistoryfilter',
array(
'critical' => t('Critical'),
'warning' => t('Warning'),
'unknown' => t('Unknown'),
'ok' => t('Ok')
),
t('Events'),
'event'
);
$eventBox->applyRequest($this->getRequest());
$form = new StatehistoryForm();
$form->setEnctype(Zend_Form::ENCTYPE_URLENCODED);
$form->setMethod('get');
$form->setTokenDisabled();
$form->setRequest($this->getRequest());
$form->buildForm();
$this->view->form = $form;
$orientation = $this->params->shift('horizontal', 0) ? 'horizontal' : 'vertical';
$orientationBox = new SelectBox(
'orientation',
@ -425,35 +384,20 @@ class Monitoring_ListController extends Controller
);
$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(
'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->view->orientationBox = $orientationBox;
$this->view->eventBox = $eventBox;
$this->view->selection = $selection;
$this->view->orientation = $orientation;
$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()
@ -735,6 +679,7 @@ class Monitoring_ListController extends Controller
'hosts',
'services',
'eventhistory',
'statehistorysummary',
'notifications'
))) {
$tabs->extend(new OutputFormat())->extend(new DashboardAction());

View File

@ -9,9 +9,7 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
<?= $this->tabs->render($this); ?>
<div class="fake-controls">
<br />
<?= $intervalBox ?>
<?= $eventBox; ?>
<?= $orientationBox; ?>
<?= $form ?>
</div>
</div>
<? endif; ?>
@ -19,34 +17,75 @@ use Icinga\Web\Widget\Chart\HistoryColorGrid;
<div class="content" data-base-target="_next">
<?php
$from = strtotime($from);
$to = time();
$settings = array(
'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();
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) {
$day = $entry->day;
$value = $entry->{$selection['column']};
$value = $entry->$column;
$caption = sprintf(
$selection['tooltip'],
$settings[$column]['tooltip'],
$value,
$this->dateFormat()->formatDate(strtotime($day))
);
$filter = Filter::matchAll(
$linkFilter = Filter::matchAll(
Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')),
Filter::expression('timestamp', '>', strtotime($day . ' 00:00:00')),
Filter::matchAny(
Filter::expression('type', '=', 'hard_state'),
Filter::expression('type', '=', 'hard_state')
),
$selection['filter']
$form->getFilter(),
$filter
);
$data[$day] = array(
'value' => $value,
'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'));
}
$grid = new HistoryColorGrid(null, $f->getTimestamp(), $end->getTimestamp());
$grid->setColor($selection['color']);
$grid->opacity = $selection['opacity'];
$grid->setColor($settings[$column]['color']);
$grid->opacity = $settings[$column]['opacity'];
$grid->orientation = $orientation;
$grid->setData($data);
$grids[] = $grid;