Improved entry page resolving to handle disabled features

This commit is contained in:
Niels Tholenaar 2019-07-10 15:10:39 +02:00
parent 86f5667039
commit 0a61ea0fcf

View File

@ -8,14 +8,14 @@ use \Grocy\Services\DemoDataGeneratorService;
class SystemController extends BaseController class SystemController extends BaseController
{ {
protected $ApplicationService;
public function __construct(\Slim\Container $container) public function __construct(\Slim\Container $container)
{ {
parent::__construct($container); parent::__construct($container);
$this->ApplicationService = new ApplicationService(); $this->ApplicationService = new ApplicationService();
} }
protected $ApplicationService;
public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
// Schema migration is done here // Schema migration is done here
@ -31,6 +31,64 @@ class SystemController extends BaseController
return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl($this->GetEntryPageRelative())); 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) public function About(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
return $this->AppContainer->view->render($response, 'about', [ return $this->AppContainer->view->render($response, 'about', [
@ -38,27 +96,4 @@ class SystemController extends BaseController
'changelog' => $this->ApplicationService->GetChangelog() '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';
}
}
} }