Code to catch empty lists and nudge user in the right direction.

This commit is contained in:
James Cole
2017-02-23 07:24:05 +01:00
parent b3df1f3d26
commit 563c668e3f
11 changed files with 309 additions and 228 deletions
+8 -5
View File
@@ -183,20 +183,23 @@ class TagController extends Controller
}
/**
* @param TagRepositoryInterface $repository
*
* @return View
*/
public function index()
public function index(TagRepositoryInterface $repository)
{
$title = 'Tags';
$mainTitleIcon = 'fa-tags';
$types = ['nothing', 'balancingAct', 'advancePayment'];
$count = $repository->count();
// loop each types and get the tags, group them by year.
$collection = [];
foreach ($types as $type) {
/** @var Collection $tags */
$tags = auth()->user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get();
$tags = $repository->getByType($type);
$tags = $tags->sortBy(
function (Tag $tag) {
$date = !is_null($tag->date) ? $tag->date->format('Ymd') : '000000';
@@ -216,7 +219,7 @@ class TagController extends Controller
}
}
return view('tags.index', compact('title', 'mainTitleIcon', 'types', 'collection'));
return view('tags.index', compact('title', 'mainTitleIcon', 'types', 'collection','count'));
}
/**
@@ -266,8 +269,8 @@ class TagController extends Controller
$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();
->withOpposingAccount()->disableInternalFilter()
->withBudgetInformation()->withCategoryInformation();
$journals = $collector->getPaginatedJournals();
$journals->setPath('tags/show/' . $tag->id . '/all');
+18
View File
@@ -68,6 +68,14 @@ class TagRepository implements TagRepositoryInterface
return false;
}
/**
* @return int
*/
public function count(): int
{
return $this->user->tags()->count();
}
/**
* @param Tag $tag
*
@@ -163,6 +171,16 @@ class TagRepository implements TagRepositoryInterface
return $tags;
}
/**
* @param string $type
*
* @return Collection
*/
public function getByType(string $type): Collection
{
return $this->user->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get();
}
/**
* @param Tag $tag
*
@@ -37,6 +37,11 @@ interface TagRepositoryInterface
*/
public function connect(TransactionJournal $journal, Tag $tag): bool;
/**
* @return int
*/
public function count(): int;
/**
* This method destroys a tag.
*
@@ -83,6 +88,13 @@ interface TagRepositoryInterface
*/
public function get(): Collection;
/**
* @param string $type
*
* @return Collection
*/
public function getByType(string $type): Collection;
/**
* @param Tag $tag
*