From 058a0f9fb229646fba855ba99010f0ad03e098e1 Mon Sep 17 00:00:00 2001
From: Sobuno
Date: Fri, 3 Jan 2025 00:08:11 +0100
Subject: [PATCH] Show excluded words in UI
---
app/Http/Controllers/SearchController.php | 3 ++-
app/Support/Search/OperatorQuerySearch.php | 5 +++++
app/Support/Search/SearchInterface.php | 1 +
resources/lang/en_US/firefly.php | 1 +
resources/views/search/index.twig | 9 +++++++--
5 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
index 6bf2204c3b..09eb820c54 100644
--- a/app/Http/Controllers/SearchController.php
+++ b/app/Http/Controllers/SearchController.php
@@ -84,11 +84,12 @@ class SearchController extends Controller
// words from query and operators:
$query = $searcher->getWordsAsString();
+ $excludedWords = $searcher->getExcludedWordsAsString();
$operators = $searcher->getOperators();
$invalidOperators = $searcher->getInvalidOperators();
$subTitle = (string) trans('breadcrumbs.search_result', ['query' => $fullQuery]);
- return view('search.index', compact('query', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged', 'invalidOperators'));
+ return view('search.index', compact('query', 'excludedWords', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged', 'invalidOperators'));
}
/**
diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php
index e6c445b231..e37b90e282 100644
--- a/app/Support/Search/OperatorQuerySearch.php
+++ b/app/Support/Search/OperatorQuerySearch.php
@@ -123,6 +123,11 @@ class OperatorQuerySearch implements SearchInterface
return implode(' ', $this->words);
}
+ public function getExcludedWordsAsString(): string
+ {
+ return implode(' ', $this->prohibitedWords);
+ }
+
/**
* @throws FireflyException
*/
diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php
index b9197e9daf..3604cacdd1 100644
--- a/app/Support/Search/SearchInterface.php
+++ b/app/Support/Search/SearchInterface.php
@@ -40,6 +40,7 @@ interface SearchInterface
public function getOperators(): Collection;
public function getWordsAsString(): string;
+ public function getExcludedWordsAsString(): string;
public function hasModifiers(): bool;
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index bd38b2404d..65e810481c 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -330,6 +330,7 @@ return [
'search_found_transactions' => 'Firefly III found :count transaction in :time seconds.|Firefly III found :count transactions in :time seconds.',
'search_found_more_transactions' => 'Firefly III found more than :count transactions in :time seconds.',
'search_for_query' => 'Firefly III is searching for transactions with all of these words in them: :query',
+ 'search_for_excluded_words' => 'Firefly III is searching for transactions with none of these words in them: :excluded_words',
'invalid_operators_list' => 'These search parameters are not valid and have been ignored.',
// old
diff --git a/resources/views/search/index.twig b/resources/views/search/index.twig
index b48dfd069e..f4346c55b1 100644
--- a/resources/views/search/index.twig
+++ b/resources/views/search/index.twig
@@ -43,6 +43,11 @@
{{ trans('firefly.search_for_query', {query: query|escape})|raw }}
{% endif %}
+ {% if '' != excludedWords %}
+
+ {{ trans('firefly.search_for_excluded_words', {excluded_words: excludedWords|escape})|raw }}
+
+ {% endif %}
{% if invalidOperators|length > 0 %}
{{ trans('firefly.invalid_operators_list') }}
@@ -70,7 +75,7 @@
- {% if query or operators|length > 0 %}
+ {% if query or excludedWords or operators|length > 0 %}
{% endif %}
- {% if query == "" and operators|length == 0 %}
+ {% if query == "" and excludedWords == "" and operators|length == 0 %}