Adds endless scrolling on albums

This commit is contained in:
2016-02-12 18:45:14 +01:00
parent c13dc5dad1
commit c5f294a818
5 changed files with 35 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
'use strict';
angular.module('satbd.satellite.bar.views.recents',[
'ngRoute'
'ngRoute',
'angular-inview'
]).config(function($routeProvider) {
$routeProvider.when('/recents', {
templateUrl: 'js/views/recents/recents.html',
@@ -9,12 +10,30 @@ angular.module('satbd.satellite.bar.views.recents',[
});
}).controller('RecentsCtrl', function( $scope, $http, $log) {
$scope.albumIDs = [];
$scope.allAlbums = [];
$scope.scrollMore = false;
//we put all the albums in one variable
$http.get('/api/recents')
.success(function(data) {
for (var i=0; i < 10; i++) {
$scope.albumIDs.push(data[i]);
}
$scope.allAlbums = data;
$scope.scrollMore = true;
}).error(function(err){
$log.error(err);
});
$scope.loadMore = function() {
$log.info('Loading more components');
if (!$scope.scrollMore || $scope.albumIDs.length >= $scope.allAlbums.length) {
$scope.scrollMore = false;
$log.info('reached the end of albums')
return;
}
var newSize = Math.min($scope.albumIDs.length + 50, $scope.allAlbums.length);
for( var i = $scope.albumIDs.length; i < newSize; i++) {
$scope.albumIDs.push($scope.allAlbums[i]);
}
}
});