From 86f5667039e741462125334a409da128a6e2b5b5 Mon Sep 17 00:00:00 2001 From: Niels Tholenaar Date: Sat, 22 Jun 2019 16:02:52 +0200 Subject: [PATCH 1/3] Allow possibility to choose custom homepage --- config-dist.php | 5 +++-- controllers/SystemController.php | 33 +++++++++++++++++--------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/config-dist.php b/config-dist.php index 2b3f2c4b..72afae5a 100644 --- a/config-dist.php +++ b/config-dist.php @@ -41,8 +41,9 @@ Setting('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin'); # set this to true Setting('DISABLE_URL_REWRITING', false); - - +# By default the homepage will be set to the stock overview. +# You can set this to any overview you want. Example: Use recipes to set the homepage to the recipes overview. +Setting('ENTRY_PAGE', 'stock'); # Default user settings # These settings can be changed per user, here the defaults diff --git a/controllers/SystemController.php b/controllers/SystemController.php index b9a8d998..cbff1bc6 100644 --- a/controllers/SystemController.php +++ b/controllers/SystemController.php @@ -41,21 +41,24 @@ class SystemController extends BaseController private function GetEntryPageRelative() { - $entryPage = '/stockoverview'; - - if (!GROCY_FEATURE_FLAG_STOCK) - { - $entryPage = '/choresoverview'; + switch (GROCY_ENTRY_PAGE) { + default: + case 'stock': + return '/stockoverview'; + case 'shoppinglist': + return '/shoppinglist'; + case 'recipes': + return '/recipes'; + case 'chores': + return '/choresoverview'; + case 'tasks': + return '/tasks'; + case 'batteries': + return '/batteriesoverview'; + case 'equipment': + return '/equipment'; + case 'calendar': + return '/calendar'; } - if (!GROCY_FEATURE_FLAG_CHORES) - { - $entryPage = '/batteriesoverview'; - } - if (!GROCY_FEATURE_FLAG_BATTERIES) - { - $entryPage = '/equipment'; - } - - return $entryPage; } } From 0a61ea0fcffb2e898afbe456e38da52391dc71eb Mon Sep 17 00:00:00 2001 From: Niels Tholenaar Date: Wed, 10 Jul 2019 15:10:39 +0200 Subject: [PATCH 2/3] Improved entry page resolving to handle disabled features --- controllers/SystemController.php | 85 ++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/controllers/SystemController.php b/controllers/SystemController.php index cbff1bc6..85361cfb 100644 --- a/controllers/SystemController.php +++ b/controllers/SystemController.php @@ -8,14 +8,14 @@ use \Grocy\Services\DemoDataGeneratorService; class SystemController extends BaseController { + protected $ApplicationService; + public function __construct(\Slim\Container $container) { parent::__construct($container); $this->ApplicationService = new ApplicationService(); } - protected $ApplicationService; - public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { // Schema migration is done here @@ -31,6 +31,64 @@ class SystemController extends BaseController return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl($this->GetEntryPageRelative())); } + /** + * Get the entry page of the application based on the value of the entry page setting. + * + * We fallback to the about page when no entry page is specified or + * when the specified entry page has been disabled. + * + * @return string + */ + private function GetEntryPageRelative() + { + if (defined('GROCY_ENTRY_PAGE')) { + $entryPage = constant('GROCY_ENTRY_PAGE'); + } else { + $entryPage = 'stock'; + } + + // Stock + if ($entryPage === 'stock' && constant('GROCY_FEATURE_FLAG_STOCK')) { + return '/stockoverview'; + } + + // Shoppinglist + if ($entryPage === 'shoppinglist' && constant('GROCY_FEATURE_FLAG_SHOPPINGLIST')) { + return '/shoppinglist'; + } + + // Recipes + if ($entryPage === 'recipes' && constant('GROCY_FEATURE_FLAG_RECIPES')) { + return '/recipes'; + } + + // Chores + if ($entryPage === 'chores' && constant('GROCY_FEATURE_FLAG_CHORES')) { + return '/choresoverview'; + } + + // Tasks + if ($entryPage === 'tasks' && constant('GROCY_FEATURE_FLAG_TASKS')) { + return '/tasks'; + } + + // Batteries + if ($entryPage === 'batteries' && constant('GROCY_FEATURE_FLAG_BATTERIES')) { + return '/batteriesoverview'; + } + + if ($entryPage === 'equipment' && constant('GROCY_FEATURE_FLAG_EQUIPMENT')) { + return '/equipment'; + } + + // Calendar + if ($entryPage === 'calendar' && constant('GROCY_FEATURE_FLAG_CALENDAR')) { + return '/calendar'; + } + + return '/about'; + } + public function About(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { return $this->AppContainer->view->render($response, 'about', [ @@ -38,27 +96,4 @@ class SystemController extends BaseController 'changelog' => $this->ApplicationService->GetChangelog() ]); } - - private function GetEntryPageRelative() - { - switch (GROCY_ENTRY_PAGE) { - default: - case 'stock': - return '/stockoverview'; - case 'shoppinglist': - return '/shoppinglist'; - case 'recipes': - return '/recipes'; - case 'chores': - return '/choresoverview'; - case 'tasks': - return '/tasks'; - case 'batteries': - return '/batteriesoverview'; - case 'equipment': - return '/equipment'; - case 'calendar': - return '/calendar'; - } - } } From e3f53aaebd8410110d4759bb4fa213018f167407 Mon Sep 17 00:00:00 2001 From: Niels Tholenaar Date: Wed, 10 Jul 2019 17:14:25 +0200 Subject: [PATCH 3/3] Added possible values to entry page config setting --- config-dist.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config-dist.php b/config-dist.php index c775054b..033a356d 100644 --- a/config-dist.php +++ b/config-dist.php @@ -46,8 +46,9 @@ Setting('STOCK_BARCODE_LOOKUP_PLUGIN', 'DemoBarcodeLookupPlugin'); # set this to true Setting('DISABLE_URL_REWRITING', false); -# By default the homepage will be set to the stock overview. -# You can set this to any overview you want. Example: Use recipes to set the homepage to the recipes overview. +# Specify an custom homepage if desired. By default the homepage will be set to the stock overview. +# You can chosen one of the following values: +# stock, shoppinglist, recipes, chores, tasks, batteries, equipment, calendar Setting('ENTRY_PAGE', 'stock'); # Set this to true if you want to disable authentication / the login screen,