Fix issue where the tester would not respect the strict yes/no setting.

This commit is contained in:
James Cole 2018-08-31 17:48:54 +02:00
parent 6377459e2f
commit 0cfe991482
4 changed files with 66 additions and 21 deletions

View File

@ -152,11 +152,13 @@ class SelectController extends Controller
$limit = (int)config('firefly.test-triggers.limit'); $limit = (int)config('firefly.test-triggers.limit');
$range = (int)config('firefly.test-triggers.range'); $range = (int)config('firefly.test-triggers.range');
$matchingTransactions = new Collection; $matchingTransactions = new Collection;
$strict = $request->get('strict') === '1';
/** @var TransactionMatcher $matcher */ /** @var TransactionMatcher $matcher */
$matcher = app(TransactionMatcher::class); $matcher = app(TransactionMatcher::class);
$matcher->setLimit($limit); $matcher->setLimit($limit);
$matcher->setRange($range); $matcher->setRange($range);
$matcher->setTriggers($triggers); $matcher->setTriggers($triggers);
$matcher->setStrict($strict);
try { try {
$matchingTransactions = $matcher->findTransactionsByTriggers(); $matchingTransactions = $matcher->findTransactionsByTriggers();
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart

View File

@ -62,6 +62,22 @@ class Processor
$this->actions = new Collection; $this->actions = new Collection;
} }
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/** /**
* Return found triggers * Return found triggers
* *

View File

@ -52,6 +52,30 @@ class TransactionMatcher
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER]; private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
/** @var array List of triggers to match */ /** @var array List of triggers to match */
private $triggers = []; private $triggers = [];
/** @var bool */
private $strict;
public function __construct()
{
$this->strict = false;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/** /**
* This method will search the user's transaction journal (with an upper limit of $range) for * This method will search the user's transaction journal (with an upper limit of $range) for
@ -96,6 +120,7 @@ class TransactionMatcher
/** @var Processor $processor */ /** @var Processor $processor */
$processor = app(Processor::class); $processor = app(Processor::class);
$processor->makeFromStringArray($this->triggers); $processor->makeFromStringArray($this->triggers);
$processor->setStrict($this->strict);
$result = $this->runProcessor($processor); $result = $this->runProcessor($processor);
// If the list of matchingTransactions is larger than the maximum number of results // If the list of matchingTransactions is larger than the maximum number of results

View File

@ -223,43 +223,43 @@ function updateActionInput(selectList) {
inputResult.removeAttr('disabled'); inputResult.removeAttr('disabled');
switch (selectList.val()) { switch (selectList.val()) {
case 'set_category': case 'set_category':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/categories'); createAutoComplete(inputResult, 'json/categories');
break; break;
case 'clear_category': case 'clear_category':
case 'clear_budget': case 'clear_budget':
case 'clear_notes': case 'clear_notes':
case 'remove_all_tags': case 'remove_all_tags':
console.log('Select list value is ' + selectList.val() +', so input needs to be disabled.'); console.log('Select list value is ' + selectList.val() + ', so input needs to be disabled.');
inputResult.attr('disabled', 'disabled'); inputResult.attr('disabled', 'disabled');
break; break;
case 'set_budget': case 'set_budget':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/budgets'); createAutoComplete(inputResult, 'json/budgets');
break; break;
case 'add_tag': case 'add_tag':
case 'remove_tag': case 'remove_tag':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/tags'); createAutoComplete(inputResult, 'json/tags');
break; break;
case 'set_description': case 'set_description':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/transaction-journals/all'); createAutoComplete(inputResult, 'json/transaction-journals/all');
break; break;
case 'set_source_account': case 'set_source_account':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/all-accounts'); createAutoComplete(inputResult, 'json/all-accounts');
break; break;
case 'set_destination_account': case 'set_destination_account':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/all-accounts'); createAutoComplete(inputResult, 'json/all-accounts');
break; break;
case 'link_to_bill': case 'link_to_bill':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/bills'); createAutoComplete(inputResult, 'json/bills');
break; break;
default: default:
console.log('Select list value is ' + selectList.val() +', destroy auto complete, do nothing else.'); console.log('Select list value is ' + selectList.val() + ', destroy auto complete, do nothing else.');
inputResult.typeahead('destroy'); inputResult.typeahead('destroy');
break; break;
} }
@ -289,30 +289,30 @@ function updateTriggerInput(selectList) {
case 'to_account_ends': case 'to_account_ends':
case 'to_account_is': case 'to_account_is':
case 'to_account_contains': case 'to_account_contains':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/all-accounts'); createAutoComplete(inputResult, 'json/all-accounts');
break; break;
case 'tag_is': case 'tag_is':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/tags'); createAutoComplete(inputResult, 'json/tags');
break; break;
case 'budget_is': case 'budget_is':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/budgets'); createAutoComplete(inputResult, 'json/budgets');
break; break;
case 'category_is': case 'category_is':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/categories'); createAutoComplete(inputResult, 'json/categories');
break; break;
case 'transaction_type': case 'transaction_type':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/transaction-types'); createAutoComplete(inputResult, 'json/transaction-types');
break; break;
case 'description_starts': case 'description_starts':
case 'description_ends': case 'description_ends':
case 'description_contains': case 'description_contains':
case 'description_is': case 'description_is':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/transaction-journals/all'); createAutoComplete(inputResult, 'json/transaction-journals/all');
break; break;
case 'has_no_category': case 'has_no_category':
@ -323,16 +323,16 @@ function updateTriggerInput(selectList) {
case 'no_notes': case 'no_notes':
case 'any_notes': case 'any_notes':
case 'has_any_tag': case 'has_any_tag':
console.log('Select list value is ' + selectList.val() +', so input needs to be disabled.'); console.log('Select list value is ' + selectList.val() + ', so input needs to be disabled.');
inputResult.prop('disabled', true); inputResult.prop('disabled', true);
inputResult.typeahead('destroy'); inputResult.typeahead('destroy');
break; break;
case 'currency_is': case 'currency_is':
console.log('Select list value is ' + selectList.val() +', so input needs auto complete.'); console.log('Select list value is ' + selectList.val() + ', so input needs auto complete.');
createAutoComplete(inputResult, 'json/currency-names'); createAutoComplete(inputResult, 'json/currency-names');
break; break;
default: default:
console.log('Select list value is ' + selectList.val() +', destroy auto complete, do nothing else.'); console.log('Select list value is ' + selectList.val() + ', destroy auto complete, do nothing else.');
inputResult.typeahead('destroy'); inputResult.typeahead('destroy');
break; break;
} }
@ -349,7 +349,7 @@ function createAutoComplete(input, URI) {
$.getJSON(URI).done(function (data) { $.getJSON(URI).done(function (data) {
console.log('Input now has auto complete from URI ' + URI); console.log('Input now has auto complete from URI ' + URI);
input.typeahead({source: data, autoSelect: false}); input.typeahead({source: data, autoSelect: false});
}).fail(function() { }).fail(function () {
console.log('Could not grab URI ' + URI + ' so autocomplete will not work'); console.log('Could not grab URI ' + URI + ' so autocomplete will not work');
}); });
@ -366,8 +366,10 @@ function testRuleTriggers() {
button.attr('disabled', 'disabled'); button.attr('disabled', 'disabled');
// Serialize all trigger data // Serialize all trigger data
var triggerData = $(".rule-trigger-tbody").find("input[type=text], input[type=checkbox], select").serializeArray(); var triggerData = $('.content').find("#ffInput_strict, .rule-trigger-tbody input[type=text], .rule-trigger-tbody input[type=checkbox], .rule-trigger-tbody select").serializeArray();
console.log('Found the following trigger data: ' + triggerData);
console.log('Found the following trigger data: ');
console.log(triggerData);
// Find a list of existing transactions that match these triggers // Find a list of existing transactions that match these triggers
$.get('rules/test', triggerData).done(function (data) { $.get('rules/test', triggerData).done(function (data) {