Files
satbd-explorer/webapp/js/views/recents/recents.js
2017-09-23 16:47:35 +02:00

43 lines
1.1 KiB
JavaScript

angular.module('satbd.satellite.bar.views.recents',[
'ngRoute',
'satbd.satellite.bar.components.album',
'angular-inview'
]).config(function($routeProvider) {
'use strict';
$routeProvider.when('/recents', {
templateUrl: 'js/views/recents/recents.html',
controller: 'RecentsCtrl'
});
}).controller('RecentsCtrl', function( $scope, $http, $log) {
'use strict';
$scope.albumIDs = [];
$scope.allAlbums = [];
$scope.scrollMore = false;
//we put all the albums in one variable
$http.get('/api/recents')
.success(function(data) {
$scope.allAlbums = data;
$scope.scrollMore = true;
}).error(function(err){
$log.error(err);
});
$scope.loadMore = function() {
var batchSize =20;
$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 + batchSize, $scope.allAlbums.length);
for( var i = $scope.albumIDs.length; i < newSize; i++) {
$scope.albumIDs.push($scope.allAlbums[i]);
}
};
});