Improve navigation for tags and rename route.

This commit is contained in:
James Cole 2018-08-07 21:00:25 +02:00
parent 477788658b
commit bc807965ab
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 88 additions and 71 deletions

View File

@ -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 */

View File

@ -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),

View File

@ -52,7 +52,7 @@
{% if periods.count > 0 %}
<div class="row">
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('categories.show-all',[category.id]) }}">{{ 'showEverything'|_ }}</a></p>
<p class="small text-center"><a href="{{ route('categories.show.all',[category.id]) }}">{{ 'showEverything'|_ }}</a></p>
</div>
</div>
{% endif %}
@ -69,7 +69,7 @@
{% if periods.count > 0 %}
<p>
<i class="fa fa-calendar"></i>
<a href="{{ route('categories.show-all', [category.id]) }}">
<a href="{{ route('categories.show.all', [category.id]) }}">
{{ 'show_all_no_filter'|_ }}
</a>
</p>

View File

@ -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 %}
<div class="box {% if period.date == start %}box-solid box-primary{% endif %}">
<div class="box-header with-border">
<h3 class="box-title"><a href="{{ route('tags.show',[tag.id, period.string]) }}">{{ period.name }}</a>
<h3 class="box-title"><a href="{{ route('tags.show',[tag.id, period.start.format('Y-m-d'), period.end.format('Y-m-d')]) }}">{{ period.name }}</a>
</h3>
</div>
<div class="box-body no-padding">

View File

@ -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])
);
}
);

View File

@ -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']);