-
Notifications
You must be signed in to change notification settings - Fork 44
/
VRouterFlowsFormView.js
321 lines (307 loc) · 15.8 KB
/
VRouterFlowsFormView.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
define([
'underscore',
'knockback',
'contrail-view',
'contrail-list-model',
'monitor/infrastructure/vrouter/ui/js/models/VRouterFlowsFormModel'
//Remove all query references once it is moved to core
], function (_, Knockback, ContrailView, ContrailListModel, VRouterFlowsFormModel) {
var VRouterFlowsFormView = ContrailView.extend({
lastFlowReq : false,
render: function (options) {
var self = this, viewConfig = self.attributes.viewConfig,
hostname = viewConfig['hostname'],
prefix = ctwl.VROUTER_FLOWS_PREFIX;
routesTmpl = contrail.getTemplate4Id(
ctwc.TMPL_FORM_RESULT),
vRouterFlowsFormModel = new VRouterFlowsFormModel(),
widgetConfig = contrail.checkIfExist(viewConfig.widgetConfig) ?
viewConfig.widgetConfig : null,
routesFormId = "#" + prefix + "-form";
self.model = vRouterFlowsFormModel;
self.$el.append(routesTmpl({prefix: prefix}));
self.renderView4Config($(self.$el).find(routesFormId),
this.model,
self.getViewConfig(options,viewConfig),
null,
null,
null,
function () {
self.model.showErrorAttr(prefix + '-container',
false);
Knockback.applyBindings(self.model,
document.getElementById(prefix + '-container'));
kbValidation.bind(self);
self.renderQueryResult(viewConfig);
$("#vrouter_flows_query").on('click', function() {
self.renderQueryResult(viewConfig);
});
}
);
if (widgetConfig !== null) {
self.renderView4Config($(self.$el).find(routesFormId),
self.model, widgetConfig, null, null, null);
}
},
renderQueryResult: function(viewConfig) {
var self = this,
prefix = ctwl.VROUTER_FLOWS_PREFIX;
hostname = viewConfig['hostname'],
introspectPort = viewConfig['introspectPort'];
queryResultId = "#" + prefix + "-results",
flowKeyStack = [], aclIterKeyStack = [],
isAclPrevFirstTimeClicked = true, isAllPrevFirstTimeClicked = true,
responseViewConfig = {
elementId: ctwl.VROUTER_FLOWS_RESULTS_VIEW,
view: "VRouterFlowsGridView",
viewPathPrefix: ctwl.VROUTER_VIEWPATH_PREFIX,
app: cowc.APP_CONTRAIL_CONTROLLER,
viewConfig: viewConfig
};
var queryParams = self.model.getQueryParams();
function constructvRouterFlowsUrl(viewConfig) {
var url = monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'];
var urlParams = $.extend({
ip: monitorInfraUtils.getIPOrHostName(viewConfig),
introspectPort: introspectPort
},queryParams);
return {
url: url,
params:urlParams
}
}
var urlObj = constructvRouterFlowsUrl(viewConfig);
// var paginationInfo;
// function getPaginationInfo() {
// return paginationInfo;
// }
var remoteConfig = {
url: urlObj['url'] + '?' + $.param(urlObj['params']),
type: 'GET'
};
var listModelConfig = {
remote : {
ajaxConfig : remoteConfig,
dataParser : function(response) {
var retData = monitorInfraParsers.parseVRouterFlowsData(response);
return retData['data'];
}
},
cacheConfig : {
// ucid: ctwc.CACHE_CONFIGNODE
}
};
var model = new ContrailListModel(listModelConfig);
model.onDataUpdate.subscribe(function() {
});
function onSelectAcl(acluuid) {
var flowGrid = $('#' + ctwl.VROUTER_FLOWS_GRID_ID).data('contrailGrid');
var newAjaxConfig = "";
self.lastFlowReq = false;
flowKeyStack = [];
aclIterKeyStack = [];
if (acluuid != 'All') {
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&aclUUID=' + acluuid + '&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
} else {
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig) +
'&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
}
// flowGrid.setRemoteAjaxConfig(newAjaxConfig);
// reloadGrid(flowGrid);
$.ajax(newAjaxConfig).done(function(response) {
var retData = monitorInfraParsers.parseVRouterFlowsData(response,acluuid);
self.lastFlowReq = retData.lastFlowReq;
if(flowGrid._dataView != null)
flowGrid._dataView.setData(retData['data']);
flowGrid.refreshView();
});
}
function onNextClick() {
var flowGrid = $('#' + ctwl.VROUTER_FLOWS_GRID_ID).data('contrailGrid');
var acluuid = self.model.acl_uuid();
var newAjaxConfig = "";
if(self.lastFlowReq) {
return;
}
isAllPrevFirstTimeClicked = true;
isAclPrevFirstTimeClicked = true;
if(acluuid == 'All' && flowKeyStack.length > 0 &&
flowKeyStack[flowKeyStack.length - 1] != null){
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&flowKey=' + flowKeyStack[flowKeyStack.length - 1] +
'&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
}
else if (acluuid != 'All' && aclIterKeyStack.length > 0 &&
aclIterKeyStack[aclIterKeyStack.length -1] != null){
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&iterKey=' + aclIterKeyStack[aclIterKeyStack.length -1] +
'&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
} else if (acluuid == "All"){
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig) +
'&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
}
// flowGrid.setRemoteAjaxConfig(newAjaxConfig);
// reloadGrid(flowGrid);
$.ajax(newAjaxConfig).done(function(response) {
var retData = monitorInfraParsers.parseVRouterFlowsData(response,acluuid);
self.lastFlowReq = retData['lastFlowReq'];
if(flowGrid._dataView != null)
flowGrid._dataView.setData(retData['data']);
flowGrid.refreshView();
});
}
function onPrevClick() {
var flowGrid = $('#' + ctwl.VROUTER_FLOWS_GRID_ID).data('contrailGrid');
var acluuid = self.model.acl_uuid();
var newAjaxConfig = "";
if(isAllPrevFirstTimeClicked) {
//we need to do this because when we click the prev for the
//first time the stack would contain the next uuid as well.
//We need to pop out the uuids 3 times to get the prev uuid.
//flowKeyStack.pop();
isAllPrevFirstTimeClicked = false;
}
flowKeyStack.pop();//need to pop twice to get the prev last flowkey
if(isAclPrevFirstTimeClicked) {
aclIterKeyStack.pop();
isAclPrevFirstTimeClicked = false;
}
aclIterKeyStack.pop();
if(acluuid == 'All' && flowKeyStack.length > 0) {
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&flowKey=' + flowKeyStack.pop()
+ '&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
} else if (acluuid == 'All' && flowKeyStack.length < 1){
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
} else if(acluuid != 'All' && aclIterKeyStack.length > 0) {
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&iterKey=' + aclIterKeyStack.pop()
+ '&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
} else if(acluuid != 'All' && aclIterKeyStack.length < 1) {
newAjaxConfig = {
url: monitorInfraConstants.monitorInfraUrls['VROUTER_FLOWS'] +
'?ip=' + monitorInfraUtils.getIPOrHostName(viewConfig)
+ '&aclUUID=' + acluuid
+ '&introspectPort=' + viewConfig['introspectPort'],
type:'Get'
};
}
// flowGrid.setRemoteAjaxConfig(newAjaxConfig);
// reloadGrid(flowGrid);
$.ajax(newAjaxConfig).done(function(response) {
var retData = monitorInfraParsers.parseVRouterFlowsData(response,acluuid);
self.lastFlowReq = retData.lastFlowReq;
if(flowGrid._dataView != null)
flowGrid._dataView.setData(retData['data'],acluuid);
flowGrid.refreshView();
});
}
self.renderView4Config($(self.$el).find(queryResultId),
model, responseViewConfig,null,null,null,function() {
var gridSel = $('#' + ctwl.VROUTER_FLOWS_GRID_ID);
self.model.__kb.view_model.model().on('change:acl_uuid',
function(model,text) {
// onSelectAcl(model.attributes.acl_uuid);
onSelectAcl(model.get('acl_uuid'));
});
gridSel.find('i.icon-forward').parent().click(function() {
onNextClick();
});
gridSel.find('i.icon-backward').parent().click(function() {
onPrevClick();
});
});
},
getViewConfig: function (options,viewConfig) {
var self = this;
var hostname = viewConfig['hostname'];
return {
view: "SectionView",
viewConfig: {
rows: [
{
columns: [
{
elementId: 'acl_uuid',
view: "FormDropdownView",
viewConfig: {
label: 'ACL UUID',
path: 'acl_uuid',
dataBindValue: 'acl_uuid',
class: "span6",
elementConfig: {
defaultValueId: 0,
dataSource: {
type: 'remote',
url: monitorInfraConstants.monitorInfraUrls['VROUTER_ACL']
+ '?' + $.param({
ip: monitorInfraUtils.getIPOrHostName(viewConfig),
introspectPort: viewConfig['introspectPort']
}),
parse:function(response){
var retArr = [{text:'All',value:'All'}];
response = jsonPath(response,'$..AclSandeshData')[0];
var uuidArr = [];
if(response != null){
if(!(response instanceof Array)){
response = [response];
}
for (var i = 0; i < response.length; i++) {
uuidArr.push(response[i].uuid);
}
}
$.each(uuidArr, function (key, value) {
retArr.push({text:value, value:value});
});
return retArr;
}
},
dataValueField:'value',
dataTextField:'text',
}
}
}],
}]
}
};
}
});
return VRouterFlowsFormView;
});