This commit is contained in:
James Cole
2020-08-26 20:18:27 +02:00
parent c985683ee3
commit cd156d6991
7 changed files with 91 additions and 50 deletions

View File

@@ -73,14 +73,16 @@ class RuleController extends Controller
public function trigger(Request $request): JsonResponse public function trigger(Request $request): JsonResponse
{ {
$count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1; $count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
$keys = array_keys(config('firefly.search.operators')); $operators = config('firefly.search.operators');
$triggers = []; $triggers = [];
foreach ($keys as $key) { foreach ($operators as $key => $operator) {
if ('user_action' !== $key) { if ('user_action' !== $key && false === $operator['alias']) {
$triggers[$key] = (string) trans('firefly.rule_trigger_' . $key . '_choice');
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
} }
} }
asort($triggers); asort($triggers);
var_dump($triggers);exit;
try { try {
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render(); $view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
@@ -91,6 +93,7 @@ class RuleController extends Controller
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
echo $view;exit;
return response()->json(['html' => $view]); return response()->json(['html' => $view]);
} }

View File

@@ -347,6 +347,21 @@ class OperatorQuerySearch implements SearchInterface
} }
break; break;
// //
// cash account
//
case 'source_is_cash':
$account = $this->getCashAccount();
$this->collector->setSourceAccounts(new Collection([$account]));
break;
case 'destination_is_cash':
$account = $this->getCashAccount();
$this->collector->setDestinationAccounts(new Collection([$account]));
break;
case 'account_is_cash':
$account = $this->getCashAccount();
$this->collector->setAccounts(new Collection([$account]));
break;
//
// description // description
// //
case 'description_starts': case 'description_starts':
@@ -713,4 +728,12 @@ class OperatorQuerySearch implements SearchInterface
{ {
$this->limit = $limit; $this->limit = $limit;
} }
/**
* @return Account
*/
private function getCashAccount(): Account
{
return $this->accountRepository->getCashAccount();
}
} }

View File

@@ -289,6 +289,12 @@ class FireflyValidator extends Validator
return null !== $account; return null !== $account;
} }
// must be numeric for piggy bank things:
if ('update_piggy' === $actionType) {
$value = str_replace(',', '.', $value);
return '' !== $value && is_numeric($value);
}
// return true for the rest. // return true for the rest.
return true; return true;
} }
@@ -337,7 +343,7 @@ class FireflyValidator extends Validator
} }
// if the type is date, the simply try to parse it and throw error when it's bad. // if the type is date, the simply try to parse it and throw error when it's bad.
if (in_array($triggerType, ['date_is'], true)) { if (in_array($triggerType, ['date_is', 'created_on', 'updated_on', 'date_before', 'date_after'], true)) {
/** @var ParseDateString $parser */ /** @var ParseDateString $parser */
$parser = app(ParseDateString::class); $parser = app(ParseDateString::class);
try { try {

View File

@@ -491,6 +491,11 @@ return [
'source_account_is' => ['alias' => false, 'needs_context' => true,], 'source_account_is' => ['alias' => false, 'needs_context' => true,],
'from_account_is' => ['alias' => true, 'alias_for' => 'source_account_is', 'needs_context' => true,], 'from_account_is' => ['alias' => true, 'alias_for' => 'source_account_is', 'needs_context' => true,],
// source or dest is cash account?
'source_is_cash' => ['alias' => false, 'needs_context' => false],
'destination_is_cash' => ['alias' => false, 'needs_context' => false],
'account_is_cash' => ['alias' => false, 'needs_context' => false],
// source account name contains + alias // source account name contains + alias
'source_account_contains' => ['alias' => false, 'needs_context' => true,], 'source_account_contains' => ['alias' => false, 'needs_context' => true,],
'from_account_contains' => ['alias' => true, 'alias_for' => 'source_account_contains', 'needs_context' => true,], 'from_account_contains' => ['alias' => true, 'alias_for' => 'source_account_contains', 'needs_context' => true,],
@@ -511,7 +516,7 @@ return [
// source account number is // source account number is
'source_account_nr_is' => ['alias' => false, 'needs_context' => true,], 'source_account_nr_is' => ['alias' => false, 'needs_context' => true,],
'from_account_nr_is' => ['alias' => true, 'needs_context' => true,], 'from_account_nr_is' => ['alias' => true, 'alias_for' => 'source_account_nr_is', 'needs_context' => true,],
// source account number contains // source account number contains
'source_account_nr_contains' => ['alias' => false, 'needs_context' => true,], 'source_account_nr_contains' => ['alias' => false, 'needs_context' => true,],

View File

@@ -4,7 +4,7 @@
</td> </td>
<td style="width:30%;"> <td style="width:30%;">
<select name="triggers[{{ count }}][type]" class="form-control"> <select name="triggers[{{ count }}][type]" class="form-control">
{% for key,type in allRuleTriggers() %} {% for key,type in triggers %}
<option value="{{ key }}" label="{{ type }}" <option value="{{ key }}" label="{{ type }}"
{% if key == oldTrigger %} {% if key == oldTrigger %}
selected selected

View File

@@ -1,3 +1,5 @@
{% set bcArgs = [objectType] %}
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block content %} {% block content %}
<div id="accounts"></div> <div id="accounts"></div>

View File

@@ -22,12 +22,13 @@
namespace Tests\Unit\Support\Search; namespace Tests\Unit\Support\Search;
use DB;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Support\Search\OperatorQuerySearch; use FireflyIII\Support\Search\OperatorQuerySearch;
use Log; use Log;
use Tests\TestCase; use Tests\TestCase;
use DB;
/** /**
* Test: * Test:
* *
@@ -52,8 +53,6 @@ class OperatorQuerySearchTest extends TestCase
*/ */
public function testParseQuery(): void public function testParseQuery(): void
{ {
$this->assertTrue(true);
return;
$this->be($this->user()); $this->be($this->user());
// mock some of the used classes to verify results. // mock some of the used classes to verify results.
@@ -75,6 +74,9 @@ class OperatorQuerySearchTest extends TestCase
'from' => 'test', 'from' => 'test',
'source_account_id' => '1', 'source_account_id' => '1',
'from_account_id' => '1', 'from_account_id' => '1',
'source_is_cash' => true,
'destination_is_cash' => true,
'account_is_cash' => true,
// source account nr // source account nr
'from_account_nr_starts' => 'test', 'from_account_nr_starts' => 'test',
@@ -138,7 +140,6 @@ class OperatorQuerySearchTest extends TestCase
'any_notes' => 'test', 'any_notes' => 'test',
// exact amount // exact amount
'amount_exactly' => '0', 'amount_exactly' => '0',
'amount_is' => '0', 'amount_is' => '0',
@@ -182,6 +183,8 @@ class OperatorQuerySearchTest extends TestCase
'tag' => 'abc', 'tag' => 'abc',
'created_on' => '2020-01-01', 'created_on' => '2020-01-01',
'updated_on' => '2020-01-01', 'updated_on' => '2020-01-01',
'created_at' => '2020-01-01',
'updated_at' => '2020-01-01',
'external_id' => 'abc', 'external_id' => 'abc',
'internal_reference' => 'def', 'internal_reference' => 'def',
]; ];
@@ -424,7 +427,6 @@ class OperatorQuerySearchTest extends TestCase
} }
/** /**
* @covers \FireflyIII\Support\Search\OperatorQuerySearch * @covers \FireflyIII\Support\Search\OperatorQuerySearch
*/ */