Skip to content
Snippets Groups Projects
Commit 3c9501c6 authored by Mike Cohen's avatar Mike Cohen
Browse files

Ajax updates for UI.

Note: Switch stats don't update yet...not sure why...coming next.
parent bb29bd78
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ var AppRouter = Backbone.Router.extend({
},
topology:function () {
console.log("switching to topology view");
//console.log("switching to topology view");
var topo = new Topology();
$('#content').html(new TopologyView({model:topo, hosts:hl}).render().el);
// TODO factor this code out
......@@ -56,7 +56,7 @@ var AppRouter = Backbone.Router.extend({
},
switchDetails:function (id) {
console.log("switching [sic] to single switch view");
//console.log("switching [sic] to single switch view");
var sw = swl.get(id);
$('#content').html(new SwitchView({model:sw}).render().el);
$('ul.nav > li').removeClass('active');
......@@ -64,14 +64,14 @@ var AppRouter = Backbone.Router.extend({
},
switchList:function () {
console.log("switching [sic] to switch list view");
//console.log("switching [sic] to switch list view");
$('#content').html(new SwitchListView({model:swl}).render().el);
$('ul.nav > li').removeClass('active');
$('li > a[href*="/switches"]').parent().addClass('active');
},
hostDetails:function (id) {
console.log("switching to single host view");
//console.log("switching to single host view");
var h = hl.get(id);
$('#content').html(new HostView({model:h}).render().el);
$('ul.nav > li').removeClass('active');
......@@ -79,7 +79,7 @@ var AppRouter = Backbone.Router.extend({
},
hostList:function () {
console.log("switching to host list view");
//console.log("switching to host list view");
$('#content').html(new HostListView({model:hl}).render().el);
$('ul.nav > li').removeClass('active');
$('li > a[href*="/hosts"]').parent().addClass('active');
......@@ -117,3 +117,11 @@ tpl.loadTemplates(['home', 'status', 'topology', 'header', 'switch', 'switch-lis
});
});
setInterval(function () {
swl.fetch();
}, 3000);
setInterval(function () {
hl.fetch();
}, 3000);
......@@ -33,12 +33,12 @@ window.HostCollection = Backbone.Collection.extend({
initialize:function () {
var self = this;
console.log("fetching host list")
//console.log("fetching host list")
$.ajax({
url:hackBase + "/wm/devicemanager/device/all/json",
dataType:"json",
success:function (data) {
console.log("fetched host list: " + _.keys(data).length);
//console.log("fetched host list: " + _.keys(data).length);
// console.log(data);
// data is a hash where each key is a MAC address
_.each(_.keys(data), function(h) {
......@@ -57,6 +57,10 @@ window.HostCollection = Backbone.Collection.extend({
}
});
},
fetch:function () {
this.initialize()
}
/*
......
......@@ -32,43 +32,47 @@ window.Switch = Backbone.Model.extend({
initialize:function () {
var self = this;
console.log("fetching switch " + this.id + " desc")
//console.log("fetching switch " + this.id + " desc")
$.ajax({
url:hackBase + "/wm/core/switch/" + self.id + '/desc/json',
dataType:"json",
success:function (data) {
console.log("fetched switch " + self.id + " desc");
//console.log("fetched switch " + self.id + " desc");
//console.log(data[self.id][0]);
self.set(data[self.id][0]);
}
});
console.log("fetching switch " + this.id + " aggregate")
//console.log("fetching switch " + this.id + " aggregate")
$.ajax({
url:hackBase + "/wm/core/switch/" + self.id + '/aggregate/json',
dataType:"json",
success:function (data) {
console.log("fetched switch " + self.id + " aggregate");
//console.log(data[self.id][0]);
//console.log("fetched switch " + self.id + " aggregate");
//console.log(data[self.id][0]);
self.set(data[self.id][0]);
}
});
self.trigger('add');
this.ports = new PortCollection();
this.flows = new FlowCollection();
this.loadPorts();
this.loadFlows();
},
fetch:function () {
this.initialize()
},
loadPorts:function () {
if (this.ports.length == 0) {
var self = this;
console.log("fetching switch " + this.id + " ports")
//console.log("fetching switch " + this.id + " ports")
$.ajax({
url:hackBase + "/wm/core/switch/" + self.id + '/port/json',
dataType:"json",
success:function (data) {
console.log("fetched switch " + self.id + " ports");
//console.log("fetched switch " + self.id + " ports");
// console.log(data[self.id]);
// create port models
// TODO maybe clean up the errors
......@@ -86,12 +90,12 @@ window.Switch = Backbone.Model.extend({
loadFlows:function () {
var self = this;
console.log("fetching switch " + this.id + " flows")
//console.log("fetching switch " + this.id + " flows")
$.ajax({
url:hackBase + "/wm/core/switch/" + self.id + '/flow/json',
dataType:"json",
success:function (data) {
console.log("fetched switch " + self.id + " flows");
//console.log("fetched switch " + self.id + " flows");
// console.log(data[self.id]);
// create flow models
var i = 0;
......@@ -119,17 +123,20 @@ window.SwitchCollection = Backbone.Collection.extend({
initialize:function () {
var self = this;
console.log("fetching switch list")
//console.log("fetching switch list")
$.ajax({
url:hackBase + "/wm/core/controller/switches/json",
dataType:"json",
success:function (data) {
console.log("fetched switch list: " + data.length);
//console.log("fetched switch list: " + data.length);
// console.log(data);
_.each(data, function(sw) {self.add({id: sw['dpid']})});
}
});
},
fetch:function () {
this.initialize()
}
......
......@@ -42,7 +42,7 @@ window.SwitchListItemView = Backbone.View.extend({
initialize:function () {
this.template = _.template(tpl.get('switch-list-item'));
this.model.bind("change", this.render, this);
//this.model.bind("destroy", this.close, this);
//this.model.bind("destroy", this.close, this);
},
render:function (eventName) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment