[icinga-checkins] icinga.org: icingaweb2/feature/actiontable-row-handline-13115: actiontable : gracefully clear and improve...

git at icinga.org git at icinga.org
Wed Nov 9 20:17:20 CET 2016


Module: icingaweb2
Branch: feature/actiontable-row-handline-13115
Commit: d2710cfb0259a84fb7cfadd6d0e39e436cef2f2b
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=d2710cfb0259a84fb7cfadd6d0e39e436cef2f2b

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed Nov  9 19:16:00 2016 +0000

actiontable: gracefully clear and improve...

...state preservation

refs #13115

---

 public/js/icinga/behavior/actiontable.js |   42 ++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/public/js/icinga/behavior/actiontable.js b/public/js/icinga/behavior/actiontable.js
index a7fc06a..980a78d 100644
--- a/public/js/icinga/behavior/actiontable.js
+++ b/public/js/icinga/behavior/actiontable.js
@@ -255,15 +255,36 @@
          * @param   url     {String}    The target url
          */
         selectUrl: function(url) {
+            var formerHref = this.$el.closest('.container').data('icinga-actiontable-former-href')
+
             var $row = this.rows().filter('[href="' + url + '"]');
+
             if ($row.length) {
+               this.clear();
                $row.addClass('active');
             } else {
-                // rows sometimes need to be displayed as active when related actions
-                // like command actions are being opened. Do not do this for col2, as it
-                // would always select the opened URL itself.
                 if (this.col !== 'col2') {
-                    this.rows().filter('[href$="' + icinga.utils.parseUrl(url).query + '"]').addClass('active');
+                    // rows sometimes need to be displayed as active when related actions
+                    // like command actions are being opened. Do not do this for col2, as it
+                    // would always select the opened URL itself.
+                    var $row = this.rows().filter('[href$="' + icinga.utils.parseUrl(url).query + '"]');
+                    if ($row.length) {
+                        this.clear();
+                        $row.addClass('active');
+                    } else {
+                        var $row = this.rows().filter('[href$="' + formerHref + '"]');
+                        if ($row.length) {
+                            this.clear();
+                            $row.addClass('active');
+                        } else {
+                            var tbl = this.$el;
+                            if (ActionTable.prototype.tables(
+                                tbl.closest('.dashboard').find('.container')).not(tbl).find('tr.active').length
+                            ) {
+                                this.clear();
+                            }
+                        }
+                    }
                 }
             }
         },
@@ -298,11 +319,11 @@
          * Refresh the displayed active columns using the current page location
          */
         refresh: function() {
-            this.clear();
             var hash = icinga.history.getCol2State().replace(/^#!/, '');
             if (this.hasMultiselection()) {
                 var query = parseSelectionQuery(hash);
                 if (query.length > 1 && this.hasMultiselectionUrl(this.icinga.utils.parseUrl(hash).path)) {
+                    this.clear();
                     // select all rows with matching filters
                     var _this = this;
                     $.each(query, function(i, selection) {
@@ -330,6 +351,7 @@
         this.loading = false;
 
         this.on('rendered', this.onRendered, this);
+        this.on('beforerender', this.beforeRender, this);
         this.on('click', 'table.action tr[href], table.table-row-selectable tr[href]', this.onRowClicked, this);
     };
     ActionTable.prototype = new Icinga.EventListener();
@@ -451,6 +473,16 @@
         $(container).find('.selection-info-count').text(table.selections().size());
     };
 
+    ActionTable.prototype.beforeRender = function(evt) {
+        var container = evt.target;
+        var _this = evt.data.self;
+
+        var active = _this.tables().find('tr.active');
+        if (active.length) {
+            $(container).data('icinga-actiontable-former-href', active.attr('href'));
+        }
+    };
+
     ActionTable.prototype.clearAll = function () {
         var _this = this;
         this.tables().each(function () {



More information about the icinga-checkins mailing list