From dbbc85a576a4ea3b779e003d20b35e3b3302d2a5 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 22 Nov 2016 19:10:38 +0100 Subject: [PATCH] Hide some boxes when the user has no bills. --- app/Http/Controllers/HomeController.php | 14 ++++--- public/js/ff/index.js | 6 ++- resources/views/index.twig | 22 +++++----- resources/views/partials/boxes.twig | 56 ++++++++++++------------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index be1fceae02..dd2e83e25e 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -19,6 +19,7 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\AccountType; use FireflyIII\Models\Tag; use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; +use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Support\Collection; @@ -121,7 +122,6 @@ class HomeController extends Controller */ public function index(ARI $repository) { - $types = config('firefly.accountTypesByIdentifier.asset'); $count = $repository->count($types); @@ -142,6 +142,11 @@ class HomeController extends Controller $accounts = $repository->getAccountsById($frontPage->data); $showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data; + // zero bills? Hide some elements from view. + /** @var BillRepositoryInterface $billRepository */ + $billRepository = app(BillRepositoryInterface::class); + $billCount = $billRepository->getBills()->count(); + foreach ($accounts as $account) { $collector = app(JournalCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1); @@ -153,7 +158,7 @@ class HomeController extends Controller } return view( - 'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage') + 'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount') ); } @@ -205,10 +210,7 @@ class HomeController extends Controller * * @return bool */ - private - function startsWithAny( - array $array, string $needle - ): bool + private function startsWithAny(array $array, string $needle): bool { foreach ($array as $entry) { if ((substr($needle, 0, strlen($entry)) === $entry)) { diff --git a/public/js/ff/index.js b/public/js/ff/index.js index f03c97445f..f797dcf142 100644 --- a/public/js/ff/index.js +++ b/public/js/ff/index.js @@ -1,4 +1,4 @@ - /* globals $, columnChart,showTour, Tour, google, pieChart, stackedColumnChart */ +/* globals $, columnChart,showTour, Tour, google, pieChart, stackedColumnChart, billCount */ $(function () { "use strict"; @@ -33,7 +33,9 @@ function endTheTour() { function drawChart() { "use strict"; lineChart('chart/account/frontpage', 'accounts-chart'); - pieChart('chart/bill/frontpage', 'bills-chart'); + if (billCount > 0) { + pieChart('chart/bill/frontpage', 'bills-chart'); + } stackedColumnChart('chart/budget/frontpage', 'budgets-chart'); columnChart('chart/category/frontpage', 'categories-chart'); columnChart('chart/account/expense', 'expense-accounts-chart'); diff --git a/resources/views/index.twig b/resources/views/index.twig index 1e72dc442f..737c74873d 100644 --- a/resources/views/index.twig +++ b/resources/views/index.twig @@ -43,20 +43,21 @@
+ {% if billCount > 0 %} + +
+
+

{{ 'bills'|_ }}

- -
-
-

{{ 'bills'|_ }}

- -
-
-
-
+
+
+ +
+
-
+ {% endif %} {% for data in transactions %} @@ -129,6 +130,7 @@ {% else %} showTour = false; {% endif %} + var billCount = {{ billCount }}; diff --git a/resources/views/partials/boxes.twig b/resources/views/partials/boxes.twig index 6b3c2221cf..5ec3003595 100644 --- a/resources/views/partials/boxes.twig +++ b/resources/views/partials/boxes.twig @@ -1,6 +1,14 @@ +{# Set box sizes: #} +{% if billCount > 0 %} + {% set boxClasses = 'col-lg-3 col-md-3 col-sm-6 col-xs-12' %} +{% else %} + {# Zero bills? Remove the boxes. #} + {% set boxClasses = 'col-lg-4 col-md-4 col-sm-6 col-xs-12' %} +{% endif %} +