From 01e9e3f5ce49a92c26212d7ca82bc47876131b77 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 9 Feb 2019 13:41:40 +0100 Subject: [PATCH] Move about dialog into separate view and add API endpoint for system info --- controllers/LoginController.php | 15 ----------- controllers/SystemApiController.php | 8 ++++++ controllers/SystemController.php | 40 +++++++++++++++++++++++++++++ grocy.openapi.json | 40 +++++++++++++++++++++++++++++ public/js/grocy.js | 9 +++++++ routes.php | 8 +++--- services/ApplicationService.php | 13 ++++++++++ views/about.blade.php | 26 +++++++++++++++++++ views/layout/default.blade.php | 28 ++------------------ 9 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 controllers/SystemController.php create mode 100644 views/about.blade.php diff --git a/controllers/LoginController.php b/controllers/LoginController.php index e1691ad4..4d2f5c2e 100644 --- a/controllers/LoginController.php +++ b/controllers/LoginController.php @@ -63,21 +63,6 @@ class LoginController extends BaseController return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/')); } - public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) - { - // Schema migration is done here - $databaseMigrationService = new DatabaseMigrationService(); - $databaseMigrationService->MigrateDatabase(); - - if (GROCY_IS_DEMO_INSTALL) - { - $demoDataGeneratorService = new DemoDataGeneratorService(); - $demoDataGeneratorService->PopulateDemoData(); - } - - return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/stockoverview')); - } - public function GetSessionCookieName() { return $this->SessionCookieName; diff --git a/controllers/SystemApiController.php b/controllers/SystemApiController.php index bb0e55f9..420c2215 100644 --- a/controllers/SystemApiController.php +++ b/controllers/SystemApiController.php @@ -3,6 +3,7 @@ namespace Grocy\Controllers; use \Grocy\Services\DatabaseService; +use \Grocy\Services\ApplicationService; class SystemApiController extends BaseApiController { @@ -10,9 +11,11 @@ class SystemApiController extends BaseApiController { parent::__construct($container); $this->DatabaseService = new DatabaseService(); + $this->ApplicationService = new ApplicationService(); } protected $DatabaseService; + protected $ApplicationService; public function GetDbChangedTime(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { @@ -38,4 +41,9 @@ class SystemApiController extends BaseApiController } } } + + public function GetSystemInfo(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->ApiResponse($this->ApplicationService->GetSystemInfo()); + } } diff --git a/controllers/SystemController.php b/controllers/SystemController.php new file mode 100644 index 00000000..22fe2cf5 --- /dev/null +++ b/controllers/SystemController.php @@ -0,0 +1,40 @@ +ApplicationService = new ApplicationService(); + } + + protected $ApplicationService; + + public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + // Schema migration is done here + $databaseMigrationService = new DatabaseMigrationService(); + $databaseMigrationService->MigrateDatabase(); + + if (GROCY_IS_DEMO_INSTALL) + { + $demoDataGeneratorService = new DemoDataGeneratorService(); + $demoDataGeneratorService->PopulateDemoData(); + } + + return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/stockoverview')); + } + + public function About(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'about', [ + 'system_info' => $this->ApplicationService->GetSystemInfo() + ]); + } +} diff --git a/grocy.openapi.json b/grocy.openapi.json index 4aca8008..606e5c56 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -24,6 +24,46 @@ } ], "paths": { + "/system/info": { + "get": { + "summary": "Returns information about the installed grocy, PHP and SQLite version", + "tags": [ + "System" + ], + "responses": { + "200": { + "description": "An DbChangedTimeResponse object", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "grocy_version": { + "type": "object", + "properties": { + "Version": { + "type": "string" + }, + "ReleaseDate": { + "type": "string", + "format": "date" + } + } + }, + "php_version": { + "type": "string" + }, + "sqlite_version": { + "type": "string" + } + } + } + } + } + } + } + } + }, "/system/db-changed-time": { "get": { "summary": "Returns the time when the database was last changed", diff --git a/public/js/grocy.js b/public/js/grocy.js index 1c5f9a9c..45766bef 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -492,3 +492,12 @@ if (window.location.hash) { $(window.location.hash).addClass("p-2 border border-info rounded"); } + +$("#about-dialog-link").on("click", function() +{ + bootbox.alert({ + message: '', + size: "large", + closeButton: false + }); +}); diff --git a/routes.php b/routes.php index 57e16a7f..b4f91538 100644 --- a/routes.php +++ b/routes.php @@ -7,8 +7,9 @@ use \Tuupola\Middleware\CorsMiddleware; $app->group('', function() { - // Base route - $this->get('/', 'LoginControllerInstance:Root')->setName('root'); + // System routes + $this->get('/', '\Grocy\Controllers\SystemController:Root')->setName('root'); + $this->get('/about', '\Grocy\Controllers\SystemController:About'); // Login routes $this->get('/login', 'LoginControllerInstance:LoginPage')->setName('login'); @@ -83,7 +84,8 @@ $app->group('/api', function() $this->get('/openapi/specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec'); // System - $this->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); + $this->get('/system/info', '\Grocy\Controllers\SystemApiController:GetSystemInfo'); + $this->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); $this->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization'); // Generic entity interaction diff --git a/services/ApplicationService.php b/services/ApplicationService.php index cfb00ec3..4869a2d7 100644 --- a/services/ApplicationService.php +++ b/services/ApplicationService.php @@ -14,4 +14,17 @@ class ApplicationService extends BaseService return $this->InstalledVersion; } + + public function GetSystemInfo() + { + $pdo = new \PDO('sqlite::memory:'); + $sqliteVersion = $pdo->query('SELECT sqlite_version()')->fetch()[0]; + $pdo = null; + + return array( + 'grocy_version' => $this->GetInstalledVersion(), + 'php_version' => phpversion(), + 'sqlite_version' => $sqliteVersion + ); + } } diff --git a/views/about.blade.php b/views/about.blade.php new file mode 100644 index 00000000..539fd828 --- /dev/null +++ b/views/about.blade.php @@ -0,0 +1,26 @@ +@extends('layout.default') + +@section('title', $L('About grocy')) + +@section('content') +
+
+

@yield('title')

+ + grocy is a project by + Bernd Bestel
+ Created with passion since 2017
+
+ Version {{ $version }}
+ {{ $L('Released on') }} {{ $releaseDate }}
+
+ PHP Version {{ $system_info['php_version'] }}
+ SQLite Version {{ $system_info['sqlite_version'] }}
+
+ Life runs on code
+ + + +
+
+@stop diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index c6d78781..1117f186 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -279,7 +279,7 @@  {{ $L('Manage API keys') }}  {{ $L('REST API & data model documentation') }} -  {{ $L('About grocy') }} (Version {{ $version }}) +  {{ $L('About grocy') }} (Version {{ $version }}) @@ -297,30 +297,6 @@ - - @@ -350,7 +326,7 @@ @stack('pageScripts') @stack('componentScripts') - + @hasSection('viewJsName')@endif @if(file_exists(GROCY_DATAPATH . '/custom_js.html')) @php include GROCY_DATAPATH . '/custom_js.html' @endphp