Group management code.

This commit is contained in:
James Cole
2020-06-20 10:10:55 +02:00
parent b54ef9f5e5
commit 5b29e78c4b
25 changed files with 737 additions and 14 deletions

View File

@@ -130,7 +130,6 @@ class ReconcileController extends Controller
$startDate = clone $start;
$startDate->subDay();
$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]);

View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use Illuminate\Http\RedirectResponse;
/**
* Class DeleteController
*/
class DeleteController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* PiggyBankController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class);
return $next($request);
}
);
}
/**
* Delete a piggy bank.
*
* @param ObjectGroup $objectGroup
*/
public function delete(ObjectGroup $objectGroup)
{
$subTitle = (string) trans('firefly.delete_object_group', ['title' => $objectGroup->title]);
$piggyBanks = $objectGroup->piggyBanks()->count();
// put previous url in session
$this->rememberPreviousUri('object-groups.delete.uri');
return view('object-groups.delete', compact('objectGroup', 'subTitle', 'piggyBanks'));
}
/**
* Destroy the piggy bank.
*
* @param ObjectGroup $objectGroup
*/
public function destroy(ObjectGroup $objectGroup): RedirectResponse
{
session()->flash('success', (string) trans('firefly.deleted_object_group', ['title' => $objectGroup->title]));
app('preferences')->mark();
$this->repository->destroy($objectGroup);
return redirect($this->getPreviousUri('object-groups.delete.uri'));
}
}

View File

@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\ObjectGroupFormRequest;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
/**
* Class EditController
*/
class EditController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* PiggyBankController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class);
return $next($request);
}
);
}
/**
* Edit an object group.
*
* @param ObjectGroup $objectGroup
*/
public function edit(ObjectGroup $objectGroup)
{
$subTitle = (string) trans('firefly.edit_object_group', ['title' => $objectGroup->title]);
$subTitleIcon = 'fa-pencil';
$targetDate = null;
$startDate = null;
if (true !== session('object-groups.edit.fromUpdate')) {
$this->rememberPreviousUri('object-groups.edit.uri');
}
session()->forget('object-groups.edit.fromUpdate');
return view('object-groups.edit', compact('subTitle', 'subTitleIcon', 'objectGroup'));
}
/**
* Update a piggy bank.
*
* @param ObjectGroupFormRequest $request
* @param ObjectGroup $objectGroup
*/
public function update(ObjectGroupFormRequest $request, ObjectGroup $objectGroup)
{
$data = $request->getObjectGroupData();
$piggyBank = $this->repository->update($objectGroup, $data);
session()->flash('success', (string) trans('firefly.updated_object_group', ['title' => $objectGroup->title]));
app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('object-groups.edit.uri'));
if (1 === (int) $request->get('return_to_edit')) {
// @codeCoverageIgnoreStart
session()->put('object-groups.edit.fromUpdate', true);
$redirect = redirect(route('object-groups.edit', [$piggyBank->id]));
// @codeCoverageIgnoreEnd
}
return $redirect;
}
}

View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\ObjectGroup;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use Illuminate\Http\Request;
use Log;
/**
* Class IndexController
*/
class IndexController extends Controller
{
private ObjectGroupRepositoryInterface $repository;
/**
* IndexController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
// translations:
$this->middleware(
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class);
return $next($request);
}
);
}
/**
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$this->repository->sort();
$subTitle = (string) trans('firefly.object_groups_index');
$objectGroups = $this->repository->get();
return view('object-groups.index', compact('subTitle', 'objectGroups'));
}
/**
* @param ObjectGroup $objectGroup
*/
public function setOrder(Request $request, ObjectGroup $objectGroup)
{
Log::debug(sprintf('Found object group #%d "%s"', $objectGroup->id, $objectGroup->title));
$newOrder = (int) $request->get('order');
$this->repository->setOrder($objectGroup, $newOrder);
return response()->json([]);
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* ObjectGroupFormRequest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\ObjectGroup;
/**
* Class ObjectGroupFormRequest.
*/
class ObjectGroupFormRequest extends Request
{
/**
* Verify the request.
*
* @return bool
*/
public function authorize(): bool
{
// Only allow logged in users
return auth()->check();
}
/**
* Returns the data required by the controller.
*
* @return array
*/
public function getObjectGroupData(): array
{
return [
'title' => $this->string('title'),
];
}
/**
* Rules for this request.
*
* @return array
*/
public function rules(): array
{
/** @var ObjectGroup $piggy */
$objectGroup = $this->route()->parameter('objectGroup');
$titleRule = 'required|between:1,255|uniqueObjectGroup';
if (null !== $objectGroup) {
$titleRule = sprintf('required|between:1,255|uniqueObjectGroup:%d', $objectGroup->id);
}
return [
'title' => $titleRule,
];
}
}