Edit rule group.

This commit is contained in:
James Cole 2016-01-13 18:50:15 +01:00
parent b2bb16c1e0
commit 06174d6afb
7 changed files with 142 additions and 13 deletions

View File

@ -47,14 +47,14 @@ class RuleController extends Controller
$subTitle = trans('firefly.make_new_rule_group');
// put previous url in session if not redirect from store (not "create another").
if (Session::get('rule-groups.create.fromStore') !== true) {
Session::put('rule-groups.create.url', URL::previous());
if (Session::get('rules.rule-group.create.fromStore') !== true) {
Session::put('rules.rule-group.create.url', URL::previous());
}
Session::forget('accounts.create.fromStore');
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'create-rule-group');
return view('rules.create-rule-group', compact('subTitleIcon', 'what', 'subTitle'));
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
}
/**
@ -78,15 +78,70 @@ class RuleController extends Controller
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
Session::put('rule-groups.create.fromStore', true);
Session::put('rules.rule-group.create.fromStore', true);
return redirect(route('rules.rule-group.create'))->withInput();
}
// redirect to previous URL.
return redirect(Session::get('rule-groups.create.url'));
return redirect(Session::get('rules.rule-group.create.url'));
}
/**
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function editRuleGroup(RuleGroup $ruleGroup)
{
$subTitle = trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
// put previous url in session if not redirect from store (not "return_to_edit").
if (Session::get('rules.rule-group.edit.fromUpdate') !== true) {
Session::put('rules.rule-group.edit.url', URL::previous());
}
Session::forget('rules.rule-group.edit.fromUpdate');
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'edit-rule-group');
return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle'));
}
/**
* @param RuleGroupFormRequest $request
* @param RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function updateRuleGroup(RuleGroupFormRequest $request, RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'active' => intval($request->input('active')) == 1,
];
$repository->update($ruleGroup, $data);
Session::flash('success', trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
Preferences::mark();
if (intval(Input::get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
Session::put('rules.rule-group.edit.fromUpdate', true);
return redirect(route('rules.rule-group.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]);
}
// redirect to previous URL.
return redirect(Session::get('rules.rule-group.edit.url'));
}
/**
* @return View
*/
@ -105,11 +160,4 @@ class RuleController extends Controller
}
/**
* @param RuleGroup $ruleGroup
*/
public function editRuleGroup(RuleGroup $ruleGroup)
{
}
}

View File

@ -248,7 +248,7 @@ Route::group(
Route::get('/rules/groups/delete/{ruleGroup}', ['uses' => 'RuleController@deleteRuleGroup', 'as' => 'rules.rule-group.delete']);
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']);
/**
* Search Controller

View File

@ -53,4 +53,21 @@ class RuleRepository implements RuleRepositoryInterface
return $newRuleGroup;
}
/**
* @param RuleGroup $ruleGroup
* @param array $data
*
* @return RuleGroup
*/
public function update(RuleGroup $ruleGroup, array $data)
{
// update the account:
$ruleGroup->title = $data['title'];
$ruleGroup->description = $data['description'];
$ruleGroup->active = $data['active'];
$ruleGroup->save();
return $ruleGroup;
}
}

View File

@ -30,4 +30,13 @@ interface RuleRepositoryInterface
*/
public function getHighestOrderRuleGroup();
/**
* @param RuleGroup $ruleGroup
* @param array $data
*
* @return RuleGroup
*/
public function update(RuleGroup $ruleGroup, array $data);
}

View File

@ -51,6 +51,9 @@ return [
'make_new_rule_group' => 'Make new rule group',
'store_new_rule_group' => 'Store new rule group',
'created_new_rule_group' => 'New rule group ":title" stored!',
'updated_rule_group' => 'Successfully updated rule group ":title".',
'edit_rule_group' => 'Edit rule group ":title"',
'update_rule_group' => 'Update rule group',
'no_rules_in_group' => 'There are no rules in this group',
// actions and triggers

View File

@ -0,0 +1,52 @@
{% extends "./layout/default.twig" %}
{% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, ruleGroup) }}
{% endblock %}
{% block content %}
{{ Form.model(ruleGroup, {'class' : 'form-horizontal','id' : 'update','url' : route('rules.rule-group.update',ruleGroup.id) } ) }}
<input type="hidden" name="id" value="{{ ruleGroup.id }}"/>
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-6">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
</div>
<div class="box-body">
{{ ExpandedForm.checkbox('active') }}
{{ ExpandedForm.text('title') }}
</div>
</div>
</div>
<div class="col-lg-6 col-md-12 col-sm-6">
<!-- optional fields -->
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
</div>
<div class="box-body">
{{ ExpandedForm.textarea('description') }}
</div>
</div>
<!-- panel for options -->
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'options'|_ }}</h3>
</div>
<div class="box-body">
{{ ExpandedForm.optionsList('update','budget') }}
</div>
<div class="box-footer">
<button type="submit" class="btn pull-right btn-success">{{ 'update_rule_group'|_ }}</button>
</div>
</div>
</div>
</div>
{{ Form.close|raw }}
{% endblock %}