Handle excludedWords on Rule management pages as well

This commit is contained in:
Sobuno
2025-01-03 01:00:17 +01:00
parent e33e3cc40f
commit dae7e7d507
2 changed files with 40 additions and 13 deletions

View File

@@ -91,15 +91,27 @@ class CreateController extends Controller
if ('' !== $query) { if ('' !== $query) {
$search = app(SearchInterface::class); $search = app(SearchInterface::class);
$search->parseQuery($query); $search->parseQuery($query);
$words = $search->getWordsAsString(); $words = $search->getWords();
$excludedWords = $search->getExcludedWords();
$operators = $search->getOperators()->toArray(); $operators = $search->getOperators()->toArray();
if ('' !== $words) { if (count($words) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words])); session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
foreach($words as $word) {
$operators[] = [ $operators[] = [
'type' => 'description_contains', 'type' => 'description_contains',
'value' => $words, 'value' => $word,
]; ];
} }
}
if (count($excludedWords) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
foreach($excludedWords as $excludedWord) {
$operators[] = [
'type' => '-description_contains',
'value' => $excludedWord,
];
}
}
$oldTriggers = $this->parseFromOperators($operators); $oldTriggers = $this->parseFromOperators($operators);
} }
// var_dump($oldTriggers);exit; // var_dump($oldTriggers);exit;

View File

@@ -87,11 +87,26 @@ class EditController extends Controller
if ('' !== $query) { if ('' !== $query) {
$search = app(SearchInterface::class); $search = app(SearchInterface::class);
$search->parseQuery($query); $search->parseQuery($query);
$words = $search->getWordsAsString(); $words = $search->getWords();
$excludedWords = $search->getExcludedWords();
$operators = $search->getOperators()->toArray(); $operators = $search->getOperators()->toArray();
if ('' !== $words) { if (count($words) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words])); session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
$operators[] = ['type' => 'description_contains', 'value' => $words]; foreach($words as $word) {
$operators[] = [
'type' => 'description_contains',
'value' => $word,
];
}
}
if (count($excludedWords) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
foreach($excludedWords as $excludedWord) {
$operators[] = [
'type' => '-description_contains',
'value' => $excludedWord,
];
}
} }
$oldTriggers = $this->parseFromOperators($operators); $oldTriggers = $this->parseFromOperators($operators);
} }