Move about dialog into separate view and add API endpoint for system info

This commit is contained in:
Bernd Bestel 2019-02-09 13:41:40 +01:00
parent b5ac319a90
commit 01e9e3f5ce
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
9 changed files with 143 additions and 44 deletions

View File

@ -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;

View File

@ -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());
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Grocy\Controllers;
use \Grocy\Services\ApplicationService;
use \Grocy\Services\DatabaseMigrationService;
use \Grocy\Services\DemoDataGeneratorService;
class SystemController extends BaseController
{
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
$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()
]);
}
}

View File

@ -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",

View File

@ -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: '<iframe height="400px" class="embed-responsive" src="' + U("/about?embedded") + '"></iframe>',
size: "large",
closeButton: false
});
});

View File

@ -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

View File

@ -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
);
}
}

26
views/about.blade.php Normal file
View File

@ -0,0 +1,26 @@
@extends('layout.default')
@section('title', $L('About grocy'))
@section('content')
<div class="row">
<div class="col-xs-12 col-md-6 col-xl-4 text-center">
<h1>@yield('title')</h1>
grocy is a project by
<a href="https://berrnd.de" class="discrete-link" target="_blank">Bernd Bestel</a><br>
Created with passion since 2017<br>
<br>
Version {{ $version }}<br>
{{ $L('Released on') }} {{ $releaseDate }} <time class="timeago timeago-contextual" datetime="{{ $releaseDate }}"></time><br>
<br>
PHP Version {{ $system_info['php_version'] }}<br>
SQLite Version {{ $system_info['sqlite_version'] }}<br>
<br>
Life runs on code<br>
<a href="https://github.com/grocy/grocy" class="discrete-link" target="_blank">
<i class="fab fa-github"></i>
</a>
</div>
</div>
@stop

View File

@ -279,7 +279,7 @@
<a class="dropdown-item discrete-link" href="{{ $U('/manageapikeys') }}"><i class="fas fa-handshake"></i>&nbsp;{{ $L('Manage API keys') }}</a>
<a class="dropdown-item discrete-link" target="_blank" href="{{ $U('/api') }}"><i class="fas fa-book"></i>&nbsp;{{ $L('REST API & data model documentation') }}</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item discrete-link" href="#" data-toggle="modal" data-target="#about-modal"><i class="fas fa-info fa-fw"></i>&nbsp;{{ $L('About grocy') }} (Version {{ $version }})</a>
<a id="about-dialog-link" class="dropdown-item discrete-link" href="#"><i class="fas fa-info fa-fw"></i>&nbsp;{{ $L('About grocy') }} (Version {{ $version }})</a>
</div>
</li>
</ul>
@ -297,30 +297,6 @@
</div>
</div>
<div class="modal fade content-text" id="about-modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content text-center">
<div class="modal-header">
<h4 class="modal-title w-100">{{ $L('About grocy') }}</h4>
<button type="button" class="close" data-dismiss="modal" title="{{ $L('Close') }}">&times;</button>
</div>
<div class="modal-body">
grocy is a project by
<a href="https://berrnd.de" class="discrete-link" target="_blank">Bernd Bestel</a><br>
Created with passion since 2017<br>
<br>
Version {{ $version }}<br>
{{ $L('Released on') }} {{ $releaseDate }} <time class="timeago timeago-contextual" datetime="{{ $releaseDate }}"></time><br>
<br>
Life runs on code<br>
<a href="https://github.com/grocy/grocy" class="discrete-link" target="_blank">
<i class="fab fa-github"></i>
</a>
</div>
</div>
</div>
</div>
<script src="{{ $U('/node_modules/jquery/dist/jquery.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/startbootstrap-sb-admin/js/sb-admin.min.js?v=', true) }}{{ $version }}"></script>
@ -350,7 +326,7 @@
<script src="{{ $U('/js/grocy_clock.js?v=', true) }}{{ $version }}"></script>
@stack('pageScripts')
@stack('componentScripts')
<script src="{{ $U('/viewjs', true) }}/@yield('viewJsName').js?v={{ $version }}"></script>
@hasSection('viewJsName')<script src="{{ $U('/viewjs', true) }}/@yield('viewJsName').js?v={{ $version }}"></script>@endif
@if(file_exists(GROCY_DATAPATH . '/custom_js.html'))
@php include GROCY_DATAPATH . '/custom_js.html' @endphp