Add version numbers; make app title configurable
This commit is contained in:
parent
186dcdc0cb
commit
8df2684e5c
|
|
@ -5,6 +5,7 @@
|
||||||
# General
|
# General
|
||||||
/tmp
|
/tmp
|
||||||
/_tmp
|
/_tmp
|
||||||
|
/VERSION
|
||||||
|
|
||||||
# PHP
|
# PHP
|
||||||
/.composer
|
/.composer
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ RUN cp $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini && \
|
||||||
pecl install xdebug && \
|
pecl install xdebug && \
|
||||||
docker-php-ext-enable xdebug
|
docker-php-ext-enable xdebug
|
||||||
|
|
||||||
|
ENV APP_ENV=development
|
||||||
|
|
||||||
# TODO: production image untested
|
# TODO: production image untested
|
||||||
#FROM base AS production
|
#FROM base AS production
|
||||||
|
|
|
||||||
12
Makefile
12
Makefile
|
|
@ -9,7 +9,7 @@ DOCKER_RUN = $(DOCKER_COMPOSE) run --rm app
|
||||||
COMPOSER = $(DOCKER_RUN) composer
|
COMPOSER = $(DOCKER_RUN) composer
|
||||||
PHPUNIT = $(DOCKER_RUN) vendor/bin/phpunit
|
PHPUNIT = $(DOCKER_RUN) vendor/bin/phpunit
|
||||||
|
|
||||||
.PHONY: all clean \
|
.PHONY: all clean VERSION \
|
||||||
docker-up docker-up-detached docker-down docker-restart docker-build docker-rebuild docker-purge docker-logs docker-run \
|
docker-up docker-up-detached docker-down docker-restart docker-build docker-rebuild docker-purge docker-logs docker-run \
|
||||||
composer-install composer-install-no-dev composer-update composer-cmd \
|
composer-install composer-install-no-dev composer-update composer-cmd \
|
||||||
test phpunit open-coverage
|
test phpunit open-coverage
|
||||||
|
|
@ -94,9 +94,17 @@ open-coverage:
|
||||||
$(or $(BROWSER),firefox) coverage/index.html
|
$(or $(BROWSER),firefox) coverage/index.html
|
||||||
|
|
||||||
|
|
||||||
|
# Version management
|
||||||
|
# ------------------
|
||||||
|
|
||||||
|
# Create VERSION file from current git tag
|
||||||
|
version:
|
||||||
|
git describe | tee VERSION
|
||||||
|
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
# --------
|
# --------
|
||||||
|
|
||||||
# Remove vendor directory, phpunit caches and other files that have been generated
|
# Remove vendor directory, phpunit caches and other files that have been generated
|
||||||
clean: docker-down
|
clean: docker-down
|
||||||
rm -rf .composer vendor .phpunit.cache coverage
|
rm -rf .composer vendor .phpunit.cache coverage VERSION
|
||||||
|
|
|
||||||
|
|
@ -57,15 +57,32 @@ header {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
padding: 0 1rem;
|
padding: 0 1rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-flow: row wrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
align-items: center;
|
align-items: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
header h1 {
|
header > * {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header > .header_appversion {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #767676;
|
||||||
|
}
|
||||||
|
|
||||||
|
header > .header_appversion > a {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
header > .header_spacer {
|
||||||
|
width: 0;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
flex: 1 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* -- Navigation bar -- */
|
/* -- Navigation bar -- */
|
||||||
nav {
|
nav {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MailAccountAdmin;
|
||||||
|
|
||||||
|
class AppInfo
|
||||||
|
{
|
||||||
|
private const REPOSITORY_URL = 'https://git.0xbd.space/0xbd/mail-account-admin';
|
||||||
|
|
||||||
|
private string $title;
|
||||||
|
private string $version;
|
||||||
|
|
||||||
|
public function __construct(string $title, string $version)
|
||||||
|
{
|
||||||
|
$this->title = $title;
|
||||||
|
$this->version = $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVersion(): string
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRepositoryUrl(): string
|
||||||
|
{
|
||||||
|
return self::REPOSITORY_URL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,18 @@ class Dependencies
|
||||||
// App settings
|
// App settings
|
||||||
$container->set(self::SETTINGS, $settings);
|
$container->set(self::SETTINGS, $settings);
|
||||||
|
|
||||||
|
// App information
|
||||||
|
$container->set(AppInfo::class, function (ContainerInterface $c) {
|
||||||
|
/** @var Settings $settings */
|
||||||
|
$settings = $c->get(self::SETTINGS);
|
||||||
|
$versionHelper = new VersionHelper();
|
||||||
|
|
||||||
|
return new AppInfo(
|
||||||
|
$settings->getAppTitle(),
|
||||||
|
$versionHelper->getAppVersion(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Twig template engine
|
// Twig template engine
|
||||||
$container->set(self::TWIG, function (ContainerInterface $c) {
|
$container->set(self::TWIG, function (ContainerInterface $c) {
|
||||||
/** @var Settings $settings */
|
/** @var Settings $settings */
|
||||||
|
|
@ -49,6 +61,10 @@ class Dependencies
|
||||||
$coreExtension->setDateFormat($settings->getDateFormat());
|
$coreExtension->setDateFormat($settings->getDateFormat());
|
||||||
$coreExtension->setTimezone($settings->getTimezone());
|
$coreExtension->setTimezone($settings->getTimezone());
|
||||||
|
|
||||||
|
// Add app information to globals
|
||||||
|
$appInfo = $c->get(AppInfo::class);
|
||||||
|
$twig->getEnvironment()->addGlobal('app_info', $appInfo);
|
||||||
|
|
||||||
// Return Twig view
|
// Return Twig view
|
||||||
return $twig;
|
return $twig;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ class BaseController
|
||||||
|
|
||||||
// Register globals
|
// Register globals
|
||||||
$twigEnv = $view->getEnvironment();
|
$twigEnv = $view->getEnvironment();
|
||||||
|
$twigEnv->addGlobal('logged_in', $userHelper->isLoggedIn());
|
||||||
$twigEnv->addGlobal('current_user_name', $userHelper->isLoggedIn() ? $userHelper->getCurrentUser()->getUsername() : null);
|
$twigEnv->addGlobal('current_user_name', $userHelper->isLoggedIn() ? $userHelper->getCurrentUser()->getUsername() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@ namespace MailAccountAdmin;
|
||||||
|
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
|
public function getAppTitle(): string
|
||||||
|
{
|
||||||
|
return getenv('APP_TITLE') ?: 'MailAccountAdmin';
|
||||||
|
}
|
||||||
|
|
||||||
public function isDebugMode(): bool
|
public function isDebugMode(): bool
|
||||||
{
|
{
|
||||||
return getenv('APP_DEBUG') === 'true';
|
return getenv('APP_DEBUG') === 'true';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MailAccountAdmin;
|
||||||
|
|
||||||
|
class VersionHelper
|
||||||
|
{
|
||||||
|
private string $version;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$version = $this->loadFromVersionFile();
|
||||||
|
if (!empty($version)) {
|
||||||
|
$this->version = $version;
|
||||||
|
} elseif ($this->inDevelopmentMode()) {
|
||||||
|
$this->version = '[dev version]';
|
||||||
|
} else {
|
||||||
|
$this->version = '[undefined version]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAppVersion(): string
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loadFromVersionFile(): ?string
|
||||||
|
{
|
||||||
|
$versionFilePath = __DIR__ . '/../VERSION';
|
||||||
|
|
||||||
|
if (file_exists($versionFilePath)) {
|
||||||
|
$fileContent = file($versionFilePath);
|
||||||
|
return $fileContent[0] ?? null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function inDevelopmentMode(): bool
|
||||||
|
{
|
||||||
|
return getenv('APP_ENV') === 'development';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<title>{% block title %}Untitled page{% endblock %} - MailAccountAdmin</title>
|
<title>{% block title %}Untitled page{% endblock %} - {{ app_info.getTitle() }}</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||||
<link rel="stylesheet" href="/static/style.css"/>
|
<link rel="stylesheet" href="/static/style.css"/>
|
||||||
</head>
|
</head>
|
||||||
|
|
@ -10,27 +10,37 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1>MailAccountAdmin</h1>
|
<h1>{{ app_info.getTitle() }}</h1>
|
||||||
|
<div class="header_appversion">
|
||||||
|
<a href="{{ app_info.getRepositoryUrl() }}">{{ app_info.getVersion() }}</a>
|
||||||
|
</div>
|
||||||
|
<div class="header_spacer"></div>
|
||||||
<div class="header_userstatus">
|
<div class="header_userstatus">
|
||||||
Hello, <b>{{ current_user_name }}</b>. | <a href="/logout">Logout</a>
|
{% if logged_in | default() %}
|
||||||
|
Hello, <b>{{ current_user_name }}</b>. | <a href="/logout">Logout</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="/login">Login</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<nav>
|
{% if logged_in | default() %}
|
||||||
<ul>
|
<nav>
|
||||||
{% macro navbar_item(path, text) -%}
|
<ul>
|
||||||
<li{% if current_url() == path or current_url() starts with path ~ '/' %} class="nav_current_page"{% endif %}>
|
{% macro navbar_item(path, text) -%}
|
||||||
<a href="{{ path }}">{{ text }}</a>
|
<li{% if current_url() == path or current_url() starts with path ~ '/' %} class="nav_current_page"{% endif %}>
|
||||||
</li>
|
<a href="{{ path }}">{{ text }}</a>
|
||||||
{%- endmacro -%}
|
</li>
|
||||||
|
{%- endmacro -%}
|
||||||
|
|
||||||
{{ _self.navbar_item('/', 'Dashboard') }}
|
{{ _self.navbar_item('/', 'Dashboard') }}
|
||||||
{{ _self.navbar_item('/domains', 'Domains') }}
|
{{ _self.navbar_item('/domains', 'Domains') }}
|
||||||
{{ _self.navbar_item('/accounts', 'Accounts') }}
|
{{ _self.navbar_item('/accounts', 'Accounts') }}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<main>
|
<main{% if main_classes is defined %} class="{{ main_classes }}"{% endif %}>
|
||||||
{% block content %}
|
{% block content %}
|
||||||
Nothing to see here...
|
Nothing to see here...
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,9 @@
|
||||||
<!DOCTYPE html>
|
{% extends "base.html.twig" %}
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<title>Login - MailAccountAdmin</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
||||||
<link rel="stylesheet" href="/static/style.css"/>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
{% block title %}Login{% endblock %}
|
||||||
|
{% set main_classes = 'login_page' %}
|
||||||
|
|
||||||
<header>
|
{% block content %}
|
||||||
<h1>MailAccountAdmin</h1>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main class="login_page">
|
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
|
|
||||||
<form action="/login" method="POST">
|
<form action="/login" method="POST">
|
||||||
|
|
@ -38,7 +28,4 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
{% endblock %}
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue