angular.module('satbd.satellite.bar.views.search',[ 'ngRoute', 'ngSanitize', 'satbd.satellite.bar.services', 'satbd.satellite.bar.components.album', 'angular-inview' ]).config(function($routeProvider) { 'use strict'; $routeProvider.when('/search', { templateUrl: 'js/views/search/search.html', controller: 'SearchCtrl' }); }).controller('SearchCtrl', function($scope,$routeParams,$log,$sce,albumService) { 'use strict'; $scope.terms=$routeParams.q; $scope.scrollMore = false; $scope.allHits = []; $scope.pushHits = function (response) { for ( var i = 0; i < response.hits.length; i++ ) { $scope.allHits.push(response.hits[i]); } // stop scrolling if we have all hits $scope.scrollMore = $scope.allHits.length < response.total_hits; }; albumService.search($scope.terms).then( function(data) { $scope.response = data; $scope.pushHits(data); }); $scope.loadMore = function () { if ( !$scope.scrollMore || $scope.allHits.length >= $scope.response.total_hits) { $scope.scrollMore = false; $log.info('Done scrolling results'); return; } $log.info('Scrolling more results'); albumService.search($scope.terms,$scope.allHits.length).then( function(data) { $scope.pushHits(data); }); }; $scope.inSecond= function(bleveValue) { return bleveValue / 1e6; }; $scope.trustedFragment = function(f) { return $sce.trustAsHtml(f); }; $scope.round4Dec = function(value) { return Math.round(value * 10000) / 10000; }; });