Fixed some bugs in various controllers and started rebuilding the category controller.

This commit is contained in:
Sander Dorigo
2014-11-10 19:03:03 +01:00
parent cb08df0770
commit af9473c126
13 changed files with 291 additions and 220 deletions

View File

@@ -312,7 +312,7 @@ class AccountController extends BaseController
default:
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
break;
case 'create_another':
case 'return_to_edit':
case 'store':
$messages = $acct->validate($data);
/** @var MessageBag $messages ['errors'] */

View File

@@ -263,7 +263,7 @@ class BudgetController extends BaseController
default:
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break;
case 'create_another':
case 'return_to_edit':
case 'update':
$messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */
@@ -277,7 +277,7 @@ class BudgetController extends BaseController
$repos->update($budget, $data);
Session::flash('success', 'Budget updated!');
if ($data['post_submit_action'] == 'create_another') {
if ($data['post_submit_action'] == 'return_to_edit') {
return Redirect::route('budgets.edit', $budget->id);
} else {
return Redirect::route('budgets.index');

View File

@@ -1,26 +1,17 @@
<?php
use Firefly\Helper\Controllers\CategoryInterface as CI;
use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
use Firefly\Exception\FireflyException;
use Illuminate\Support\MessageBag;
/**
* Class CategoryController
*
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
*/
class CategoryController extends BaseController
{
protected $_repository;
protected $_category;
/**
* @param CRI $repository
* @param CI $category
*
*/
public function __construct(CRI $repository, CI $category)
public function __construct()
{
$this->_repository = $repository;
$this->_category = $category;
View::share('title', 'Categories');
View::share('mainTitleIcon', 'fa-bar-chart');
}
@@ -40,8 +31,7 @@ class CategoryController extends BaseController
*/
public function delete(Category $category)
{
return View::make('categories.delete')->with('category', $category)
->with('subTitle', 'Delete category "' . $category->name . '"');
return View::make('categories.delete')->with('category', $category)->with('subTitle', 'Delete category "' . $category->name . '"');
}
/**
@@ -51,7 +41,10 @@ class CategoryController extends BaseController
*/
public function destroy(Category $category)
{
$this->_repository->destroy($category);
/** @var \FireflyIII\Database\Category $repos */
$repos = App::make('FireflyIII\Database\Category');
$repos->destroy($category);
Session::flash('success', 'The category was deleted.');
return Redirect::route('categories.index');
}
@@ -72,10 +65,7 @@ class CategoryController extends BaseController
*/
public function index()
{
$categories = $this->_repository->get();
return View::make('categories.index')->with('categories', $categories)
->with('subTitle', 'All your categories');
return View::make('categories.index');
}
/**
@@ -124,15 +114,40 @@ class CategoryController extends BaseController
*/
public function update(Category $category)
{
$category = $this->_repository->update($category, Input::all());
if ($category->validate()) {
Session::flash('success', 'Category "' . $category->name . '" updated.');
/** @var \FireflyIII\Database\Category $repos */
$repos = App::make('FireflyIII\Database\Category');
$data = Input::except('_token');
return Redirect::route('categories.index');
} else {
Session::flash('success', 'Could not update category "' . $category->name . '".');
switch (Input::get('post_submit_action')) {
default:
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
break;
case 'return_to_edit':
case 'update':
$messages = $repos->validate($data);
/** @var MessageBag $messages ['errors'] */
if ($messages['errors']->count() > 0) {
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('error', 'Could not save category: ' . $messages['errors']->first());
return Redirect::route('categories.edit', $category->id)->withInput()->withErrors($messages['errors']);
}
// store!
$repos->update($category, $data);
Session::flash('success', 'Category updated!');
return Redirect::route('categories.edit')->withErrors($category->errors())->withInput();
if ($data['post_submit_action'] == 'return_to_edit') {
return Redirect::route('categories.edit', $category->id);
} else {
return Redirect::route('categories.index');
}
case 'validate_only':
$messageBags = $repos->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
return Redirect::route('categories.edit', $category->id)->withInput();
break;
}

View File

@@ -8,6 +8,38 @@ use Firefly\Exception\FireflyException;
class GoogleTableController extends BaseController
{
/**
* @return \Illuminate\Http\JsonResponse
*/
public function categoryList()
{
/** @var \FireflyIII\Database\Category $repos */
$repos = App::make('FireflyIII\Database\Category');
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
$chart->addColumn('ID', 'number');
$chart->addColumn('ID_Edit', 'string');
$chart->addColumn('ID_Delete', 'string');
$chart->addColumn('Name_URL', 'string');
$chart->addColumn('Name', 'string');
$list = $repos->get();
/** @var Category $entry */
foreach ($list as $entry) {
$chart->addRow(
$entry->id, route('categories.edit', $entry->id), route('categories.delete', $entry->id), route('categories.show', $entry->id), $entry->name
);
}
$chart->generate();
return Response::json($chart->getData());
}
/**
* @param $what
*
@@ -84,8 +116,8 @@ class GoogleTableController extends BaseController
if (is_null($repetition)) {
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get();
} else {
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->
after($repetition->startdate)->before($repetition->enddate)->orderBy('date', 'DESC')->get();
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->after($repetition->startdate)
->before($repetition->enddate)->orderBy('date', 'DESC')->get();
}
/** @var TransactionJournal $transaction */
foreach ($journals as $journal) {