diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php index 623cdaab9d..540d5a1864 100644 --- a/app/Http/Controllers/Category/ShowController.php +++ b/app/Http/Controllers/Category/ShowController.php @@ -92,7 +92,7 @@ class ShowController extends Controller /** @var Carbon $start */ $start = $start ?? session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ - $end = $end ?? session('end', Carbon::now()->startOfMonth()); + $end = $end ?? session('end', Carbon::now()->endOfMonth()); $subTitleIcon = 'fa-bar-chart'; $moment = ''; $page = (int)$request->get('page'); @@ -142,7 +142,7 @@ class ShowController extends Controller /** @var Carbon $start */ $start = $first ?? new Carbon; $end = new Carbon; - $path = route('categories.show-all', [$category->id]); + $path = route('categories.show.all', [$category->id]); /** @var JournalCollectorInterface $collector */ diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 102f1d7bff..73e2cccbfb 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -177,54 +177,20 @@ class TagController extends Controller * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function show(Request $request, Tag $tag, string $moment = null) + public function show(Request $request, Tag $tag, Carbon $start = null, Carbon $end = null) { // default values: - $moment = $moment ?? ''; - $subTitle = $tag->tag; $subTitleIcon = 'fa-tag'; $page = (int)$request->get('page'); $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; - $range = app('preferences')->get('viewRange', '1M')->data; - $start = null; - $end = null; - $periods = new Collection; - $path = route('tags.show', [$tag->id]); - - // prep for "all" view. - if ('all' === $moment) { - $subTitle = (string)trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]); - $start = $this->repository->firstUseDate($tag) ?? new Carbon; - $end = new Carbon; - $path = route('tags.show', [$tag->id, 'all']); - } - - // prep for "specific date" view. - if ('all' !== $moment && \strlen($moment) > 0) { - $start = new Carbon($moment); - /** @var Carbon $end */ - $end = app('navigation')->endOfPeriod($start, $range); - $subTitle = trans( - 'firefly.journals_in_period_for_tag', - ['tag' => $tag->tag, - 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat),] - ); - $periods = $this->getPeriodOverview($tag); - $path = route('tags.show', [$tag->id, $moment]); - } - - // prep for current period - if ('' === $moment) { - /** @var Carbon $start */ - $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range)); - /** @var Carbon $end */ - $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range)); - $periods = $this->getPeriodOverview($tag); - $subTitle = trans( - 'firefly.journals_in_period_for_tag', - ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ); - } + $start = $start ?? session('start'); + $end = $end ?? session('end'); + $subTitle = trans( + 'firefly.journals_in_period_for_tag', ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), + 'end' => $end->formatLocalized($this->monthAndDayFormat),] + ); + $periods = $this->getPeriodOverview($tag); + $path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); @@ -235,7 +201,41 @@ class TagController extends Controller $sums = $this->repository->sumsOfTag($tag, $start, $end); - return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end', 'moment')); + return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end')); + } + + /** + * Show a single tag. + * + * @param Request $request + * @param Tag $tag + * @param string|null $moment + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + public function showAll(Request $request, Tag $tag) + { + // default values: + $subTitleIcon = 'fa-tag'; + $page = (int)$request->get('page'); + $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $periods = new Collection; + $subTitle = (string)trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]); + $start = $this->repository->firstUseDate($tag) ?? new Carbon; + $end = new Carbon; + $path = route('tags.show', [$tag->id, 'all']); + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount() + ->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class); + $transactions = $collector->getPaginatedJournals(); + $transactions->setPath($path); + $sums = $this->repository->sumsOfTag($tag, $start, $end); + + return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end')); } /** @@ -334,6 +334,8 @@ class TagController extends Controller $arr = [ 'string' => $end->format('Y-m-d'), 'name' => app('navigation')->periodShow($currentEnd, $range), + 'start' => clone $currentStart, + 'end' => clone $currentEnd, 'date' => clone $end, 'spent' => $this->repository->spentInPeriod($tag, $currentStart, $currentEnd), 'earned' => $this->repository->earnedInPeriod($tag, $currentStart, $currentEnd), diff --git a/resources/views/categories/show.twig b/resources/views/categories/show.twig index d3ccd0f5e6..a8a3171ce5 100644 --- a/resources/views/categories/show.twig +++ b/resources/views/categories/show.twig @@ -52,7 +52,7 @@ {% if periods.count > 0 %}
-

{{ 'showEverything'|_ }}

+

{{ 'showEverything'|_ }}

{% endif %} @@ -69,7 +69,7 @@ {% if periods.count > 0 %}

- + {{ 'show_all_no_filter'|_ }}

diff --git a/resources/views/tags/show.twig b/resources/views/tags/show.twig index 52b4d64025..42f8b48b7f 100644 --- a/resources/views/tags/show.twig +++ b/resources/views/tags/show.twig @@ -1,7 +1,7 @@ {% extends "./layout/default" %} {% block breadcrumbs %} - {{ Breadcrumbs.render(Route.getCurrentRoute.getName, tag, moment, start, end) }} + {{ Breadcrumbs.render(Route.getCurrentRoute.getName, tag, start, end) }} {% endblock %} {% block content %} @@ -158,7 +158,7 @@ {% if period.spent != 0 or period.earned != 0 %}
-

{{ period.name }} +

{{ period.name }}

diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index a096c1a25d..f0b0e2e854 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -447,7 +447,7 @@ try { Breadcrumbs::register( 'categories.edit', function (BreadcrumbsGenerator $breadcrumbs, Category $category) { - $breadcrumbs->parent('categories.show-all', $category, '', new Carbon, new Carbon); + $breadcrumbs->parent('categories.show.all', $category, '', new Carbon, new Carbon); $breadcrumbs->push(trans('firefly.edit_category', ['name' => limitStringLength($category->name)]), route('categories.edit', [$category->id])); } ); @@ -474,7 +474,7 @@ try { ); Breadcrumbs::register( - 'categories.show-all', + 'categories.show.all', function (BreadcrumbsGenerator $breadcrumbs, Category $category, string $moment, Carbon $start, Carbon $end) { $breadcrumbs->parent('categories.index'); $breadcrumbs->push(limitStringLength($category->name), route('categories.show', [$category->id])); @@ -959,21 +959,30 @@ try { Breadcrumbs::register( 'tags.show', - function (BreadcrumbsGenerator $breadcrumbs, Tag $tag, string $moment, Carbon $start, Carbon $end) { + function (BreadcrumbsGenerator $breadcrumbs, Tag $tag, Carbon $start = null, Carbon $end = null) { $breadcrumbs->parent('tags.index'); - $breadcrumbs->push($tag->tag, route('tags.show', [$tag->id, $moment])); - if ('all' === $moment) { - $breadcrumbs->push(trans('firefly.everything'), route('tags.show', [$tag->id, $moment])); - } - // when is specific period or when empty: - if ('all' !== $moment && '(nothing)' !== $moment) { - $title = trans( - 'firefly.between_dates_breadcrumb', - ['start' => $start->formatLocalized((string)trans('config.month_and_day')), - 'end' => $end->formatLocalized((string)trans('config.month_and_day')),] - ); - $breadcrumbs->push($title, route('tags.show', [$tag->id, $moment])); - } + + $start = $start ?? session('start'); + $end = $end ?? session('end'); + + $breadcrumbs->push($tag->tag, route('tags.show', [$tag->id, $start, $end])); + $title = trans( + 'firefly.between_dates_breadcrumb', + ['start' => $start->formatLocalized((string)trans('config.month_and_day')), + 'end' => $end->formatLocalized((string)trans('config.month_and_day')),] + ); + $breadcrumbs->push($title, route('tags.show', [$tag->id, $start, $end])); + } + ); + + + Breadcrumbs::register( + 'tags.show.all', + function (BreadcrumbsGenerator $breadcrumbs, Tag $tag) { + $breadcrumbs->parent('tags.index'); + $breadcrumbs->push($tag->tag, route('tags.show', $tag->id,null,null)); + $title = (string)trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]); + $breadcrumbs->push($title, route('tags.show.all',$tag->id)); } ); @@ -1017,7 +1026,9 @@ try { 'transactions.edit', function (BreadcrumbsGenerator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); - $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => limitStringLength($journal->description)]), route('transactions.edit', [$journal->id])); + $breadcrumbs->push( + trans('breadcrumbs.edit_journal', ['description' => limitStringLength($journal->description)]), route('transactions.edit', [$journal->id]) + ); } ); @@ -1027,7 +1038,8 @@ try { function (BreadcrumbsGenerator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); $breadcrumbs->push( - trans('breadcrumbs.edit_reconciliation', ['description' => limitStringLength($journal->description)]), route('accounts.reconcile.edit', [$journal->id]) + trans('breadcrumbs.edit_reconciliation', ['description' => limitStringLength($journal->description)]), + route('accounts.reconcile.edit', [$journal->id]) ); } ); @@ -1036,7 +1048,9 @@ try { 'transactions.delete', function (BreadcrumbsGenerator $breadcrumbs, TransactionJournal $journal) { $breadcrumbs->parent('transactions.show', $journal); - $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => limitStringLength($journal->description)]), route('transactions.delete', [$journal->id])); + $breadcrumbs->push( + trans('breadcrumbs.delete_journal', ['description' => limitStringLength($journal->description)]), route('transactions.delete', [$journal->id]) + ); } ); diff --git a/routes/web.php b/routes/web.php index 4627af911e..257317497f 100755 --- a/routes/web.php +++ b/routes/web.php @@ -242,7 +242,7 @@ Route::group( Route::post('destroy/{category}', ['uses' => 'CategoryController@destroy', 'as' => 'destroy']); // show category: - Route::get('show/{category}/all', ['uses' => 'Category\ShowController@showAll', 'as' => 'show-all']); + Route::get('show/{category}/all', ['uses' => 'Category\ShowController@showAll', 'as' => 'show.all']); Route::get('show/{category}/{start_date?}/{end_date?}', ['uses' => 'Category\ShowController@show', 'as' => 'show']); // no category controller: @@ -848,7 +848,8 @@ Route::group( Route::get('', ['uses' => 'TagController@index', 'as' => 'index']); Route::get('create', ['uses' => 'TagController@create', 'as' => 'create']); - Route::get('show/{tag}/{moment?}', ['uses' => 'TagController@show', 'as' => 'show']); + Route::get('show/{tag}/all', ['uses' => 'TagController@showAll', 'as' => 'show.all']); + Route::get('show/{tag}/{start_date?}/{end_date?}', ['uses' => 'TagController@show', 'as' => 'show']); Route::get('edit/{tag}', ['uses' => 'TagController@edit', 'as' => 'edit']); Route::get('delete/{tag}', ['uses' => 'TagController@delete', 'as' => 'delete']);