Repository: cloudstack
Updated Branches:
  refs/heads/4.5 acf1baf1a -> 5522120b0


CLOUDSTACK-8766: Fix infinite scrolling pagination for zonal template listing

Uses listViewDataProvider to implement pagination for listing templates and ISOs
in the zones tab. Dedupes isos and templates in the list views.

This closes #739

Signed-off-by: Rohit Yadav <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/26700fbe
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/26700fbe
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/26700fbe

Branch: refs/heads/4.5
Commit: 26700fbe766e06c3b953ee9ebae3f51ff1a08968
Parents: 0b4f972
Author: Rohit Yadav <[email protected]>
Authored: Tue Aug 25 11:29:21 2015 +0530
Committer: Rohit Yadav <[email protected]>
Committed: Wed Aug 26 12:41:31 2015 +0530

----------------------------------------------------------------------
 ui/scripts/templates.js | 72 +++++++++++++++++++++++++++-----------------
 1 file changed, 44 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26700fbe/ui/scripts/templates.js
----------------------------------------------------------------------
diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js
index f0b8103..ffad8e2 100644
--- a/ui/scripts/templates.js
+++ b/ui/scripts/templates.js
@@ -15,8 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 (function(cloudStack, $) {
-       var ostypeObjs;
-       
+    var ostypeObjs;
+    var previousCollection = [];
+    var previousFilterType = null;
+
     cloudStack.sections.templates = {
         title: 'label.menu.templates',
         id: 'templates',
@@ -588,6 +590,10 @@
                         var ignoreProject = false;
                         if (args.filterBy != null) { //filter dropdown
                             if (args.filterBy.kind != null) {
+                                if (previousFilterType != args.filterBy.kind 
|| args.page == 1) {
+                                    previousFilterType = args.filterBy.kind;
+                                    previousCollection = [];
+                                }
                                 switch (args.filterBy.kind) {
                                     case "all":
                                         ignoreProject = true;
@@ -631,19 +637,19 @@
                                 var itemsView = [];
                                                                
                                 $(items).each(function(index, item) {
-                                    var existing = $.grep(itemsView, 
function(it){
+                                    var existing = $.grep(previousCollection, 
function(it){
                                         return it != null && it.id !=null && 
it.id == item.id;
                                     });
-                                                               
-                                    if (existing.length == 0) {
-                                        itemsView.push($.extend(item, {        
                                    
+
+                                    if (existing.length > 0) {
+                                        return true; // skip adding this entry
+                                    } else {
+                                        var templateItem = $.extend(item, {
                                             zones: item.zonename,
                                             zoneids: [item.zoneid]
-                                        }));
-                                    }
-                                    else {
-                                        existing[0].zones = 
'label.multiplezones';
-                                        existing[0].zoneids.push(item.zoneid);
+                                        });
+                                        itemsView.push(templateItem);
+                                        previousCollection.push(templateItem);
                                     }
                                 });                                            
                
 
@@ -1080,12 +1086,13 @@
 
 
                                     dataProvider: function(args) {  // UI > 
Templates menu (listing) > select a template from listing > Details tab > Zones 
tab (listing) 
-                                       $.ajax({
+                                        var data = { templatefilter: "self",
+                                                     id: 
args.context.templates[0].id
+                                                   };
+                                        listViewDataProvider(args, data);
+                                        $.ajax({
                                             url: createURL("listTemplates"),
-                                            data: {
-                                               templatefilter: "self",
-                                               id: args.context.templates[0].id
-                                            },
+                                            data: data,
                                             success: function(json) {
                                                var jsonObjs = 
json.listtemplatesresponse.template;
                                                                                
                
@@ -1724,6 +1731,10 @@
                         var ignoreProject = false;
                         if (args.filterBy != null) { //filter dropdown
                             if (args.filterBy.kind != null) {
+                                if (previousFilterType != args.filterBy.kind 
|| args.page == 1) {
+                                    previousFilterType = args.filterBy.kind;
+                                    previousCollection = [];
+                                }
                                 switch (args.filterBy.kind) {
                                     case "all":
                                         ignoreProject = true;
@@ -1767,22 +1778,24 @@
 
                                 var itemsView = [];
                                 $(items).each(function(index, item) {
-                                    var existing = $.grep(itemsView, 
function(it){
+                                    var existing = $.grep(previousCollection, 
function(it){
                                         return it != null && it.id !=null && 
it.id == item.id;
                                     });
-                                    if (existing.length == 0) {
-                                        itemsView.push({
+
+
+                                    if (existing.length > 0) {
+                                        return true; // skip adding this entry
+                                    } else {
+                                        var isoItem = {
                                             id: item.id,
                                             name: item.name,
                                             description: item.description,
                                             ostypeid: item.ostypeid,
                                             zones: item.zonename,
                                             zoneids: [item.zoneid]
-                                        });
-                                    }
-                                    else {
-                                        existing[0].zones = 'Multiple Zones';
-                                        existing[0].zoneids.push(item.zoneid);
+                                        };
+                                        itemsView.push(isoItem);
+                                        previousCollection.push(isoItem);
                                     }
                                 }
 );
@@ -2081,11 +2094,14 @@
                                     hideSearchBar: true,
 
                                     dataProvider: function(args) {
-                                                var jsonObj = 
args.context.isos[0];
-                                                var apiCmd = 
"listIsos&isofilter=self&id=" + jsonObj.id;
-
+                                                var data = {
+                                                    isofilter: 'self',
+                                                    id: args.context.isos[0].id
+                                                };
+                                                listViewDataProvider(args, 
data);
                                                 $.ajax({
-                                                    url: createURL(apiCmd),
+                                                    url: createURL('listIsos'),
+                                                    data: data,
                                                     dataType: "json",
                                                     success: function(json) {
                                                             var isos = 
json.listisosresponse.iso;

Reply via email to