Move methods around

This commit is contained in:
James Cole 2016-01-15 13:06:17 +01:00
parent 466d739da8
commit 0809cfdc6d
3 changed files with 205 additions and 182 deletions

View File

@ -44,25 +44,6 @@ class RuleController extends Controller
View::share('mainTitleIcon', 'fa-random');
}
/**
* @return View
*/
public function createRuleGroup()
{
$subTitleIcon = 'fa-clone';
$subTitle = trans('firefly.make_new_rule_group');
// put previous url in session if not redirect from store (not "create another").
if (Session::get('rules.rule-group.create.fromStore') !== true) {
Session::put('rules.rule-group.create.url', URL::previous());
}
Session::forget('rules.rule-group.create.fromStore');
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'create-rule-group');
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
}
/**
* @param RuleFormRequest $request
* @param RuleRepositoryInterface $repository
@ -180,35 +161,10 @@ class RuleController extends Controller
}
/**
* @param RuleGroupFormRequest $request
* @param RuleRepositoryInterface $repository
* @param Rule $rule
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @return View
*/
public function storeRuleGroup(RuleGroupFormRequest $request, RuleRepositoryInterface $repository)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'user' => Auth::user()->id,
];
$ruleGroup = $repository->storeRuleGroup($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'));
}
public function editRule(Rule $rule)
{
@ -371,60 +327,6 @@ class RuleController extends Controller
return redirect(Session::get('rules.rule.edit.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->updateRuleGroup($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 RuleRepositoryInterface $repository
* @param Rule $rule
@ -444,26 +346,7 @@ class RuleController extends Controller
}
/**
* @param RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function deleteRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
$ruleGroupList = Expandedform::makeSelectList($repository->getRuleGroups(), true);
unset($ruleGroupList[$ruleGroup->id]);
// 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', 'ruleGroupList'));
}
/**
* @param Rule $rule
@ -484,28 +367,6 @@ class RuleController extends Controller
return redirect(Session::get('rules.rule.delete.url'));
}
/**
* @param RuleGroup $ruleGroup
* @param RuleRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroyRuleGroup(RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$title = $ruleGroup->title;
$moveTo = Auth::user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete')));
$repository->destroyRuleGroup($ruleGroup, $moveTo);
Session::flash('success', trans('firefly.deleted_rule_group', ['title' => $title]));
Preferences::mark();
return redirect(Session::get('rules.rule-group.delete.url'));
}
/**
* @param RuleRepositoryInterface $repository
* @param Rule $rule
@ -598,32 +459,5 @@ 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'));
}
}

View File

@ -2,13 +2,28 @@
namespace FireflyIII\Http\Controllers;
use Auth;
use ExpandedForm;
use FireflyIII\Http\Requests\RuleGroupFormRequest;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use Input;
use Preferences;
use Session;
use URL;
use View;
/**
* Class RuleGroupController
*
* @package FireflyIII\Http\Controllers
*/
class RuleGroupController extends Controller
{
/**
* RuleGroupController constructor.
*/
public function __construct()
{
parent::__construct();
@ -16,4 +31,179 @@ class RuleGroupController extends Controller
View::share('mainTitleIcon', 'fa-random');
}
/**
* @return View
*/
public function createRuleGroup()
{
$subTitleIcon = 'fa-clone';
$subTitle = trans('firefly.make_new_rule_group');
// put previous url in session if not redirect from store (not "create another").
if (Session::get('rules.rule-group.create.fromStore') !== true) {
Session::put('rules.rule-group.create.url', URL::previous());
}
Session::forget('rules.rule-group.create.fromStore');
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'create-rule-group');
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
}
/**
* @param RuleGroupFormRequest $request
* @param RuleRepositoryInterface $repository
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function storeRuleGroup(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'user' => Auth::user()->id,
];
$ruleGroup = $repository->storeRuleGroup($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 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, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$data = [
'title' => $request->input('title'),
'description' => $request->input('description'),
'active' => intval($request->input('active')) == 1,
];
$repository->updateRuleGroup($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 RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return View
*/
public function deleteRuleGroup(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
$ruleGroupList = Expandedform::makeSelectList($repository->getRuleGroups(), true);
unset($ruleGroupList[$ruleGroup->id]);
// 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', 'ruleGroupList'));
}
/**
* @param RuleGroup $ruleGroup
* @param RuleRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroyRuleGroup(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$title = $ruleGroup->title;
$moveTo = Auth::user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete')));
$repository->destroyRuleGroup($ruleGroup, $moveTo);
Session::flash('success', trans('firefly.deleted_rule_group', ['title' => $title]));
Preferences::mark();
return redirect(Session::get('rules.rule-group.delete.url'));
}
/**
* @param RuleRepositoryInterface $repository
* @param RuleGroup $ruleGroup
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function upRuleGroup(RuleGroupRepositoryInterface $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(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup)
{
$repository->moveRuleGroupDown($ruleGroup);
return redirect(route('rules.index'));
}
}

View File

@ -236,36 +236,35 @@ Route::group(
/**
* Rules Controller
*/
// index
Route::get('/rules', ['uses' => 'RuleController@index', 'as' => 'rules.index']);
// rules:
// rules GET:
Route::get('/rules/create/{ruleGroup}', ['uses' => 'RuleController@createRule', 'as' => 'rules.rule.create']);
Route::get('/rules/rules/up/{rule}', ['uses' => 'RuleController@upRule', 'as' => 'rules.rule.up']);
Route::get('/rules/rules/down/{rule}', ['uses' => 'RuleController@downRule', 'as' => 'rules.rule.down']);
Route::get('/rules/rules/edit/{rule}', ['uses' => 'RuleController@editRule', 'as' => 'rules.rule.edit']);
Route::get('/rules/rules/delete/{rule}', ['uses' => 'RuleController@deleteRule', 'as' => 'rules.rule.delete']);
// rules POST:
Route::post('/rules/rules/trigger/reorder/{rule}', ['uses' => 'RuleController@reorderRuleTriggers']);
Route::post('/rules/rules/action/reorder/{rule}', ['uses' => 'RuleController@reorderRuleActions']);
Route::post('/rules/store/{ruleGroup}', ['uses' => 'RuleController@storeRule', 'as' => 'rules.rule.store']);
Route::post('/rules/update/{rule}', ['uses' => 'RuleController@updateRule', 'as' => 'rules.rule.update']);
Route::post('/rules/destroy/{rule}', ['uses' => 'RuleController@destroyRule', 'as' => 'rules.rule.destroy']);
// rule groups:
Route::get('/rules/groups/create', ['uses' => 'RuleController@createRuleGroup', 'as' => 'rules.rule-group.create']);
Route::get('/rules/groups/edit/{ruleGroup}', ['uses' => 'RuleController@editRuleGroup', 'as' => 'rules.rule-group.edit']);
Route::get('/rules/groups/delete/{ruleGroup}', ['uses' => 'RuleController@deleteRuleGroup', 'as' => 'rules.rule-group.delete']);
// rule groups GET
Route::get('/rules/groups/create', ['uses' => 'RuleGroupController@createRuleGroup', 'as' => 'rules.rule-group.create']);
Route::get('/rules/groups/edit/{ruleGroup}', ['uses' => 'RuleGroupController@editRuleGroup', 'as' => 'rules.rule-group.edit']);
Route::get('/rules/groups/delete/{ruleGroup}', ['uses' => 'RuleGroupController@deleteRuleGroup', 'as' => 'rules.rule-group.delete']);
Route::get('/rules/groups/up/{ruleGroup}', ['uses' => 'RuleGroupController@upRuleGroup', 'as' => 'rules.rule-group.up']);
Route::get('/rules/groups/down/{ruleGroup}', ['uses' => 'RuleGroupController@downRuleGroup', 'as' => 'rules.rule-group.down']);
Route::get('/rules/groups/up/{ruleGroup}', ['uses' => 'RuleController@upRuleGroup', 'as' => 'rules.rule-group.up']);
Route::get('/rules/groups/down/{ruleGroup}', ['uses' => 'RuleController@downRuleGroup', 'as' => 'rules.rule-group.down']);
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/destroy/{ruleGroup}', ['uses' => 'RuleController@destroyRuleGroup', 'as' => 'rules.rule-group.destroy']);
// rule groups POST
Route::post('/rules/groups/store', ['uses' => 'RuleGroupController@storeRuleGroup', 'as' => 'rules.rule-group.store']);
Route::post('/rules/groups/update/{ruleGroup}', ['uses' => 'RuleGroupController@updateRuleGroup', 'as' => 'rules.rule-group.update']);
Route::post('/rules/groups/destroy/{ruleGroup}', ['uses' => 'RuleGroupController@destroyRuleGroup', 'as' => 'rules.rule-group.destroy']);
/**
* Search Controller