fix bug where details view wasn't closing, so was loading way too much and 
sometimes breaking datatables


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

Branch: refs/heads/0.5.0
Commit: 29a836365f6defd57794112a6421668713d24221
Parents: 1ca7bc9
Author: Alex Heneveld <[email protected]>
Authored: Mon Dec 3 09:24:23 2012 -0600
Committer: Alex Heneveld <[email protected]>
Committed: Mon Dec 3 09:24:23 2012 -0600

----------------------------------------------------------------------
 usage/jsgui/src/main/webapp/assets/js/router.js       | 14 ++++++++------
 .../main/webapp/assets/js/view/application-tree.js    |  6 +++++-
 .../main/webapp/assets/js/view/entity-activities.js   |  2 +-
 .../src/main/webapp/assets/js/view/entity-config.js   |  2 +-
 .../src/main/webapp/assets/js/view/entity-policies.js |  2 +-
 .../src/main/webapp/assets/js/view/entity-sensors.js  |  8 ++++----
 usage/jsgui/src/main/webapp/assets/js/view/home.js    |  4 ++--
 usage/jsgui/src/test/javascript/specs/home-spec.js    |  2 +-
 .../test/javascript/specs/view/entity-details-spec.js |  2 +-
 9 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/router.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/router.js 
b/usage/jsgui/src/main/webapp/assets/js/router.js
index ff14e28..623f98f 100644
--- a/usage/jsgui/src/main/webapp/assets/js/router.js
+++ b/usage/jsgui/src/main/webapp/assets/js/router.js
@@ -14,19 +14,21 @@ define([
         if (this.beforeClose) {
             this.beforeClose()
         }
-        for (var index in this._periodicFunctions) {
-            clearInterval(this._periodicFunctions[index])
-        }
+        _.each(this._periodicFunctions, function(i) {
+            clearInterval(i)
+        })
         this.remove()
         this.unbind()
     }
     
     // registers a callback (cf setInterval) but it cleanly gets unregistered 
when view closes
-    Backbone.View.prototype.callPeriodically = function (callback, interval) {
+    Backbone.View.prototype.callPeriodically = function (uid, callback, 
interval) {
         if (!this._periodicFunctions) {
-            this._periodicFunctions = []
+            this._periodicFunctions = {}
         }
-        this._periodicFunctions.push(setInterval(callback, interval))
+        var old = this._periodicFunctions[uid]
+        if (old) clearInterval(old)
+        this._periodicFunctions[uid] = setInterval(callback, interval)
     }
 
 

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js 
b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js
index 6a35ed2..969a0ff 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/application-tree.js
@@ -4,7 +4,7 @@
  */
 define([
     "underscore", "jquery", "backbone", "model/app-tree", "./entity-details", 
"model/entity-summary",
-    "model/application", "text!tpl/apps/tree-item.html", 
"text!tpl/apps/details.html"
+    "model/application", "text!tpl/apps/tree-item.html", 
"text!tpl/apps/details.html", "brooklyn-utils"
 ], function (_, $, Backbone, AppTree, EntityDetailsView, EntitySummary, 
Application, TreeItemHtml, EntityDetailsEmptyHtml) {
 
     var ApplicationTreeView = Backbone.View.extend({
@@ -104,6 +104,8 @@ define([
             }
             window.history.pushState(stateId, "", href)
                this.displayEntityId(entityId, 
$(eventName.currentTarget).data("parent-app"));
+            // don't traverse the link further (not sure this is needed)
+            return false
         },
         displayEntityId:function (id, appName) {
             var entitySummary = new EntitySummary.Model,
@@ -137,6 +139,8 @@ define([
                     that.detailsView.close()
                 }
             }
+            if (that.detailsView)
+                that.detailsView.close()
             that.detailsView = new EntityDetailsView({
                 model:entitySummary,
                 application:app

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js 
b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
index 09d9f46..fb30921 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-activities.js
@@ -18,7 +18,7 @@ define([
             this.collection.url = this.model.getLinkByName("activities")
             this.collection.fetch()
             this.collection.on("reset", this.render, this)
-            this.callPeriodically(function () {
+            this.callPeriodically("entity-activities", function () {
                 that.collection.fetch()
             }, 5000)
         },

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js 
b/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js
index dc08ff9..899b0a4 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-config.js
@@ -52,7 +52,7 @@ define([
         updateConfigPeriodically:function (that) {
             var self = this;
             that.updateConfigNow(that)
-            that.callPeriodically(function() { self.updateConfigNow(that) }, 
3000)
+            that.callPeriodically("entity-config", function() { 
self.updateConfigNow(that) }, 3000)
         },
         updateConfigNow:function (that) {
             // NB: this won't add new dynamic config

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/view/entity-policies.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/entity-policies.js 
b/usage/jsgui/src/main/webapp/assets/js/view/entity-policies.js
index 5525bfa..fec2476 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/entity-policies.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/entity-policies.js
@@ -23,7 +23,7 @@ define([
             this._policies = new PolicySummary.Collection()
             // fetch the list of policies and create a view for each one
             this._policies.url = this.model.getLinkByName("policies")
-            this.callPeriodically(function() { that.refresh() }, 3000)
+            this.callPeriodically("entity-policies", function() { 
that.refresh() }, 3000)
             this.refresh()
         },
         refresh: function() {

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/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 35b7c97..19c5cdc 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
@@ -4,7 +4,7 @@
  */
 define([
     "underscore", "jquery", "backbone", "view/viewutils", 
"model/sensor-summary", "text!tpl/apps/sensors.html",
-    "text!tpl/apps/sensor-row.html", "tablesorter"
+    "text!tpl/apps/sensor-row.html", "tablesorter", "brooklyn-utils"
 ], function (_, $, Backbone, ViewUtils, SensorSummary, SensorsHtml, 
SensorRowHtml) {
 
     var EntitySensorsView = Backbone.View.extend({
@@ -59,7 +59,7 @@ define([
         updateSensorsPeriodically:function (that) {
             var self = this;
             that.updateSensorsNow(that)
-            that.callPeriodically(function() { self.updateSensorsNow(that) }, 
3000)
+            that.callPeriodically("entity-sensors", function() { 
self.updateSensorsNow(that) }, 3000)
         },
         updateSensorsNow:function (that) {
             // NB: this won't add new dynamic sensors
@@ -75,7 +75,7 @@ define([
                         $table.dataTable().fnUpdate(_.escape(v), row, 2)
                     })
                 })
-            }
-        })
+        }
+    })
     return EntitySensorsView
 })
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/main/webapp/assets/js/view/home.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/home.js 
b/usage/jsgui/src/main/webapp/assets/js/view/home.js
index 758d146..71e0275 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/home.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/home.js
@@ -48,7 +48,7 @@ define([
                                        )
                                var locatedLocations = new 
Location.UsageLocated()
                                that.updateCircles(that, locatedLocations, 
GoogleMaps, map)
-                               that.callPeriodically(function() {
+                               that.callPeriodically("circles", function() {
                                    that.updateCircles(that, locatedLocations, 
GoogleMaps, map)
                                }, 10000)
                        }, function (error) {
@@ -56,7 +56,7 @@ define([
                });
             }
             
-            this.callPeriodically(function() {
+            this.callPeriodically("home", function() {
                that.refresh(that);                     
             }, 5000)
             this.refresh(this)

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/test/javascript/specs/home-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/home-spec.js 
b/usage/jsgui/src/test/javascript/specs/home-spec.js
index d720675..e7c5f15 100644
--- a/usage/jsgui/src/test/javascript/specs/home-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/home-spec.js
@@ -11,7 +11,7 @@ define([
     "underscore", "jquery", "model/application", "model/location", "view/home"
 ], function (_, $, Application, Location, HomeView) {
 
-    Backbone.View.prototype.callPeriodically = function (callback, interval) {
+    Backbone.View.prototype.callPeriodically = function (uid, callback, 
interval) {
         if (!this._periodicFunctions) {
             this._periodicFunctions = []
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/29a83636/usage/jsgui/src/test/javascript/specs/view/entity-details-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/view/entity-details-spec.js 
b/usage/jsgui/src/test/javascript/specs/view/entity-details-spec.js
index 83f5e0a..2804543 100644
--- a/usage/jsgui/src/test/javascript/specs/view/entity-details-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/view/entity-details-spec.js
@@ -7,7 +7,7 @@ define([
         return "fixtures/sensor-current-state.json"
     }
 
-    Backbone.View.prototype.callPeriodically = function (callback, interval) {
+    Backbone.View.prototype.callPeriodically = function (uid, callback, 
interval) {
         if (!this._periodicFunctions) {
             this._periodicFunctions = []
         }

Reply via email to