chartboard/app/Views/layouts/main.php
2026-03-30 09:51:33 +05:30

168 lines
11 KiB
PHP

<!doctype html>
<html lang="en" data-cb-theme-pref="<?= esc($themePreference ?? 'light', 'attr') ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= esc($title ?? 'Chart-Board') ?></title>
<link rel="icon" type="image/svg+xml" href="<?= base_url('assets/images/logo-mark.svg') ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght@400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="<?= base_url('assets/css/variables.css') ?>">
<?= $this->renderSection('styles') ?>
</head>
<body class="cb-body">
<?php
$path = service('request')->getPath();
$segment = service('request')->getUri()->getSegment(1) ?: 'workspace';
$activeMain = match ($segment) {
'workspace', 'invite' => 'workspace',
'datasource' => 'datasource',
'query' => 'queries',
'chart' => 'charts',
'dashboard' => 'dashboards',
'alert' => 'alerts',
'settings', 'audit', 'profile' => 'settings',
'admin' => 'settings',
default => 'workspace',
};
$canWsAdmin = ! empty($canWorkspaceAdmin);
$roleUser = (string) ($currentUser['role'] ?? '');
$workspaceSub = [
['icon' => 'dashboard_customize', 'label' => 'Workspace Overview', 'url' => base_url('workspace')],
['icon' => 'add_circle', 'label' => 'Create Workspace', 'url' => base_url('workspace/create')],
['icon' => 'groups', 'label' => 'Members', 'url' => ($activeWorkspaceId ?? 0) ? base_url('workspace/members/' . $activeWorkspaceId) : base_url('workspace')],
['icon' => 'mail', 'label' => 'Invitations', 'url' => ($activeWorkspaceId ?? 0) ? base_url('workspace/invite/' . $activeWorkspaceId) : base_url('workspace')],
['icon' => 'settings', 'label' => 'Workspace Settings', 'url' => ($activeWorkspaceId ?? 0) ? base_url('workspace/settings/' . $activeWorkspaceId) : base_url('workspace')],
];
$settingsSub = array_values(array_filter([
['icon' => 'tune', 'label' => 'Workspace preferences', 'url' => base_url('settings/workspace')],
['icon' => 'person', 'label' => 'Profile', 'url' => base_url('profile')],
$canWsAdmin ? ['icon' => 'notifications', 'label' => 'Notifications', 'url' => base_url('settings/notifications')] : null,
$canWsAdmin ? ['icon' => 'history', 'label' => 'Audit log', 'url' => base_url('audit')] : null,
$roleUser === 'superadmin' ? ['icon' => 'shield_person', 'label' => 'App settings', 'url' => base_url('admin/settings')] : null,
$roleUser === 'superadmin' ? ['icon' => 'group', 'label' => 'Manage users', 'url' => base_url('admin/users')] : null,
]));
$itemPathActive = static function (string $itemUrl) use ($path): bool {
$p = trim(parse_url($itemUrl, PHP_URL_PATH) ?? '', '/');
return $p !== '' && str_starts_with($path, $p);
};
?>
<header class="cb-topbar">
<div class="cb-topbar-row d-flex align-items-center justify-content-between gap-2 px-3 px-md-4">
<div class="d-flex align-items-center gap-2 gap-md-3 flex-shrink-0">
<a href="<?= base_url('dashboard') ?>" class="cb-brand-unit d-flex align-items-center gap-2 text-decoration-none text-body">
<img src="<?= base_url('assets/images/logo-mark.svg') ?>" alt="Chart Board" width="22" height="22">
<span class="cb-brand-text d-none d-sm-inline">CHART BOARD</span>
</a>
<div class="cb-topbar-divider d-none d-md-block flex-shrink-0" aria-hidden="true"></div>
</div>
<nav class="cb-top-main-nav cb-top-nav-scroll d-flex align-items-center flex-grow-1 min-w-0" aria-label="Primary">
<div class="dropdown cb-top-nav-dropdown">
<button type="button" class="cb-top-main-link dropdown-toggle <?= $activeMain === 'workspace' ? 'active' : '' ?>" data-bs-toggle="dropdown" data-bs-popper-config='{"strategy":"fixed"}' aria-expanded="false" id="cbNavWorkspace">
Workspaces
</button>
<ul class="dropdown-menu cb-top-dropdown-menu shadow border-0 py-2" aria-labelledby="cbNavWorkspace">
<?php foreach ($workspaceSub as $item): ?>
<?php $ia = $itemPathActive($item['url']); ?>
<li>
<a class="dropdown-item cb-top-dropdown-item d-flex align-items-center gap-2 <?= $ia ? 'active' : '' ?>" href="<?= $item['url'] ?>">
<span class="material-symbols-outlined cb-top-dropdown-icon" aria-hidden="true"><?= esc($item['icon']) ?></span>
<?= esc($item['label']) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<a class="cb-top-main-link <?= $activeMain === 'datasource' ? 'active' : '' ?>" href="<?= base_url('datasource') ?>">Data Sources</a>
<a class="cb-top-main-link <?= $activeMain === 'queries' ? 'active' : '' ?>" href="<?= base_url('query') ?>">Queries</a>
<a class="cb-top-main-link <?= $activeMain === 'charts' ? 'active' : '' ?>" href="<?= base_url('chart') ?>">Charts</a>
<a class="cb-top-main-link <?= $activeMain === 'dashboards' ? 'active' : '' ?>" href="<?= base_url('dashboard') ?>">Dashboards</a>
<a class="cb-top-main-link <?= $activeMain === 'alerts' ? 'active' : '' ?>" href="<?= base_url('alert') ?>">
Alerts
<?php if (! empty($alertBadgeCount)): ?>
<span class="badge bg-danger ms-1 cb-top-nav-badge"><?= (int) $alertBadgeCount ?></span>
<?php endif; ?>
</a>
<div class="dropdown cb-top-nav-dropdown">
<button type="button" class="cb-top-main-link dropdown-toggle <?= $activeMain === 'settings' ? 'active' : '' ?>" data-bs-toggle="dropdown" data-bs-popper-config='{"strategy":"fixed"}' aria-expanded="false" id="cbNavSettings">
Settings
</button>
<ul class="dropdown-menu cb-top-dropdown-menu shadow border-0 py-2 dropdown-menu-end" aria-labelledby="cbNavSettings">
<?php foreach ($settingsSub as $item): ?>
<?php $ia = $itemPathActive($item['url']); ?>
<li>
<a class="dropdown-item cb-top-dropdown-item d-flex align-items-center gap-2 <?= $ia ? 'active' : '' ?>" href="<?= $item['url'] ?>">
<span class="material-symbols-outlined cb-top-dropdown-icon" aria-hidden="true"><?= esc($item['icon']) ?></span>
<?= esc($item['label']) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</nav>
<div class="d-flex align-items-center gap-2 gap-md-3 flex-shrink-0 cb-topbar-actions">
<span class="material-symbols-outlined cb-topbar-action-icon text-muted d-none d-sm-inline" role="img" aria-label="Notifications">notifications</span>
<span class="material-symbols-outlined cb-topbar-action-icon text-muted d-none d-sm-inline" role="img" aria-label="Help">help</span>
<?php if (! empty($workspaceList)): ?>
<div class="cb-top-ws-wrap d-flex align-items-center">
<label class="visually-hidden" for="cbTopWsSelect">Active workspace</label>
<select id="cbTopWsSelect" class="form-select form-select-sm cb-top-ws-select" title="Switch workspace" aria-label="Switch workspace" onchange="if(this.value){window.location.href=this.value;}">
<?php foreach ($workspaceList as $workspace): ?>
<option value="<?= base_url('workspace/switch/' . $workspace['id']) ?>" <?= (int) ($activeWorkspaceId ?? 0) === (int) $workspace['id'] ? 'selected' : '' ?>>
<?= esc($workspace['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<div class="dropdown">
<button type="button" class="cb-user-avatar rounded-circle bg-dark text-white d-flex align-items-center justify-content-center border-0 dropdown-toggle p-0" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Account menu" id="cbNavUser">
<?= esc(strtoupper(substr((string) ($currentUser['name'] ?? 'JD'), 0, 2))) ?>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow border-0 py-2 cb-top-dropdown-menu" aria-labelledby="cbNavUser">
<li><a class="dropdown-item cb-top-dropdown-item d-flex align-items-center gap-2" href="<?= base_url('profile') ?>">
<span class="material-symbols-outlined cb-top-dropdown-icon" aria-hidden="true">person</span> Profile
</a></li>
<li><a class="dropdown-item cb-top-dropdown-item d-flex align-items-center gap-2" href="<?= base_url('settings/workspace') ?>">
<span class="material-symbols-outlined cb-top-dropdown-icon" aria-hidden="true">tune</span> Preferences
</a></li>
<li><hr class="dropdown-divider my-2"></li>
<li><a class="dropdown-item cb-top-dropdown-item d-flex align-items-center gap-2 text-danger" href="<?= base_url('logout') ?>">
<span class="material-symbols-outlined cb-top-dropdown-icon" aria-hidden="true">logout</span> Sign out
</a></li>
</ul>
</div>
</div>
</div>
</header>
<div class="cb-content">
<main class="cb-page">
<?= $this->renderSection('content') ?>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<?php if ((int) (session()->get('user_id') ?? 0) > 0): ?>
<?= $this->include('share/modal') ?>
<?php endif; ?>
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
<!-- Pin 3.x: unversioned npm/apexcharts resolves to 5.x and breaks our v3-style options (e.g. sameValueSeriesFix). -->
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.54.1/dist/apexcharts.min.js"></script>
<script src="<?= base_url('assets/js/app.js') ?>"></script>
<?= $this->renderSection('scripts') ?>
</body>
</html>