Files
nexus/partials/landingpages/dashboards.php
Lars Gebhardt-Kusche 3ed4fba58c
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped
nexus base
2026-05-15 01:19:31 +02:00

143 lines
6.1 KiB
PHP

<?php
declare(strict_types=1);
require_auth();
$service = dashboards();
$ownerKey = auth_user_key();
$notice = null;
$error = null;
if (!$service->available() || $ownerKey === '') {
echo '<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack"><section class="section-box">Dashboard-System nicht verfügbar.</section></div></div></div>';
return;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = trim((string) ($_POST['action'] ?? ''));
try {
if ($action === 'create_dashboard') {
$service->createDashboard($ownerKey, [
'title' => trim((string) ($_POST['title'] ?? '')),
'slug' => trim((string) ($_POST['slug'] ?? '')),
'description' => trim((string) ($_POST['description'] ?? '')),
'visibility' => trim((string) ($_POST['visibility'] ?? 'private')),
'is_default' => isset($_POST['is_default']),
]);
$notice = 'Dashboard angelegt.';
} elseif ($action === 'set_default') {
$service->setDefaultDashboard($ownerKey, (int) ($_POST['dashboard_id'] ?? 0));
$notice = 'Standard-Dashboard gesetzt.';
} elseif ($action === 'delete_dashboard') {
$service->deleteDashboard((int) ($_POST['dashboard_id'] ?? 0), $ownerKey);
$notice = 'Dashboard gelöscht.';
}
} catch (\Throwable $exception) {
$error = $exception->getMessage();
}
}
$dashboardsList = $service->listDashboardsForOwner($ownerKey);
$GLOBALS['layout_header_base_title'] = 'Nexus';
$GLOBALS['layout_header_title'] = 'Nexus';
$GLOBALS['layout_header_context'] = 'Dashboards';
$GLOBALS['layout_header_text'] = 'Verwaltung persönlicher und später freigebbarer Dashboard-Flächen.';
?>
<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack">
<header class="module-hero submenu-box">
<div class="module-hero-top module-hero-top--compact">
<nav class="module-tabs" aria-label="Dashboard Verwaltung">
<a class="module-button module-button--tab" href="/dashboard">Dashboard</a>
<a class="module-button module-button--tab-active" href="/dashboards">Dashboards</a>
<a class="module-button module-button--tab" href="/integrations">Integrationen</a>
<a class="module-button module-button--tab" href="/page-modules">Seitenmodule</a>
</nav>
<div class="module-hero-actions module-submenu-actions">
<a class="module-button module-button--secondary module-button--small" href="/">Nexus Übersicht</a>
</div>
</div>
</header>
<?php if ($error !== null): ?>
<section class="section-box"><?= e($error) ?></section>
<?php elseif ($notice !== null): ?>
<section class="section-box"><?= e($notice) ?></section>
<?php endif; ?>
<section class="section-box">
<h2>Neues Dashboard</h2>
<form method="post" class="setup-form">
<input type="hidden" name="action" value="create_dashboard">
<div class="setup-grid">
<label class="setup-field muted">
<span>Titel</span>
<input type="text" name="title" required>
</label>
<label class="setup-field muted">
<span>Slug optional</span>
<input type="text" name="slug">
</label>
</div>
<div class="setup-grid">
<label class="setup-field muted">
<span>Beschreibung</span>
<input type="text" name="description">
</label>
<label class="setup-field muted">
<span>Sichtbarkeit</span>
<select name="visibility">
<option value="private">Privat</option>
<option value="public">Öffentlich</option>
</select>
</label>
</div>
<label class="setup-field muted">
<input type="checkbox" name="is_default" value="1">
<span>Als Standard-Dashboard setzen</span>
</label>
<div class="setup-actions setup-actions--footer">
<button class="cta-button" type="submit">Dashboard anlegen</button>
</div>
</form>
</section>
<div class="module-admin-grid">
<?php foreach ($dashboardsList as $dashboard): ?>
<article class="card-box module-admin-card">
<div class="module-admin-card__head">
<div class="module-admin-card__title">
<h2><?= e((string) ($dashboard['title'] ?? 'Dashboard')) ?></h2>
<p><?= e((string) ($dashboard['description'] ?? 'Persönliche Dashboard-Fläche.')) ?></p>
</div>
</div>
<div class="module-admin-meta">
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Sichtbarkeit</span>
<strong class="module-admin-badge"><?= e(ucfirst((string) ($dashboard['visibility'] ?? 'private'))) ?></strong>
</div>
<div class="module-admin-meta__item">
<span class="module-admin-meta__label">Standard</span>
<strong class="module-admin-badge<?= !empty($dashboard['is_default']) ? ' module-admin-badge--success' : '' ?>"><?= !empty($dashboard['is_default']) ? 'Ja' : 'Nein' ?></strong>
</div>
</div>
<div class="module-admin-actions">
<a class="module-button module-button--secondary module-button--small" href="/dashboard?id=<?= (int) ($dashboard['id'] ?? 0) ?>">Öffnen</a>
<?php if (empty($dashboard['is_default'])): ?>
<form method="post">
<input type="hidden" name="action" value="set_default">
<input type="hidden" name="dashboard_id" value="<?= (int) ($dashboard['id'] ?? 0) ?>">
<button class="module-button module-button--secondary module-button--small" type="submit">Als Standard</button>
</form>
<?php endif; ?>
<form method="post">
<input type="hidden" name="action" value="delete_dashboard">
<input type="hidden" name="dashboard_id" value="<?= (int) ($dashboard['id'] ?? 0) ?>">
<button class="module-button module-button--secondary module-button--small" type="submit">Löschen</button>
</form>
</div>
</article>
<?php endforeach; ?>
</div>
</div></div></div>