From 7688d7c619ba49b69dce86444277368da9755e15 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 24 Jan 2017 15:38:41 +0100 Subject: [PATCH] Include trigger that responds to tags --- app/Rules/Triggers/TagIs.php | 74 +++++++++++++++++++++++++++++++ config/firefly.php | 3 +- public/js/ff/rules/create-edit.js | 10 +++++ resources/lang/en_US/firefly.php | 1 + 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/Rules/Triggers/TagIs.php diff --git a/app/Rules/Triggers/TagIs.php b/app/Rules/Triggers/TagIs.php new file mode 100644 index 0000000000..684d806760 --- /dev/null +++ b/app/Rules/Triggers/TagIs.php @@ -0,0 +1,74 @@ +tags()->get(); + /** @var Tag $tag */ + foreach ($tags as $tag) { + $name = strtolower($tag->tag); + // match on journal: + if ($name === strtolower($this->triggerValue)) { + Log::debug(sprintf('RuleTrigger TagIs for journal #%d: is tagged with "%s", return true.', $journal->id, $name)); + + return true; + } + } + Log::debug(sprintf('RuleTrigger TagIs for journal #%d: is not tagged with "%s", return false.', $journal->id, $this->triggerValue)); + + return false; + } +} diff --git a/config/firefly.php b/config/firefly.php index a68e72bb74..d3b9e7a268 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -166,7 +166,6 @@ return [ 'to_account_ends' => 'FireflyIII\Rules\Triggers\ToAccountEnds', 'to_account_is' => 'FireflyIII\Rules\Triggers\ToAccountIs', 'to_account_contains' => 'FireflyIII\Rules\Triggers\ToAccountContains', - 'transaction_type' => 'FireflyIII\Rules\Triggers\TransactionType', 'amount_less' => 'FireflyIII\Rules\Triggers\AmountLess', 'amount_exactly' => 'FireflyIII\Rules\Triggers\AmountExactly', 'amount_more' => 'FireflyIII\Rules\Triggers\AmountMore', @@ -174,8 +173,10 @@ return [ 'description_ends' => 'FireflyIII\Rules\Triggers\DescriptionEnds', 'description_contains' => 'FireflyIII\Rules\Triggers\DescriptionContains', 'description_is' => 'FireflyIII\Rules\Triggers\DescriptionIs', + 'transaction_type' => 'FireflyIII\Rules\Triggers\TransactionType', 'category_is' => 'FireflyIII\Rules\Triggers\CategoryIs', 'budget_is' => 'FireflyIII\Rules\Triggers\BudgetIs', + 'tag_is' => 'FireflyIII\Rules\Triggers\TagIs', ], 'rule-actions' => [ 'set_category' => 'FireflyIII\Rules\Actions\SetCategory', diff --git a/public/js/ff/rules/create-edit.js b/public/js/ff/rules/create-edit.js index ebee001611..c47ccdf140 100644 --- a/public/js/ff/rules/create-edit.js +++ b/public/js/ff/rules/create-edit.js @@ -268,6 +268,16 @@ function updateTriggerInput(selectList) { case 'to_account_contains': createAutoComplete(input, 'json/all-accounts'); break; + case 'tag_is': + // also make tag thing? + createAutoComplete(input, 'json/tags'); + break; + case 'budget_is': + createAutoComplete(input, 'json/budgets'); + break; + case 'category_is': + createAutoComplete(input, 'json/categories'); + break; case 'transaction_type': createAutoComplete(input, 'json/transaction-types'); break; diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index abee277d95..d54d34d4a6 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -262,6 +262,7 @@ return [ 'rule_trigger_description_is_choice' => 'Description is..', 'rule_trigger_category_is_choice' => 'Category is..', 'rule_trigger_budget_is_choice' => 'Budget is..', + 'rule_trigger_tag_is_choice' => '(A) tag is..', 'rule_trigger_store_journal' => 'When a transaction is created', 'rule_trigger_update_journal' => 'When a transaction is updated', 'rule_action_set_category' => 'Set category to ":action_value"',