This commit is contained in:
James Cole
2019-09-08 20:21:44 +02:00
parent 2de79ea392
commit 5ae91845c1
6 changed files with 36 additions and 11 deletions

View File

@@ -61,14 +61,14 @@ class SearchController extends Controller
public function index(Request $request, SearchInterface $searcher) public function index(Request $request, SearchInterface $searcher)
{ {
$fullQuery = (string)$request->get('search'); $fullQuery = (string)$request->get('search');
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
// parse search terms: // parse search terms:
$searcher->parseQuery($fullQuery); $searcher->parseQuery($fullQuery);
$query = $searcher->getWordsAsString(); $query = $searcher->getWordsAsString();
$modifiers = $searcher->getModifiers(); $modifiers = $searcher->getModifiers();
$subTitle = (string)trans('breadcrumbs.search_result', ['query' => $query]); $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'));
} }
/** /**
@@ -82,14 +82,19 @@ class SearchController extends Controller
public function search(Request $request, SearchInterface $searcher): JsonResponse 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->parseQuery($fullQuery);
$searcher->setPage($page);
$searcher->setLimit((int)config('firefly.search_result_limit')); $searcher->setLimit((int)config('firefly.search_result_limit'));
$groups = $searcher->searchTransactions(); $groups = $searcher->searchTransactions();
$hasPages = $groups->hasPages();
$searchTime = round($searcher->searchTime(), 3); // in seconds $searchTime = round($searcher->searchTime(), 3); // in seconds
$parameters = ['search' => $fullQuery];
$url = route('search.index') . '?' . http_build_query($parameters);
$groups->setPath($url);
try { try {
$html = view('search.search', compact('groups','searchTime'))->render(); $html = view('search.search', compact('groups', 'hasPages', 'searchTime'))->render();
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
} catch (Throwable $e) { } catch (Throwable $e) {
Log::error(sprintf('Cannot render search.search: %s', $e->getMessage())); Log::error(sprintf('Cannot render search.search: %s', $e->getMessage()));

View File

@@ -64,12 +64,15 @@ class Search implements SearchInterface
private $validModifiers; private $validModifiers;
/** @var array */ /** @var array */
private $words = []; private $words = [];
/** @var int */
private $page;
/** /**
* Search constructor. * Search constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->page = 1;
$this->modifiers = new Collection; $this->modifiers = new Collection;
$this->validModifiers = (array)config('firefly.search_modifiers'); $this->validModifiers = (array)config('firefly.search_modifiers');
$this->startTime = microtime(true); $this->startTime = microtime(true);
@@ -149,12 +152,11 @@ class Search implements SearchInterface
{ {
Log::debug('Start of searchTransactions()'); Log::debug('Start of searchTransactions()');
$pageSize = 50; $pageSize = 50;
$page = 1;
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setLimit($pageSize)->setPage($page)->withAccountInformation(); $collector->setLimit($pageSize)->setPage($this->page)->withAccountInformation();
$collector->withCategoryInformation()->withBudgetInformation(); $collector->withCategoryInformation()->withBudgetInformation();
$collector->setSearchWords($this->words); $collector->setSearchWords($this->words);
@@ -308,4 +310,12 @@ class Search implements SearchInterface
} }
} }
} }
/**
* @param int $page
*/
public function setPage(int $page): void
{
$this->page = $page;
}
} }

View File

@@ -41,6 +41,11 @@ interface SearchInterface
*/ */
public function getWordsAsString(): string; public function getWordsAsString(): string;
/**
* @param int $page
*/
public function setPage(int $page): void;
/** /**
* @return bool * @return bool
*/ */

View File

@@ -101,7 +101,7 @@
{# destination account name for withdrawals #} {# destination account name for withdrawals #}
{#{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }} #} {#{{ 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')}) }} {{ AccountForm.activeWithdrawalDestinations('withdrawal_destination_id', null, {label: trans('form.withdrawal_destination_id')}) }}
</div> </div>
</div> </div>

View File

@@ -121,7 +121,8 @@
var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}"; var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}";
var searchQuery = "{{ fullQuery|escape('js') }}"; var searchQuery = "{{ fullQuery|escape('js') }}";
var searchUri = "{{ route('search.search') }}"; var searchUri = "{{ route('search.search') }}?page={{ page }}";
var searchPage = {{ page }};
</script> </script>
{# required for groups.twig #} {# required for groups.twig #}
<script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script>

View File

@@ -1,6 +1,10 @@
<p> <p>
<p class="search_count"> <p class="search_count">
{% if hasPages %}
{{ trans('firefly.search_found_transactions', {count: '>'~groups.perPage, time: searchTime}) }}
{% else %}
{{ trans('firefly.search_found_transactions', {count: groups.count, time: searchTime}) }} {{ trans('firefly.search_found_transactions', {count: groups.count, time: searchTime}) }}
{% endif %}
</p> </p>
{% include 'list.groups' %} {% include 'list.groups' %}