2017-04-07 21:25:44 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Search page.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
|
|
|
pages.create('search', 'search.html', SearchCtrl, {
|
|
|
|
'title': 'Search'
|
|
|
|
});
|
|
|
|
}]);
|
|
|
|
|
2018-04-24 20:25:12 +00:00
|
|
|
function SearchCtrl($scope, ApiService, $routeParams, $location, Config) {
|
2017-04-07 21:25:44 +00:00
|
|
|
var refreshResults = function() {
|
|
|
|
$scope.currentPage = ($routeParams['page'] || '1') * 1;
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'query': $routeParams['q'],
|
|
|
|
'page': $scope.currentPage
|
|
|
|
};
|
|
|
|
|
2018-04-24 20:25:12 +00:00
|
|
|
var MAX_PAGE_RESULTS = Config['SEARCH_MAX_RESULT_PAGE_COUNT'];
|
|
|
|
var page = $routeParams['page'] || 1;
|
|
|
|
|
2017-04-07 21:25:44 +00:00
|
|
|
$scope.maxPopularity = 0;
|
|
|
|
$scope.resultsResource = ApiService.conductRepoSearchAsResource(params).get(function(resp) {
|
|
|
|
$scope.results = resp['results'];
|
2018-04-24 20:25:12 +00:00
|
|
|
// 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;
|
2017-04-07 21:25:44 +00:00
|
|
|
$scope.startIndex = resp['start_index'];
|
|
|
|
resp['results'].forEach(function(result) {
|
|
|
|
$scope.maxPopularity = Math.max($scope.maxPopularity, result['popularity']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.previousPage = function() {
|
|
|
|
$location.search('page', (($routeParams['page'] || 1) * 1) - 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.nextPage = function() {
|
|
|
|
$location.search('page', (($routeParams['page'] || 1) * 1) + 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.currentQuery = $routeParams['q'];
|
|
|
|
refreshResults();
|
|
|
|
|
|
|
|
$scope.$on('$routeUpdate', function(){
|
|
|
|
$scope.currentQuery = $routeParams['q'];
|
|
|
|
refreshResults();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-24 20:25:12 +00:00
|
|
|
SearchCtrl.$inject = ['$scope', 'ApiService', '$routeParams', '$location', 'Config'];
|
2017-04-07 21:25:44 +00:00
|
|
|
})();
|