mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Routine to delete rules. Should include routine to move rules to other group.
This commit is contained in:
@@ -124,7 +124,7 @@ class RuleController extends Controller
|
|||||||
'active' => intval($request->input('active')) == 1,
|
'active' => intval($request->input('active')) == 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
$repository->update($ruleGroup, $data);
|
$repository->updateRuleGroup($ruleGroup, $data);
|
||||||
|
|
||||||
Session::flash('success', trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
|
Session::flash('success', trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
|
||||||
Preferences::mark();
|
Preferences::mark();
|
||||||
@@ -141,6 +141,43 @@ class RuleController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RuleGroup $budget
|
||||||
|
*
|
||||||
|
* @return \Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function deleteRuleGroup(RuleGroup $ruleGroup)
|
||||||
|
{
|
||||||
|
$subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
|
||||||
|
|
||||||
|
// put previous url in session
|
||||||
|
Session::put('rules.rule-group.delete.url', URL::previous());
|
||||||
|
Session::flash('gaEventCategory', 'rules');
|
||||||
|
Session::flash('gaEventAction', 'delete-rule-group');
|
||||||
|
|
||||||
|
return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RuleGroup $ruleGroup
|
||||||
|
* @param RuleRepositoryInterface $repository
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function destroyRuleGroup(RuleGroup $ruleGroup, RuleRepositoryInterface $repository)
|
||||||
|
{
|
||||||
|
|
||||||
|
$title = $ruleGroup->title;
|
||||||
|
$repository->destroyRuleGroup($ruleGroup);
|
||||||
|
|
||||||
|
|
||||||
|
Session::flash('success', trans('firefly.deleted_rule_group', ['title' => $title]));
|
||||||
|
Preferences::mark();
|
||||||
|
|
||||||
|
|
||||||
|
return redirect(Session::get('rules.rule-group.delete.url'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return View
|
* @return View
|
||||||
|
@@ -249,6 +249,7 @@ Route::group(
|
|||||||
|
|
||||||
Route::post('/rules/groups/store', ['uses' => 'RuleController@storeRuleGroup', 'as' => 'rules.rule-group.store']);
|
Route::post('/rules/groups/store', ['uses' => 'RuleController@storeRuleGroup', 'as' => 'rules.rule-group.store']);
|
||||||
Route::post('/rules/groups/update/{ruleGroup}', ['uses' => 'RuleController@updateRuleGroup', 'as' => 'rules.rule-group.update']);
|
Route::post('/rules/groups/update/{ruleGroup}', ['uses' => 'RuleController@updateRuleGroup', 'as' => 'rules.rule-group.update']);
|
||||||
|
Route::post('/rules/groups/destroy/{ruleGroup}', ['uses' => 'RuleController@destroyRuleGroup', 'as' => 'rules.rule-group.destroy']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search Controller
|
* Search Controller
|
||||||
|
@@ -11,6 +11,7 @@ namespace FireflyIII\Models;
|
|||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +36,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
*/
|
*/
|
||||||
class Rule extends Model
|
class Rule extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDeletes;
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
*/
|
*/
|
||||||
|
@@ -11,6 +11,7 @@ namespace FireflyIII\Models;
|
|||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +32,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
*/
|
*/
|
||||||
class RuleGroup extends Model
|
class RuleGroup extends Model
|
||||||
{
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = ['user_id', 'order', 'title', 'description', 'active'];
|
protected $fillable = ['user_id', 'order', 'title', 'description', 'active'];
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
namespace FireflyIII\Repositories\Rule;
|
namespace FireflyIII\Repositories\Rule;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +51,7 @@ class RuleRepository implements RuleRepositoryInterface
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
$newRuleGroup->save();
|
$newRuleGroup->save();
|
||||||
|
$this->resetRuleGroupOrder();
|
||||||
|
|
||||||
return $newRuleGroup;
|
return $newRuleGroup;
|
||||||
}
|
}
|
||||||
@@ -60,14 +62,54 @@ class RuleRepository implements RuleRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return RuleGroup
|
* @return RuleGroup
|
||||||
*/
|
*/
|
||||||
public function update(RuleGroup $ruleGroup, array $data)
|
public function updateRuleGroup(RuleGroup $ruleGroup, array $data)
|
||||||
{
|
{
|
||||||
// update the account:
|
// update the account:
|
||||||
$ruleGroup->title = $data['title'];
|
$ruleGroup->title = $data['title'];
|
||||||
$ruleGroup->description = $data['description'];
|
$ruleGroup->description = $data['description'];
|
||||||
$ruleGroup->active = $data['active'];
|
$ruleGroup->active = $data['active'];
|
||||||
$ruleGroup->save();
|
$ruleGroup->save();
|
||||||
|
$this->resetRuleGroupOrder();
|
||||||
|
|
||||||
return $ruleGroup;
|
return $ruleGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RuleGroup $ruleGroup
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function destroyRuleGroup(RuleGroup $ruleGroup)
|
||||||
|
{
|
||||||
|
/** @var Rule $rule */
|
||||||
|
foreach ($ruleGroup->rules as $rule) {
|
||||||
|
$rule->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$ruleGroup->delete();
|
||||||
|
|
||||||
|
$this->resetRuleGroupOrder();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function resetRuleGroupOrder()
|
||||||
|
{
|
||||||
|
Auth::user()->ruleGroups()->whereNotNull('deleted_at')->update(['order' => 0]);
|
||||||
|
|
||||||
|
$set = Auth::user()->ruleGroups()->where('active', 1)->orderBy('order', 'ASC')->get();
|
||||||
|
$count = 1;
|
||||||
|
/** @var RuleGroup $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$entry->order = $count;
|
||||||
|
$entry->save();
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -37,6 +37,19 @@ interface RuleRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @return RuleGroup
|
* @return RuleGroup
|
||||||
*/
|
*/
|
||||||
public function update(RuleGroup $ruleGroup, array $data);
|
public function updateRuleGroup(RuleGroup $ruleGroup, array $data);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RuleGroup $ruleGroup
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function destroyRuleGroup(RuleGroup $ruleGroup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function resetRuleGroupOrder();
|
||||||
|
|
||||||
}
|
}
|
@@ -37,8 +37,6 @@ class ChangesForV370 extends Migration
|
|||||||
// connect rule groups to users
|
// connect rule groups to users
|
||||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
|
|
||||||
// order must be unique for rule group:
|
|
||||||
$table->unique(['user_id', 'order']);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -65,8 +63,6 @@ class ChangesForV370 extends Migration
|
|||||||
// connect rules to rule groups
|
// connect rules to rule groups
|
||||||
$table->foreign('rule_group_id')->references('id')->on('rule_groups')->onDelete('cascade');
|
$table->foreign('rule_group_id')->references('id')->on('rule_groups')->onDelete('cascade');
|
||||||
|
|
||||||
// order must be unique for rules:
|
|
||||||
$table->unique(['user_id', 'order']);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -53,6 +53,8 @@ return [
|
|||||||
'created_new_rule_group' => 'New rule group ":title" stored!',
|
'created_new_rule_group' => 'New rule group ":title" stored!',
|
||||||
'updated_rule_group' => 'Successfully updated rule group ":title".',
|
'updated_rule_group' => 'Successfully updated rule group ":title".',
|
||||||
'edit_rule_group' => 'Edit rule group ":title"',
|
'edit_rule_group' => 'Edit rule group ":title"',
|
||||||
|
'delete_rule_group' => 'Delete rule group ":title"',
|
||||||
|
'deleted_rule_group' => 'Deleted rule group ":title"',
|
||||||
'update_rule_group' => 'Update rule group',
|
'update_rule_group' => 'Update rule group',
|
||||||
'no_rules_in_group' => 'There are no rules in this group',
|
'no_rules_in_group' => 'There are no rules in this group',
|
||||||
|
|
||||||
|
@@ -76,10 +76,12 @@ return [
|
|||||||
'delete_currency' => 'Delete currency ":name"',
|
'delete_currency' => 'Delete currency ":name"',
|
||||||
'delete_journal' => 'Delete transaction with description ":description"',
|
'delete_journal' => 'Delete transaction with description ":description"',
|
||||||
'delete_attachment' => 'Delete attachment ":name"',
|
'delete_attachment' => 'Delete attachment ":name"',
|
||||||
|
'delete_rule_group' => 'Delete rule group ":title"',
|
||||||
|
|
||||||
'attachment_areYouSure' => 'Are you sure you want to delete the attachment named ":name"?',
|
'attachment_areYouSure' => 'Are you sure you want to delete the attachment named ":name"?',
|
||||||
'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?',
|
'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?',
|
||||||
'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?',
|
'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?',
|
||||||
|
'ruleGroup_areYouSure' => 'Are you sure you want to delete the rule group titles ":title"?',
|
||||||
'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?',
|
'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?',
|
||||||
'category_areYouSure' => 'Are you sure you want to delete the category named ":name"?',
|
'category_areYouSure' => 'Are you sure you want to delete the category named ":name"?',
|
||||||
'currency_areYouSure' => 'Are you sure you want to delete the currency named ":name"?',
|
'currency_areYouSure' => 'Are you sure you want to delete the currency named ":name"?',
|
||||||
@@ -89,6 +91,7 @@ return [
|
|||||||
|
|
||||||
'permDeleteWarning' => 'Deleting stuff from Firely is permanent and cannot be undone.',
|
'permDeleteWarning' => 'Deleting stuff from Firely is permanent and cannot be undone.',
|
||||||
'also_delete_transactions' => 'The only transaction connected to this account will be deleted as well.|All :count transactions connected to this account will be deleted as well.',
|
'also_delete_transactions' => 'The only transaction connected to this account will be deleted as well.|All :count transactions connected to this account will be deleted as well.',
|
||||||
|
'also_delete_rules' => 'The only rule connected to this rule group will be deleted as well.|All :count rules connected to this rule group will be deleted as well.',
|
||||||
'also_delete_piggyBanks' => 'The only piggy bank connected to this account will be deleted as well.|All :count piggy bank connected to this account will be deleted as well.',
|
'also_delete_piggyBanks' => 'The only piggy bank connected to this account will be deleted as well.|All :count piggy bank connected to this account will be deleted as well.',
|
||||||
'bill_keep_transactions' => 'The only transaction connected to this bill will not be deleted.|All :count transactions connected to this bill will spared deletion.',
|
'bill_keep_transactions' => 'The only transaction connected to this bill will not be deleted.|All :count transactions connected to this bill will spared deletion.',
|
||||||
'budget_keep_transactions' => 'The only transaction connected to this budget will not be deleted.|All :count transactions connected to this budget will spared deletion.',
|
'budget_keep_transactions' => 'The only transaction connected to this budget will not be deleted.|All :count transactions connected to this budget will spared deletion.',
|
||||||
|
41
resources/views/rules/rule-group/delete.twig
Normal file
41
resources/views/rules/rule-group/delete.twig
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{% extends "./layout/default.twig" %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, ruleGroup) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{{ Form.open({'class' : 'form-horizontal','id' : 'destroy','url' : route('rules.rule-group.destroy',ruleGroup.id) }) }}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-lg-offset-3 col-md-12 col-sm-12">
|
||||||
|
<div class="box box-danger">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ trans('form.delete_rule_group', {'title': ruleGroup.title}) }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ trans('form.permDeleteWarning') }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{ trans('form.ruleGroup_areYouSure', {'title': ruleGroup.title}) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="text-danger">
|
||||||
|
{% if ruleGroup.rules|length > 0 %}
|
||||||
|
{{ Lang.choice('form.also_delete_rules', ruleGroup.rules|length, {count: ruleGroup.rules|length}) }}
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="box-footer">
|
||||||
|
<input type="submit" name="submit" value="{{ trans('form.deletePermanently') }}" class="btn btn-danger pull-right"/>
|
||||||
|
<a href="{{ URL.previous() }}" class="btn-default btn">{{ trans('form.cancel') }}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ Form.close|raw }}
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user