mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This isn't really working.
This commit is contained in:
parent
5b1d9e1a0d
commit
cd60b852a1
@ -10,8 +10,10 @@
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Config;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
use FireflyIII\Http\Requests\RuleGroupFormRequest;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
@ -64,10 +66,11 @@ class RuleController extends Controller
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function storeRule(RuleGroup $ruleGroup)
|
||||
public function storeRule(RuleFormRequest $request, RuleGroup $ruleGroup)
|
||||
{
|
||||
echo '<pre>';
|
||||
var_dump(Input::all());exit();
|
||||
var_dump(Input::all());
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +80,51 @@ class RuleController extends Controller
|
||||
*/
|
||||
public function createRule(RuleGroup $ruleGroup)
|
||||
{
|
||||
// count for possible present previous entered triggers/actions.
|
||||
$triggerCount = 0;
|
||||
$actionCount = 0;
|
||||
|
||||
// collection of those triggers/actions.
|
||||
$oldTriggers = [];
|
||||
$oldActions = [];
|
||||
|
||||
// array of valid values for triggers.
|
||||
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
||||
$possibleTriggers = [];
|
||||
foreach ($ruleTriggers as $key) {
|
||||
if ($key != 'user_action') {
|
||||
$possibleTriggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
|
||||
}
|
||||
}
|
||||
unset($key, $ruleTriggers);
|
||||
|
||||
// has old input?
|
||||
if (Input::old()) {
|
||||
// process old triggers.
|
||||
foreach (Input::old('rule-trigger') as $index => $entry) {
|
||||
$count = ($index + 1);
|
||||
$triggerCount++;
|
||||
$oldTrigger = $entry;
|
||||
$oldValue = Input::old('rule-trigger-value')[$index];
|
||||
$oldChecked = isset(Input::old('rule-action-value')[$index]) ? true : false;
|
||||
$oldTriggers[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => $oldTrigger,
|
||||
'oldValue' => $oldValue,
|
||||
'oldChecked' => $oldChecked,
|
||||
'triggers' => $possibleTriggers,
|
||||
'count' => $count
|
||||
]
|
||||
)->render();
|
||||
}
|
||||
// echo '<pre>';
|
||||
// var_dump(Input::old());
|
||||
// var_dump($oldTriggers);
|
||||
// exit;
|
||||
}
|
||||
|
||||
|
||||
$subTitleIcon = 'fa-clone';
|
||||
$subTitle = trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
|
||||
|
||||
@ -95,7 +143,7 @@ class RuleController extends Controller
|
||||
Session::flash('gaEventCategory', 'rules');
|
||||
Session::flash('gaEventAction', 'create-rule-group');
|
||||
|
||||
return view('rules.rule.create', compact('subTitleIcon', 'ruleGroup', 'subTitle', 'journalTriggers'));
|
||||
return view('rules.rule.create', compact('subTitleIcon','oldTriggers', 'triggerCount', 'actionCount', 'ruleGroup', 'subTitle', 'journalTriggers'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
55
app/Http/Requests/RuleFormRequest.php
Normal file
55
app/Http/Requests/RuleFormRequest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* RuleFormRequest.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use Auth;
|
||||
use Config;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
* Class RuleFormRequest
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class RuleFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
|
||||
$validTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
||||
|
||||
$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)
|
||||
];
|
||||
}
|
||||
}
|
@ -3,9 +3,14 @@
|
||||
<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') %}
|
||||
<span class="form-control-feedback"><i class="fa fa-fw fa-remove"></i></span>
|
||||
<p class="text-danger">{{ errors.first('xxxx') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<select name="rule-action[{{ count }}]" class="form-control">
|
||||
{% for key,name in actions %}
|
||||
<option name="{{ key }}" label="{{ name }}">{{ name }}</option>
|
||||
<option value="{{ key }}" label="{{ name }}">{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</td>
|
||||
|
@ -3,19 +3,30 @@
|
||||
<a href="#" class="btn btn-danger btn-sm remove-trigger"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
<td style="width:30%;">
|
||||
{% if errors.has('rule-trigger.'~count) %}
|
||||
<span class="form-control-feedback"><i class="fa fa-fw fa-remove"></i></span>
|
||||
<p class="text-danger">{{ errors.first('rule-trigger.'~count) }}</p>
|
||||
{% endif %}
|
||||
|
||||
<select name="rule-trigger[{{ count }}]" class="form-control">
|
||||
{% for key,name in triggers %}
|
||||
<option name="{{ 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-trigger-value[{{ count }}]" class="form-control">
|
||||
<input type="text" value="{{ oldValue }}" name="rule-trigger-value[{{ count }}]" class="form-control">
|
||||
</td>
|
||||
<td style="width:20%;">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="rule-trigger-stop[{{ count }}]" value="1"/>
|
||||
<input type="checkbox" name="rule-trigger-stop[{{ count }}]" value="1"
|
||||
{% if oldChecked %}checked{% endif %}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -41,6 +41,10 @@
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'rule_triggers'|_ }}</h3>
|
||||
</div>
|
||||
<!-- display any error -->
|
||||
{% if errors.has('rule-trigger.1') %}
|
||||
{{ errors.first('rule-trigger.1') }}
|
||||
{% endif %}
|
||||
<div class="box-body rule-trigger-box">
|
||||
<table class="table table-condensed table-bordered table-striped">
|
||||
<thead>
|
||||
@ -51,6 +55,9 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="rule-trigger-tbody">
|
||||
{% for trigger in oldTriggers %}
|
||||
{{ trigger|raw }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
@ -80,6 +87,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="rule-action-tbody">
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
@ -93,7 +101,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-lg-offset-6 col-md-offset-6 col-md-6 col-sm-12">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<!-- panel for options -->
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
@ -116,5 +124,9 @@
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script type="text/javascript" src="js/rules/create-edit.js"></script>
|
||||
<script type="text/javascript">
|
||||
var triggerCount = {{ triggerCount }};
|
||||
var actionCount = {{ actionCount }};
|
||||
</script>
|
||||
<script type="text/javascript" src="js/rules/edit.js"></script>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user