mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #3440
This commit is contained in:
parent
8da6ec3f5b
commit
5a03f3395c
@ -24,15 +24,14 @@ namespace FireflyIII\Http\Controllers\Rule;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\RuleManagement;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
@ -66,20 +65,6 @@ class IndexController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move rule down in list.
|
||||
*
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function down(Rule $rule)
|
||||
{
|
||||
$this->ruleRepos->moveDown($rule);
|
||||
|
||||
return redirect(route('rules.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Index of all rules and groups.
|
||||
*
|
||||
@ -135,17 +120,18 @@ class IndexController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Move rule ip.
|
||||
* @param Request $request
|
||||
* @param Rule $rule
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return RedirectResponse|Redirector
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function up(Rule $rule)
|
||||
public function moveRule(Request $request, Rule $rule, RuleGroup $ruleGroup): JsonResponse
|
||||
{
|
||||
$this->ruleRepos->moveUp($rule);
|
||||
$order = (int) $request->get('order');
|
||||
$this->ruleRepos->moveRule($rule, $ruleGroup, (int) $order);
|
||||
|
||||
return redirect(route('rules.index'));
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -483,4 +483,18 @@ class RuleRepository implements RuleRepositoryInterface
|
||||
|
||||
return $newRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule
|
||||
{
|
||||
$rule->order = $order;
|
||||
if ($rule->rule_group_id !== $ruleGroup->id) {
|
||||
$rule->rule_group_id = $ruleGroup->id;
|
||||
}
|
||||
$rule->save();
|
||||
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,15 @@ interface RuleRepositoryInterface
|
||||
*/
|
||||
public function count(): int;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param int $order
|
||||
*
|
||||
* @return Rule
|
||||
*/
|
||||
public function moveRule(Rule $rule, RuleGroup $ruleGroup, int $order): Rule;
|
||||
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*
|
||||
|
3
public/v1/css/firefly.css
vendored
3
public/v1/css/firefly.css
vendored
@ -90,6 +90,9 @@ p.tagcloud .label {
|
||||
.piggy-handle {
|
||||
cursor: move;
|
||||
}
|
||||
.rule-handle {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
body.waiting * {
|
||||
cursor: progress;
|
||||
|
55
public/v1/js/ff/rules/index.js
vendored
55
public/v1/js/ff/rules/index.js
vendored
@ -31,18 +31,11 @@ var fixHelper = function (e, tr) {
|
||||
|
||||
$(function () {
|
||||
"use strict";
|
||||
$('.rule-triggers').sortable(
|
||||
{
|
||||
helper: fixHelper,
|
||||
stop: sortStop,
|
||||
cursor: "move"
|
||||
}
|
||||
);
|
||||
|
||||
$('.rule-actions').sortable(
|
||||
$('.group-rules').find('tbody').sortable(
|
||||
{
|
||||
helper: fixHelper,
|
||||
stop: sortStop,
|
||||
handle: '.rule-handle',
|
||||
cursor: "move"
|
||||
|
||||
}
|
||||
@ -102,27 +95,35 @@ function disableRuleSpinners() {
|
||||
|
||||
function sortStop(event, ui) {
|
||||
"use strict";
|
||||
var current = $(ui.item);
|
||||
var parent = current.parent();
|
||||
var ruleId = current.parent().data('id');
|
||||
var entries = [];
|
||||
// who am i?
|
||||
|
||||
$.each(parent.children(), function (i, v) {
|
||||
var trigger = $(v);
|
||||
var id = trigger.data('id');
|
||||
entries.push(id);
|
||||
// resort / move rule
|
||||
$.each($('.group-rules'), function(i,v) {
|
||||
$.each($('tr.single-rule', $(v)), function (i, v) {
|
||||
var holder = $(v);
|
||||
var position = parseInt(holder.data('position'));
|
||||
var ruleGroupId = holder.data('group-id');
|
||||
var ruleId = holder.data('id');
|
||||
var originalOrder = parseInt(holder.data('order'));
|
||||
var newOrder;
|
||||
|
||||
if (position === i) {
|
||||
// not changed, position is what it should be.
|
||||
return;
|
||||
}
|
||||
if (position < i) {
|
||||
// position is less.
|
||||
console.log('Rule #' + ruleId + ' moved down from position ' + originalOrder + ' to ' + (i + 1));
|
||||
}
|
||||
if (position > i) {
|
||||
console.log('Rule #' + ruleId + ' moved up from position ' + originalOrder + ' to ' + (i + 1));
|
||||
}
|
||||
// update position:
|
||||
holder.data('position', i);
|
||||
newOrder = i+1;
|
||||
|
||||
$.post('rules/move-rule/' + ruleId + '/' + ruleGroupId, {order: newOrder, _token: token});
|
||||
});
|
||||
});
|
||||
if (parent.hasClass('rule-triggers')) {
|
||||
$.post('rules/trigger/order/' + ruleId, {triggers: entries, _token: token}).fail(function () {
|
||||
alert('Could not re-order rule triggers. Please refresh the page.');
|
||||
});
|
||||
} else {
|
||||
$.post('rules/action/order/' + ruleId, {actions: entries, _token: token}).fail(function () {
|
||||
alert('Could not re-order rule actions. Please refresh the page.');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,22 +56,23 @@
|
||||
</p>
|
||||
|
||||
{% if ruleGroup.rules.count > 0 %}
|
||||
<table class="table table-hover table-striped">
|
||||
<table class="table table-hover table-striped group-rules">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th> </th>
|
||||
<th> </th>
|
||||
<th>{{ 'rule_name'|_ }}</th>
|
||||
<th class="hidden-xs">{{ 'rule_triggers'|_ }}</th>
|
||||
<th class="hidden-xs">{{ 'rule_actions'|_ }}</th>
|
||||
<th style="width:5%;"> </th>
|
||||
<th style="width:10%;"> </th>
|
||||
<th style="width:10%;"> </th>
|
||||
<th style="width:25%;">{{ 'rule_name'|_ }}</th>
|
||||
<th style="width:25%;" class="hidden-xs">{{ 'rule_triggers'|_ }}</th>
|
||||
<th style="width:25%;" class="hidden-xs">{{ 'rule_actions'|_ }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody class="rule-connected-list">
|
||||
{% for rule in ruleGroup.rules %}
|
||||
<tr>
|
||||
<tr class="single-rule" data-order="{{ rule.order }}" data-id="{{ rule.id }}" data-group-id="{{ ruleGroup.id }}" data-position="{{ loop.index0 }}">
|
||||
<td>
|
||||
<div class="btn-group btn-group-xs prio_buttons">
|
||||
{#
|
||||
{% if rule.order > 1 %}
|
||||
<a title="{{ 'rule_priority_up'|_ }}"
|
||||
href="{{ route('rules.up', rule.id) }}"
|
||||
@ -91,6 +92,8 @@
|
||||
<button disabled="disabled" class="btn btn-default"><span
|
||||
class="fa fa-fw"></span></button>
|
||||
{% endif %}
|
||||
#}
|
||||
<i class="fa fa-fw fa-bars rule-handle"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@ -144,7 +147,7 @@
|
||||
</td>
|
||||
<td class="hidden-xs">
|
||||
{% if rule.ruleTriggers.count > 0 %}
|
||||
<ul class="small rule-triggers" data-id="{{ rule.id }}">
|
||||
<ul class="small" data-id="{{ rule.id }}">
|
||||
{% for trigger in rule.ruleTriggers %}
|
||||
{% if trigger.trigger_type != "user_action" %}
|
||||
<li
|
||||
@ -164,7 +167,7 @@
|
||||
</td>
|
||||
<td class="hidden-xs">
|
||||
{% if rule.ruleActions.count > 0 %}
|
||||
<ul class="small rule-actions" data-id="{{ rule.id }}">
|
||||
<ul class="small" data-id="{{ rule.id }}">
|
||||
{% for action in rule.ruleActions %}
|
||||
<li
|
||||
{% if not rule.active %}
|
||||
|
@ -923,8 +923,12 @@ Route::group(
|
||||
|
||||
// index controller
|
||||
Route::get('', ['uses' => 'Rule\IndexController@index', 'as' => 'index']);
|
||||
Route::get('up/{rule}', ['uses' => 'Rule\IndexController@up', 'as' => 'up']);
|
||||
Route::get('down/{rule}', ['uses' => 'Rule\IndexController@down', 'as' => 'down']);
|
||||
|
||||
//Route::get('up/{rule}', ['uses' => 'Rule\IndexController@up', 'as' => 'up']);
|
||||
//Route::get('down/{rule}', ['uses' => 'Rule\IndexController@down', 'as' => 'down']);
|
||||
Route::post('move-rule/{rule}/{ruleGroup}', ['uses' => 'Rule\IndexController@moveRule', 'as' => 'move-rule']);
|
||||
|
||||
|
||||
Route::post('trigger/order/{rule}', ['uses' => 'Rule\IndexController@reorderRuleTriggers', 'as' => 'reorder-triggers']);
|
||||
Route::post('action/order/{rule}', ['uses' => 'Rule\IndexController@reorderRuleActions', 'as' => 'reorder-actions']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user