Skip to content

Firefly III: a personal finances manager

Some more rule things before I merge a change to the CSV importer.

James Cole9703439a4c22
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php
index f6410c7894..f378bc448d 100644
--- a/app/Http/Controllers/RuleController.php
+++ b/app/Http/Controllers/RuleController.php
@@ -98,6 +98,15 @@ class RuleController extends Controller
}
unset($key, $ruleTriggers);
+ // array of valid values for actions
+ $ruleActions = array_keys(Config::get('firefly.rule-actions'));
+ $possibleActions = [];
+ foreach ($ruleActions as $key) {
+ $possibleActions[$key] = trans('firefly.rule_action_' . $key . '_choice');
+ }
+ unset($key, $ruleActions);
+
+
// has old input?
if (Input::old()) {
// process old triggers.
@@ -107,7 +116,7 @@ class RuleController extends Controller
$triggerCount++;
$oldTrigger = $entry;
$oldValue = Input::old('rule-trigger-value')[$index];
- $oldChecked = isset(Input::old('rule-action-value')[$index]) ? true : false;
+ $oldChecked = isset(Input::old('rule-trigger-stop')[$index]) ? true : false;
$oldTriggers[] = view(
'rules.partials.trigger',
[
@@ -120,12 +129,28 @@ class RuleController extends Controller
)->render();
$newIndex++;
}
-// echo '<pre>';
-// var_dump(Input::old());
-// var_dump($oldTriggers);
-// exit;
- }
+ // process old actions
+ $newIndex = 0;
+ foreach (Input::old('rule-action') as $index => $entry) {
+ $count = ($newIndex + 1);
+ $actionCount++;
+ $oldAction = $entry;
+ $oldValue = Input::old('rule-action-value')[$index];
+ $oldChecked = isset(Input::old('rule-action-stop')[$index]) ? true : false;
+ $oldActions[] = view(
+ 'rules.partials.action',
+ [
+ 'oldTrigger' => $oldAction,
+ 'oldValue' => $oldValue,
+ 'oldChecked' => $oldChecked,
+ 'actions' => $possibleActions,
+ 'count' => $count
+ ]
+ )->render();
+ $newIndex++;
+ }
+ }
$subTitleIcon = 'fa-clone';
$subTitle = trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
@@ -143,9 +168,11 @@ class RuleController extends Controller
}
Session::forget('rules.rule.create.fromStore');
Session::flash('gaEventCategory', 'rules');
- Session::flash('gaEventAction', 'create-rule-group');
+ Session::flash('gaEventAction', 'create-rule');
- return view('rules.rule.create', compact('subTitleIcon','oldTriggers', 'triggerCount', 'actionCount', 'ruleGroup', 'subTitle', 'journalTriggers'));
+ return view(
+ 'rules.rule.create', compact('subTitleIcon', 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount', 'ruleGroup', 'subTitle', 'journalTriggers')
+ );
}
/**
diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.php
index 521ecf3d43..e8f18055ab 100644
--- a/app/Http/Requests/RuleFormRequest.php
+++ b/app/Http/Requests/RuleFormRequest.php
@@ -38,21 +38,26 @@ class RuleFormRequest extends Request
{
$validTriggers = array_keys(Config::get('firefly.rule-triggers'));
+ $validActions = array_keys(Config::get('firefly.rule-actions'));
+
+ // some actions require text:
+ $contextActions = Config::get('firefly.rule-actions-text');
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
if (RuleGroup::find(Input::get('id'))) {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval(Input::get('id'));
}
- return [
- 'title' => $titleRule,
- 'description' => 'between:1,5000',
- 'stop_processing' => 'boolean',
- 'trigger' => 'required|in:store-journal,update-journal',
- 'rule-trigger.*' => 'required|in:' . join(',', $validTriggers),
- 'rule-trigger-value.*' => 'required|min:1'
-
-
+ $rules = [
+ 'title' => $titleRule,
+ 'description' => 'between:1,5000',
+ 'stop_processing' => 'boolean',
+ 'trigger' => 'required|in:store-journal,update-journal',
+ 'rule-trigger.*' => 'required|in:' . join(',', $validTriggers),
+ 'rule-trigger-value.*' => 'required|min:1',
+ 'rule-action.*' => 'required|in:' . join(',', $validActions),
+ 'rule-action-value.*' => 'required_if:rule-action.*,' . join(',', $contextActions)
];
+
}
}
diff --git a/config/firefly.php b/config/firefly.php
index ddef1a0805..952f9463e6 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -170,7 +170,7 @@ return [
'end_date' => 'FireflyIII\Support\Binder\Date'
],
- 'rule-triggers' => [
+ 'rule-triggers' => [
'user_action' => 'FireflyIII\Rules\Triggers\UserAction',
'from_account_starts' => 'FireflyIII\Rules\Triggers\FromAccountStarts',
'from_account_ends' => 'FireflyIII\Rules\Triggers\FromAccountEnds',
@@ -189,7 +189,7 @@ return [
'description_contains' => 'FireflyIII\Rules\Triggers\DescriptionContains',
'description_is' => 'FireflyIII\Rules\Triggers\DescriptionIs',
],
- 'rule-actions' => [
+ 'rule-actions' => [
'set_category' => 'FireflyIII\Rules\Actions\SetCategory',
'clear_category' => 'FireflyIII\Rules\Actions\ClearCategory',
'set_budget' => 'FireflyIII\Rules\Actions\SetBudget',
@@ -201,5 +201,15 @@ return [
'append_description' => 'FireflyIII\Rules\Actions\AppendDescription',
'prepend_description' => 'FireflyIII\Rules\Actions\PrependDescription',
],
+ // all rule actions that require text input:
+ 'rule-actions-text' => [
+ 'set_category',
+ 'set_budget',
+ 'add_tag',
+ 'remove_tag',
+ 'set_description',
+ 'append_description',
+ 'prepend_description',
+ ]
];
diff --git a/public/js/rules/create.js b/public/js/rules/create.js
index 9182c31001..5fe38cb550 100644
--- a/public/js/rules/create.js
+++ b/public/js/rules/create.js
@@ -14,8 +14,11 @@ $(function () {
if (triggerCount == 0) {
addNewTrigger();
}
+ if (actionCount == 0) {
+ addNewAction();
+ }
+
- addNewAction();
$('.add_rule_trigger').click(function () {
addNewTrigger();
diff --git a/resources/views/rules/partials/action.twig b/resources/views/rules/partials/action.twig
index edb4d77bf5..e7ec792c79 100644
--- a/resources/views/rules/partials/action.twig
+++ b/resources/views/rules/partials/action.twig
@@ -3,24 +3,37 @@
<a href="#" class="btn btn-danger btn-sm remove-action"><i class="fa fa-trash"></i></a>
</td>
<td style="width:30%;">
- {% if errors.has('XXX') %}
+ {% if errors.has('rule-action.'~count) %}
<span class="form-control-feedback"><i class="fa fa-fw fa-remove"></i></span>
- <p class="text-danger">{{ errors.first('xxxx') }}</p>
+ <p class="text-danger">{{ errors.first('rule-action.'~count) }}</p>
{% endif %}
<select name="rule-action[{{ count }}]" class="form-control">
{% for key,name in actions %}
- <option value="{{ key }}" label="{{ name }}">{{ name }}</option>
+ <option value="{{ key }}" label="{{ name }}"
+ {% if key == oldTrigger %}
+ selected
+ {% endif %}
+ >{{ name }}</option>
{% endfor %}
</select>
</td>
<td>
- <input type="text" name="rule-action-value[{{ count }}]" class="form-control">
+
+ <input type="text" value="{{ oldValue }}" name="rule-action-value[{{ count }}]"
+ class="form-control">
+ {% if errors.has(('rule-action-value.'~count)) %}
+ <p class="text-danger">
+ {{ errors.first('rule-action-value.'~count) }}
+ </p>
+ {% endif %}
</td>
<td style="width:20%;">
<div class="checkbox">
<label>
- <input type="checkbox" name="rule-action-stop[{{ count }}]" value="1"/>
+ <input type="checkbox" name="rule-action-stop[{{ count }}]" value="1"
+ {% if oldChecked %}checked{% endif %}
+ />
</label>
</div>
</td>
diff --git a/resources/views/rules/rule/create.twig b/resources/views/rules/rule/create.twig
index 5a35d69925..8c907753f4 100644
--- a/resources/views/rules/rule/create.twig
+++ b/resources/views/rules/rule/create.twig
@@ -84,7 +84,9 @@
</tr>
</thead>
<tbody class="rule-action-tbody">
-
+ {% for action in oldActions %}
+ {{ action|raw }}
+ {% endfor %}
</tbody>
</table>