From ddefb0debcaa9ed7342eafbc8d6278d938df225d Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 18 Jun 2015 18:05:06 +0200 Subject: [PATCH] Improved tag view [skip ci] --- app/Http/Controllers/TagController.php | 21 +++++++++++-- resources/lang/en/firefly.php | 5 +++ resources/lang/nl/firefly.php | 5 +++ resources/twig/tags/index.twig | 43 ++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 673b2813d7..3ec7878858 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -178,9 +178,24 @@ class TagController extends Controller $title = 'Tags'; $mainTitleIcon = 'fa-tags'; $helpHidden = $helpHiddenPref->data; - $tags = Auth::user()->tags()->get(); - return view('tags.index', compact('title', 'mainTitleIcon', 'helpHidden', 'tags')); + // group years. + $types = ['nothing','balancingAct', 'advancePayment']; + + // loop each types and get the tags, group them by year. + $collection = []; + foreach ($types as $type) { + $tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date','ASC')->get(); + /** @var Tag $tag */ + foreach ($tags as $tag) { + $year = is_null($tag->date) ? trans('firefly.no_year') : $tag->date->year; + $month = is_null($tag->date) ? trans('firefly.no_month') : $tag->date->formatLocalized($this->monthFormat); + $collection[$type][$year][$month][] = $tag; + } + } + + + return view('tags.index', compact('title', 'mainTitleIcon','types', 'helpHidden', 'collection')); } /** @@ -193,7 +208,7 @@ class TagController extends Controller $subTitle = $tag->tag; $subTitleIcon = 'fa-tag'; - return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon')); + return view('tags.show', compact('tag', 'subTitle','types', 'subTitleIcon')); } /** diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php index 9b9c54a95b..7c436b42d1 100644 --- a/resources/lang/en/firefly.php +++ b/resources/lang/en/firefly.php @@ -286,6 +286,11 @@ return [ 'delete_tag' => 'Delete tag ":name"', 'new_tag' => 'Make new tag', 'edit_tag' => 'Edit tag ":tag"', + 'no_year' => 'No year set', + 'no_month' => 'No month set', + 'tag_title_nothing' => 'Default tags', + 'tag_title_balancingAct' => 'Balancing act tags', + 'tag_title_advancePayment' => 'Advance payment tags', // reminders 'reminder_for_piggy' => 'Reminder for piggy bank ":name"', diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index 4a42b5ae8e..5b740824db 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -295,6 +295,11 @@ return [ 'delete_tag' => 'Verwijder tag ":name"', 'new_tag' => 'Maak nieuwe tag', 'edit_tag' => 'Wijzig tag ":tag"', + 'no_year' => 'Zonder jaar', + 'no_maand' => 'Zonder jaar', + 'tag_title_nothing' => 'Standaard tags', + 'tag_title_balancingAct' => 'Balancing act tags', + 'tag_title_advancePayment' => 'Advance payment tags', // reminders 'reminder_for_piggy' => 'Herinnering voor spaarpotje ":name"', diff --git a/resources/twig/tags/index.twig b/resources/twig/tags/index.twig index e9ce66c161..86b5feac8e 100644 --- a/resources/twig/tags/index.twig +++ b/resources/twig/tags/index.twig @@ -41,6 +41,49 @@ {% endif %}

+ + + + +
+ {% for type in types %} +
+
+
{{ ('tag_title_'~type)|_ }}
+
+ {% for year,months in collection[type] %} +

{{ year }}

+ + {% for month,tags in months %} +
{{ month }}
+

+ {% for tag in tags %} + + {% if tag.tagMode == 'nothing' %} + + {% endif %} + {% if tag.tagMode == 'balancingAct' %} + + {% endif %} + {% if tag.tagMode == 'advancePayment' %} + + {% endif %} + {{tag.tag}} + + {% endfor %} +

+ {% endfor %} + {% endfor %} + + +
+
+
+ {% endfor %} + +
+ +

Create new tag