-
Notifications
You must be signed in to change notification settings - Fork 44
/
VRouterDashboardView.js
132 lines (128 loc) · 5.86 KB
/
VRouterDashboardView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
define(
['underscore', 'contrail-view', 'monitor-infra-vrouter-model',
'contrail-list-model','cf-datasource'],
function(_, ContrailView, VRouterListModel,ContrailListModel,
CFDataSource) {
var VRouterDashobardView = ContrailView.extend(
(function() {
var self = this;
//Returning inside IIFE to make private static variable
var totalCntModel = new Backbone.Model({
vnCnt:''
});
return {
render: function() {
var self = this;
var cfDataSource = new CFDataSource();
var vRouterUIListModel = new ContrailListModel({data:[]});
self.cfDataSource = cfDataSource;
function onUpdatevRouterListModel() {
cfDataSource.updateData(self.model.getItems());
if(cfDataSource.getDimension('colorFilter') == null) {
cfDataSource.addDimension('colorFilter',function(d) {
return d['color'];
});
}
cfDataSource.fireCallBacks({source:'fetch'});
}
cfDataSource.addCallBack('updateCFListModel',function(data) {
//Update listUIModel with crossfilter data
vRouterUIListModel.setData(cfDataSource.getFilteredData());
});
this.renderView4Config(self.$el,
vRouterUIListModel,
getVRouterListViewConfig({totalCntModel:totalCntModel,cfDataSource:cfDataSource}),null,null,null,
function() {
self.model.onDataUpdate.subscribe(onUpdatevRouterListModel);
if(self.model.loadedFromCache) {
onUpdatevRouterListModel();
}
updateVnCnt(totalCntModel);
});
}
}
})()
);
function updateVnCnt(totalCntModel) {
var self = this;
var vnCnt = 0;
//Issue a call to get Network count
$.ajax({
url:'/api/tenant/networking/virtual-networks/list',
type:'POST',
data:{}
}).done(function(response) {
if(response != null) {
$.each(response,function(idx,obj) {
if((obj['name'].indexOf(':default-project:') == -1) && obj['name'] != '__UNKNOWN__') {
if($.isNumeric(vnCnt)) {
vnCnt++;
} else {
vnCnt = 1;
}
}
});
totalCntModel.set({vnCnt:vnCnt});
}
});
}
function getVRouterListViewConfig(cfgObj) {
return {
elementId: cowu.formatElementId([
ctwl.VROUTER_DASHBOARD_SECTION_ID
]),
view: "SectionView",
viewConfig: {
rows: [{
columns: [{
elementId: ctwl.VROUTER_DASHBOARD_SPARKLINE_ID,
title: ctwl.VROUTER_SUMMARY_TITLE,
view: "BarChartInfoView",
viewConfig: {
// class:'span3',
width: '135px',
config:[{
field:'instCnt',
title:'Instances',
yLbl: 'vRouters',
excludeList: [{
key:'vRouterType',
value:'tor-agent'
}]
},{
field:'intfCnt',
title:'Interfaces',
yLbl: 'vRouters',
excludeList: [{
key:'vRouterType',
value:'tor-agent'
}]
},{
field:'vnCnt',
title:'VNs',
yLbl: 'vRouters'
}],
totalCntModel: cfgObj['totalCntModel']
}
},{
elementId: ctwl.VROUTER_DASHBOARD_CHART_ID,
title: ctwl.VROUTER_SUMMARY_TITLE,
view: "VRouterScatterChartView",
viewConfig : {
// class: 'span9'
'margin-left': '160px',
cfDataSource : cfgObj['cfDataSource']
},
viewPathPrefix: "monitor/infrastructure/" +
"common/ui/js/views/",
app: cowc.APP_CONTRAIL_CONTROLLER,
}]
}]
}
};
};
return VRouterDashobardView;
});