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

@ -12,7 +12,7 @@ from auth.permissions import (OrganizationMemberPermission, ReadRepositoryPermis
ReadRepositoryPermission)
from auth.auth_context import get_authenticated_user
from auth import scopes
from app import avatar, authentication
from app import app, avatar, authentication
from flask import abort
from operator import itemgetter
from stringscore import liquidmetal
@ -335,7 +335,8 @@ class ConductSearch(ApiResource):
return {'results': sorted(results, key=itemgetter('score'), reverse=True)}
MAX_PER_PAGE = 10
MAX_PER_PAGE = app.config.get('SEARCH_RESULTS_PER_PAGE', 10)
MAX_RESULT_PAGE_COUNT = app.config.get('SEARCH_MAX_RESULT_PAGE_COUNT', 10)
@resource('/v1/find/repositories')
class ConductRepositorySearch(ApiResource):
@ -347,7 +348,7 @@ class ConductRepositorySearch(ApiResource):
def get(self, parsed_args):
""" Get a list of apps and repositories that match the specified query. """
query = parsed_args['query']
page = min(max(1, parsed_args['page']), 10)
page = min(max(1, parsed_args['page']), MAX_RESULT_PAGE_COUNT)
offset = (page - 1) * MAX_PER_PAGE
limit = offset + MAX_PER_PAGE + 1