mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 00:04:24 +00:00
Fix #3735
This commit is contained in:
@@ -34,6 +34,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use Log;
|
||||
use Throwable;
|
||||
|
||||
@@ -315,8 +316,20 @@ trait RenderPartialViews
|
||||
*/
|
||||
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
|
||||
{
|
||||
$index = 0;
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
|
||||
$index = 0;
|
||||
$renderedEntries = [];
|
||||
// todo must be repos
|
||||
$currentTriggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
||||
/** @var RuleTrigger $entry */
|
||||
@@ -324,13 +337,14 @@ trait RenderPartialViews
|
||||
if ('user_action' !== $entry->trigger_type) {
|
||||
$count = ($index + 1);
|
||||
try {
|
||||
$triggers[] = view(
|
||||
$renderedEntries[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => $entry->trigger_type,
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($entry->trigger_type),
|
||||
'oldValue' => $entry->trigger_value,
|
||||
'oldChecked' => $entry->stop_processing,
|
||||
'count' => $count,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
@@ -343,7 +357,7 @@ trait RenderPartialViews
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Search\OperatorQuerySearch;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Throwable;
|
||||
@@ -128,19 +128,31 @@ trait RuleManagement
|
||||
*/
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
{
|
||||
$index = 0;
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
$renderedEntries = [];
|
||||
$oldInput = $request->old('triggers');
|
||||
if (is_array($oldInput)) {
|
||||
foreach ($oldInput as $oldTrigger) {
|
||||
try {
|
||||
$triggers[] = view(
|
||||
$renderedEntries[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => $oldTrigger['type'],
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']),
|
||||
'oldValue' => $oldTrigger['value'],
|
||||
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
@@ -151,7 +163,7 @@ trait RuleManagement
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -234,7 +234,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if ($this->updateCollector($operator, $value)) {
|
||||
$this->operators->push(
|
||||
[
|
||||
'type' => $this->getRootOperator($operator),
|
||||
'type' => self::getRootOperator($operator),
|
||||
'value' => $value,
|
||||
]
|
||||
);
|
||||
@@ -256,7 +256,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
Log::debug(sprintf('updateCollector(%s, %s)', $operator, $value));
|
||||
|
||||
// check if alias, replace if necessary:
|
||||
$operator = $this->getRootOperator($operator);
|
||||
$operator = self::getRootOperator($operator);
|
||||
|
||||
switch ($operator) {
|
||||
default:
|
||||
@@ -687,8 +687,9 @@ class OperatorQuerySearch implements SearchInterface
|
||||
/**
|
||||
* @param string $operator
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRootOperator(string $operator): string
|
||||
public static function getRootOperator(string $operator): string
|
||||
{
|
||||
$config = config(sprintf('firefly.search.operators.%s', $operator));
|
||||
if (null === $config) {
|
||||
|
Reference in New Issue
Block a user