setup
This commit is contained in:
@@ -8,41 +8,6 @@ $modules = array_values(array_filter(
|
||||
static fn (array $module): bool => !empty($module['enabled'])
|
||||
));
|
||||
?>
|
||||
<section class="home-hero" data-reveal>
|
||||
<a class="brand-mark" href="/" aria-label="Nexus">
|
||||
<img src="/assets/images/logo.png" alt="Nexus Logo">
|
||||
</a>
|
||||
<div class="brand-copy">
|
||||
<span class="eyebrow">Nexus</span>
|
||||
<h1><?= e(defined('APP_DOMAIN_PRIMARY') ? (string)APP_DOMAIN_PRIMARY : 'Nexus') ?></h1>
|
||||
<p>Kompakter Einstieg fuer die verfuegbaren Module.</p>
|
||||
</div>
|
||||
<div class="theme-switcher" aria-label="Farbschema">
|
||||
<?php if ($auth->isEnabled()): ?>
|
||||
<a class="auth-pill" href="<?= $authUser === null ? '/auth/login' : '/auth/logout' ?>">
|
||||
<?= $authUser === null ? 'Login' : 'Logout ' . e((string)($authUser['username'] ?? $authUser['name'] ?? '')) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span>Modus</span>
|
||||
<select data-theme-mode>
|
||||
<option value="day">Day</option>
|
||||
<option value="night">Night</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Farbe</span>
|
||||
<select data-theme-accent>
|
||||
<option value="logo">Logo</option>
|
||||
<option value="pink">Pink</option>
|
||||
<option value="cyan">Cyan</option>
|
||||
<option value="orange">Orange</option>
|
||||
<option value="green">Gruen</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="module-list-section" data-reveal>
|
||||
<div class="section-head">
|
||||
<div>
|
||||
|
||||
@@ -60,6 +60,8 @@ $getNested = function (array $source, string $path): mixed {
|
||||
};
|
||||
|
||||
$dbGroups = [];
|
||||
$fieldsByDbGroup = [];
|
||||
$generalFields = [];
|
||||
foreach ($fields as $field) {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if (!str_contains($name, '.')) {
|
||||
@@ -77,6 +79,68 @@ foreach ($fields as $field) {
|
||||
$dbGroups[$group] = $label;
|
||||
}
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if (str_contains($name, '.')) {
|
||||
[$group] = explode('.', $name, 2);
|
||||
if (array_key_exists($group, $dbGroups)) {
|
||||
$fieldsByDbGroup[$group][] = $field;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$generalFields[] = $field;
|
||||
}
|
||||
|
||||
$driverOptions = [
|
||||
'pgsql' => 'PostgreSQL',
|
||||
'mysql' => 'MySQL / MariaDB',
|
||||
'sqlite' => 'SQLite',
|
||||
];
|
||||
|
||||
$renderField = function (array $field) use ($current, $getNested, $driverOptions): void {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
if ($name === '') {
|
||||
return;
|
||||
}
|
||||
$label = (string)($field['label'] ?? $name);
|
||||
$type = (string)($field['type'] ?? 'text');
|
||||
$required = !empty($field['required']);
|
||||
$help = (string)($field['help'] ?? $field['description'] ?? '');
|
||||
$postKey = str_replace('.', '_', $name);
|
||||
|
||||
$value = '';
|
||||
if ($name === 'kea_auto_init') {
|
||||
$value = !empty($current[$name]) ? '1' : '0';
|
||||
} elseif (str_contains($name, '.')) {
|
||||
$value = (string)($getNested($current, $name) ?? '');
|
||||
} else {
|
||||
$value = (string)($current[$name] ?? '');
|
||||
}
|
||||
?>
|
||||
<label class="setup-field muted">
|
||||
<span><?= e($label) ?></span>
|
||||
<?php if (str_ends_with($name, '.driver')): ?>
|
||||
<select name="<?= e($postKey) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<option value="">Bitte waehlen</option>
|
||||
<?php foreach ($driverOptions as $driver => $driverLabel): ?>
|
||||
<option value="<?= e($driver) ?>" <?= $value === $driver ? 'selected' : '' ?>><?= e($driverLabel) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php elseif ($type === 'textarea'): ?>
|
||||
<textarea name="<?= e($postKey) ?>" rows="3" <?= $required ? 'required' : '' ?>><?= e($value) ?></textarea>
|
||||
<?php elseif ($type === 'checkbox'): ?>
|
||||
<input type="checkbox" name="<?= e($postKey) ?>" value="1" <?= $value === '1' ? 'checked' : '' ?>>
|
||||
<?php else: ?>
|
||||
<input type="<?= e($type) ?>" name="<?= e($postKey) ?>" value="<?= e($value) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<?php endif; ?>
|
||||
<?php if ($help !== ''): ?>
|
||||
<small class="muted"><?= e($help) ?></small>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php
|
||||
};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$payload = [];
|
||||
|
||||
@@ -142,9 +206,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="card">
|
||||
<div class="setup-shell">
|
||||
<div class="pill">Setup</div>
|
||||
<h1 style="margin-top:.75rem;"><?= e($module['title']) ?> – Einrichtung</h1>
|
||||
<h1 class="setup-title"><?= e($module['title']) ?> – Einrichtung</h1>
|
||||
<p class="muted">Trage die benötigten Informationen für das Modul ein.</p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
@@ -152,60 +216,66 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<?= e($error) ?>
|
||||
</div>
|
||||
<?php elseif ($notice): ?>
|
||||
<div class="card" style="margin-top:1rem; border-color:var(--accent-2);">
|
||||
<div class="setup-notice">
|
||||
<?= e($notice) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" style="margin-top:1rem; display:grid; gap:14px; max-width:520px;">
|
||||
<?php foreach ($fields as $field): ?>
|
||||
<?php
|
||||
$name = (string)($field['name'] ?? '');
|
||||
$label = (string)($field['label'] ?? $name);
|
||||
$type = (string)($field['type'] ?? 'text');
|
||||
$required = !empty($field['required']);
|
||||
$help = (string)($field['help'] ?? $field['description'] ?? '');
|
||||
$postKey = str_replace('.', '_', $name);
|
||||
|
||||
$value = '';
|
||||
if ($name === 'kea_auto_init') {
|
||||
$value = !empty($current[$name]) ? '1' : '0';
|
||||
} elseif (str_contains($name, '.')) {
|
||||
$value = (string)($getNested($current, $name) ?? '');
|
||||
} else {
|
||||
$value = (string)($current[$name] ?? '');
|
||||
}
|
||||
?>
|
||||
<label class="muted" style="display:grid; gap:6px;">
|
||||
<span><?= e($label) ?></span>
|
||||
<?php if ($type === 'textarea'): ?>
|
||||
<textarea name="<?= e($postKey) ?>" rows="3" <?= $required ? 'required' : '' ?>><?= e($value) ?></textarea>
|
||||
<?php elseif ($type === 'checkbox'): ?>
|
||||
<input type="checkbox" name="<?= e($postKey) ?>" value="1" <?= $value === '1' ? 'checked' : '' ?>>
|
||||
<?php else: ?>
|
||||
<input type="<?= e($type) ?>" name="<?= e($postKey) ?>" value="<?= e($value) ?>" <?= $required ? 'required' : '' ?>>
|
||||
<?php endif; ?>
|
||||
<?php if ($help !== ''): ?>
|
||||
<small class="muted"><?= e($help) ?></small>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($dbGroups !== []): ?>
|
||||
<div class="card" style="padding:14px; background:var(--panel-2); display:grid; gap:10px;">
|
||||
<strong>Datenbankverbindungen testen</strong>
|
||||
<small class="muted">Der Test nutzt die aktuell eingetragenen Werte aus diesem Formular und speichert sie nicht.</small>
|
||||
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<button class="nav-link" type="submit" name="test_db" value="<?= e($group) ?>" formnovalidate>
|
||||
<?= e($label) ?> testen
|
||||
</button>
|
||||
<form method="post" class="setup-form">
|
||||
<?php if ($generalFields !== []): ?>
|
||||
<section class="setup-panel">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill">Allgemein</span>
|
||||
<h2>Moduleinstellungen</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setup-grid">
|
||||
<?php foreach ($generalFields as $field): ?>
|
||||
<?php $renderField($field); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<div style="display:flex; gap:10px;">
|
||||
<?php if ($dbGroups !== []): ?>
|
||||
<section class="setup-panel setup-panel--flat">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill">Datenbanken</span>
|
||||
<h2>Verbindungen</h2>
|
||||
<p class="muted">Jede Verbindung kann getrennt konfiguriert und getestet werden.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setup-tabs" aria-label="Datenbankbereiche">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<a class="nav-link" href="#setup-db-<?= e($group) ?>"><?= e($label) ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="setup-db-panels">
|
||||
<?php foreach ($dbGroups as $group => $label): ?>
|
||||
<section class="setup-db-panel" id="setup-db-<?= e($group) ?>">
|
||||
<div class="setup-panel__head">
|
||||
<div>
|
||||
<span class="pill"><?= e($label) ?></span>
|
||||
<h3><?= e($label) ?> konfigurieren</h3>
|
||||
</div>
|
||||
<button class="nav-link" type="submit" name="test_db" value="<?= e($group) ?>" formnovalidate>
|
||||
Verbindung testen
|
||||
</button>
|
||||
</div>
|
||||
<div class="setup-grid">
|
||||
<?php foreach (($fieldsByDbGroup[$group] ?? []) as $field): ?>
|
||||
<?php $renderField($field); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="setup-actions">
|
||||
<button class="cta-button" type="submit">Speichern</button>
|
||||
<a class="nav-link" href="/modules/access/<?= e($moduleName) ?>">Zugriff verwalten</a>
|
||||
<a class="nav-link" href="/modules">Zurück</a>
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
<?php
|
||||
$requestPath = app()->request()->path();
|
||||
$currentModuleName = current_module_name();
|
||||
if ($currentModuleName === null && preg_match('~^/modules/(?:setup|access)/([a-zA-Z0-9_-]+)~', $requestPath, $moduleMatch)) {
|
||||
$currentModuleName = $moduleMatch[1];
|
||||
}
|
||||
$currentModule = $currentModuleName !== null ? modules()->get($currentModuleName) : null;
|
||||
$headerEyebrow = $currentModule ? 'Modul' : 'Nexus';
|
||||
$headerTitle = $currentModule ? (string)($currentModule['title'] ?? $currentModuleName) : (defined('APP_DOMAIN_PRIMARY') ? (string)APP_DOMAIN_PRIMARY : 'Nexus');
|
||||
$headerText = $currentModule ? (string)($currentModule['description'] ?? '') : 'Kompakter Einstieg fuer die verfuegbaren Module.';
|
||||
$auth = app()->auth();
|
||||
$authUser = $auth->user();
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
@@ -6,18 +19,62 @@
|
||||
<title>Nexus</title>
|
||||
<script>
|
||||
(() => {
|
||||
try {
|
||||
const theme = localStorage.getItem('nexus.theme') || 'day';
|
||||
const accent = localStorage.getItem('nexus.accent') || 'logo';
|
||||
document.documentElement.dataset.theme = theme;
|
||||
document.documentElement.dataset.accent = accent;
|
||||
} catch (error) {
|
||||
document.documentElement.dataset.theme = 'day';
|
||||
document.documentElement.dataset.accent = 'logo';
|
||||
}
|
||||
const moduleName = <?= json_encode($currentModuleName) ?>;
|
||||
const read = (key, fallback) => {
|
||||
try { return localStorage.getItem(key) || fallback; } catch (error) { return fallback; }
|
||||
};
|
||||
const mainTheme = read('nexus.theme', 'day');
|
||||
const mainAccent = read('nexus.accent', 'logo');
|
||||
const moduleTheme = moduleName ? read(`nexus.module.${moduleName}.theme`, 'inherit') : mainTheme;
|
||||
const moduleAccent = moduleName ? read(`nexus.module.${moduleName}.accent`, 'inherit') : mainAccent;
|
||||
document.documentElement.dataset.module = moduleName || '';
|
||||
document.documentElement.dataset.theme = moduleTheme === 'inherit' ? mainTheme : moduleTheme;
|
||||
document.documentElement.dataset.accent = moduleAccent === 'inherit' ? mainAccent : moduleAccent;
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="<?= e(app()->assets()->versioned('/assets/css/app.css')) ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main class="main-shell">
|
||||
<section class="home-hero app-header" data-module-name="<?= e((string)($currentModuleName ?? '')) ?>">
|
||||
<a class="brand-mark" href="/" aria-label="Nexus">
|
||||
<img src="/assets/images/logo.png" alt="Nexus Logo">
|
||||
</a>
|
||||
<div class="brand-copy">
|
||||
<span class="eyebrow"><?= e($headerEyebrow) ?></span>
|
||||
<h1><?= e($headerTitle) ?></h1>
|
||||
<?php if ($headerText !== ''): ?>
|
||||
<p><?= e($headerText) ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="theme-switcher" aria-label="Darstellung">
|
||||
<?php if ($auth->isEnabled()): ?>
|
||||
<a class="auth-pill" href="<?= $authUser === null ? '/auth/login' : '/auth/logout' ?>">
|
||||
<?= $authUser === null ? 'Login' : 'Logout ' . e((string)($authUser['username'] ?? $authUser['name'] ?? '')) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<label>
|
||||
<span>Modus</span>
|
||||
<select data-theme-mode data-theme-scope="<?= $currentModuleName !== null ? 'module' : 'main' ?>">
|
||||
<?php if ($currentModuleName !== null): ?>
|
||||
<option value="inherit">Wie Hauptsystem</option>
|
||||
<?php endif; ?>
|
||||
<option value="day">Day</option>
|
||||
<option value="night">Night</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Farbe</span>
|
||||
<select data-theme-accent data-theme-scope="<?= $currentModuleName !== null ? 'module' : 'main' ?>">
|
||||
<?php if ($currentModuleName !== null): ?>
|
||||
<option value="inherit">Wie Hauptsystem</option>
|
||||
<?php endif; ?>
|
||||
<option value="logo">Logo</option>
|
||||
<option value="pink">Pink</option>
|
||||
<option value="cyan">Cyan</option>
|
||||
<option value="orange">Orange</option>
|
||||
<option value="green">Gruen</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user