CLOUDSTACK-5996: UI - In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1), because in project view, all API calls are appended with projectid=[projectID]. Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.

This commit is contained in:
Jessica Wang 2014-01-30 14:44:49 -08:00
parent c6118ad92e
commit d84a6937d7

View File

@ -325,7 +325,6 @@
virtualRouterCount: function (data) {
var data2 = {
projectid: -1,
page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
};
@ -334,24 +333,35 @@
data: data2,
success: function (json) {
var total1 = json.listroutersresponse.count ? json.listroutersresponse.count: 0;
var total2 = 0; //reset
/*
* In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1),
* because in project view, all API calls are appended with projectid=[projectID].
* Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.
*/
if (cloudStack.context && cloudStack.context.projects == null) { //non-project view
var data3 = {
listAll: true,
projectid: -1,
page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
};
$.ajax({
url: createURL('listRouters'),
data: data3,
async: false,
success: function (json) {
var total2 = json.listroutersresponse.count ? json.listroutersresponse.count: 0;
total2 = json.listroutersresponse.count ? json.listroutersresponse.count : 0;
}
});
}
dataFns.capacity($.extend(data, {
virtualRouterCount: (total1 + total2)
}));
}
});
}
});
},
capacity: function (data) {
@ -2356,10 +2366,16 @@
routers.push(item);
});
// Get project routers
/*
* In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1),
* because in project view, all API calls are appended with projectid=[projectID].
* Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.
*/
if (cloudStack.context && cloudStack.context.projects == null) { //non-project view
$.ajax({
url: createURL("listRouters&zoneid=" + selectedZoneObj.id + "&listAll=true&page=" + args.page + "&pagesize=" + pageSize + array1.join("") + "&projectid=-1"),
data: data2,
async: false,
success: function (json) {
var items = json.listroutersresponse.router ?
json.listroutersresponse.router:[];
@ -2367,14 +2383,16 @@
$(items).map(function (index, item) {
routers.push(item);
});
}
});
}
args.response.success({
actionFilter: routerActionfilter,
data: $(routers).map(mapRouterType)
});
}
});
}
});
},
detailView: {
name: 'Virtual applicance details',
@ -3444,25 +3462,32 @@
routers.push(item);
});
// Get project routers
/*
* In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1),
* because in project view, all API calls are appended with projectid=[projectID].
* Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.
*/
if (cloudStack.context && cloudStack.context.projects == null) { //non-project view
$.ajax({
url: createURL("listRouters&zoneid=" + selectedZoneObj.id + "&listAll=true&page=" + args.page + "&pagesize=" + pageSize + array1.join("") + "&projectid=-1"),
dataType: 'json',
data: data2,
async: true,
async: false,
success: function (json) {
var items = json.listroutersresponse.router;
$(items).map(function (index, item) {
routers.push(item);
});
}
});
}
args.response.success({
actionFilter: routerActionfilter,
data: $(routers).map(mapRouterType)
});
}
});
}
});
},
detailView: {
name: 'Virtual applicance details',
@ -8336,24 +8361,24 @@
routers.push(item);
});
//get project-owned routers
var toSearchByProjectid = true;
//if account is specified in advanced search, don't search project-owned routers
var accountIsNotSpecifiedInAdvSearch = true;
if (args.filterBy != null) {
if (args.filterBy.advSearch != null && typeof (args.filterBy.advSearch) == "object") {
//advanced search
if ('account' in args.filterBy.advSearch && args.filterBy.advSearch.account.length > 0) {
//if account is specified in advanced search, don't search project-owned routers
toSearchByProjectid = false; //since account and projectid can't be specified together
if (args.filterBy.advSearch != null && typeof(args.filterBy.advSearch) == "object") { //advanced search
if ('account' in args.filterBy.advSearch && args.filterBy.advSearch.account.length > 0) {
accountIsNotSpecifiedInAdvSearch = false; //since account and projectid can't be specified together
}
}
}
if (toSearchByProjectid) {
if (accountIsNotSpecifiedInAdvSearch) {
/*
* In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1),
* because in project view, all API calls are appended with projectid=[projectID].
* Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.
*/
if (cloudStack.context && cloudStack.context.projects == null) { //non-project view
$.ajax({
url: createURL('listRouters'),
data: $.extend(data, {
listAll: true,
projectid: -1
}),
url: createURL("listRouters&listAll=true&page=" + args.page + "&pagesize=" + pageSize + "&projectid=-1"),
async: false,
success: function (json) {
var items = json.listroutersresponse.router ? json.listroutersresponse.router:[];
@ -8362,7 +8387,14 @@
});
}
});
}
}
args.response.success({
actionFilter: routerActionfilter,
data: $(routers).map(mapRouterType)
});
}
});
@ -8632,10 +8664,17 @@
$(items).map(function (index, item) {
routers.push(item);
});
// Get project routers
/*
* In project view, the first listRotuers API(without projectid=-1) will return the same objects as the second listRouters API(with projectid=-1),
* because in project view, all API calls are appended with projectid=[projectID].
* Therefore, we only call the second listRouters API(with projectid=-1) in non-project view.
*/
if (cloudStack.context && cloudStack.context.projects == null) { //non-project view
$.ajax({
url: createURL("listRouters&listAll=true&page=" + args.page + "&pagesize=" + pageSize + array1.join("") + "&projectid=-1"),
data: data2,
async: false,
success: function (json) {
var items = json.listroutersresponse.router ?
json.listroutersresponse.router:[];
@ -8643,14 +8682,16 @@
$(items).map(function (index, item) {
routers.push(item);
});
}
});
}
args.response.success({
actionFilter: routerActionfilter,
data: $(routers).map(mapRouterType)
});
}
});
}
});
},
detailView: {
name: 'Virtual applicance details',