Fix bug that caused the detail view to stay open, even when nothing was selected

fixes #4749
This commit is contained in:
Matthias Jentsch 2013-10-22 16:57:28 +02:00
parent a3099c82f2
commit eaa3c81f7a
15 changed files with 268 additions and 112 deletions

View File

@ -0,0 +1,27 @@
<?php
class Zend_View_Helper_SelectionToolbar extends Zend_View_Helper_Abstract
{
/**
* Create a selection toolbar
*
* @param $type
* @param null $target
*
* @return string
*/
public function selectionToolbar($type, $target = null)
{
if ($type == 'multi') {
return 'Select
<a href="' . $target . '"> All </a>
<a href="#"> None </a>';
} else if ($type == 'single') {
return 'Select <a href="#"> None </a>';
} else {
return '';
}
}
}

View File

@ -15,15 +15,26 @@
</div> </div>
</div> </div>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->sortControl->render($this); ?> <div class="container pull-left">
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> <div class="row">
<div class="col-md-12">
<?= $this->sortControl->render($this); ?>
</div>
</div>
<table class="table table-condensed"> <div class="row">
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div>
<table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach ($comments as $comment): ?> <?php foreach ($comments as $comment): ?>
<?php <?php
@ -145,5 +156,7 @@
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> <div class="container pull-left">
</div> <?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div>

View File

@ -11,21 +11,21 @@ $contactHelper = $this->getHelper('ContactFlags');
</div> </div>
</div> </div>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="none"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="none">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?> <div class="container pull-left">
<table class="table table-condensed">
<thead> <div class="row">
<tr> <div class="col-md-12">
<th> Contact Name </th> <?= $this->sortControl->render($this); ?>
<th> Alias </th> </div>
<th> Email Address </th> </div>
<th> Pager Address / Number </th>
<th> Service Notification Options </th> <div class="row">
<th> Host Notification Options </th> <?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?>
<th> Service Notification Period </th> </div>
<th> Host Notification Period </th> </div>
</tr>
</thead> <table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach($contacts as $contact): ?> <?php foreach($contacts as $contact): ?>
<?php $periodLink = $this->href('monitoring/show/contacts', array('contact' => $contact->contact_name)); ?> <?php $periodLink = $this->href('monitoring/show/contacts', array('contact' => $contact->contact_name)); ?>
@ -42,5 +42,8 @@ $contactHelper = $this->getHelper('ContactFlags');
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?>
<div class="pull-left">
<?= $this->paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div> </div>

View File

@ -9,63 +9,79 @@ $commandHelper = $this->getHelper('CommandForm');
<?= $this->tabs->render($this); ?> <?= $this->tabs->render($this); ?>
</div> </div>
</div> </div>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<div>
<?= $this->sortControl->render($this); ?> <div class="container pull-left">
<div class="row">
<div class="col-md-12">
<?= $this->sortControl->render($this); ?>
</div>
</div>
<div class="row">
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div> </div>
<div>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> <?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed"> <table class="table table-condensed">
<tbody> <tbody>
<?php foreach ($downtimes as $downtime): ?> <?php foreach ($downtimes as $downtime): ?>
<tr> <tr>
<td> <td>
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> - <?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> -
<?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_end); ?> <?= $this->dateFormat()->formatDateTime((int) $downtime->downtime_end); ?>
<br /> <br />
<small>Duration: <?= $this->util()->showHourMin((int) $downtime->downtime_duration); ?></small> <small>Duration: <?= $this->util()->showHourMin((int) $downtime->downtime_duration); ?></small>
<br /> <br />
<small>The <?php if($downtime->downtime_is_flexible): ?>flexible<?php else: ?>fixed<?php endif; ?> downtime is <?php if(!$downtime->downtime_is_in_effect): ?>not <?php endif; ?>in effect</small> <small>The <?php if($downtime->downtime_is_flexible): ?>flexible<?php else: ?>fixed<?php endif; ?> downtime is <?php if(!$downtime->downtime_is_in_effect): ?>not <?php endif; ?>in effect</small>
</td> </td>
<td> <td>
<?php if (isset($downtime->service)): ?> <?php if (isset($downtime->service)): ?>
<a href="<?= $this->href('monitoring/show/service', array( <a href="<?= $this->href('monitoring/show/service', array(
'host' => (string) $downtime->host, 'host' => (string) $downtime->host,
'service' => (string) $downtime->service 'service' => (string) $downtime->service
)); ?>"><?= $downtime->service ?></a> )); ?>"><?= $downtime->service ?></a>
<small>on <?= $downtime->host ?></small> <small>on <?= $downtime->host ?></small>
<?php else: ?> <?php else: ?>
<a href="<?= $this->href('monitoring/show/host', array( <a href="<?= $this->href('monitoring/show/host', array(
'host' => (string) $downtime->host 'host' => (string) $downtime->host
)); ?>"><?= $downtime->host ?> </a> )); ?>"><?= $downtime->host ?> </a>
<?php endif; ?> <?php endif; ?>
<br /> <br />
<?= $downtime->downtime_author ?>: <?= $downtime->downtime_comment ?> <?= $downtime->downtime_author ?>: <?= $downtime->downtime_comment ?>
<br /> <br />
<small>Entry Time: <?= ($downtime->downtime_entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->downtime_entry_time) : ''; ?> <small>Entry Time: <?= ($downtime->downtime_entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->downtime_entry_time) : ''; ?>
</small> </small>
<td> <td>
<?php <?php
$data = array( $data = array(
'downtimeid' => $downtime->downtime_internal_downtime_id, 'downtimeid' => $downtime->downtime_internal_downtime_id,
'host' => $downtime->host 'host' => $downtime->host
); );
if (isset($downtime->service)) { if (isset($downtime->service)) {
$data['service'] = $downtime->service; $data['service'] = $downtime->service;
} }
echo $commandHelper->iconSubmitForm( echo $commandHelper->iconSubmitForm(
'icinga-icon-remove', 'icinga-icon-remove',
'Remove Downtime', 'Remove Downtime',
'btn-small', 'btn-small',
'removedowntime', 'removedowntime',
$data $data
); );
?> ?>
</td> </td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>
</tbody> </tbody>
</table> </table>
<div class="container pull-left">
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> <?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
</div> </div>
</div> </div>

View File

@ -7,9 +7,18 @@
</div> </div>
</div> </div>
<?php if (!empty($history)): ?> <?php if (!empty($history)): ?>
<div data-icinga-component="app/mainDetailGrid"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
<table class="table table-condensed"> <div class="container pull-left">
<div class="row">
<?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div>
<table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach ($history as $event): ?> <?php foreach ($history as $event): ?>
<?php <?php
@ -106,6 +115,10 @@
<? endforeach; ?> <? endforeach; ?>
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
<div class="container pull-left">
<?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@ -6,10 +6,25 @@
<?= $this->tabs->render($this); ?> <?= $this->tabs->render($this); ?>
</div> </div>
</div> </div>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->sortControl->render($this); ?> <div class="container pull-left">
<?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?> <div class="row">
<table> <div class="col-md-12">
<?= $this->sortControl->render($this); ?>
</div>
</div>
<div class="row">
<?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div>
<table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach($hostgroups as $hostgroup): ?> <?php foreach($hostgroups as $hostgroup): ?>
<tr> <tr>
@ -90,5 +105,8 @@
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?>
<div class="container pull-left">
<?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div> </div>

View File

@ -15,19 +15,19 @@ $viewHelper = $this->getHelper('MonitoringState');
<div class="container pull-left"> <div class="container pull-left">
<div class="row"> <div class="row">
<div class="col-md-5"> <div class="col-md-5">
<?= $this->filterBox->render($this); ?> <?= $this->filterBox->render($this); ?>
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
<?= $this->sortControl->render($this); ?> <?= $this->sortControl->render($this); ?>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)); ?> <?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)); ?>
</div> </div>
<div class="row"> <div class="row">
Select <?= $this->selectionToolbar('multi', $this->href('monitoring/multi/host',array( 'host' => '*' ))); ?>
<a href='<?=$this->href('monitoring/multi/host',array( 'host' => '*' ))?>'> All </a>
<a href='#'> None </a>
</div> </div>
</div> </div>

View File

@ -9,9 +9,24 @@
<?php if (!empty($notifications)): ?> <?php if (!empty($notifications)): ?>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?> <div class="container pull-left">
<table class="table table-condensed" > <div class="row">
<div class="col-md-12">
<?= $this->sortControl->render($this); ?>
</div>
</div>
<div class="row">
<?= $this->paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div>
<table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach ($notifications as $notification): ?> <?php foreach ($notifications as $notification): ?>
<?php <?php
@ -56,7 +71,10 @@
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?>
<div class="container pull-left">
<?= $this->paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div> </div>
<?php else: ?> <?php else: ?>
No notifications yet No notifications yet

View File

@ -6,11 +6,25 @@
<?= $this->tabs->render($this); ?> <?= $this->tabs->render($this); ?>
</div> </div>
</div> </div>
<div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single"> <div data-icinga-component="app/mainDetailGrid" data-icinga-grid-selection-type="single">
<?= $this->sortControl->render($this); ?>
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?> <div class="container pull-left">
<table> <div class="row">
<div class="col-md-12">
<?= $this->sortControl->render($this); ?>
</div>
</div>
<div class="row">
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="row">
<?= $this->selectionToolbar('single'); ?>
</div>
</div>
<table class="table table-condensed pull-left">
<tbody> <tbody>
<?php foreach($servicegroups as $servicegroup): ?> <?php foreach($servicegroups as $servicegroup): ?>
<tr> <tr>
@ -91,5 +105,8 @@
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?>
<div class="container pull-left">
<?= $this->paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?>
</div>
</div> </div>

View File

@ -24,9 +24,7 @@ $viewHelper = $this->getHelper('MonitoringState');
<?= $this->paginationControl($services, null, null, array('preserve' => $this->preserve)); ?> <?= $this->paginationControl($services, null, null, array('preserve' => $this->preserve)); ?>
</div> </div>
<div class="row"> <div class="row">
Select <?= $this->selectionToolbar('multi', $this->href('monitoring/multi/service', array( 'service' => '*', 'host' => '*' ))); ?>
<a href='<?=$this->href('monitoring/multi/service',array( 'host' => '*', 'service' => '*' ))?>'> All </a>
<a href='#'> None </a>
</div> </div>
</div> </div>

View File

@ -455,7 +455,12 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
$(window).on('hashchange', (function() { $(window).on('hashchange', (function() {
urlMgr.syncWithUrl(); urlMgr.syncWithUrl();
Container.getDetailContainer().replaceDomAsync(urlMgr.detailUrl); if (urlMgr.detailUrl) {
Container.getDetailContainer().replaceDomAsync(urlMgr.detailUrl);
} else {
Container.hideDetail();
}
})); }));

View File

@ -167,9 +167,11 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection
this.registerTableLinks = function(domContext) { this.registerTableLinks = function(domContext) {
domContext = domContext || contentNode; domContext = domContext || contentNode;
$('tbody tr', domContext).on('click', function(ev) { $('tbody tr', domContext).click(function(ev) {
var targetEl = ev.target || ev.toElement || ev.relatedTarget, var targetEl = ev.target || ev.toElement || ev.relatedTarget,
a = $(targetEl).closest('a'); a = $(targetEl).closest('a');
ev.preventDefault();
ev.stopPropagation();
var nodeNames = []; var nodeNames = [];
nodeNames.push($(targetEl).prop('nodeName').toLowerCase()); nodeNames.push($(targetEl).prop('nodeName').toLowerCase());
@ -189,15 +191,13 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection
switch (selectionMode) { switch (selectionMode) {
case 'multi': case 'multi':
var selectable = new Selectable(this);
if (ev.ctrlKey || ev.metaKey) { if (ev.ctrlKey || ev.metaKey) {
selection.toggle(selectable); selection.toggle(new Selectable(this));
} else if (ev.shiftKey) { } else if (ev.shiftKey) {
// select range ? selection.add(new Selectable(this));
selection.add(selectable);
} else { } else {
selection.clear(); selection.clear();
selection.add(selectable); selection.add(new Selectable(this));
} }
break; break;
@ -217,7 +217,8 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection
var segments = url.segment(); var segments = url.segment();
if (selection.size() === 0) { if (selection.size() === 0) {
// don't open anything // don't open anything
url.search('?'); urlMgr.setDetailUrl('');
return false;
} else if (selection.size() > 1 && segments.length > 3) { } else if (selection.size() > 1 && segments.length > 3) {
// open detail view for multiple objects // open detail view for multiple objects
segments[2] = 'multi'; segments[2] = 'multi';
@ -228,6 +229,18 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection
urlMgr.setDetailUrl(url); urlMgr.setDetailUrl(url);
return false; return false;
}); });
/*
* Clear the URL when deselected or when a wildcard is used
*/
$(window).on('hashchange', function(){
if (
!location.hash ||
location.hash.match(/(host=%2A)|(service=%2A)/)
) {
selection.clear();
}
});
}; };
/** /**

View File

@ -43,6 +43,7 @@ function($, URI, Selectable) {
* @param {URI} The query that contains the selected rows. * @param {URI} The query that contains the selected rows.
*/ */
return function MultiSelection(table, detailUrl) { return function MultiSelection(table, detailUrl) {
var self = this; var self = this;
/** /**
* Contains all selected selectables * Contains all selected selectables

View File

@ -72,6 +72,11 @@ define(['jquery', 'URIjs/URI'], function($, URI) {
return href.query(true); return href.query(true);
}; };
/**
* Set the current selection state
*
* @param {boolean} The new state
*/
this.setActive = function(value) { this.setActive = function(value) {
if (value) { if (value) {
$(tableRow).addClass('active'); $(tableRow).addClass('active');
@ -79,5 +84,15 @@ define(['jquery', 'URIjs/URI'], function($, URI) {
$(tableRow).removeClass('active'); $(tableRow).removeClass('active');
} }
}; };
/**
* Return the current selection state
*
* @returns {boolean} True when the object is selected
*/
this.isActive = function()
{
return $(tableRow).hasClass('active');
};
}; };
}); });

View File

@ -25,7 +25,7 @@
*/ */
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
define(['jquery', 'URIjs/URI'], function($, URI, Container) { define(['jquery', 'logging', 'URIjs/URI'], function($, log, URI, Container) {
"use strict"; "use strict";
var currentUrl = URI(window.location.href); var currentUrl = URI(window.location.href);
@ -126,7 +126,6 @@ define(['jquery', 'URIjs/URI'], function($, URI, Container) {
this.detailUrl = url.clone().fragment('').href(); this.detailUrl = url.clone().fragment('').href();
} }
this.detailAnchor = this.getMainAnchor(url); this.detailAnchor = this.getMainAnchor(url);
window.location.hash = this.getUrlHash(); window.location.hash = this.getUrlHash();
}; };