176 lines
8.7 KiB
PHP
176 lines
8.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
$auth = app()->auth();
|
|
$authUser = $auth->user();
|
|
$service = dashboards();
|
|
$ownerKey = auth_user_key();
|
|
$groups = auth_groups();
|
|
$selectedDashboardId = (int) ($_GET['board'] ?? 0);
|
|
$currentDashboard = $service->available()
|
|
? $service->resolveHomeDashboard($ownerKey !== '' ? $ownerKey : null, $groups, $authUser !== null, $selectedDashboardId)
|
|
: null;
|
|
$dashboardItems = $currentDashboard !== null ? $service->listItems((int) ($currentDashboard['id'] ?? 0)) : [];
|
|
$accessibleApps = ($authUser !== null && $service->available()) ? $service->listApps($ownerKey, true) : [];
|
|
$appsById = [];
|
|
foreach ($accessibleApps as $appEntry) {
|
|
$appsById[(int) ($appEntry['id'] ?? 0)] = $appEntry;
|
|
}
|
|
$widgetTemplates = ($authUser !== null && $service->available()) ? $service->listWidgetTemplates($ownerKey, true) : [];
|
|
$widgetTemplatesById = [];
|
|
foreach ($widgetTemplates as $template) {
|
|
$widgetTemplatesById[(int) ($template['id'] ?? 0)] = $template;
|
|
}
|
|
$priorityModuleEntries = [];
|
|
if ($authUser !== null) {
|
|
$accessibleModules = $auth->filterModules(array_values(modules()->all()));
|
|
$accessibleModulesByName = [];
|
|
foreach ($accessibleModules as $module) {
|
|
$name = trim((string) ($module['name'] ?? ''));
|
|
if ($name !== '' && !empty($module['enabled'])) {
|
|
$accessibleModulesByName[$name] = $module;
|
|
}
|
|
}
|
|
|
|
foreach (['mining-checker', 'boersenchecker'] as $moduleName) {
|
|
if (isset($accessibleModulesByName[$moduleName])) {
|
|
$priorityModuleEntries[] = $accessibleModulesByName[$moduleName];
|
|
}
|
|
}
|
|
}
|
|
|
|
$GLOBALS['layout_header_base_title'] = 'Nexus';
|
|
$GLOBALS['layout_header_title'] = 'Nexus';
|
|
$GLOBALS['layout_header_context'] = $currentDashboard !== null ? (string) ($currentDashboard['title'] ?? 'Dashboard') : 'Dashboard';
|
|
$GLOBALS['layout_header_text'] = $currentDashboard !== null
|
|
? (string) ($currentDashboard['description'] ?? '')
|
|
: 'Kein öffentliches oder persönliches Home-Dashboard verfügbar.';
|
|
|
|
$renderBookmarks = static function (array $config): array {
|
|
$items = [];
|
|
$raw = trim((string) ($config['bookmarks'] ?? ''));
|
|
if ($raw === '') {
|
|
return [];
|
|
}
|
|
foreach (preg_split('/\r\n|\r|\n/', $raw) ?: [] as $line) {
|
|
$line = trim($line);
|
|
if ($line === '') {
|
|
continue;
|
|
}
|
|
[$label, $url] = array_pad(array_map('trim', explode('|', $line, 2)), 2, '');
|
|
if ($label !== '' && $url !== '') {
|
|
$items[] = ['label' => $label, 'url' => $url];
|
|
}
|
|
}
|
|
return $items;
|
|
};
|
|
?>
|
|
<div class="module-shell"><div class="module-page-bg"><div class="module-page-stack">
|
|
<?php if ($priorityModuleEntries !== []): ?>
|
|
<section class="section-box">
|
|
<h2>Schnellzugriff</h2>
|
|
<p class="muted">Wichtige Module für deinen direkten Einstieg.</p>
|
|
<div class="dashboard-links">
|
|
<?php foreach ($priorityModuleEntries as $moduleEntry): ?>
|
|
<a class="module-button module-button--secondary module-button--small" href="/module/<?= rawurlencode((string) ($moduleEntry['name'] ?? '')) ?>">
|
|
<?= e((string) ($moduleEntry['title'] ?? $moduleEntry['name'] ?? 'Modul')) ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
<?php if ($currentDashboard === null): ?>
|
|
<section class="section-box">
|
|
<h2>Kein Home-Dashboard verfügbar</h2>
|
|
<p class="muted">Lege als Administrator ein öffentliches Dashboard fest oder richte dein persönliches Dashboard ein.</p>
|
|
<?php if ($authUser !== null): ?>
|
|
<a class="module-button module-button--secondary module-button--small" href="/dashboard">Zum Dashboard</a>
|
|
<?php endif; ?>
|
|
</section>
|
|
<?php elseif ($dashboardItems === []): ?>
|
|
<section class="section-box">
|
|
<h2><?= e((string) ($currentDashboard['title'] ?? 'Dashboard')) ?></h2>
|
|
<p class="muted">Dieses Dashboard enthält noch keine Elemente.</p>
|
|
<?php if ($authUser !== null): ?>
|
|
<a class="module-button module-button--secondary module-button--small" href="/dashboard?id=<?= (int) ($currentDashboard['id'] ?? 0) ?>">Dashboard bearbeiten</a>
|
|
<?php endif; ?>
|
|
</section>
|
|
<?php else: ?>
|
|
<div class="dashboard-grid">
|
|
<?php foreach ($dashboardItems as $item): ?>
|
|
<?php
|
|
$itemType = (string) ($item['item_type'] ?? 'link');
|
|
$config = is_array($item['config'] ?? null) ? $item['config'] : [];
|
|
if ($itemType === 'widget_template' && !empty($config['widget_template_id']) && isset($widgetTemplatesById[(int) $config['widget_template_id']])) {
|
|
$template = $widgetTemplatesById[(int) $config['widget_template_id']];
|
|
$itemType = (string) ($template['widget_type'] ?? $itemType);
|
|
$config = array_merge(is_array($template['config'] ?? null) ? $template['config'] : [], $config);
|
|
}
|
|
$columnSpan = max(1, min(4, (int) ($item['column_span'] ?? 1)));
|
|
$rowSpan = max(1, min(4, (int) ($item['row_span'] ?? 1)));
|
|
$gridStyles = 'grid-column: span ' . $columnSpan . '; grid-row: span ' . $rowSpan . ';';
|
|
if (!empty($item['grid_column'])) {
|
|
$gridStyles .= 'grid-column-start:' . (int) $item['grid_column'] . ';';
|
|
}
|
|
if (!empty($item['grid_row'])) {
|
|
$gridStyles .= 'grid-row-start:' . (int) $item['grid_row'] . ';';
|
|
}
|
|
$targetUrl = trim((string) ($config['url'] ?? ''));
|
|
$pageModule = null;
|
|
if ($itemType === 'page_module' && !empty($config['page_module_id'])) {
|
|
$pageModule = $service->getPageModule((int) $config['page_module_id'], $ownerKey, $groups);
|
|
$targetUrl = trim((string) ($pageModule['target_url'] ?? $targetUrl));
|
|
}
|
|
$appEntry = null;
|
|
if ($itemType === 'app' && !empty($config['app_id'])) {
|
|
$appEntry = $appsById[(int) $config['app_id']] ?? null;
|
|
$targetUrl = trim((string) ($appEntry['app_url'] ?? $targetUrl));
|
|
}
|
|
$bookmarks = $itemType === 'bookmark_group' ? $renderBookmarks($config) : [];
|
|
?>
|
|
<article class="card-box dashboard-widget" style="<?= e($gridStyles) ?>">
|
|
<div class="dashboard-widget__head">
|
|
<div>
|
|
<span class="module-admin-meta__label"><?= e(strtoupper(str_replace('_', ' ', $itemType))) ?></span>
|
|
<h2><?= e((string) ($item['title'] ?? 'Element')) ?></h2>
|
|
<?php if (!empty($item['description'])): ?>
|
|
<p><?= e((string) $item['description']) ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($itemType === 'bookmark_group' && $bookmarks !== []): ?>
|
|
<div class="dashboard-links">
|
|
<?php foreach ($bookmarks as $bookmark): ?>
|
|
<a class="module-button module-button--secondary module-button--small" href="<?= e($bookmark['url']) ?>" target="_blank" rel="noreferrer"><?= e($bookmark['label']) ?></a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php elseif (($itemType === 'iframe' || ($pageModule !== null && (string) ($pageModule['module_type'] ?? '') === 'iframe')) && $targetUrl !== ''): ?>
|
|
<iframe class="dashboard-widget__frame" src="<?= e($targetUrl) ?>" loading="lazy" referrerpolicy="no-referrer"></iframe>
|
|
<?php elseif ($appEntry !== null): ?>
|
|
<div class="dashboard-widget__meta">
|
|
<?php if (!empty($appEntry['icon_url'])): ?>
|
|
<img class="dashboard-app-icon" src="<?= e((string) $appEntry['icon_url']) ?>" alt="">
|
|
<?php endif; ?>
|
|
<p><?= e((string) ($appEntry['description'] ?? $targetUrl)) ?></p>
|
|
<a class="module-button module-button--secondary module-button--small" href="<?= e($targetUrl) ?>" target="_blank" rel="noreferrer">App öffnen</a>
|
|
</div>
|
|
<?php elseif ($pageModule !== null): ?>
|
|
<div class="dashboard-widget__meta">
|
|
<p><?= e((string) ($pageModule['description'] ?? 'Seitenmodul aus dem Nexus-System.')) ?></p>
|
|
<a class="module-button module-button--secondary module-button--small" href="/page-modules/view/<?= (int) ($pageModule['id'] ?? 0) ?>">Öffnen</a>
|
|
</div>
|
|
<?php elseif ($targetUrl !== ''): ?>
|
|
<div class="dashboard-widget__meta">
|
|
<p><?= e($targetUrl) ?></p>
|
|
<a class="module-button module-button--secondary module-button--small" href="<?= e($targetUrl) ?>" target="_blank" rel="noreferrer">Öffnen</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="dashboard-empty">Für dieses Element ist noch kein Inhalt hinterlegt.</div>
|
|
<?php endif; ?>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div></div></div>
|