Update tag view

This commit is contained in:
James Cole 2017-02-22 17:15:54 +01:00
parent adcddb09cd
commit 35aeb7e04a
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 141 additions and 53 deletions

View File

@ -226,24 +226,71 @@ class TagController extends Controller
*
* @return View
*/
public function show(Request $request, JournalCollectorInterface $collector, Tag $tag, string $moment = '')
public function show(Request $request, JournalCollectorInterface $collector, Tag $tag)
{
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
$subTitle = $tag->tag;
$subTitleIcon = 'fa-tag';
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$periods = $this->getPeriodOverview($tag);
// use collector:
$collector->setAllAssetAccounts()
->setLimit($pageSize)->setPage($page)->setTag($tag)->withOpposingAccount()->disableInternalFilter()
->withBudgetInformation()->withCategoryInformation()->setRange($start, $end);
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id);
$sum = $journals->sum(
function (Transaction $transaction) {
return $transaction->transaction_amount;
}
);
return view('tags.show', compact('tag', 'periods', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end'));
}
/**
* @param Request $request
* @param JournalCollectorInterface $collector
* @param Tag $tag
*
* @return View
*/
public function showAll(Request $request, JournalCollectorInterface $collector, Tag $tag)
{
$subTitle = $tag->tag;
$subTitleIcon = 'fa-tag';
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page)->setTag($tag)
->withOpposingAccount()->disableInternalFilter()
->withBudgetInformation()->withCategoryInformation();
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id . '/all');
$sum = $journals->sum(
function (Transaction $transaction) {
return $transaction->transaction_amount;
}
);
return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon', 'journals', 'sum', 'start', 'end'));
}
public function showByDate(Request $request, JournalCollectorInterface $collector, Tag $tag, string $date)
{
$range = Preferences::get('viewRange', '1M')->data;
$start = new Carbon;
$end = new Carbon;
if (strlen($moment) > 0) {
try {
$start = new Carbon($moment);
$end = Navigation::endOfPeriod($start, $range);
} catch (Exception $e) {
$start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range);
$end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range);
}
}
if (strlen($moment) === 0) {
$start = clone session('start', Carbon::now()->startOfMonth());
$end = clone session('end', Carbon::now()->endOfMonth());
try {
$start = new Carbon($date);
$end = Navigation::endOfPeriod($start, $range);
} catch (Exception $e) {
$start = Navigation::startOfPeriod($this->repository->firstUseDate($tag), $range);
$end = Navigation::startOfPeriod($this->repository->lastUseDate($tag), $range);
}
$subTitle = $tag->tag;
@ -254,7 +301,7 @@ class TagController extends Controller
// use collector:
$collector->setAllAssetAccounts()
->setLimit($pageSize)->setPage($page)->setTag($tag)
->setLimit($pageSize)->setPage($page)->setTag($tag)->withOpposingAccount()->disableInternalFilter()
->withBudgetInformation()->withCategoryInformation()->setRange($start, $end);
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id);

View File

@ -75,13 +75,15 @@
</div>
</div>
</div>
<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('tags.show',[tag.id,'all']) }}">{{ 'showEverything'|_ }}</a></p>
{% if periods %}
<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('tags.show.all',[tag.id]) }}">{{ 'showEverything'|_ }}</a></p>
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
<div class="{% if periods %}col-lg-10 col-md-10 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
@ -100,45 +102,82 @@
</div>
</div>
<div class="box-body">
{% if periods %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('tags.show.all', [tag.id]) }}">
{{ 'show_all_no_filter'|_ }}
</a>
</p>
{% else %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('tags.show', [tag.id]) }}">
{{ 'show_the_current_period_and_overview'|_ }}
</a>
</p>
{% endif %}
{% include 'list/journals-tasker' %}
{% if periods %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('tags.show.all', [tag.id]) }}">
{{ 'show_all_no_filter'|_ }}
</a>
</p>
{% else %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('tags.show', [tag.id]) }}">
{{ 'show_the_current_period_and_overview'|_ }}
</a>
</p>
{% endif %}
</div>
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
{% for period in periods %}
{% 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.date_string]) }}">{{ period.date_name }}</a>
</h3>
{% if periods %}
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
{% for period in periods %}
{% 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.date',[tag.id, period.date_string]) }}">{{ period.date_name }}</a>
</h3>
</div>
<div class="box-body no-padding">
<table class="table table-hover">
{% if period.spent != 0 %}
<tr>
<td style="width:33%;">{{ 'spent'|_ }}</td>
<td style="text-align: right;">{{ period.spent|formatAmount }}</td>
</tr>
{% endif %}
{% if period.earned != 0 %}
<tr>
<td style="width:33%;">{{ 'earned'|_ }}</td>
<td style="text-align: right;">{{ period.earned|formatAmount }}</td>
</tr>
{% endif %}
</table>
</div>
</div>
<div class="box-body no-padding">
<table class="table table-hover">
{% if period.spent != 0 %}
<tr>
<td style="width:33%;">{{ 'spent'|_ }}</td>
<td style="text-align: right;">{{ period.spent|formatAmount }}</td>
</tr>
{% endif %}
{% if period.earned != 0 %}
<tr>
<td style="width:33%;">{{ 'earned'|_ }}</td>
<td style="text-align: right;">{{ period.earned|formatAmount }}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% endif %}
{% endif %}
{% endfor %}
</div>
{% endfor %}
</div>
{% endif %}
</div>
<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('tags.show',[tag.id,'all']) }}">{{ 'showEverything'|_ }}</a></p>
{% if periods %}
<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('tags.show.all',[tag.id]) }}">{{ 'showEverything'|_ }}</a></p>
</div>
</div>
</div>
{% endif %}
{% endblock %}
{% block scripts %}

View File

@ -601,7 +601,9 @@ Route::group(
Route::get('', ['uses' => 'TagController@index', 'as' => 'index']);
Route::get('create', ['uses' => 'TagController@create', 'as' => 'create']);
Route::get('show/{tag}/{date?}', ['uses' => 'TagController@show', 'as' => 'show']);
Route::get('show/{tag}/all', ['uses' => 'TagController@showAll', 'as' => 'show.all']);
Route::get('show/{tag}/{date}', ['uses' => 'TagController@showByDate', 'as' => 'show.date']);
Route::get('show/{tag}', ['uses' => 'TagController@show', 'as' => 'show']);
Route::get('edit/{tag}', ['uses' => 'TagController@edit', 'as' => 'edit']);
Route::get('delete/{tag}', ['uses' => 'TagController@delete', 'as' => 'delete']);