diff --git a/src/main/resources/web/js/main.js b/src/main/resources/web/js/main.js index 9fddd1013669d31589de758abb26de519eb30416..b33878a6dafff30d68f34d246bddaf1528d6b11e 100644 --- a/src/main/resources/web/js/main.js +++ b/src/main/resources/web/js/main.js @@ -91,11 +91,13 @@ var AppRouter = Backbone.Router.extend({ var swl = new SwitchCollection(); var hl = new HostCollection(); +var updating = true; + tpl.loadTemplates(['home', 'status', 'topology', 'header', 'switch', 'switch-list', 'switch-list-item', 'host', 'host-list', 'host-list-item', 'port-list', 'port-list-item', 'flow-list', 'flow-list-item'], function () { app = new AppRouter(); Backbone.history.start({pushState: true}); - // console.log("started history") + //console.log("started history") $(document).ready(function () { // trigger Backbone routing when clicking on links, thanks to Atinux and pbnv @@ -113,15 +115,16 @@ tpl.loadTemplates(['home', 'status', 'topology', 'header', 'switch', 'switch-lis window.addEventListener('popstate', function(e) { app.navigate(location.pathname.substr(1), true); }); - + + // wait for the page to be rendered before loading any data + swl.fetch(); + hl.fetch(); + + setInterval(function () { + if(updating) { + swl.fetch(); + hl.fetch(); + } + }, 3000); }); }); - -var updating = true; - -setInterval(function () { - if(updating) { - swl.fetch(); - hl.fetch(); - } -}, 3000); diff --git a/src/main/resources/web/js/models/hostmodel.js b/src/main/resources/web/js/models/hostmodel.js index 2f2c15eaf53c33fba8d75006dcbdb39dacd99fbd..8de3dd67baa870c718badc22ff6f06da766dd273 100644 --- a/src/main/resources/web/js/models/hostmodel.js +++ b/src/main/resources/web/js/models/hostmodel.js @@ -31,7 +31,7 @@ window.HostCollection = Backbone.Collection.extend({ model:Host, - initialize:function () { + fetch:function () { var self = this; //console.log("fetching host list") $.ajax({ @@ -66,10 +66,6 @@ window.HostCollection = Backbone.Collection.extend({ }, - fetch:function () { - this.initialize(); - } - /* * findByName:function (key) { // TODO: Modify service to include firstName * in search var url = (key == '') ? '/host/' : "/host/search/" + key; diff --git a/src/main/resources/web/js/models/switchmodel.js b/src/main/resources/web/js/models/switchmodel.js index f5850e3e8834a59eaa1550a86cb73b91bd4d4ac6..4104dd0dfd898d9e462da0cc04f3fb6808342981 100644 --- a/src/main/resources/web/js/models/switchmodel.js +++ b/src/main/resources/web/js/models/switchmodel.js @@ -265,7 +265,7 @@ window.SwitchCollection = Backbone.Collection.extend({ model:Switch, - initialize:function () { + fetch:function () { var self = this; //console.log("fetching switch list") $.ajax({ @@ -292,9 +292,4 @@ window.SwitchCollection = Backbone.Collection.extend({ }); }, - fetch:function () { - this.initialize() - } - - });