Skip to content

Commit 8221ebd

Browse files
committed
Merge pull request #740 from shapeblue/CLOUDSTACK-8766-master
CLOUDSTACK-8766: Fix infinite scrolling pagination for zonal template listing Uses listViewDataProvider to implement pagination on listTemplates API requests in the UI, when a template's zone tab is viewed. (cherry picked from commit 95c76ef) This from the other PR, for master branch. * pr/740: CLOUDSTACK-8766: Fix infinite scrolling pagination for zonal template listing Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents eb60ac9 + 462bb06 commit 8221ebd

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

ui/scripts/templates.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
(function(cloudStack, $) {
1818
var ostypeObjs;
19+
var previousCollection = [];
20+
var previousFilterType = null;
1921

2022
cloudStack.sections.templates = {
2123
title: 'label.menu.templates',
@@ -881,6 +883,10 @@
881883
var ignoreProject = false;
882884
if (args.filterBy != null) { //filter dropdown
883885
if (args.filterBy.kind != null) {
886+
if (previousFilterType != args.filterBy.kind || args.page == 1) {
887+
previousFilterType = args.filterBy.kind;
888+
previousCollection = [];
889+
}
884890
switch (args.filterBy.kind) {
885891
case "all":
886892
ignoreProject = true;
@@ -924,19 +930,19 @@
924930
var itemsView = [];
925931

926932
$(items).each(function(index, item) {
927-
var existing = $.grep(itemsView, function(it){
933+
var existing = $.grep(previousCollection, function(it){
928934
return it != null && it.id !=null && it.id == item.id;
929935
});
930936

931-
if (existing.length == 0) {
932-
itemsView.push($.extend(item, {
937+
if (existing.length > 0) {
938+
return true; // skip adding this entry
939+
} else {
940+
var templateItem = $.extend(item, {
933941
zones: item.zonename,
934942
zoneids: [item.zoneid]
935-
}));
936-
}
937-
else {
938-
existing[0].zones = 'label.multiplezones';
939-
existing[0].zoneids.push(item.zoneid);
943+
});
944+
itemsView.push(templateItem);
945+
previousCollection.push(templateItem);
940946
}
941947
});
942948

@@ -1377,12 +1383,13 @@
13771383

13781384

13791385
dataProvider: function(args) { // UI > Templates menu (listing) > select a template from listing > Details tab > Zones tab (listing)
1386+
var data = { templatefilter: "self",
1387+
id: args.context.templates[0].id
1388+
};
1389+
listViewDataProvider(args, data);
13801390
$.ajax({
13811391
url: createURL("listTemplates"),
1382-
data: {
1383-
templatefilter: "self",
1384-
id: args.context.templates[0].id
1385-
},
1392+
data: data,
13861393
success: function(json) {
13871394
var jsonObjs = json.listtemplatesresponse.template;
13881395

@@ -2021,6 +2028,10 @@
20212028
var ignoreProject = false;
20222029
if (args.filterBy != null) { //filter dropdown
20232030
if (args.filterBy.kind != null) {
2031+
if (previousFilterType != args.filterBy.kind || args.page == 1) {
2032+
previousFilterType = args.filterBy.kind;
2033+
previousCollection = [];
2034+
}
20242035
switch (args.filterBy.kind) {
20252036
case "all":
20262037
ignoreProject = true;
@@ -2064,22 +2075,24 @@
20642075

20652076
var itemsView = [];
20662077
$(items).each(function(index, item) {
2067-
var existing = $.grep(itemsView, function(it){
2078+
var existing = $.grep(previousCollection, function(it){
20682079
return it != null && it.id !=null && it.id == item.id;
20692080
});
2070-
if (existing.length == 0) {
2071-
itemsView.push({
2081+
2082+
2083+
if (existing.length > 0) {
2084+
return true; // skip adding this entry
2085+
} else {
2086+
var isoItem = {
20722087
id: item.id,
20732088
name: item.name,
20742089
description: item.description,
20752090
ostypeid: item.ostypeid,
20762091
zones: item.zonename,
20772092
zoneids: [item.zoneid]
2078-
});
2079-
}
2080-
else {
2081-
existing[0].zones = 'Multiple Zones';
2082-
existing[0].zoneids.push(item.zoneid);
2093+
};
2094+
itemsView.push(isoItem);
2095+
previousCollection.push(isoItem);
20832096
}
20842097
}
20852098
);
@@ -2382,11 +2395,14 @@
23822395
hideSearchBar: true,
23832396

23842397
dataProvider: function(args) {
2385-
var jsonObj = args.context.isos[0];
2386-
var apiCmd = "listIsos&isofilter=self&id=" + jsonObj.id;
2387-
2398+
var data = {
2399+
isofilter: 'self',
2400+
id: args.context.isos[0].id
2401+
};
2402+
listViewDataProvider(args, data);
23882403
$.ajax({
2389-
url: createURL(apiCmd),
2404+
url: createURL('listIsos'),
2405+
data: data,
23902406
dataType: "json",
23912407
success: function(json) {
23922408
var isos = json.listisosresponse.iso;

0 commit comments

Comments
 (0)