From eaa3c81f7ab68f7695a4bfd3dbebacc9efa4d0ef Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 22 Oct 2013 16:57:28 +0200 Subject: [PATCH] Fix bug that caused the detail view to stay open, even when nothing was selected fixes #4749 --- .../views/helpers/SelectionToolbar.php | 27 ++++ .../views/scripts/list/comments.phtml | 27 +++- .../views/scripts/list/contacts.phtml | 35 ++--- .../views/scripts/list/downtimes.phtml | 126 ++++++++++-------- .../views/scripts/list/eventhistory.phtml | 21 ++- .../views/scripts/list/hostgroups.phtml | 26 +++- .../views/scripts/list/hosts.phtml | 8 +- .../views/scripts/list/notifications.phtml | 26 +++- .../views/scripts/list/servicegroups.phtml | 27 +++- .../views/scripts/list/services.phtml | 4 +- public/js/icinga/components/container.js | 7 +- public/js/icinga/components/mainDetailGrid.js | 27 +++- public/js/icinga/selection/multiSelection.js | 1 + public/js/icinga/selection/selectable.js | 15 +++ public/js/icinga/util/url.js | 3 +- 15 files changed, 268 insertions(+), 112 deletions(-) create mode 100644 modules/monitoring/application/views/helpers/SelectionToolbar.php diff --git a/modules/monitoring/application/views/helpers/SelectionToolbar.php b/modules/monitoring/application/views/helpers/SelectionToolbar.php new file mode 100644 index 000000000..ce4aa2c34 --- /dev/null +++ b/modules/monitoring/application/views/helpers/SelectionToolbar.php @@ -0,0 +1,27 @@ + All + None '; + + } else if ($type == 'single') { + return 'Select None '; + + } else { + return ''; + } + } +} diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index 764f28863..dab2b4cd1 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -15,15 +15,26 @@ - -
- sortControl->render($this); ?> +
- paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> +
+
+ sortControl->render($this); ?> +
+
- +
+ paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> +
+ +
+ selectionToolbar('single'); ?> +
+ + +
- paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> -
\ No newline at end of file +
+ paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?> +
+
diff --git a/modules/monitoring/application/views/scripts/list/contacts.phtml b/modules/monitoring/application/views/scripts/list/contacts.phtml index 319c33937..096276c11 100644 --- a/modules/monitoring/application/views/scripts/list/contacts.phtml +++ b/modules/monitoring/application/views/scripts/list/contacts.phtml @@ -11,21 +11,21 @@ $contactHelper = $this->getHelper('ContactFlags');
- sortControl->render($this); ?> - paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?> - - - - - - - - - - - - - + +
+ +
+
+ sortControl->render($this); ?> +
+
+ +
+ paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?> +
+
+ +
Contact Name Alias Email Address Pager Address / Number Service Notification Options Host Notification Options Service Notification Period Host Notification Period
href('monitoring/show/contacts', array('contact' => $contact->contact_name)); ?> @@ -42,5 +42,8 @@ $contactHelper = $this->getHelper('ContactFlags');
- paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?> + +
+ paginationControl($contacts, null, null, array('preserve' => $this->preserve)); ?> +
diff --git a/modules/monitoring/application/views/scripts/list/downtimes.phtml b/modules/monitoring/application/views/scripts/list/downtimes.phtml index 0f14f1d27..02e381b41 100644 --- a/modules/monitoring/application/views/scripts/list/downtimes.phtml +++ b/modules/monitoring/application/views/scripts/list/downtimes.phtml @@ -9,63 +9,79 @@ $commandHelper = $this->getHelper('CommandForm'); tabs->render($this); ?> +
-
- sortControl->render($this); ?> + +
+
+
+ sortControl->render($this); ?> +
+
+ +
+ paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> +
+ +
+ selectionToolbar('single'); ?> +
-
- paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> - - - - - - - - - -
- dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> - - dateFormat()->formatDateTime((int) $downtime->downtime_end); ?> -
- Duration: util()->showHourMin((int) $downtime->downtime_duration); ?> -
- The downtime_is_flexible): ?>flexiblefixed downtime is downtime_is_in_effect): ?>not in effect -
- service)): ?> - service ?> - on host ?> - - host ?> - -
- downtime_author ?>: downtime_comment ?> -
- Entry Time: downtime_entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->downtime_entry_time) : ''; ?> - -
- $downtime->downtime_internal_downtime_id, - 'host' => $downtime->host - ); - if (isset($downtime->service)) { - $data['service'] = $downtime->service; - } - echo $commandHelper->iconSubmitForm( - 'icinga-icon-remove', - 'Remove Downtime', - 'btn-small', - 'removedowntime', - $data - ); - ?> -
+ + paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> + + + + + + + + + +
+ dateFormat()->formatDateTime((int) $downtime->downtime_start); ?> - + dateFormat()->formatDateTime((int) $downtime->downtime_end); ?> +
+ Duration: util()->showHourMin((int) $downtime->downtime_duration); ?> +
+ The downtime_is_flexible): ?>flexiblefixed downtime is downtime_is_in_effect): ?>not in effect +
+ service)): ?> + service ?> + on host ?> + + host ?> + +
+ downtime_author ?>: downtime_comment ?> +
+ Entry Time: downtime_entry_time) ? $this->dateFormat()->formatDateTime((int) $downtime->downtime_entry_time) : ''; ?> + +
+ $downtime->downtime_internal_downtime_id, + 'host' => $downtime->host + ); + if (isset($downtime->service)) { + $data['service'] = $downtime->service; + } + echo $commandHelper->iconSubmitForm( + 'icinga-icon-remove', + 'Remove Downtime', + 'btn-small', + 'removedowntime', + $data + ); + ?> +
+ +
paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
diff --git a/modules/monitoring/application/views/scripts/list/eventhistory.phtml b/modules/monitoring/application/views/scripts/list/eventhistory.phtml index f93dd79cb..757358009 100644 --- a/modules/monitoring/application/views/scripts/list/eventhistory.phtml +++ b/modules/monitoring/application/views/scripts/list/eventhistory.phtml @@ -7,9 +7,18 @@
-
- paginationControl($history, null, null, array('preserve' => $this->preserve)); ?> - +
+ +
+
+ paginationControl($history, null, null, array('preserve' => $this->preserve)); ?> +
+
+ selectionToolbar('single'); ?> +
+
+ +
- paginationControl($history, null, null, array('preserve' => $this->preserve)); ?> + +
+ paginationControl($history, null, null, array('preserve' => $this->preserve)); ?> +
+
diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 0f7bc6c1a..c48cc23d4 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -6,10 +6,25 @@ tabs->render($this); ?> +
- sortControl->render($this); ?> - paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?> - +
+
+
+ sortControl->render($this); ?> +
+
+ +
+ paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?> +
+ +
+ selectionToolbar('single'); ?> +
+
+ +
@@ -90,5 +105,8 @@
- paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?> + +
+ paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?> +
diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 312187393..2383db43c 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -15,19 +15,19 @@ $viewHelper = $this->getHelper('MonitoringState');
- filterBox->render($this); ?> + filterBox->render($this); ?>
sortControl->render($this); ?>
+
paginationControl($hosts, null, null, array('preserve' => $this->preserve)); ?>
+
- Select - '*' ))?>'> All - None + selectionToolbar('multi', $this->href('monitoring/multi/host',array( 'host' => '*' ))); ?>
diff --git a/modules/monitoring/application/views/scripts/list/notifications.phtml b/modules/monitoring/application/views/scripts/list/notifications.phtml index b3f5651e1..dc5267829 100644 --- a/modules/monitoring/application/views/scripts/list/notifications.phtml +++ b/modules/monitoring/application/views/scripts/list/notifications.phtml @@ -9,9 +9,24 @@
- sortControl->render($this); ?> - paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?> - + +
+
+
+ sortControl->render($this); ?> +
+
+ +
+ paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?> +
+ +
+ selectionToolbar('single'); ?> +
+
+ +
- paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?> + +
+ paginationControl($notifications, null, null, array('preserve' => $this->preserve)); ?> +
No notifications yet diff --git a/modules/monitoring/application/views/scripts/list/servicegroups.phtml b/modules/monitoring/application/views/scripts/list/servicegroups.phtml index 7d2bf7385..54b20f238 100644 --- a/modules/monitoring/application/views/scripts/list/servicegroups.phtml +++ b/modules/monitoring/application/views/scripts/list/servicegroups.phtml @@ -6,11 +6,25 @@ tabs->render($this); ?> -
- sortControl->render($this); ?> - paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?> - + +
+
+
+ sortControl->render($this); ?> +
+
+ +
+ paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?> +
+ +
+ selectionToolbar('single'); ?> +
+
+ +
@@ -91,5 +105,8 @@
- paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?> + +
+ paginationControl($servicegroups, null, null, array('preserve' => $this->preserve)); ?> +
diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 980b57462..f1c285b6f 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -24,9 +24,7 @@ $viewHelper = $this->getHelper('MonitoringState'); paginationControl($services, null, null, array('preserve' => $this->preserve)); ?>
- Select - '*', 'service' => '*' ))?>'> All - None + selectionToolbar('multi', $this->href('monitoring/multi/service', array( 'service' => '*', 'host' => '*' ))); ?>
diff --git a/public/js/icinga/components/container.js b/public/js/icinga/components/container.js index cd5a0f337..a056e040a 100644 --- a/public/js/icinga/components/container.js +++ b/public/js/icinga/components/container.js @@ -455,7 +455,12 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe $(window).on('hashchange', (function() { urlMgr.syncWithUrl(); - Container.getDetailContainer().replaceDomAsync(urlMgr.detailUrl); + if (urlMgr.detailUrl) { + Container.getDetailContainer().replaceDomAsync(urlMgr.detailUrl); + } else { + Container.hideDetail(); + } + })); diff --git a/public/js/icinga/components/mainDetailGrid.js b/public/js/icinga/components/mainDetailGrid.js index a75845ecf..45c5b9255 100644 --- a/public/js/icinga/components/mainDetailGrid.js +++ b/public/js/icinga/components/mainDetailGrid.js @@ -167,9 +167,11 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection this.registerTableLinks = function(domContext) { domContext = domContext || contentNode; - $('tbody tr', domContext).on('click', function(ev) { + $('tbody tr', domContext).click(function(ev) { var targetEl = ev.target || ev.toElement || ev.relatedTarget, a = $(targetEl).closest('a'); + ev.preventDefault(); + ev.stopPropagation(); var nodeNames = []; nodeNames.push($(targetEl).prop('nodeName').toLowerCase()); @@ -189,15 +191,13 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection switch (selectionMode) { case 'multi': - var selectable = new Selectable(this); if (ev.ctrlKey || ev.metaKey) { - selection.toggle(selectable); + selection.toggle(new Selectable(this)); } else if (ev.shiftKey) { - // select range ? - selection.add(selectable); + selection.add(new Selectable(this)); } else { selection.clear(); - selection.add(selectable); + selection.add(new Selectable(this)); } break; @@ -217,7 +217,8 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection var segments = url.segment(); if (selection.size() === 0) { // don't open anything - url.search('?'); + urlMgr.setDetailUrl(''); + return false; } else if (selection.size() > 1 && segments.length > 3) { // open detail view for multiple objects segments[2] = 'multi'; @@ -228,6 +229,18 @@ function(Container, $, logger, URI, tpl, urlMgr, Selectable, TableMultiSelection urlMgr.setDetailUrl(url); 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(); + } + }); }; /** diff --git a/public/js/icinga/selection/multiSelection.js b/public/js/icinga/selection/multiSelection.js index 486e1fc79..9cba2bdcd 100644 --- a/public/js/icinga/selection/multiSelection.js +++ b/public/js/icinga/selection/multiSelection.js @@ -43,6 +43,7 @@ function($, URI, Selectable) { * @param {URI} The query that contains the selected rows. */ return function MultiSelection(table, detailUrl) { + var self = this; /** * Contains all selected selectables diff --git a/public/js/icinga/selection/selectable.js b/public/js/icinga/selection/selectable.js index 098e59d32..61f06e675 100644 --- a/public/js/icinga/selection/selectable.js +++ b/public/js/icinga/selection/selectable.js @@ -72,6 +72,11 @@ define(['jquery', 'URIjs/URI'], function($, URI) { return href.query(true); }; + /** + * Set the current selection state + * + * @param {boolean} The new state + */ this.setActive = function(value) { if (value) { $(tableRow).addClass('active'); @@ -79,5 +84,15 @@ define(['jquery', 'URIjs/URI'], function($, URI) { $(tableRow).removeClass('active'); } }; + + /** + * Return the current selection state + * + * @returns {boolean} True when the object is selected + */ + this.isActive = function() + { + return $(tableRow).hasClass('active'); + }; }; }); \ No newline at end of file diff --git a/public/js/icinga/util/url.js b/public/js/icinga/util/url.js index 7fb337a33..a1e9714b7 100644 --- a/public/js/icinga/util/url.js +++ b/public/js/icinga/util/url.js @@ -25,7 +25,7 @@ */ // {{{ICINGA_LICENSE_HEADER}}} -define(['jquery', 'URIjs/URI'], function($, URI, Container) { +define(['jquery', 'logging', 'URIjs/URI'], function($, log, URI, Container) { "use strict"; var currentUrl = URI(window.location.href); @@ -126,7 +126,6 @@ define(['jquery', 'URIjs/URI'], function($, URI, Container) { this.detailUrl = url.clone().fragment('').href(); } this.detailAnchor = this.getMainAnchor(url); - window.location.hash = this.getUrlHash(); };