diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 13d8f325ba..f9a1a6986b 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -61,14 +61,14 @@ class SearchController extends Controller public function index(Request $request, SearchInterface $searcher) { $fullQuery = (string)$request->get('search'); - + $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); // parse search terms: $searcher->parseQuery($fullQuery); $query = $searcher->getWordsAsString(); $modifiers = $searcher->getModifiers(); $subTitle = (string)trans('breadcrumbs.search_result', ['query' => $query]); - return view('search.index', compact('query', 'modifiers', 'fullQuery', 'subTitle')); + return view('search.index', compact('query', 'modifiers', 'page','fullQuery', 'subTitle')); } /** @@ -81,15 +81,20 @@ class SearchController extends Controller */ public function search(Request $request, SearchInterface $searcher): JsonResponse { - $fullQuery = (string)$request->get('query'); + $fullQuery = (string)$request->get('query'); + $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $searcher->parseQuery($fullQuery); + $searcher->setPage($page); $searcher->setLimit((int)config('firefly.search_result_limit')); - $groups = $searcher->searchTransactions(); + $groups = $searcher->searchTransactions(); + $hasPages = $groups->hasPages(); $searchTime = round($searcher->searchTime(), 3); // in seconds - + $parameters = ['search' => $fullQuery]; + $url = route('search.index') . '?' . http_build_query($parameters); + $groups->setPath($url); try { - $html = view('search.search', compact('groups','searchTime'))->render(); + $html = view('search.search', compact('groups', 'hasPages', 'searchTime'))->render(); // @codeCoverageIgnoreStart } catch (Throwable $e) { Log::error(sprintf('Cannot render search.search: %s', $e->getMessage())); diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 2c9f48885a..099a4b57f9 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -64,12 +64,15 @@ class Search implements SearchInterface private $validModifiers; /** @var array */ private $words = []; + /** @var int */ + private $page; /** * Search constructor. */ public function __construct() { + $this->page = 1; $this->modifiers = new Collection; $this->validModifiers = (array)config('firefly.search_modifiers'); $this->startTime = microtime(true); @@ -149,12 +152,11 @@ class Search implements SearchInterface { Log::debug('Start of searchTransactions()'); $pageSize = 50; - $page = 1; /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); - $collector->setLimit($pageSize)->setPage($page)->withAccountInformation(); + $collector->setLimit($pageSize)->setPage($this->page)->withAccountInformation(); $collector->withCategoryInformation()->withBudgetInformation(); $collector->setSearchWords($this->words); @@ -308,4 +310,12 @@ class Search implements SearchInterface } } } + + /** + * @param int $page + */ + public function setPage(int $page): void + { + $this->page = $page; + } } diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php index df8876d5ae..f3f45511f6 100644 --- a/app/Support/Search/SearchInterface.php +++ b/app/Support/Search/SearchInterface.php @@ -41,6 +41,11 @@ interface SearchInterface */ public function getWordsAsString(): string; + /** + * @param int $page + */ + public function setPage(int $page): void; + /** * @return bool */ diff --git a/resources/views/v1/recurring/create.twig b/resources/views/v1/recurring/create.twig index 9185a278ad..3aa50df483 100644 --- a/resources/views/v1/recurring/create.twig +++ b/resources/views/v1/recurring/create.twig @@ -101,7 +101,7 @@ {# destination account name for withdrawals #} {#{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }} #} - {# for withdrawals, also a drop down with expense accounts, loans, debts, mortgages or (cash). #} + {# NEW for withdrawals, also a drop down with expense accounts, loans, debts, mortgages or (cash). #} {{ AccountForm.activeWithdrawalDestinations('withdrawal_destination_id', null, {label: trans('form.withdrawal_destination_id')}) }} diff --git a/resources/views/v1/search/index.twig b/resources/views/v1/search/index.twig index 692849ef48..b4afc13d83 100644 --- a/resources/views/v1/search/index.twig +++ b/resources/views/v1/search/index.twig @@ -121,7 +121,8 @@ var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}"; var searchQuery = "{{ fullQuery|escape('js') }}"; - var searchUri = "{{ route('search.search') }}"; + var searchUri = "{{ route('search.search') }}?page={{ page }}"; + var searchPage = {{ page }}; {# required for groups.twig #} diff --git a/resources/views/v1/search/search.twig b/resources/views/v1/search/search.twig index 2206add94d..d200bad228 100644 --- a/resources/views/v1/search/search.twig +++ b/resources/views/v1/search/search.twig @@ -1,6 +1,10 @@
- {{ trans('firefly.search_found_transactions', {count: groups.count, time: searchTime}) }} + {% if hasPages %} + {{ trans('firefly.search_found_transactions', {count: '>'~groups.perPage, time: searchTime}) }} + {% else %} + {{ trans('firefly.search_found_transactions', {count: groups.count, time: searchTime}) }} + {% endif %}
{% include 'list.groups' %}