Updated Branches: refs/heads/master c6118ad92 -> d84a6937d
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. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d84a6937 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d84a6937 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d84a6937 Branch: refs/heads/master Commit: d84a6937d7211db0d4b8d195b07854db2223da7e Parents: c6118ad Author: Jessica Wang <jessicaw...@apache.org> Authored: Thu Jan 30 14:44:49 2014 -0800 Committer: Jessica Wang <jessicaw...@apache.org> Committed: Thu Jan 30 14:44:49 2014 -0800 ---------------------------------------------------------------------- ui/scripts/system.js | 95 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d84a6937/ui/scripts/system.js ---------------------------------------------------------------------- diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 4c0543e..955d391 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -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,8 +8387,15 @@ }); } }); + } } + + args.response.success({ + actionFilter: routerActionfilter, + data: $(routers).map(mapRouterType) + }); + } }); args.response.success({ @@ -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',