From ea1d543795d055bee53175b37a1855867a8a3622 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 25 Sep 2017 09:28:16 +0200 Subject: [PATCH] Fix #853 --- .../ExecuteRuleOnExistingTransactions.php | 20 ++++++++++++++----- app/TransactionRules/Processor.php | 7 ++++++- public/js/ff/rules/index.js | 20 ++++++++++++++++++- public/js/ff/rules/select-transactions.js | 5 ++++- resources/lang/en_US/firefly.php | 2 ++ resources/views/rules/index.twig | 3 +-- .../rules/rule-group/select-transactions.twig | 6 ++++++ .../views/rules/rule/select-transactions.twig | 6 ++++++ 8 files changed, 59 insertions(+), 10 deletions(-) diff --git a/app/Jobs/ExecuteRuleOnExistingTransactions.php b/app/Jobs/ExecuteRuleOnExistingTransactions.php index 33d7ba7d34..e1dff7ef7d 100644 --- a/app/Jobs/ExecuteRuleOnExistingTransactions.php +++ b/app/Jobs/ExecuteRuleOnExistingTransactions.php @@ -20,6 +20,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Collection; +use Log; /** * Class ExecuteRuleOnExistingTransactions @@ -128,18 +129,27 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue { // Lookup all journals that match the parameters specified $transactions = $this->collectJournals(); - $processor = Processor::make($this->rule); - + $processor = Processor::make($this->rule, true); + $hits = 0; + $misses = 0; + $total = 0; // Execute the rules for each transaction foreach ($transactions as $transaction) { - - $processor->handleTransaction($transaction); - + $total++; + $result = $processor->handleTransaction($transaction); + if($result) { + $hits++; + } + if(!$result) { + $misses++; + } + Log::info(sprintf('Current progress: %d Transactions. Hits: %d, misses: %d', $total, $hits, $misses)); // Stop processing this group if the rule specifies 'stop_processing' if ($processor->getRule()->stop_processing) { break; } } + Log::info(sprintf('Total transactions: %d. Hits: %d, misses: %d', $total, $hits, $misses)); } diff --git a/app/TransactionRules/Processor.php b/app/TransactionRules/Processor.php index 449edea798..509b229d26 100644 --- a/app/TransactionRules/Processor.php +++ b/app/TransactionRules/Processor.php @@ -40,7 +40,7 @@ final class Processor public $rule; /** @var Collection */ public $triggers; - + /** @var int */ protected $foundTriggers = 0; /** @@ -170,9 +170,14 @@ final class Processor // get all triggers: $triggered = $this->triggered(); if ($triggered) { + Log::debug('Rule is triggered, go to actions.'); if ($this->actions->count() > 0) { + Log::debug('Has more than zero actions.'); $this->actions(); } + if ($this->actions->count() === 0) { + Log::info('Rule has no actions!'); + } return true; } diff --git a/public/js/ff/rules/index.js b/public/js/ff/rules/index.js index e7cfeae014..df057ce7a7 100644 --- a/public/js/ff/rules/index.js +++ b/public/js/ff/rules/index.js @@ -44,12 +44,25 @@ $(function () { ); function testRuleTriggers(e) { + var obj = $(e.target); var ruleId = parseInt(obj.data('id')); + var icon = obj; + if(obj.prop("tagName") === 'A') { + icon = $('i', obj); + } + // change icon: + icon.addClass('fa-spinner fa-spin').removeClass('fa-flask'); + + var modal = $("#testTriggerModal"); + // respond to modal: + modal.on('hide.bs.modal', function (e) { + disableRuleSpinners(); + }); // Find a list of existing transactions that match these triggers $.get('rules/test-rule/' + ruleId).done(function (data) { - var modal = $("#testTriggerModal"); + // Set title and body modal.find(".transactions-list").html(data.html); @@ -66,11 +79,16 @@ function testRuleTriggers(e) { modal.modal(); }).fail(function () { alert('Cannot get transactions for given triggers.'); + disableRuleSpinners(); }); return false; } +function disableRuleSpinners() { + $('i.test_rule_triggers').removeClass('fa-spin fa-spinner').addClass('fa-flask'); +} + function sortStop(event, ui) { "use strict"; diff --git a/public/js/ff/rules/select-transactions.js b/public/js/ff/rules/select-transactions.js index 675a5fe730..32e5176bbf 100644 --- a/public/js/ff/rules/select-transactions.js +++ b/public/js/ff/rules/select-transactions.js @@ -6,7 +6,7 @@ * See the LICENSE file for details. */ -/** global: Modernizr */ +/** global: Modernizr, askReadWarning */ $(document).ready(function () { "use strict"; @@ -17,4 +17,7 @@ $(document).ready(function () { } ); } + $('form.form-horizontal').on('submit', function () { + return confirm(askReadWarning); + }); }); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 6d4caf22ba..e43c0c1a8a 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -319,6 +319,8 @@ return [ 'rule_action_set_source_account' => 'Set source account to :action_value', 'rule_action_set_destination_account_choice' => 'Set destination account to...', 'rule_action_set_destination_account' => 'Set destination account to :action_value', + 'rules_have_read_warning' => 'Have you read the warning?', + 'apply_rule_warning' => 'Warning: running a rule(group) on a large selection of transactions could take ages, and it could time-out. If it does, the rule(group) will only be applied to an unknown subset of your transactions. This might leave your financial administration in tatters. Please be careful.', // tags 'store_new_tag' => 'Store new tag', diff --git a/resources/views/rules/index.twig b/resources/views/rules/index.twig index 4ef73d26c5..2768eb10c5 100644 --- a/resources/views/rules/index.twig +++ b/resources/views/rules/index.twig @@ -107,8 +107,7 @@
{# show which transactions would match #} - + {# actually execute rule #} {{ trans('firefly.apply_rule_group_selection_intro', {title: ruleGroup.title}) }}

+

+ {{ 'apply_rule_warning'|_ }} +

{{ ExpandedForm.date('start_date', first) }} @@ -41,6 +44,9 @@ {% endblock %} {% block scripts %} + diff --git a/resources/views/rules/rule/select-transactions.twig b/resources/views/rules/rule/select-transactions.twig index 4429c48338..a98ea000e0 100644 --- a/resources/views/rules/rule/select-transactions.twig +++ b/resources/views/rules/rule/select-transactions.twig @@ -21,6 +21,9 @@

{{ trans('firefly.apply_rule_selection_intro', {title: rule.title}) }}

+

+ {{ 'apply_rule_warning'|_ }} +

{{ ExpandedForm.date('start_date', first) }} @@ -41,6 +44,9 @@ {% endblock %} {% block scripts %} +