Configurable options for search, info when at max

includes the options for  maximum search results per page, and the
maximum number of pages available before help text is shown, and
the next page button is disabled
This commit is contained in:
Sam Chow 2018-04-24 16:25:12 -04:00
parent 8d5e8fc685
commit 1afedafcbb
7 changed files with 50 additions and 9 deletions

View file

@ -8,7 +8,7 @@
});
}]);
function SearchCtrl($scope, ApiService, $routeParams, $location) {
function SearchCtrl($scope, ApiService, $routeParams, $location, Config) {
var refreshResults = function() {
$scope.currentPage = ($routeParams['page'] || '1') * 1;
@ -17,10 +17,16 @@
'page': $scope.currentPage
};
var MAX_PAGE_RESULTS = Config['SEARCH_MAX_RESULT_PAGE_COUNT'];
var page = $routeParams['page'] || 1;
$scope.maxPopularity = 0;
$scope.resultsResource = ApiService.conductRepoSearchAsResource(params).get(function(resp) {
$scope.results = resp['results'];
$scope.hasAdditional = resp['has_additional'];
// Only show "Next Page" if we have more results, and we aren't on the max page
$scope.showNextButton = page < MAX_PAGE_RESULTS && resp['has_additional'];
// Show some help text if we're on the last page, making them specify the search more
$scope.showMaxResultsHelpText = page >= MAX_PAGE_RESULTS;
$scope.startIndex = resp['start_index'];
resp['results'].forEach(function(result) {
$scope.maxPopularity = Math.max($scope.maxPopularity, result['popularity']);
@ -45,5 +51,5 @@
});
}
SearchCtrl.$inject = ['$scope', 'ApiService', '$routeParams', '$location'];
SearchCtrl.$inject = ['$scope', 'ApiService', '$routeParams', '$location', 'Config'];
})();