mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-24 16:10:37 -06:00
Organise object groups
This commit is contained in:
parent
16b0307b0a
commit
471cdefcff
@ -7,6 +7,7 @@ namespace FireflyIII\Http\Controllers\PiggyBank;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\ObjectGroup\OrganisesObjectGroups;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\AccountTransformer;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
@ -21,6 +22,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
*/
|
||||
class IndexController extends Controller
|
||||
{
|
||||
use OrganisesObjectGroups;
|
||||
private PiggyBankRepositoryInterface $piggyRepos;
|
||||
|
||||
/**
|
||||
@ -46,6 +48,7 @@ class IndexController extends Controller
|
||||
|
||||
/**
|
||||
* Show overview of all piggy banks.
|
||||
* TODO complicated
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
@ -53,6 +56,7 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->cleanupObjectGroups();
|
||||
$this->piggyRepos->correctOrder();
|
||||
$collection = $this->piggyRepos->getPiggyBanks();
|
||||
$accounts = [];
|
||||
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\ObjectGroup;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@ -18,7 +19,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
*/
|
||||
public function get(): Collection
|
||||
{
|
||||
return ObjectGroup::orderBy('order')->get();
|
||||
return ObjectGroup::orderBy('order', 'ASC')->orderBy('title', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,7 +29,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
*/
|
||||
public function search(string $query): Collection
|
||||
{
|
||||
$dbQuery = ObjectGroup::orderBy('order');
|
||||
$dbQuery = ObjectGroup::orderBy('order', 'ASC')->orderBy('title', 'ASC');
|
||||
if ('' !== $query) {
|
||||
// split query on spaces just in case:
|
||||
$parts = explode(' ', $query);
|
||||
@ -41,4 +42,35 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
|
||||
|
||||
return $dbQuery->get(['object_groups.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteEmpty(): void
|
||||
{
|
||||
$all = $this->get();
|
||||
/** @var ObjectGroup $group */
|
||||
foreach ($all as $group) {
|
||||
$count = DB::table('object_groupables')->where('object_groupables.object_group_id', $group->id)->count();
|
||||
if (0 === $count) {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function sort(): void
|
||||
{
|
||||
$all = $this->get();
|
||||
/**
|
||||
* @var int $index
|
||||
* @var ObjectGroup $group
|
||||
*/
|
||||
foreach ($all as $index => $group) {
|
||||
$group->order = $index + 1;
|
||||
$group->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,14 @@ interface ObjectGroupRepositoryInterface
|
||||
*/
|
||||
public function search(string $query): Collection;
|
||||
|
||||
/**
|
||||
* Delete empty ones.
|
||||
*/
|
||||
public function deleteEmpty(): void;
|
||||
|
||||
/**
|
||||
* Sort
|
||||
*/
|
||||
public function sort(): void;
|
||||
|
||||
}
|
||||
|
37
app/Repositories/ObjectGroup/OrganisesObjectGroups.php
Normal file
37
app/Repositories/ObjectGroup/OrganisesObjectGroups.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\ObjectGroup;
|
||||
|
||||
/**
|
||||
* Trait OrganisesRoleGroups
|
||||
*/
|
||||
trait OrganisesObjectGroups
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function cleanupObjectGroups(): void
|
||||
{
|
||||
$this->deleteEmptyObjectGroups();
|
||||
$this->sortObjectGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function deleteEmptyObjectGroups(): void
|
||||
{
|
||||
$repository = app(ObjectGroupRepositoryInterface::class);
|
||||
$repository->deleteEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function sortObjectGroups(): void
|
||||
{
|
||||
$repository = app(ObjectGroupRepositoryInterface::class);
|
||||
$repository->sort();
|
||||
}
|
||||
}
|
@ -181,6 +181,7 @@ trait ModifiesPiggyBanks
|
||||
*/
|
||||
public function destroy(PiggyBank $piggyBank): bool
|
||||
{
|
||||
$piggyBank->objectGroups()->sync([]);
|
||||
$piggyBank->delete();
|
||||
|
||||
return true;
|
||||
|
@ -90,6 +90,7 @@
|
||||
"jc5/google2fa-laravel": "2.0.4",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravel/passport": "8.*",
|
||||
"laravel/ui": "^2.0",
|
||||
"laravelcollective/html": "6.*",
|
||||
"league/commonmark": "1.*",
|
||||
"league/fractal": "0.*",
|
||||
|
85
composer.lock
generated
85
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b0ee6a1f70a2e9aa15012ac9110d95de",
|
||||
"content-hash": "c87d6fc7dfa25bdd667573fd4f924d0b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adldap2/adldap2",
|
||||
@ -476,6 +476,20 @@
|
||||
"sqlserver",
|
||||
"sqlsrv"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.doctrine-project.org/sponsorship.html",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpdoctrine",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-20T17:19:26+00:00"
|
||||
},
|
||||
{
|
||||
@ -1627,6 +1641,61 @@
|
||||
],
|
||||
"time": "2020-05-05T14:25:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/ui",
|
||||
"version": "v2.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/ui.git",
|
||||
"reference": "15368c5328efb7ce94f35ca750acde9b496ab1b1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/ui/zipball/15368c5328efb7ce94f35ca750acde9b496ab1b1",
|
||||
"reference": "15368c5328efb7ce94f35ca750acde9b496ab1b1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/console": "^7.0",
|
||||
"illuminate/filesystem": "^7.0",
|
||||
"illuminate/support": "^7.0",
|
||||
"php": "^7.2.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"phpunit/phpunit": "^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Ui\\UiServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Ui\\": "src/",
|
||||
"Illuminate\\Foundation\\Auth\\": "auth-backend/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "Laravel UI utilities and presets.",
|
||||
"keywords": [
|
||||
"laravel",
|
||||
"ui"
|
||||
],
|
||||
"time": "2020-04-29T15:06:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravelcollective/html",
|
||||
"version": "v6.1.2",
|
||||
@ -2757,6 +2826,20 @@
|
||||
"x.509",
|
||||
"x509"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/terrafrost",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpseclib",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-04T23:17:33+00:00"
|
||||
},
|
||||
{
|
||||
|
@ -186,7 +186,7 @@ return [
|
||||
'ExpandedForm' => [
|
||||
'is_safe' => [
|
||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'file', 'staticText',
|
||||
'password', 'nonSelectableAmount', 'number', 'amountNoCurrency', 'percentage',
|
||||
'password', 'nonSelectableAmount', 'number', 'amountNoCurrency', 'percentage','objectGroup'
|
||||
|
||||
],
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user