Start work on adding a rule.

This commit is contained in:
James Cole 2016-01-14 16:41:15 +01:00
parent e02657a7c7
commit 5b1d9e1a0d
11 changed files with 733 additions and 464 deletions

View File

@ -2,13 +2,17 @@
use Amount;
use Carbon\Carbon;
use Config;
use FireflyIII\Helpers\Report\ReportQueryInterface;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Input;
use Preferences;
use Response;
use Session;
@ -38,6 +42,49 @@ class JsonController extends Controller
return Response::json('true');
}
/**
* @param RuleTrigger|null $trigger
*
* @return \Illuminate\Http\JsonResponse
*/
public function trigger(RuleTrigger $trigger = null)
{
$count = intval(Input::get('count')) > 0 ? intval(Input::get('count')) : 1;
$keys = array_keys(Config::get('firefly.rule-triggers'));
$triggers = [];
foreach ($keys as $key) {
if ($key != 'user_action') {
$triggers[$key] = trans('firefly.rule_trigger_' . $key . '_choice');
}
}
$view = view('rules.partials.trigger', compact('triggers', 'trigger', 'count'))->render();
return Response::json(['html' => $view]);
}
/**
* @param RuleAction|null $action
*
* @return \Illuminate\Http\JsonResponse
*/
public function action(RuleAction $action = null)
{
$count = intval(Input::get('count')) > 0 ? intval(Input::get('count')) : 1;
$keys = array_keys(Config::get('firefly.rule-actions'));
$actions = [];
foreach ($keys as $key) {
$actions[$key] = trans('firefly.rule_action_' . $key . '_choice');
}
$view = view('rules.partials.action', compact('actions', 'action', 'count'))->render();
return Response::json(['html' => $view]);
}
/**
*
*/

View File

@ -61,6 +61,18 @@ class RuleController extends Controller
/**
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function storeRule(RuleGroup $ruleGroup)
{
echo '<pre>';
var_dump(Input::all());exit();
}
/**
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function createRule(RuleGroup $ruleGroup)
@ -68,6 +80,13 @@ class RuleController extends Controller
$subTitleIcon = 'fa-clone';
$subTitle = trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
// mandatory field: rule triggers on update-journal or store-journal.
$journalTriggers = [
'store-journal' => trans('firefly.rule_trigger_store_journal'),
'update-journal' => trans('firefly.rule_trigger_update_journal')
];
// put previous url in session if not redirect from store (not "create another").
if (Session::get('rules.rule.create.fromStore') !== true) {
Session::put('rules.rule.create.url', URL::previous());
@ -76,7 +95,7 @@ class RuleController extends Controller
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'create-rule-group');
return view('rules.rule.create', compact('subTitleIcon','ruleGroup', 'subTitle'));
return view('rules.rule.create', compact('subTitleIcon', 'ruleGroup', 'subTitle', 'journalTriggers'));
}
/**
@ -208,6 +227,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param Rule $rule
*
* @return \Illuminate\Http\JsonResponse
*/
public function reorderRuleTriggers(RuleRepositoryInterface $repository, Rule $rule)
@ -224,6 +244,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param Rule $rule
*
* @return \Illuminate\Http\JsonResponse
*/
public function reorderRuleActions(RuleRepositoryInterface $repository, Rule $rule)
@ -268,6 +289,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param Rule $rule
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function upRule(RuleRepositoryInterface $repository, Rule $rule)
@ -281,6 +303,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param Rule $rule
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function downRule(RuleRepositoryInterface $repository, Rule $rule)
@ -294,6 +317,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function upRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
@ -307,6 +331,7 @@ class RuleController extends Controller
/**
* @param RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function downRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)

View File

@ -186,6 +186,9 @@ Route::group(
Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']);
Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals');
Route::get('/json/trigger/{RuleTrigger?}', ['uses' => 'JsonController@trigger', 'as' => 'json.trigger']);
Route::get('/json/action/{RuleAction?}', ['uses' => 'JsonController@action', 'as' => 'json.action']);
/**
* New user Controller
*/

View File

@ -0,0 +1,41 @@
/*
* create-edit.js
* 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.
*/
var triggerCount = 0;
var actionCount = 0;
$(function () {
"use strict";
console.log("create-edit");
});
function addNewTrigger() {
"use strict";
triggerCount++;
$.getJSON('json/trigger', {count: triggerCount}).success(function (data) {
//console.log(data.html);
$('tbody.rule-trigger-tbody').append(data.html);
}).fail(function () {
alert('Cannot get a new trigger.');
});
}
function addNewAction() {
"use strict";
triggerCount++;
$.getJSON('json/action', {count: actionCount}).success(function (data) {
//console.log(data.html);
$('tbody.rule-action-tbody').append(data.html);
}).fail(function () {
alert('Cannot get a new action.');
});
}

27
public/js/rules/edit.js Normal file
View File

@ -0,0 +1,27 @@
/*
* edit.js
* 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.
*/
// make a line.
$(function () {
"use strict";
console.log("edit");
addNewTrigger();
addNewAction();
$('.add_rule_trigger').click(function () {
addNewTrigger();
return false;
});
$('.add_rule_action').click(function () {
addNewAction();
return false;
});
});

View File

@ -1,4 +1,11 @@
/* global comboChart,token, billID */
/*
* index.js
* 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.
*/
// Return a helper with preserved width of cells
var fixHelper = function (e, tr) {
@ -13,7 +20,6 @@ var fixHelper = function (e, tr) {
$(function () {
"use strict";
console.log("Hello");
$('.rule-triggers').sortable({
helper: fixHelper,
stop: sortStop,

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,7 @@ return [
'filename' => 'File name',
'mime' => 'Mime type',
'size' => 'Size',
'trigger' => 'Trigger',
'stop_processing' => 'Stop processing',

View File

@ -0,0 +1,22 @@
<tr data-count="{{ count }}">
<td style="width:40px;">
<a href="#" class="btn btn-danger btn-sm remove-action"><i class="fa fa-trash"></i></a>
</td>
<td style="width:30%;">
<select name="rule-action[{{ count }}]" class="form-control">
{% for key,name in actions %}
<option name="{{ key }}" label="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</td>
<td>
<input type="text" name="rule-action-value[{{ count }}]" class="form-control">
</td>
<td style="width:20%;">
<div class="checkbox">
<label>
<input type="checkbox" name="rule-action-stop[{{ count }}]" value="1"/>
</label>
</div>
</td>
</tr>

View File

@ -0,0 +1,22 @@
<tr data-count="{{ count }}">
<td style="width:40px;">
<a href="#" class="btn btn-danger btn-sm remove-trigger"><i class="fa fa-trash"></i></a>
</td>
<td style="width:30%;">
<select name="rule-trigger[{{ count }}]" class="form-control">
{% for key,name in triggers %}
<option name="{{ key }}" label="{{ name }}">{{ name }}</option>
{% endfor %}
</select>
</td>
<td>
<input type="text" 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"/>
</label>
</div>
</td>
</tr>

View File

@ -15,6 +15,7 @@
</div>
<div class="box-body">
{{ ExpandedForm.text('title') }}
{{ ExpandedForm.select('trigger',journalTriggers) }}
{{ ExpandedForm.checkbox('stop_processing',1,null, {helpText: trans('firefly.rule_help_stop_processing')}) }}
</div>
</div>
@ -40,8 +41,23 @@
<div class="box-header with-border">
<h3 class="box-title">{{ 'rule_triggers'|_ }}</h3>
</div>
<div class="box-body">
Here
<div class="box-body rule-trigger-box">
<table class="table table-condensed table-bordered table-striped">
<thead>
<tr>
<th colspan="2">{{ 'trigger'|_ }}</th>
<th>{{ 'trigger_value'|_ }}</th>
<th>{{ 'stop_processing_other_triggers'|_ }}</th>
</tr>
</thead>
<tbody class="rule-trigger-tbody">
</tbody>
</table>
<p>
<br/>
<a href="#" class="btn btn-default add_rule_trigger">{{ 'add_rule_trigger'|_ }}</a>
</p>
</div>
</div>
</div>
@ -55,7 +71,22 @@
<h3 class="box-title">{{ 'rule_actions'|_ }}</h3>
</div>
<div class="box-body">
Here
<table class="table table-condensed table-bordered table-striped">
<thead>
<tr>
<th colspan="2">{{ 'action'|_ }}</th>
<th>{{ 'action_value'|_ }}</th>
<th>{{ 'stop_executing_other_actions'|_ }}</th>
</tr>
</thead>
<tbody class="rule-action-tbody">
</tbody>
</table>
<p>
<br/>
<a href="#" class="btn btn-default add_rule_action">{{ 'add_rule_action'|_ }}</a>
</p>
</div>
</div>
</div>
@ -83,3 +114,7 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="js/rules/create-edit.js"></script>
<script type="text/javascript" src="js/rules/edit.js"></script>
{% endblock %}