mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 10:39:28 +00:00
Fix #2564
This commit is contained in:
@@ -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()));
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -41,6 +41,11 @@ interface SearchInterface
|
||||
*/
|
||||
public function getWordsAsString(): string;
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function setPage(int $page): void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -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')}) }}
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -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 }};
|
||||
</script>
|
||||
{# required for groups.twig #}
|
||||
<script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_VERSION }}"></script>
|
||||
|
@@ -1,6 +1,10 @@
|
||||
<p>
|
||||
<p class="search_count">
|
||||
{{ 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 %}
|
||||
</p>
|
||||
|
||||
{% include 'list.groups' %}
|
||||
|
Reference in New Issue
Block a user