From eb5a9150ab18032a4f4c7066ac38f20a194da521 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 5 Jan 2014 19:51:33 -0700 Subject: [PATCH] hall: use infinite-scroll to load patrons, since there are so many --- bower.json | 3 ++- public/js/app.js | 2 +- public/js/controllers/hallCtrl.js | 12 +++++++++++- public/manifest.json | 1 + src/controllers/hall.js | 4 ++++ src/routes/apiv2.coffee | 5 ++++- views/options/social/hall.jade | 2 +- 7 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index d66189fe30..74d3ee1067 100644 --- a/bower.json +++ b/bower.json @@ -39,7 +39,8 @@ "sticky": "*", "bootstrap-tour": "~0.8.0", "angular-ui-utils": "~0.1.0", - "swagger-ui": "https://github.com/wordnik/swagger-ui.git#105c516f5f055b140e935e9cfe0c36f841921dff" + "swagger-ui": "https://github.com/wordnik/swagger-ui.git#105c516f5f055b140e935e9cfe0c36f841921dff", + "ngInfiniteScroll": "~1.0.0" }, "resolutions": { "jquery": "~2.0.3", diff --git a/public/js/app.js b/public/js/app.js index 63374c4c5b..f65ace1d79 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -18,7 +18,7 @@ window.env.t = function(string){ window.habitrpg = angular.module('habitrpg', ['ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'challengeServices', 'authServices', 'notificationServices', 'guideServices', - 'ui.bootstrap', 'ui.keypress', 'ui.router', 'chieffancypants.loadingBar', 'At', 'pasvaz.bindonce']) + 'ui.bootstrap', 'ui.keypress', 'ui.router', 'chieffancypants.loadingBar', 'At', 'pasvaz.bindonce', 'infinite-scroll']) // @see https://github.com/angular-ui/ui-router/issues/110 and https://github.com/HabitRPG/habitrpg/issues/1705 // temporary hack until they have a better solution diff --git a/public/js/controllers/hallCtrl.js b/public/js/controllers/hallCtrl.js index f047d0bcb3..2223bb1078 100644 --- a/public/js/controllers/hallCtrl.js +++ b/public/js/controllers/hallCtrl.js @@ -21,5 +21,15 @@ habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notifica habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource', function($scope, $rootScope, User, Notification, API_URL, $resource) { var Patron = $resource(API_URL + '/api/v2/hall/patrons/:uid', {uid:'@_id'}); - $scope.patrons = Patron.query(); + + var page = 0; + $scope.patrons = []; + + $scope.loadMore = function(){ + Patron.query({page: page++}, function(patrons){ + $scope.patrons = $scope.patrons.concat(patrons); + }) + } + $scope.loadMore(); + }]); diff --git a/public/manifest.json b/public/manifest.json index 186150cf9f..63daeeb6a7 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -18,6 +18,7 @@ "bower_components/angular-bindonce/bindonce.js", "bower_components/js-emoji/emoji.js", "bower_components/sticky/jquery.sticky.js", + "bower_components/ngInfiniteScroll/ng-infinite-scroll.js", "bower_components/bootstrap/docs/assets/js/bootstrap.js", "bower_components/angular-bootstrap/ui-bootstrap.js", diff --git a/src/controllers/hall.js b/src/controllers/hall.js index 1b14a2fada..c7f0321b6f 100644 --- a/src/controllers/hall.js +++ b/src/controllers/hall.js @@ -23,9 +23,13 @@ api.getHeroes = function(req,res,next) { } api.getPatrons = function(req,res,next){ + var page = req.query.page || 0, + perPage = 50; User.find({'backer.tier':{$ne:null}}) .select('contributor backer profile.name') .sort('-backer.tier') + .skip(page*perPage) + .limit(perPage) .exec(function(err, users){ if (err) return next(err); res.json(users); diff --git a/src/routes/apiv2.coffee b/src/routes/apiv2.coffee index 958430bc10..f0bc19afc4 100644 --- a/src/routes/apiv2.coffee +++ b/src/routes/apiv2.coffee @@ -511,7 +511,10 @@ module.exports = (swagger, v2) -> action: hall.updateHero "/hall/patrons": - spec: {} + spec: + params: [ + query 'page','Page number to fetch (this list is long)','string' + ] middleware:[auth.auth] action: hall.getPatrons diff --git a/views/options/social/hall.jade b/views/options/social/hall.jade index aae5ccb1ec..b311c3c6e2 100644 --- a/views/options/social/hall.jade +++ b/views/options/social/hall.jade @@ -82,7 +82,7 @@ script(type='text/ng-template', id='partials/options.social.hall.heroes.html') markdown(ng-model='hero.contributor.contributions', target='_blank') script(type='text/ng-template', id='partials/options.social.hall.patrons.html') - table.table.table-striped + table.table.table-striped(infinite-scroll="loadMore()",infinite-scroll-distance="3") tr thead tr