Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Re-order rule groups.
James Cole97770da61966
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.phpindex 0d0caa2ca1..563c653154 100644--- a/app/Http/Controllers/RuleController.php+++ b/app/Http/Controllers/RuleController.php@@ -184,8 +184,8 @@ class RuleController extends Controller*/public function index(){- $ruleGroups = Auth::user()->ruleGroups()->with(['rules' => function($query) {- $query->orderBy('order','ASC');+ $ruleGroups = Auth::user()->ruleGroups()->orderBy('order','ASC') ->with(['rules' => function ($query) {+ $query->orderBy('order', 'ASC');}])->get();@@ -219,4 +219,30 @@ class RuleController extends Controller}+ /**+ * @param RuleRepositoryInterface $repository+ * @param RuleGroup $ruleGroup+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector+ */+ public function upRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)+ {+ $repository->moveRuleGroupUp($ruleGroup);++ return redirect(route('rules.index'));++ }++ /**+ * @param RuleRepositoryInterface $repository+ * @param RuleGroup $ruleGroup+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector+ */+ public function downRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)+ {+ $repository->moveRuleGroupDown($ruleGroup);++ return redirect(route('rules.index'));++ }+}diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.phpindex f29681fba6..71509ee640 100644--- a/app/Repositories/Rule/RuleRepository.php+++ b/app/Repositories/Rule/RuleRepository.php@@ -175,4 +175,44 @@ class RuleRepository implements RuleRepositoryInterface}}++ /**+ * @param RuleGroup $ruleGroup+ * @return bool+ */+ public function moveRuleGroupUp(RuleGroup $ruleGroup)+ {+ $order = $ruleGroup->order;++ // find the rule with order-1 and give it order+1+ $other = Auth::user()->ruleGroups()->where('order', ($order - 1))->first();+ if ($other) {+ $other->order = ($other->order + 1);+ $other->save();+ }++ $ruleGroup->order = ($ruleGroup->order - 1);+ $ruleGroup->save();+ $this->resetRuleGroupOrder();+ }++ /**+ * @param RuleGroup $ruleGroup+ * @return bool+ */+ public function moveRuleGroupDown(RuleGroup $ruleGroup)+ {+ $order = $ruleGroup->order;++ // find the rule with order+1 and give it order-1+ $other = Auth::user()->ruleGroups()->where('order', ($order + 1))->first();+ if ($other) {+ $other->order = ($other->order - 1);+ $other->save();+ }++ $ruleGroup->order = ($ruleGroup->order + 1);+ $ruleGroup->save();+ $this->resetRuleGroupOrder();+ }}\ No newline at end of filediff --git a/app/Repositories/Rule/RuleRepositoryInterface.php b/app/Repositories/Rule/RuleRepositoryInterface.phpindex 9406ef9140..f497e0568d 100644--- a/app/Repositories/Rule/RuleRepositoryInterface.php+++ b/app/Repositories/Rule/RuleRepositoryInterface.php@@ -70,4 +70,16 @@ interface RuleRepositoryInterface*/public function moveRuleDown(Rule $rule);+ /**+ * @param RuleGroup $ruleGroup+ * @return bool+ */+ public function moveRuleGroupUp(RuleGroup $ruleGroup);++ /**+ * @param RuleGroup $ruleGroup+ * @return bool+ */+ public function moveRuleGroupDown(RuleGroup $ruleGroup);+}\ No newline at end of file