Some code cleanup and reordering

This commit is contained in:
James Cole
2016-01-24 15:58:16 +01:00
parent 2832d308f1
commit 97db618cd8
10 changed files with 453 additions and 458 deletions

View File

@@ -49,90 +49,6 @@ class RuleGroupController extends Controller
return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
}
/**
* @param RuleGroupFormRequest $request
* @param RuleGroupRepositoryInterface $repository
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'user' => Auth::user()->id,
];
$ruleGroup = $repository->store($data);
Session::flash('success', trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
Session::put('rules.rule-group.create.fromStore', true);
return redirect(route('rules.rule-group.create'))->withInput();
}
// redirect to previous URL.
return redirect(Session::get('rules.rule-group.create.url'));
}
/**
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function edit(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 RuleGroupRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $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'));
}
/**
* @param RuleGroupRepositoryInterface $repository
* @param RuleGroup $ruleGroup
@@ -177,6 +93,70 @@ class RuleGroupController extends Controller
return redirect(Session::get('rules.rule-group.delete.url'));
}
/**
* @param RuleGroupRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function down(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$repository->moveDown($ruleGroup);
return redirect(route('rules.index'));
}
/**
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function edit(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 RuleGroupRepositoryInterface $repository
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'user' => Auth::user()->id,
];
$ruleGroup = $repository->store($data);
Session::flash('success', trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
Preferences::mark();
if (intval(Input::get('create_another')) === 1) {
// set value so create routine will not overwrite URL:
Session::put('rules.rule-group.create.fromStore', true);
return redirect(route('rules.rule-group.create'))->withInput();
}
// redirect to previous URL.
return redirect(Session::get('rules.rule-group.create.url'));
}
/**
* @param RuleGroupRepositoryInterface $repository
@@ -193,16 +173,34 @@ class RuleGroupController extends Controller
}
/**
* @param RuleGroupFormRequest $request
* @param RuleGroupRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function down(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$repository->moveDown($ruleGroup);
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'active' => intval($request->input('active')) == 1,
];
return redirect(route('rules.index'));
$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'));
}