You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:52:20 UTC

[36/50] [abbrv] brooklyn-ui git commit: fix rendering of "open" action (links) for sensors, by forcing row update when sensor metadata changes

fix rendering of "open" action (links) for sensors, by forcing row update when sensor metadata changes


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/bef0f7ba
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/bef0f7ba
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/bef0f7ba

Branch: refs/heads/0.6.0
Commit: bef0f7ba61f83381eaf7076b1ae4568133d12b6f
Parents: 08b9a73
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 26 12:27:17 2013 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 26 12:27:17 2013 +0100

----------------------------------------------------------------------
 .../webapp/assets/js/view/entity-sensors.js     | 28 +++++++++++++++-----
 .../src/main/webapp/assets/js/view/viewutils.js | 11 +++++---
 2 files changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/bef0f7ba/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js b/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js
index 919056c..f932b50 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-sensors.js
@@ -75,7 +75,7 @@ define([
             this.toggleFilterEmpty();
             return this;
         },
-
+        
         render: function() {
             return this;
         },
@@ -111,7 +111,7 @@ define([
         isRefreshActive: function() { return this.refreshActive; },
         updateSensorsNow:function () {
             var that = this
-            ViewUtils.get(that, that.model.getSensorUpdateUrl(), function(data) { that.updateWithData(data) },
+            ViewUtils.get(that, that.model.getSensorUpdateUrl(), that.updateWithData,
                     { enablement: that.isRefreshActive });
         },
         updateSensorsPeriodically:function () {
@@ -122,17 +122,21 @@ define([
         updateWithData: function (data) {
             var that = this
             $table = that.$('#sensors-table');
+            var options = {}
+            if (that.fullRedraw) {
+                options.refreshAllRows = true
+                that.fullRedraw = false
+            }
             ViewUtils.updateMyDataTable($table, data, function(value, name) {
                 var metadata = that.sensorMetadata[name]
                 if (metadata==null) {                        
-                    // TODO should reload metadata when this happens (new sensor for which no metadata known)
-                    // (currently if we have dynamic sensors, their metadata won't appear
-                    // until the page is refreshed; don't think that's a big problem -- mainly tooltips
-                    // for now, we just return the partial value
+                    // kick off reload metadata when this happens (new sensor for which no metadata known)
+                    // but only if we haven't loaded metadata for a while
+                    that.loadSensorMetadataIfStale(name, 10000);
                     return [name, {'name':name}, value]
                 } 
                 return [name, metadata, value];
-            });
+            }, options);
         },
 
         /**
@@ -142,6 +146,7 @@ define([
         loadSensorMetadata: function() {
             var url = this.model.getLinkByName('sensors'),
                 that = this;
+            that.lastSensorMetadataLoadTime = new Date().getTime();
             $.get(url, function (data) {
                 _.each(data, function(sensor) {
                     var actions = {};
@@ -157,10 +162,19 @@ define([
                         type: sensor.type
                     }
                 });
+                that.fullRedraw = true
                 that.updateSensorsNow();
                 that.table.find('*[rel="tooltip"]').tooltip();
             });
             return this;
+        },
+        
+        loadSensorMetadataIfStale: function(sensorName, recency) {
+            var that = this
+            if (!that.lastSensorMetadataLoadTime || that.lastSensorMetadataLoadTime + recency < new Date().getTime()) {
+//                log("reloading metadata because new sensor "+sensorName+" identified")
+                that.loadSensorMetadata();
+            }
         }
     });
 

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/bef0f7ba/usage/jsgui/src/main/webapp/assets/js/view/viewutils.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/viewutils.js b/usage/jsgui/src/main/webapp/assets/js/view/viewutils.js
index fb04172..76b3d5a 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/viewutils.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/viewutils.js
@@ -8,6 +8,7 @@ define([
             var settings = {
                 "bDestroy": true,
                 "iDisplayLength": 25,
+                "bDeferRender": true,
                 "sPaginationType": "full_numbers",
                 "sDom": "fp<'brook-db-top-toolbar'>tilp<'brook-db-bot-toolbar'>",
                 "oLanguage": {
@@ -57,9 +58,13 @@ define([
          * whose first element is the ID (hidden first column of table)
          * and other elements are the other columns in the table;
          * alternatively it can return null if the entry should be excluded
+         * 
+         * option refreshAllRows can be passed to force all rows to be re-rendered;
+         * useful if rendering data may have changed even if value has not
          */ 
-        updateMyDataTable: function(table, collection, fnConvertData) {
+        updateMyDataTable: function(table, collection, fnConvertData, options) {
             if (table==null) return;
+            if (options==null) options = {}
             var oldDisplayDataList = []
             try {
                 oldDisplayDataList = table.dataTable().fnGetData();
@@ -100,7 +105,7 @@ define([
                 var oldProps = oldDisplayData[rowProps[0]]
                 for (idx in rowProps) {
                     var v = rowProps[idx]
-                    if (!_.isEqual(v,oldProps[idx])) {
+                    if (options['refreshAllRows'] || !_.isEqual(v,oldProps[idx])) {
                         // update individual columns as values change
                         try {
                             table.fnUpdate( v, Number(prop), idx, false, false )
@@ -138,8 +143,8 @@ define([
                     log(newDisplayData[prop])
                 }
             }
-//            table.fnAdjustColumnSizing();
             try {
+                // redraw, but keeping pagination
                 table.fnStandingRedraw();
             } catch (e) {
                 log("WARNING: could not redraw")