Attachments for categories #2828

This commit is contained in:
James Cole
2020-03-19 18:37:57 +01:00
parent 417a0d0f83
commit 1f919b6d0e
4 changed files with 25 additions and 7 deletions

View File

@@ -86,6 +86,7 @@ class ShowController extends Controller
$end = $end ?? session('end', Carbon::now()->endOfMonth()); $end = $end ?? session('end', Carbon::now()->endOfMonth());
$subTitleIcon = 'fa-bar-chart'; $subTitleIcon = 'fa-bar-chart';
$page = (int) $request->get('page'); $page = (int) $request->get('page');
$attachments = $this->repository->getAttachments($category);
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear(); $oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear();
$periods = $this->getCategoryPeriodOverview($category, $oldest, $end); $periods = $this->getCategoryPeriodOverview($category, $oldest, $end);
@@ -107,7 +108,7 @@ class ShowController extends Controller
//Log::debug('End of show()'); //Log::debug('End of show()');
return view('categories.show', compact('category', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end')); return view('categories.show', compact('category','attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
} }
/** /**
@@ -134,7 +135,7 @@ class ShowController extends Controller
$start = $first ?? new Carbon; $start = $first ?? new Carbon;
$end = new Carbon; $end = new Carbon;
$path = route('categories.show.all', [$category->id]); $path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
@@ -145,6 +146,6 @@ class ShowController extends Controller
$groups = $collector->getPaginatedGroups(); $groups = $collector->getPaginatedGroups();
$groups->setPath($path); $groups->setPath($path);
return view('categories.show', compact('category', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end')); return view('categories.show', compact('category','attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
} }
} }

View File

@@ -179,7 +179,7 @@ class CategoryRepository implements CategoryRepositoryInterface
public function getCategories(): Collection public function getCategories(): Collection
{ {
/** @var Collection $set */ /** @var Collection $set */
$set = $this->user->categories()->orderBy('name', 'ASC')->get(); $set = $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
return $set; return $set;
} }

View File

@@ -8,7 +8,7 @@
<div class="row"> <div class="row">
{% if Route.getCurrentRoute.getName == 'categories.show' %} {% if Route.getCurrentRoute.getName == 'categories.show' %}
{# both charts #} {# both charts #}
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12"> <div class="{% if attachments.count == 0 %}col-lg-6 col-md-12 col-sm-12 col-xs-12{% else %}col-lg-4 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"> <h3 class="box-title">
@@ -20,7 +20,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12"> <div class="{% if attachments.count == 0 %}col-lg-6 col-md-12 col-sm-12 col-xs-12{% else %}col-lg-4 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"> <h3 class="box-title">
@@ -35,7 +35,7 @@
{% endif %} {% endif %}
{% if Route.getCurrentRoute.getName == 'categories.show.all' %} {% if Route.getCurrentRoute.getName == 'categories.show.all' %}
{# all chart #} {# all chart #}
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="{% if attachments.count == 0 %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% else %}col-lg-8 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"> <h3 class="box-title">
@@ -48,6 +48,20 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if attachments.count > 0 %}
<div class="col-lg-4 col-md-12 col-sm-12 col-xs-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
{{ 'attachments'|_ }}
</h3>
</div>
<div class="box-body table-responsive no-padding">
{% include 'list.attachments' %}
</div>
</div>
</div>
{% endif %}
</div> </div>
{% if periods|length > 0 %} {% if periods|length > 0 %}
<div class="row"> <div class="row">

View File

@@ -25,6 +25,9 @@
</td> </td>
<td data-value="{{ category.name }}"> <td data-value="{{ category.name }}">
<a href="{{ route('categories.show', category.id) }}" title="{{ category.name }}">{{ category.name }}</a> <a href="{{ route('categories.show', category.id) }}" title="{{ category.name }}">{{ category.name }}</a>
{% if category.attachments.count > 0 %}
<i class="fa fa-fw fa-paperclip"></i>
{% endif %}
</td> </td>
{% if category.lastActivity %} {% if category.lastActivity %}
<td class="hidden-sm hidden-xs" data-value="{{ category.lastActivity.format('Y-m-d H-i-s') }}"> <td class="hidden-sm hidden-xs" data-value="{{ category.lastActivity.format('Y-m-d H-i-s') }}">