Skip to content

Commit 21ff99b

Browse files
author
Jessica Wang
committed
CLOUDSTACK-7450: UI - dashboard - pass &pageSize=1&page=1 to listXXX API calls that are for getting total number of items.
1 parent 718fd5f commit 21ff99b

1 file changed

Lines changed: 63 additions & 21 deletions

File tree

ui/scripts/dashboard.js

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,62 @@
2828
user: {
2929
dataProvider: function(args) {
3030
var dataFns = {
31-
instances: function(data) {
32-
$.ajax({
33-
url: createURL('listVirtualMachines'),
31+
instances: function(data) {
32+
var totalInstanceCount = 0;
33+
$.ajax({
34+
url: createURL("listVirtualMachines"),
3435
data: {
35-
listAll: true
36+
listAll: true,
37+
page: 1,
38+
pageSize: 1
3639
},
37-
success: function(json) {
38-
var instances = json.listvirtualmachinesresponse.virtualmachine ?
39-
json.listvirtualmachinesresponse.virtualmachine : [];
40-
41-
dataFns.account($.extend(data, {
42-
runningInstances: $.grep(instances, function(instance) {
43-
return instance.state == 'Running';
44-
}).length,
45-
stoppedInstances: $.grep(instances, function(instance) {
46-
return instance.state == 'Stopped';
47-
}).length,
48-
totalInstances: instances.length
49-
}));
40+
async: false,
41+
success: function(json) {
42+
if (json.listvirtualmachinesresponse.count != undefined) {
43+
totalInstanceCount = json.listvirtualmachinesresponse.count;
44+
}
5045
}
5146
});
47+
48+
var RunningInstanceCount = 0;
49+
$.ajax({
50+
url: createURL("listVirtualMachines"),
51+
data: {
52+
listAll: true,
53+
page: 1,
54+
pageSize: 1,
55+
state: "Running"
56+
},
57+
async: false,
58+
success: function(json) {
59+
if (json.listvirtualmachinesresponse.count != undefined) {
60+
RunningInstanceCount = json.listvirtualmachinesresponse.count;
61+
}
62+
}
63+
});
64+
65+
var stoppedInstanceCount = 0;
66+
$.ajax({
67+
url: createURL("listVirtualMachines"),
68+
data: {
69+
listAll: true,
70+
page: 1,
71+
pageSize: 1,
72+
state: "Stopped"
73+
},
74+
async: false,
75+
success: function(json) {
76+
if (json.listvirtualmachinesresponse.count != undefined) {
77+
stoppedInstanceCount = json.listvirtualmachinesresponse.count;
78+
}
79+
}
80+
});
81+
82+
dataFns.account($.extend(data, {
83+
runningInstances: RunningInstanceCount,
84+
stoppedInstances: stoppedInstanceCount,
85+
totalInstances: totalInstanceCount
86+
}));
5287
},
5388

5489
account: function(data) {
@@ -68,7 +103,8 @@
68103
data: {
69104
listAll: true,
70105
page: 1,
71-
pageSize: 4
106+
pageSize: (pageSize > 4? 4: pageSize) //if default.page.size > 4, show 4 items only (since space on dashboard is limited)
107+
//pageSize: 1 //for testing only
72108
},
73109
success: function(json) {
74110
dataFns.ipAddresses($.extend(data, {
@@ -83,6 +119,8 @@
83119
url: createURL('listNetworks'),
84120
data: {
85121
listAll: true,
122+
page: 1,
123+
pageSize: 1,
86124
type: 'isolated',
87125
supportedServices: 'SourceNat'
88126
},
@@ -92,6 +130,10 @@
92130

93131
$.ajax({
94132
url: createURL('listPublicIpAddresses'),
133+
data: {
134+
page: 1,
135+
pageSize: 1
136+
},
95137
success: function(json) {
96138
var ipTotal = json.listpublicipaddressesresponse.count ?
97139
json.listpublicipaddressesresponse.count : 0;
@@ -163,7 +205,7 @@
163205
url: createURL('listAlerts'),
164206
data: {
165207
page: 1,
166-
pageSize: 4
208+
pageSize: (pageSize > 4? 4: pageSize) //if default.page.size > 4, show 4 items only (since space on dashboard is limited)
167209
},
168210
success: function(json) {
169211
var alerts = json.listalertsresponse.alert ?
@@ -188,7 +230,7 @@
188230
data: {
189231
state: 'Alert',
190232
page: 1,
191-
pageSize: 4
233+
pageSize: (pageSize > 4? 4: pageSize) //if default.page.size > 4, show 4 items only (since space on dashboard is limited)
192234
},
193235
success: function(json) {
194236
var hosts = json.listhostsresponse.host ?
@@ -213,7 +255,7 @@
213255
fetchLatest: false,
214256
sortBy: 'usage',
215257
page: 0,
216-
pagesize: 8
258+
pageSize: (pageSize > 8? 8: pageSize)
217259
},
218260
success: function(json) {
219261
var capacities = json.listcapacityresponse.capacity ?

0 commit comments

Comments
 (0)