40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
angular.module('satbd.satellite.bar.views.recents',[
|
|
'ngRoute',
|
|
'angular-inview'
|
|
]).config(function($routeProvider) {
|
|
$routeProvider.when('/recents', {
|
|
templateUrl: 'js/views/recents/recents.html',
|
|
controller: 'RecentsCtrl'
|
|
});
|
|
}).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) {
|
|
$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]);
|
|
}
|
|
}
|
|
|
|
});
|