131 lines
5.2 KiB
PHP
131 lines
5.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_admin();
|
|
|
|
$service = dashboards();
|
|
$ownerKey = 'system';
|
|
$notice = null;
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$action = trim((string) ($_POST['action'] ?? ''));
|
|
try {
|
|
if ($action === 'create_widget') {
|
|
$service->createWidgetTemplate($ownerKey, [
|
|
'name' => trim((string) ($_POST['name'] ?? '')),
|
|
'widget_type' => trim((string) ($_POST['widget_type'] ?? 'link')),
|
|
'description' => trim((string) ($_POST['description'] ?? '')),
|
|
'visibility' => 'public',
|
|
'config' => [
|
|
'url' => trim((string) ($_POST['target_url'] ?? '')),
|
|
'bookmarks' => trim((string) ($_POST['bookmarks'] ?? '')),
|
|
],
|
|
]);
|
|
$notice = 'Widget-Vorlage gespeichert.';
|
|
} elseif ($action === 'delete_widget') {
|
|
$service->deleteWidgetTemplate((int) ($_POST['widget_id'] ?? 0), $ownerKey);
|
|
$notice = 'Widget-Vorlage gelöscht.';
|
|
}
|
|
} catch (\Throwable $exception) {
|
|
$error = $exception->getMessage();
|
|
}
|
|
}
|
|
|
|
$widgets = $service->listWidgetTemplates($ownerKey, true);
|
|
|
|
$GLOBALS['layout_header_base_title'] = 'Nexus Setup';
|
|
$GLOBALS['layout_header_title'] = 'Nexus Setup';
|
|
$GLOBALS['layout_header_context'] = 'Widgets';
|
|
$GLOBALS['layout_header_text'] = 'Globale Widget-Vorlagen, die andere Nutzer in ihre Dashboards übernehmen können.';
|
|
?>
|
|
<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="Nexus Setup Navigation">
|
|
<a class="module-button module-button--tab" href="/settings">Allgemein</a>
|
|
<a class="module-button module-button--tab-active" href="/settings/widgets">Widgets</a>
|
|
<a class="module-button module-button--tab" href="/integrations">Integrationen</a>
|
|
<a class="module-button module-button--tab" href="/settings/search-engines">Suchmaschinen</a>
|
|
<a class="module-button module-button--tab" href="/settings/apps">Apps</a>
|
|
<a class="module-button module-button--tab" href="/dashboards">Dashboards</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>Neue Widget-Vorlage</h2>
|
|
<form method="post" class="setup-form">
|
|
<input type="hidden" name="action" value="create_widget">
|
|
<div class="setup-grid">
|
|
<label class="setup-field muted">
|
|
<span>Name</span>
|
|
<input type="text" name="name" required>
|
|
</label>
|
|
<label class="setup-field muted">
|
|
<span>Typ</span>
|
|
<select name="widget_type">
|
|
<option value="link">Link</option>
|
|
<option value="iframe">iFrame</option>
|
|
<option value="bookmark_group">Linkliste</option>
|
|
</select>
|
|
</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>Ziel-URL</span>
|
|
<input type="url" name="target_url" placeholder="https://...">
|
|
</label>
|
|
</div>
|
|
<div class="setup-grid">
|
|
<label class="setup-field muted">
|
|
<span>Linkliste optional</span>
|
|
<textarea name="bookmarks" rows="5" placeholder="Name | https://ziel.example Monitoring | https://grafana.example"></textarea>
|
|
</label>
|
|
</div>
|
|
<div class="setup-actions setup-actions--footer">
|
|
<button class="cta-button" type="submit">Widget speichern</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<div class="module-admin-grid">
|
|
<?php foreach ($widgets as $widget): ?>
|
|
<article class="card-box module-admin-card">
|
|
<div class="module-admin-card__head">
|
|
<div class="module-admin-card__title">
|
|
<h2><?= e((string) ($widget['name'] ?? 'Widget')) ?></h2>
|
|
<p><?= e((string) ($widget['description'] ?? 'Globale Widget-Vorlage.')) ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="module-admin-meta">
|
|
<div class="module-admin-meta__item">
|
|
<span class="module-admin-meta__label">Typ</span>
|
|
<strong class="module-admin-badge"><?= e((string) ($widget['widget_type'] ?? 'link')) ?></strong>
|
|
</div>
|
|
</div>
|
|
<div class="module-admin-actions">
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="delete_widget">
|
|
<input type="hidden" name="widget_id" value="<?= (int) ($widget['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>
|