mirror of
https://github.com/grocy/grocy.git
synced 2025-04-28 17:23:56 +00:00
Prepare for embedded mode
This commit is contained in:
parent
db9ee93d2b
commit
3b4141eb4d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/public/node_modules
|
||||
/vendor
|
||||
/.release
|
||||
embedded.txt
|
@ -59,13 +59,16 @@ There is no plugin included for any service, see the reference implementation in
|
||||
### Database migrations
|
||||
Database schema migration is automatically done when visiting the root (`/`) route (click on the logo in the left upper edge).
|
||||
|
||||
### Demo mode
|
||||
When the file `data/demo.txt` exists, the application will work in a demo mode which means authentication is disabled and some demo data will be generated during the database schema migration.
|
||||
|
||||
### Adding your own CSS or JS without to have to modify the application itself
|
||||
- When the file `data/custom_js.html` exists, the contents of the file will be added just before `</body>` (end of body) on every page
|
||||
- When the file `data/custom_css.html` exists, the contents of the file will be added just before `</head>` (end of head) on every page
|
||||
|
||||
### Demo mode
|
||||
When the file `data/demo.txt` exists, the application will work in a demo mode which means authentication is disabled and some demo data will be generated during the database schema migration.
|
||||
|
||||
### Embedded mode
|
||||
When the file `/embedded.txt` exists, it must contain a valid and writable path which will be used as the data directory instead of `data/` and authentication will be disabled (used in [grocy-desktop](https://github.com/berrnd/grocy-desktop)).
|
||||
|
||||
## Screenshots
|
||||
#### Dashboard
|
||||

|
||||
|
13
app.php
13
app.php
@ -6,8 +6,17 @@ use \Psr\Http\Message\ResponseInterface as Response;
|
||||
use \Grocy\Helpers\UrlManager;
|
||||
use \Grocy\Controllers\LoginController;
|
||||
|
||||
if (file_exists(__DIR__ . '/embedded.txt'))
|
||||
{
|
||||
define('DATAPATH', file_get_contents(__DIR__ . '/embedded.txt'));
|
||||
}
|
||||
else
|
||||
{
|
||||
define('DATAPATH', __DIR__ . '/data');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/data/config.php';
|
||||
require_once DATAPATH . '/config.php';
|
||||
require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones
|
||||
|
||||
// Setup base application
|
||||
@ -18,7 +27,7 @@ $appContainer = new \Slim\Container([
|
||||
],
|
||||
'view' => function($container)
|
||||
{
|
||||
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
|
||||
return new \Slim\Views\Blade(__DIR__ . '/views', DATAPATH . '/viewcache');
|
||||
},
|
||||
'LoginControllerInstance' => function($container)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
|
||||
$route = $request->getAttribute('route');
|
||||
$routeName = $route->getName();
|
||||
|
||||
if ($this->ApplicationService->IsDemoInstallation())
|
||||
if ($this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
|
||||
{
|
||||
$response = $next($request, $response);
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ class SessionAuthMiddleware extends BaseMiddleware
|
||||
$route = $request->getAttribute('route');
|
||||
$routeName = $route->getName();
|
||||
|
||||
if ($routeName === 'root' || $this->ApplicationService->IsDemoInstallation())
|
||||
if ($routeName === 'root' || $this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation())
|
||||
{
|
||||
define('AUTHENTICATED', $this->ApplicationService->IsDemoInstallation());
|
||||
define('AUTHENTICATED', $this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation());
|
||||
$response = $next($request, $response);
|
||||
}
|
||||
else
|
||||
|
@ -9,7 +9,15 @@ class ApplicationService extends BaseService
|
||||
*/
|
||||
public function IsDemoInstallation()
|
||||
{
|
||||
return file_exists(__DIR__ . '/../data/demo.txt');
|
||||
return file_exists(DATAPATH . '/demo.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function IsEmbeddedInstallation()
|
||||
{
|
||||
return file_exists(__DIR__ . '/../embedded.txt');
|
||||
}
|
||||
|
||||
private $InstalledVersion;
|
||||
|
@ -14,7 +14,7 @@ class DatabaseService
|
||||
{
|
||||
if ($this->DbConnectionRaw == null)
|
||||
{
|
||||
$pdo = new \PDO('sqlite:' . __DIR__ . '/../data/grocy.db');
|
||||
$pdo = new \PDO('sqlite:' . DATAPATH . '/grocy.db');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->DbConnectionRaw = $pdo;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ class DemoDataGeneratorService extends BaseService
|
||||
|
||||
public function RecreateDemo()
|
||||
{
|
||||
unlink(__DIR__ . '/../data/grocy.db');
|
||||
unlink(DATAPATH . '/grocy.db');
|
||||
$this->PopulateDemoData();
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class LocalizationService
|
||||
|
||||
private function LogMissingLocalization(string $culture, string $text)
|
||||
{
|
||||
$file = __DIR__ . "/../data/missing_translations_$culture.json";
|
||||
$file = DATAPATH . "/missing_translations_$culture.json";
|
||||
|
||||
$missingTranslations = array();
|
||||
if (file_exists($file))
|
||||
|
@ -222,7 +222,7 @@ class StockService extends BaseService
|
||||
throw new \Exception('No barcode lookup plugin defined');
|
||||
}
|
||||
|
||||
$path = __DIR__ . "/../data/plugins/$pluginName.php";
|
||||
$path = DATAPATH . "/plugins/$pluginName.php";
|
||||
if (file_exists($path))
|
||||
{
|
||||
require_once $path;
|
||||
|
@ -30,8 +30,8 @@
|
||||
<script src="{{ $U('/node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js?v=', true) }}{{ $version }}"></script>
|
||||
<script src="{{ $U('/viewjs', true) }}/openapiui.js?v={{ $version }}"></script>
|
||||
|
||||
@if(file_exists(__DIR__ . '/../../data/add_before_end_body.html'))
|
||||
@php include __DIR__ . '/../../data/add_before_end_body.html' @endphp
|
||||
@if(file_exists(DATAPATH . '/add_before_end_body.html'))
|
||||
@php include DATAPATH . '/add_before_end_body.html' @endphp
|
||||
@endif
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user