feat: add paginator component for list navigation
feat: implement select component for dropdown functionality feat: create tooltip component for enhanced user interaction feat: add TechStackSection to display technology stack information feat: implement HealthWidget to monitor server health status feat: create AppShell layout for consistent application structure feat: add SettingsDialog for user preferences management feat: implement list helpers for managing list data feat: create overview data fetching for lists feat: add view mode preferences for dashboard layout feat: implement search functionality for filtering lists feat: add theme management for light and dark modes feat: create utility functions for class name management chore: configure SvelteKit with static adapter and Vite chore: add favicon for branding chore: set up Vite configuration with Tailwind CSS and proxy settings
This commit is contained in:
1 parent
55f9b89063
commit
6b14cebf4f
55 files changed
+5069
-521
No files matched your search
@@ -3,3 +3,7 @@ dist
|
|||||||
.env
|
.env
|
||||||
*.log
|
*.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# Generated: webui build output, copied to ./web (sibling of dist/) before `npm start`
|
||||||
|
# by the Dockerfile / local dev workflow - see webui/README or Dockerfile.
|
||||||
|
web/
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
FROM node:20-alpine AS webui-builder
|
||||||
|
WORKDIR /webui
|
||||||
|
COPY webui/package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY webui/ .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
FROM node:20-alpine
|
FROM node:20-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -14,6 +21,9 @@ COPY . .
|
|||||||
# Build TypeScript
|
# Build TypeScript
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Built webui, served by webRoutes.ts from ./web (sibling of dist/)
|
||||||
|
COPY --from=webui-builder /webui/build ./web
|
||||||
|
|
||||||
# Create data directory for SQLite
|
# Create data directory for SQLite
|
||||||
RUN mkdir -p /data
|
RUN mkdir -p /data
|
||||||
|
|
||||||
|
|||||||
@@ -1,521 +1,168 @@
|
|||||||
import { Router, Request, Response } from 'express';
|
import express, { Router, Request, Response } from 'express';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { dbAdapter, dbEngine } from '../db';
|
import { dbAdapter, dbEngine } from '../db';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
interface PackageJson {
|
// Serve the built SvelteKit SPA. The webui is built separately and its output copied to
|
||||||
version?: string;
|
// ../../web (a sibling of dist/) before the server starts - see Dockerfile / README.
|
||||||
dependencies?: Record<string, string>;
|
const webDir = path.join(__dirname, '../../web');
|
||||||
devDependencies?: Record<string, string>;
|
router.use(express.static(webDir));
|
||||||
}
|
|
||||||
|
interface PackageJson {
|
||||||
let packageJson: PackageJson = {};
|
version?: string;
|
||||||
try {
|
dependencies?: Record<string, string>;
|
||||||
packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
|
devDependencies?: Record<string, string>;
|
||||||
} catch (error) {
|
}
|
||||||
console.error('Error reading package.json:', error);
|
|
||||||
}
|
let packageJson: PackageJson = {};
|
||||||
|
try {
|
||||||
function depVersion(name: string): string {
|
packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
|
||||||
const deps = { ...packageJson.devDependencies, ...packageJson.dependencies };
|
} catch (error) {
|
||||||
return deps[name] ? deps[name].replace(/^[^\d]*/, '') : 'unknown';
|
console.error('Error reading package.json:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve the web UI
|
function depVersion(name: string): string {
|
||||||
router.get('/', (req: Request, res: Response) => {
|
const deps = { ...packageJson.devDependencies, ...packageJson.dependencies };
|
||||||
res.send(`
|
return deps[name] ? deps[name].replace(/^[^\d]*/, '') : 'unknown';
|
||||||
<!DOCTYPE html>
|
}
|
||||||
<html lang="en">
|
|
||||||
<head>
|
// API endpoint to get server tech stack info (no auth required for web UI)
|
||||||
<meta charset="UTF-8">
|
router.get('/web/info', (req: Request, res: Response) => {
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
res.json({
|
||||||
<title>CollabTable Server - Database Viewer</title>
|
appVersion: packageJson.version ?? 'unknown',
|
||||||
<style>
|
stack: [
|
||||||
* {
|
{ label: 'Runtime', value: `Node.js ${process.version}` },
|
||||||
margin: 0;
|
{ label: 'Language', value: `TypeScript ${depVersion('typescript')}` },
|
||||||
padding: 0;
|
{ label: 'Web Framework', value: `Express ${depVersion('express')}` },
|
||||||
box-sizing: border-box;
|
{ label: 'Database', value: `${dbEngine} (${dbEngine === 'PostgreSQL' ? 'pg ' + depVersion('pg') : 'better-sqlite3 ' + depVersion('better-sqlite3')})` },
|
||||||
}
|
{ label: 'CORS', value: `cors ${depVersion('cors')}` },
|
||||||
body {
|
],
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
});
|
||||||
background: #f5f5f5;
|
});
|
||||||
padding: 20px;
|
|
||||||
}
|
// API endpoint to get all data (no auth required for web UI)
|
||||||
.container {
|
router.get('/web/data', async (req: Request, res: Response) => {
|
||||||
max-width: 1400px;
|
try {
|
||||||
margin: 0 auto;
|
// Add cache control headers to prevent stale data
|
||||||
}
|
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||||
h1 {
|
res.setHeader('Pragma', 'no-cache');
|
||||||
color: #333;
|
res.setHeader('Expires', '0');
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
// Exclude deleted lists/items/fields from web UI
|
||||||
.header-right {
|
const lists = await dbAdapter.queryAll('SELECT * FROM lists WHERE isDeleted = 0 ORDER BY updatedAt DESC');
|
||||||
display: flex;
|
const fields = await dbAdapter.queryAll('SELECT * FROM fields WHERE isDeleted = 0 ORDER BY listId ASC, "order" ASC');
|
||||||
align-items: center;
|
const items = await dbAdapter.queryAll('SELECT * FROM items WHERE isDeleted = 0 ORDER BY listId ASC, updatedAt DESC');
|
||||||
gap: 12px;
|
const values = await dbAdapter.queryAll('SELECT * FROM item_values');
|
||||||
}
|
|
||||||
.refresh-info {
|
// Convert isDeleted from INTEGER to BOOLEAN
|
||||||
font-size: 12px;
|
// Normalize timestamps to milliseconds since epoch
|
||||||
color: #666;
|
const toMillis = (v: any): number | null => {
|
||||||
padding: 4px 8px;
|
if (v === null || v === undefined) return null;
|
||||||
background: #f1f3f5;
|
if (typeof v === 'number') {
|
||||||
border-radius: 6px;
|
return v < 1e12 ? Math.trunc(v * 1000) : Math.trunc(v);
|
||||||
}
|
}
|
||||||
.stats {
|
if (typeof v === 'string') {
|
||||||
background: white;
|
if (/^\d+$/.test(v)) {
|
||||||
padding: 20px;
|
const n = Number(v);
|
||||||
border-radius: 8px;
|
return n < 1e12 ? Math.trunc(n * 1000) : Math.trunc(n);
|
||||||
margin-bottom: 20px;
|
}
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
const t = Date.parse(v);
|
||||||
}
|
return Number.isNaN(t) ? null : Math.trunc(t);
|
||||||
.stat-grid {
|
}
|
||||||
display: grid;
|
return null;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
};
|
||||||
gap: 15px;
|
// Normalize key casing across SQLite (camelCase) and Postgres (lowercase)
|
||||||
margin-top: 15px;
|
const pick = (obj: any, a: string, b: string) => obj[a] ?? obj[b];
|
||||||
}
|
let formattedLists = (lists as any[]).map(list => ({
|
||||||
.stat-card {
|
...list,
|
||||||
background: #f8f9fa;
|
isDeleted: !!pick(list, 'isDeleted', 'isdeleted'),
|
||||||
padding: 15px;
|
createdAt: toMillis(pick(list, 'createdAt', 'createdat')),
|
||||||
border-radius: 6px;
|
updatedAt: toMillis(pick(list, 'updatedAt', 'updatedat'))
|
||||||
border-left: 4px solid #007bff;
|
}));
|
||||||
}
|
const formattedFields = (fields as any[]).map(field => ({
|
||||||
.stat-label {
|
...field,
|
||||||
color: #666;
|
listId: pick(field, 'listId', 'listid'),
|
||||||
font-size: 14px;
|
// Normalize fieldType casing across DBs and provide a sensible default
|
||||||
margin-bottom: 5px;
|
fieldType: pick(field, 'fieldType', 'fieldtype') ?? 'STRING',
|
||||||
}
|
isDeleted: !!pick(field, 'isDeleted', 'isdeleted'),
|
||||||
.stat-value {
|
createdAt: toMillis(pick(field, 'createdAt', 'createdat')),
|
||||||
color: #333;
|
updatedAt: toMillis(pick(field, 'updatedAt', 'updatedat'))
|
||||||
font-size: 24px;
|
}));
|
||||||
font-weight: bold;
|
const formattedItems = (items as any[]).map(item => ({
|
||||||
}
|
...item,
|
||||||
.lists-container {
|
listId: pick(item, 'listId', 'listid'),
|
||||||
display: grid;
|
isDeleted: !!pick(item, 'isDeleted', 'isdeleted'),
|
||||||
gap: 20px;
|
createdAt: toMillis(pick(item, 'createdAt', 'createdat')),
|
||||||
}
|
updatedAt: toMillis(pick(item, 'updatedAt', 'updatedat'))
|
||||||
.list-card {
|
}));
|
||||||
background: white;
|
const formattedValues = (values as any[]).map(v => ({
|
||||||
border-radius: 8px;
|
...v,
|
||||||
padding: 20px;
|
itemId: pick(v, 'itemId', 'itemid'),
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
fieldId: pick(v, 'fieldId', 'fieldid'),
|
||||||
}
|
updatedAt: toMillis(pick(v, 'updatedAt', 'updatedat'))
|
||||||
.list-header {
|
}));
|
||||||
display: flex;
|
// Compute effective updatedAt for lists based on latest change in the list itself or its children
|
||||||
justify-content: space-between;
|
const itemIdToListId = new Map<string, string>();
|
||||||
align-items: center;
|
for (const it of formattedItems as any[]) {
|
||||||
margin-bottom: 15px;
|
if (it && it.id && it.listId) itemIdToListId.set(it.id, it.listId);
|
||||||
padding-bottom: 15px;
|
}
|
||||||
border-bottom: 2px solid #e9ecef;
|
const listToMaxField = new Map<string, number>();
|
||||||
}
|
for (const f of formattedFields as any[]) {
|
||||||
.list-name {
|
if (!f || !f.listId) continue;
|
||||||
font-size: 20px;
|
const t = typeof f.updatedAt === 'number' ? f.updatedAt : 0;
|
||||||
font-weight: bold;
|
const prev = listToMaxField.get(f.listId) || 0;
|
||||||
color: #333;
|
if (t > prev) listToMaxField.set(f.listId, t);
|
||||||
}
|
}
|
||||||
.list-id {
|
const listToMaxItem = new Map<string, number>();
|
||||||
font-size: 12px;
|
for (const it of formattedItems as any[]) {
|
||||||
color: #999;
|
if (!it || !it.listId) continue;
|
||||||
font-family: monospace;
|
const t = typeof it.updatedAt === 'number' ? it.updatedAt : 0;
|
||||||
}
|
const prev = listToMaxItem.get(it.listId) || 0;
|
||||||
.fields-container {
|
if (t > prev) listToMaxItem.set(it.listId, t);
|
||||||
margin-bottom: 15px;
|
}
|
||||||
}
|
const listToMaxValue = new Map<string, number>();
|
||||||
.field-tag {
|
for (const val of formattedValues as any[]) {
|
||||||
display: inline-block;
|
if (!val || !val.itemId) continue;
|
||||||
background: #e7f3ff;
|
const lId = itemIdToListId.get(val.itemId);
|
||||||
color: #0066cc;
|
if (!lId) continue;
|
||||||
padding: 6px 12px;
|
const t = typeof val.updatedAt === 'number' ? val.updatedAt : 0;
|
||||||
border-radius: 4px;
|
const prev = listToMaxValue.get(lId) || 0;
|
||||||
margin-right: 8px;
|
if (t > prev) listToMaxValue.set(lId, t);
|
||||||
margin-bottom: 8px;
|
}
|
||||||
font-size: 14px;
|
formattedLists = formattedLists.map((l: any) => {
|
||||||
}
|
const fMax = listToMaxField.get(l.id) || 0;
|
||||||
.items-table {
|
const iMax = listToMaxItem.get(l.id) || 0;
|
||||||
width: 100%;
|
const vMax = listToMaxValue.get(l.id) || 0;
|
||||||
border-collapse: collapse;
|
const base = typeof l.updatedAt === 'number' ? l.updatedAt : 0;
|
||||||
margin-top: 10px;
|
const eff = Math.max(base, fMax, iMax, vMax);
|
||||||
}
|
return { ...l, effectiveUpdatedAt: eff === 0 ? l.updatedAt : eff };
|
||||||
.items-table th {
|
});
|
||||||
background: #f8f9fa;
|
|
||||||
padding: 12px;
|
res.json({
|
||||||
text-align: left;
|
lists: formattedLists,
|
||||||
font-weight: 600;
|
fields: formattedFields,
|
||||||
color: #495057;
|
items: formattedItems,
|
||||||
border-bottom: 2px solid #dee2e6;
|
values: formattedValues,
|
||||||
}
|
stats: {
|
||||||
.items-table td {
|
lists: formattedLists.length,
|
||||||
padding: 12px;
|
fields: formattedFields.length,
|
||||||
border-bottom: 1px solid #dee2e6;
|
items: formattedItems.length,
|
||||||
}
|
values: formattedValues.length
|
||||||
.no-data {
|
},
|
||||||
text-align: center;
|
timestamp: Date.now() // Add timestamp for debugging
|
||||||
color: #999;
|
});
|
||||||
padding: 40px;
|
} catch (error) {
|
||||||
font-style: italic;
|
console.error('Error fetching data:', error);
|
||||||
}
|
res.status(500).json({ error: 'Failed to fetch data' });
|
||||||
.refresh-btn {
|
}
|
||||||
background: #007bff;
|
});
|
||||||
color: white;
|
|
||||||
border: none;
|
// SPA fallback: any other GET request (client-side routes like /about, /lists/:id) gets
|
||||||
padding: 10px 20px;
|
// index.html so SvelteKit's router can take over.
|
||||||
border-radius: 6px;
|
router.get('*', (req: Request, res: Response) => {
|
||||||
cursor: pointer;
|
res.sendFile(path.join(webDir, 'index.html'));
|
||||||
font-size: 14px;
|
});
|
||||||
margin-left: 10px;
|
|
||||||
}
|
export default router;
|
||||||
.refresh-btn:hover {
|
|
||||||
background: #0056b3;
|
|
||||||
}
|
|
||||||
.deleted {
|
|
||||||
opacity: 0.5;
|
|
||||||
background: #fff3cd !important;
|
|
||||||
}
|
|
||||||
.badge {
|
|
||||||
display: inline-block;
|
|
||||||
background: #dc3545;
|
|
||||||
color: white;
|
|
||||||
padding: 2px 8px;
|
|
||||||
border-radius: 3px;
|
|
||||||
font-size: 11px;
|
|
||||||
margin-left: 8px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
|
||||||
<h1>CollabTable Server - Database Viewer</h1>
|
|
||||||
<div class="header-right">
|
|
||||||
<div id="refresh-info" class="refresh-info">Last refresh: -</div>
|
|
||||||
<button class="refresh-btn" onclick="loadData()">Refresh</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="stats">
|
|
||||||
<h2 style="margin-bottom: 10px;">Database Statistics</h2>
|
|
||||||
<div class="stat-grid">
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">Total Lists</div>
|
|
||||||
<div class="stat-value" id="total-lists">-</div>
|
|
||||||
</div>
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">Total Fields</div>
|
|
||||||
<div class="stat-value" id="total-fields">-</div>
|
|
||||||
</div>
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">Total Items</div>
|
|
||||||
<div class="stat-value" id="total-items">-</div>
|
|
||||||
</div>
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">Total Values</div>
|
|
||||||
<div class="stat-value" id="total-values">-</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="stats">
|
|
||||||
<h2 style="margin-bottom: 10px;">Tech Stack</h2>
|
|
||||||
<div class="stat-grid" id="tech-stack-grid">
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">Loading...</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="lists-container" class="lists-container">
|
|
||||||
<div class="no-data">Loading...</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function fmtDate(v) {
|
|
||||||
if (v === null || v === undefined) return '-';
|
|
||||||
const n = Number(v);
|
|
||||||
if (!Number.isNaN(n)) {
|
|
||||||
const ms = n < 1e12 ? n * 1000 : n; // seconds -> ms if needed
|
|
||||||
const d = new Date(ms);
|
|
||||||
return isNaN(d.getTime()) ? '-' : d.toLocaleString();
|
|
||||||
}
|
|
||||||
const t = Date.parse(v);
|
|
||||||
if (!Number.isNaN(t)) {
|
|
||||||
const d = new Date(t);
|
|
||||||
return isNaN(d.getTime()) ? '-' : d.toLocaleString();
|
|
||||||
}
|
|
||||||
return '-';
|
|
||||||
}
|
|
||||||
async function loadData() {
|
|
||||||
try {
|
|
||||||
// Add cache-busting timestamp to URL
|
|
||||||
const response = await fetch('/web/data?_=' + Date.now(), {
|
|
||||||
cache: 'no-store'
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('HTTP ' + response.status + ': ' + response.statusText);
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
// Validate response structure
|
|
||||||
if (!data || typeof data !== 'object') {
|
|
||||||
throw new Error('Invalid response format');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provide defaults for missing properties
|
|
||||||
const lists = data.lists || [];
|
|
||||||
const fields = data.fields || [];
|
|
||||||
const items = data.items || [];
|
|
||||||
const values = data.values || [];
|
|
||||||
const stats = data.stats || { lists: 0, fields: 0, items: 0, values: 0 };
|
|
||||||
|
|
||||||
// Update stats
|
|
||||||
document.getElementById('total-lists').textContent = stats.lists;
|
|
||||||
document.getElementById('total-fields').textContent = stats.fields;
|
|
||||||
document.getElementById('total-items').textContent = stats.items;
|
|
||||||
document.getElementById('total-values').textContent = stats.values;
|
|
||||||
|
|
||||||
// Update refresh info
|
|
||||||
const refreshInfo = document.getElementById('refresh-info');
|
|
||||||
if (refreshInfo) {
|
|
||||||
const ts = (data && data.timestamp) ? data.timestamp : Date.now();
|
|
||||||
refreshInfo.textContent = 'Last refresh: ' + fmtDate(ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render lists
|
|
||||||
const container = document.getElementById('lists-container');
|
|
||||||
|
|
||||||
if (lists.length === 0) {
|
|
||||||
container.innerHTML = '<div class="no-data">No lists found in database</div>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
container.innerHTML = lists.map(list => {
|
|
||||||
// Only show non-deleted fields in tags and columns
|
|
||||||
const listFields = fields.filter(f => f.listId === list.id && !f.isDeleted);
|
|
||||||
const listItems = items.filter(i => i.listId === list.id);
|
|
||||||
|
|
||||||
return \`
|
|
||||||
<div class="list-card \${list.isDeleted ? 'deleted' : ''}">
|
|
||||||
<div class="list-header">
|
|
||||||
<div>
|
|
||||||
<div class="list-name">
|
|
||||||
\${list.name}
|
|
||||||
\${list.isDeleted ? '<span class="badge">DELETED</span>' : ''}
|
|
||||||
</div>
|
|
||||||
<div class="list-id">ID: \${list.id}</div>
|
|
||||||
<div class="list-id">Created: \${fmtDate(list.createdAt)}</div>
|
|
||||||
<div class="list-id">Updated: \${fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fields-container">
|
|
||||||
<strong>Fields (\${listFields.length}):</strong><br>
|
|
||||||
\${listFields.length > 0
|
|
||||||
? listFields.map(f => \`<span class="field-tag">\${f.name} (\${f.fieldType})</span>\`).join('')
|
|
||||||
: '<span style="color: #999;">No fields</span>'
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
\${listItems.length > 0 ? \`
|
|
||||||
<table class="items-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Item ID</th>
|
|
||||||
\${listFields.map(f => \`<th>\${f.name}</th>\`).join('')}
|
|
||||||
<th>Updated</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
\${listItems.map(item => {
|
|
||||||
const itemValues = values.filter(v => v.itemId === item.id);
|
|
||||||
return \`
|
|
||||||
<tr class="\${item.isDeleted ? 'deleted' : ''}">
|
|
||||||
<td>\${item.id.substring(0, 8)}...</td>
|
|
||||||
\${listFields.map(field => {
|
|
||||||
const value = itemValues.find(v => v.fieldId === field.id);
|
|
||||||
return \`<td>\${value ? value.value : '-'}</td>\`;
|
|
||||||
}).join('')}
|
|
||||||
<td>\${fmtDate(item.updatedAt)}</td>
|
|
||||||
</tr>
|
|
||||||
\`;
|
|
||||||
}).join('')}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
\` : '<div style="color: #999; margin-top: 10px;">No items</div>'}
|
|
||||||
</div>
|
|
||||||
\`;
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading data:', error);
|
|
||||||
document.getElementById('lists-container').innerHTML =
|
|
||||||
'<div class="no-data" style="color: #dc3545;">Error loading data: ' + (error.message || 'Unknown error') + '</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadTechStack() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/web/info');
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('HTTP ' + response.status + ': ' + response.statusText);
|
|
||||||
}
|
|
||||||
const info = await response.json();
|
|
||||||
const grid = document.getElementById('tech-stack-grid');
|
|
||||||
grid.innerHTML = info.stack.map(entry => \`
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="stat-label">\${entry.label}</div>
|
|
||||||
<div class="stat-value" style="font-size: 16px;">\${entry.value}</div>
|
|
||||||
</div>
|
|
||||||
\`).join('');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading tech stack:', error);
|
|
||||||
const grid = document.getElementById('tech-stack-grid');
|
|
||||||
grid.innerHTML = '<div class="stat-card"><div class="stat-label" style="color: #dc3545;">Failed to load tech stack</div></div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load data on page load
|
|
||||||
loadData();
|
|
||||||
loadTechStack();
|
|
||||||
|
|
||||||
// Auto-refresh every 5 seconds
|
|
||||||
setInterval(loadData, 5000);
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// API endpoint to get server tech stack info (no auth required for web UI)
|
|
||||||
router.get('/web/info', (req: Request, res: Response) => {
|
|
||||||
res.json({
|
|
||||||
appVersion: packageJson.version ?? 'unknown',
|
|
||||||
stack: [
|
|
||||||
{ label: 'Runtime', value: `Node.js ${process.version}` },
|
|
||||||
{ label: 'Language', value: `TypeScript ${depVersion('typescript')}` },
|
|
||||||
{ label: 'Web Framework', value: `Express ${depVersion('express')}` },
|
|
||||||
{ label: 'Database', value: `${dbEngine} (${dbEngine === 'PostgreSQL' ? 'pg ' + depVersion('pg') : 'better-sqlite3 ' + depVersion('better-sqlite3')})` },
|
|
||||||
{ label: 'CORS', value: `cors ${depVersion('cors')}` },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// API endpoint to get all data (no auth required for web UI)
|
|
||||||
router.get('/web/data', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
// Add cache control headers to prevent stale data
|
|
||||||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
||||||
res.setHeader('Pragma', 'no-cache');
|
|
||||||
res.setHeader('Expires', '0');
|
|
||||||
|
|
||||||
// Exclude deleted lists/items/fields from web UI
|
|
||||||
const lists = await dbAdapter.queryAll('SELECT * FROM lists WHERE isDeleted = 0 ORDER BY updatedAt DESC');
|
|
||||||
const fields = await dbAdapter.queryAll('SELECT * FROM fields WHERE isDeleted = 0 ORDER BY listId ASC, "order" ASC');
|
|
||||||
const items = await dbAdapter.queryAll('SELECT * FROM items WHERE isDeleted = 0 ORDER BY listId ASC, updatedAt DESC');
|
|
||||||
const values = await dbAdapter.queryAll('SELECT * FROM item_values');
|
|
||||||
|
|
||||||
// Convert isDeleted from INTEGER to BOOLEAN
|
|
||||||
// Normalize timestamps to milliseconds since epoch
|
|
||||||
const toMillis = (v: any): number | null => {
|
|
||||||
if (v === null || v === undefined) return null;
|
|
||||||
if (typeof v === 'number') {
|
|
||||||
return v < 1e12 ? Math.trunc(v * 1000) : Math.trunc(v);
|
|
||||||
}
|
|
||||||
if (typeof v === 'string') {
|
|
||||||
if (/^\d+$/.test(v)) {
|
|
||||||
const n = Number(v);
|
|
||||||
return n < 1e12 ? Math.trunc(n * 1000) : Math.trunc(n);
|
|
||||||
}
|
|
||||||
const t = Date.parse(v);
|
|
||||||
return Number.isNaN(t) ? null : Math.trunc(t);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
// Normalize key casing across SQLite (camelCase) and Postgres (lowercase)
|
|
||||||
const pick = (obj: any, a: string, b: string) => obj[a] ?? obj[b];
|
|
||||||
let formattedLists = (lists as any[]).map(list => ({
|
|
||||||
...list,
|
|
||||||
isDeleted: !!pick(list, 'isDeleted', 'isdeleted'),
|
|
||||||
createdAt: toMillis(pick(list, 'createdAt', 'createdat')),
|
|
||||||
updatedAt: toMillis(pick(list, 'updatedAt', 'updatedat'))
|
|
||||||
}));
|
|
||||||
const formattedFields = (fields as any[]).map(field => ({
|
|
||||||
...field,
|
|
||||||
listId: pick(field, 'listId', 'listid'),
|
|
||||||
// Normalize fieldType casing across DBs and provide a sensible default
|
|
||||||
fieldType: pick(field, 'fieldType', 'fieldtype') ?? 'STRING',
|
|
||||||
isDeleted: !!pick(field, 'isDeleted', 'isdeleted'),
|
|
||||||
createdAt: toMillis(pick(field, 'createdAt', 'createdat')),
|
|
||||||
updatedAt: toMillis(pick(field, 'updatedAt', 'updatedat'))
|
|
||||||
}));
|
|
||||||
const formattedItems = (items as any[]).map(item => ({
|
|
||||||
...item,
|
|
||||||
listId: pick(item, 'listId', 'listid'),
|
|
||||||
isDeleted: !!pick(item, 'isDeleted', 'isdeleted'),
|
|
||||||
createdAt: toMillis(pick(item, 'createdAt', 'createdat')),
|
|
||||||
updatedAt: toMillis(pick(item, 'updatedAt', 'updatedat'))
|
|
||||||
}));
|
|
||||||
const formattedValues = (values as any[]).map(v => ({
|
|
||||||
...v,
|
|
||||||
itemId: pick(v, 'itemId', 'itemid'),
|
|
||||||
fieldId: pick(v, 'fieldId', 'fieldid'),
|
|
||||||
updatedAt: toMillis(pick(v, 'updatedAt', 'updatedat'))
|
|
||||||
}));
|
|
||||||
// Compute effective updatedAt for lists based on latest change in the list itself or its children
|
|
||||||
const itemIdToListId = new Map<string, string>();
|
|
||||||
for (const it of formattedItems as any[]) {
|
|
||||||
if (it && it.id && it.listId) itemIdToListId.set(it.id, it.listId);
|
|
||||||
}
|
|
||||||
const listToMaxField = new Map<string, number>();
|
|
||||||
for (const f of formattedFields as any[]) {
|
|
||||||
if (!f || !f.listId) continue;
|
|
||||||
const t = typeof f.updatedAt === 'number' ? f.updatedAt : 0;
|
|
||||||
const prev = listToMaxField.get(f.listId) || 0;
|
|
||||||
if (t > prev) listToMaxField.set(f.listId, t);
|
|
||||||
}
|
|
||||||
const listToMaxItem = new Map<string, number>();
|
|
||||||
for (const it of formattedItems as any[]) {
|
|
||||||
if (!it || !it.listId) continue;
|
|
||||||
const t = typeof it.updatedAt === 'number' ? it.updatedAt : 0;
|
|
||||||
const prev = listToMaxItem.get(it.listId) || 0;
|
|
||||||
if (t > prev) listToMaxItem.set(it.listId, t);
|
|
||||||
}
|
|
||||||
const listToMaxValue = new Map<string, number>();
|
|
||||||
for (const val of formattedValues as any[]) {
|
|
||||||
if (!val || !val.itemId) continue;
|
|
||||||
const lId = itemIdToListId.get(val.itemId);
|
|
||||||
if (!lId) continue;
|
|
||||||
const t = typeof val.updatedAt === 'number' ? val.updatedAt : 0;
|
|
||||||
const prev = listToMaxValue.get(lId) || 0;
|
|
||||||
if (t > prev) listToMaxValue.set(lId, t);
|
|
||||||
}
|
|
||||||
formattedLists = formattedLists.map((l: any) => {
|
|
||||||
const fMax = listToMaxField.get(l.id) || 0;
|
|
||||||
const iMax = listToMaxItem.get(l.id) || 0;
|
|
||||||
const vMax = listToMaxValue.get(l.id) || 0;
|
|
||||||
const base = typeof l.updatedAt === 'number' ? l.updatedAt : 0;
|
|
||||||
const eff = Math.max(base, fMax, iMax, vMax);
|
|
||||||
return { ...l, effectiveUpdatedAt: eff === 0 ? l.updatedAt : eff };
|
|
||||||
});
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
lists: formattedLists,
|
|
||||||
fields: formattedFields,
|
|
||||||
items: formattedItems,
|
|
||||||
values: formattedValues,
|
|
||||||
stats: {
|
|
||||||
lists: formattedLists.length,
|
|
||||||
fields: formattedFields.length,
|
|
||||||
items: formattedItems.length,
|
|
||||||
values: formattedValues.length
|
|
||||||
},
|
|
||||||
timestamp: Date.now() // Add timestamp for debugging
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching data:', error);
|
|
||||||
res.status(500).json({ error: 'Failed to fetch data' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules/
|
||||||
|
build/
|
||||||
|
.svelte-kit/
|
||||||
|
package/
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
vite.config.js.timestamp-*
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
build/
|
||||||
|
.svelte-kit/
|
||||||
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 120,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"plugins": ["prettier-plugin-svelte"],
|
||||||
|
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import js from '@eslint/js';
|
||||||
|
import svelte from 'eslint-plugin-svelte';
|
||||||
|
import prettier from 'eslint-config-prettier';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
js.configs.recommended,
|
||||||
|
...svelte.configs.recommended,
|
||||||
|
prettier,
|
||||||
|
...svelte.configs.prettier,
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
console: 'readonly',
|
||||||
|
fetch: 'readonly',
|
||||||
|
window: 'readonly',
|
||||||
|
document: 'readonly',
|
||||||
|
localStorage: 'readonly',
|
||||||
|
setTimeout: 'readonly',
|
||||||
|
clearTimeout: 'readonly',
|
||||||
|
navigator: 'readonly',
|
||||||
|
__FRONTEND_TECH_STACK__: 'readonly',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['*.config.js'],
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
process: 'readonly',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ignores: ['build/', '.svelte-kit/', 'dist/', 'node_modules/'],
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"extends": "./.svelte-kit/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"moduleResolution": "bundler"
|
||||||
|
}
|
||||||
|
}
|
||||||
+3424
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "collabtable-server-webui",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite dev",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"format:check": "prettier --check ."
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "latest",
|
||||||
|
"@sveltejs/adapter-static": "latest",
|
||||||
|
"@sveltejs/kit": "latest",
|
||||||
|
"@sveltejs/vite-plugin-svelte": "latest",
|
||||||
|
"@tailwindcss/vite": "latest",
|
||||||
|
"eslint": "latest",
|
||||||
|
"eslint-config-prettier": "latest",
|
||||||
|
"eslint-plugin-svelte": "latest",
|
||||||
|
"prettier": "latest",
|
||||||
|
"prettier-plugin-svelte": "latest",
|
||||||
|
"svelte": "latest",
|
||||||
|
"svelte-check": "latest",
|
||||||
|
"tailwindcss": "latest",
|
||||||
|
"tw-animate-css": "latest",
|
||||||
|
"vite": "latest"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@lucide/svelte": "latest",
|
||||||
|
"@tanstack/svelte-query": "latest",
|
||||||
|
"bits-ui": "latest",
|
||||||
|
"class-variance-authority": "latest",
|
||||||
|
"clsx": "latest",
|
||||||
|
"tailwind-merge": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
@import 'tailwindcss';
|
||||||
|
@import 'tw-animate-css';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Semantic color tokens, one block per theme. Components should only ever
|
||||||
|
* use the Tailwind utilities mapped below (bg-bg, text-fg, bg-surface, etc.),
|
||||||
|
* never the raw values, so switching theme/data-attribute is all it takes.
|
||||||
|
*/
|
||||||
|
:root,
|
||||||
|
[data-theme='dark'] {
|
||||||
|
--color-bg: #0d1117;
|
||||||
|
--color-surface: #161b22;
|
||||||
|
--color-surface-hover: #1c2333;
|
||||||
|
--color-border: #30363d;
|
||||||
|
--color-fg: #e6edf3;
|
||||||
|
--color-muted-fg: #8b949e;
|
||||||
|
--color-primary: #3b82f6;
|
||||||
|
--color-primary-fg: #04122e;
|
||||||
|
--color-secondary: #60a5fa;
|
||||||
|
--color-secondary-fg: #04122e;
|
||||||
|
--color-accent: #3b82f6;
|
||||||
|
--color-accent-fg: #04122e;
|
||||||
|
--color-danger: #ef4444;
|
||||||
|
--color-danger-fg: #ffffff;
|
||||||
|
--color-success: #22c55e;
|
||||||
|
--color-success-fg: #04210f;
|
||||||
|
--color-warning: #f59e0b;
|
||||||
|
--color-warning-fg: #2a1a00;
|
||||||
|
--color-ring: #60a5fa;
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme='light'] {
|
||||||
|
--color-bg: #f6f8fa;
|
||||||
|
--color-surface: #ffffff;
|
||||||
|
--color-surface-hover: #eaeef2;
|
||||||
|
--color-border: #d0d7de;
|
||||||
|
--color-fg: #1f2328;
|
||||||
|
--color-muted-fg: #59636e;
|
||||||
|
--color-primary: #2563eb;
|
||||||
|
--color-primary-fg: #ffffff;
|
||||||
|
--color-secondary: #1d4ed8;
|
||||||
|
--color-secondary-fg: #ffffff;
|
||||||
|
--color-accent: #2563eb;
|
||||||
|
--color-accent-fg: #ffffff;
|
||||||
|
--color-danger: #dc2626;
|
||||||
|
--color-danger-fg: #ffffff;
|
||||||
|
--color-success: #16a34a;
|
||||||
|
--color-success-fg: #ffffff;
|
||||||
|
--color-warning: #b45309;
|
||||||
|
--color-warning-fg: #ffffff;
|
||||||
|
--color-ring: #2563eb;
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-bg: var(--color-bg);
|
||||||
|
--color-surface: var(--color-surface);
|
||||||
|
--color-surface-hover: var(--color-surface-hover);
|
||||||
|
--color-border: var(--color-border);
|
||||||
|
--color-fg: var(--color-fg);
|
||||||
|
--color-muted-fg: var(--color-muted-fg);
|
||||||
|
--color-primary: var(--color-primary);
|
||||||
|
--color-primary-fg: var(--color-primary-fg);
|
||||||
|
--color-secondary: var(--color-secondary);
|
||||||
|
--color-secondary-fg: var(--color-secondary-fg);
|
||||||
|
--color-accent: var(--color-accent);
|
||||||
|
--color-accent-fg: var(--color-accent-fg);
|
||||||
|
--color-danger: var(--color-danger);
|
||||||
|
--color-danger-fg: var(--color-danger-fg);
|
||||||
|
--color-success: var(--color-success);
|
||||||
|
--color-success-fg: var(--color-success-fg);
|
||||||
|
--color-warning: var(--color-warning);
|
||||||
|
--color-warning-fg: var(--color-warning-fg);
|
||||||
|
--color-ring: var(--color-ring);
|
||||||
|
--font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
color: var(--color-fg);
|
||||||
|
font-family: var(--font-sans);
|
||||||
|
transition:
|
||||||
|
background-color 150ms ease,
|
||||||
|
color 150ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
::selection {
|
||||||
|
background-color: var(--color-primary);
|
||||||
|
color: var(--color-primary-fg);
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="%sveltekit.assets%/favicon.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>CollabTable Server</title>
|
||||||
|
%sveltekit.head%
|
||||||
|
</head>
|
||||||
|
<body data-sveltekit-preload-data="hover" class="h-full">
|
||||||
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
declare const __FRONTEND_TECH_STACK__: { name: string; version: string }[];
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
async function getJson(url) {
|
||||||
|
const res = await fetch(url, { cache: 'no-store' });
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchOverview() {
|
||||||
|
return getJson('/web/data');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchTechStack() {
|
||||||
|
return getJson('/web/info');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchHealth() {
|
||||||
|
const res = await fetch('/health');
|
||||||
|
return { up: res.ok };
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<script module>
|
||||||
|
import { Info, LayoutDashboard } from '@lucide/svelte';
|
||||||
|
|
||||||
|
const navItems = [
|
||||||
|
{ to: '/', end: true, icon: LayoutDashboard, label: 'Overview' },
|
||||||
|
{ to: '/about', icon: Info, label: 'About' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function isActive(pathname, target, end) {
|
||||||
|
if (end) return pathname === target;
|
||||||
|
return pathname === target || pathname.startsWith(`${target}/`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { page } from '$app/state';
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
import { Menu, Table2, Settings, X } from '@lucide/svelte';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
|
import HealthWidget from '$lib/features/health/HealthWidget.svelte';
|
||||||
|
import SettingsDialog from '$lib/features/layout/SettingsDialog.svelte';
|
||||||
|
|
||||||
|
const navLinkClass = (active) =>
|
||||||
|
cn(
|
||||||
|
'inline-flex shrink-0 items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-colors hover:bg-surface-hover',
|
||||||
|
active && 'bg-surface-hover text-primary',
|
||||||
|
);
|
||||||
|
|
||||||
|
let navOpen = $state(false);
|
||||||
|
let settingsOpen = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<header class="sticky top-0 z-40 flex h-14 items-center gap-2 border-b border-border bg-bg px-3">
|
||||||
|
<a href={resolve('/')} class="flex shrink-0 items-center gap-2 pr-1 font-semibold text-fg">
|
||||||
|
<Table2 class="size-5 text-primary" />
|
||||||
|
<span>CollabTable</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
class="ml-auto min-[640px]:hidden"
|
||||||
|
aria-label="Toggle navigation"
|
||||||
|
aria-expanded={navOpen}
|
||||||
|
aria-controls="primary-navigation"
|
||||||
|
onclick={() => (navOpen = !navOpen)}
|
||||||
|
>
|
||||||
|
{#if navOpen}
|
||||||
|
<X class="size-5" />
|
||||||
|
{:else}
|
||||||
|
<Menu class="size-5" />
|
||||||
|
{/if}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<nav
|
||||||
|
id="primary-navigation"
|
||||||
|
class={cn(
|
||||||
|
'min-[640px]:flex min-[640px]:items-center min-[640px]:gap-1',
|
||||||
|
'absolute left-0 right-0 top-full flex flex-col gap-1 border-b border-border bg-bg p-2 shadow-lg min-[640px]:static min-[640px]:flex-row min-[640px]:border-b-0 min-[640px]:bg-transparent min-[640px]:p-0 min-[640px]:shadow-none',
|
||||||
|
!navOpen && 'hidden min-[640px]:flex',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{#each navItems as item (item.to)}
|
||||||
|
{@const href = resolve(item.to)}
|
||||||
|
<a
|
||||||
|
{href}
|
||||||
|
class={cn(
|
||||||
|
navLinkClass(isActive(page.url.pathname, href, item.end)),
|
||||||
|
'w-full justify-start py-2 min-[640px]:w-auto min-[640px]:py-1.5',
|
||||||
|
)}
|
||||||
|
onclick={() => (navOpen = false)}
|
||||||
|
>
|
||||||
|
<item.icon class="size-4" />
|
||||||
|
{item.label}
|
||||||
|
</a>
|
||||||
|
{/each}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="flex shrink-0 items-center gap-1 min-[640px]:ml-auto">
|
||||||
|
<HealthWidget />
|
||||||
|
<Button variant="ghost" size="icon" aria-label="Settings" onclick={() => (settingsOpen = true)}>
|
||||||
|
<Settings class="size-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<SettingsDialog bind:open={settingsOpen} />
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script>
|
||||||
|
import { Table2 } from '@lucide/svelte';
|
||||||
|
import { listFieldsFor, listItemsFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||||
|
|
||||||
|
let { list, fields, items, onClick } = $props();
|
||||||
|
|
||||||
|
const listFields = $derived(listFieldsFor(fields, list.id));
|
||||||
|
const listItems = $derived(listItemsFor(items, list.id));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="w-full rounded-lg border border-border bg-surface p-3 text-left transition-colors hover:bg-surface-hover"
|
||||||
|
onclick={() => onClick(list)}
|
||||||
|
>
|
||||||
|
<div class="mb-2 flex items-center gap-2">
|
||||||
|
<Table2 class="size-4 text-primary" />
|
||||||
|
<span class="flex-1 truncate text-sm font-medium text-fg" title={list.name}>{list.name}</span>
|
||||||
|
{#if list.isDeleted}
|
||||||
|
<span class="rounded-full bg-danger/15 px-2 py-0.5 text-[11px] font-medium text-danger">Deleted</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-3 text-xs text-muted-fg">
|
||||||
|
<span>{listFields.length} {listFields.length === 1 ? 'field' : 'fields'}</span>
|
||||||
|
<span>{listItems.length} {listItems.length === 1 ? 'item' : 'items'}</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-1.5 text-xs text-muted-fg">
|
||||||
|
Updated {fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { listFieldsFor, listItemsFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||||
|
|
||||||
|
let { list, fields, items, onClick } = $props();
|
||||||
|
|
||||||
|
const listFields = $derived(listFieldsFor(fields, list.id));
|
||||||
|
const listItems = $derived(listItemsFor(items, list.id));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<tr class="cursor-pointer border-t border-border hover:bg-surface-hover" onclick={() => onClick(list)}>
|
||||||
|
<td class="py-2">
|
||||||
|
<span class="font-medium text-fg">{list.name}</span>
|
||||||
|
{#if list.isDeleted}
|
||||||
|
<span class="ml-2 rounded-full bg-danger/15 px-2 py-0.5 text-[11px] font-medium text-danger">Deleted</span>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
<td class="py-2 text-muted-fg">{listFields.length}</td>
|
||||||
|
<td class="py-2 text-muted-fg">{listItems.length}</td>
|
||||||
|
<td class="py-2 text-muted-fg">{fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
import ListCard from './ListCard.svelte';
|
||||||
|
|
||||||
|
let { lists, fields, items, onSelect } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if lists.length === 0}
|
||||||
|
<div class="flex flex-col items-center gap-2 py-16 text-center">
|
||||||
|
<div class="text-4xl">🔍</div>
|
||||||
|
<div class="text-fg">No lists match your filters</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||||
|
{#each lists as list (list.id)}
|
||||||
|
<ListCard {list} {fields} {items} onClick={onSelect} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<script>
|
||||||
|
import ListRow from './ListRow.svelte';
|
||||||
|
|
||||||
|
let { lists, fields, items, onSelect } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<table class="w-full text-left text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-muted-fg">
|
||||||
|
<th class="py-2 font-medium">Name</th>
|
||||||
|
<th class="py-2 font-medium">Fields</th>
|
||||||
|
<th class="py-2 font-medium">Items</th>
|
||||||
|
<th class="py-2 font-medium">Updated</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each lists as list (list.id)}
|
||||||
|
<ListRow {list} {fields} {items} onClick={onSelect} />
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{#if lists.length === 0}
|
||||||
|
<div class="flex flex-col items-center gap-2 py-16 text-center">
|
||||||
|
<div class="text-4xl">🔍</div>
|
||||||
|
<div class="text-fg">No lists match your filters</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<script module>
|
||||||
|
import { cva } from 'class-variance-authority';
|
||||||
|
|
||||||
|
export const buttonVariants = cva(
|
||||||
|
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0',
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: 'bg-primary text-primary-fg hover:opacity-90',
|
||||||
|
secondary: 'bg-surface text-fg hover:bg-surface-hover border border-border',
|
||||||
|
ghost: 'hover:bg-surface-hover text-fg',
|
||||||
|
outline: 'border border-border bg-transparent hover:bg-surface-hover text-fg',
|
||||||
|
danger: 'bg-danger text-danger-fg hover:opacity-90',
|
||||||
|
link: 'text-primary underline-offset-4 hover:underline',
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: 'h-9 px-4 py-2',
|
||||||
|
sm: 'h-8 rounded-md px-3 text-xs',
|
||||||
|
lg: 'h-10 rounded-md px-6',
|
||||||
|
icon: 'h-9 w-9',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: 'default',
|
||||||
|
size: 'default',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { class: className, variant, size, type = 'button', ref = $bindable(null), children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button bind:this={ref} {type} class={cn(buttonVariants({ variant, size }), className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<script>
|
||||||
|
import { Dialog } from 'bits-ui';
|
||||||
|
import { X } from '@lucide/svelte';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog.Portal>
|
||||||
|
<Dialog.Overlay class="fixed inset-0 z-50 bg-black/50 animate-in fade-in-0" />
|
||||||
|
<Dialog.Content
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
'fixed left-1/2 top-1/2 z-50 max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-lg border border-border bg-bg p-6 shadow-lg animate-in fade-in-0 zoom-in-95',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
<Dialog.Close
|
||||||
|
class="absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none"
|
||||||
|
>
|
||||||
|
<X class="size-4" />
|
||||||
|
<span class="sr-only">Close</span>
|
||||||
|
</Dialog.Close>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Portal>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { class: className, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={cn('mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { class: className, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={cn('mb-4 flex flex-col gap-1', className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Dialog as DialogPrimitive } from 'bits-ui';
|
||||||
|
|
||||||
|
export const Dialog = DialogPrimitive.Root;
|
||||||
|
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||||
|
export const DialogClose = DialogPrimitive.Close;
|
||||||
|
|
||||||
|
export { default as DialogContent } from './content.svelte';
|
||||||
|
export { default as DialogHeader } from './header.svelte';
|
||||||
|
export { default as DialogTitle } from './title.svelte';
|
||||||
|
export { default as DialogFooter } from './footer.svelte';
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import { Dialog } from 'bits-ui';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog.Title bind:ref class={cn('text-lg font-semibold', className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</Dialog.Title>
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<script>
|
||||||
|
import { ChevronFirst, ChevronLast, ChevronLeft, ChevronRight } from '@lucide/svelte';
|
||||||
|
import Button from './button.svelte';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './select';
|
||||||
|
import { SimpleTooltip } from './tooltip';
|
||||||
|
|
||||||
|
let { page, pageSize, pageSizes = [12, 24, 48, 96], pageLength = 0, totalLength = 0, onPaging } = $props();
|
||||||
|
|
||||||
|
const hasPreviousPage = $derived(page > 1);
|
||||||
|
const firstItemIndex = $derived((page - 1) * pageSize + 1);
|
||||||
|
const lastItemIndex = $derived((page - 1) * pageSize + pageLength);
|
||||||
|
const hasNextPage = $derived(page * pageSize < totalLength);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center justify-end gap-4 px-2 py-3 text-sm">
|
||||||
|
<Select
|
||||||
|
type="single"
|
||||||
|
value={String(pageSize)}
|
||||||
|
onValueChange={(value) => onPaging({ page: 1, pageSize: Number(value) })}
|
||||||
|
>
|
||||||
|
<SelectTrigger class="w-24">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{#each pageSizes as size (size)}
|
||||||
|
<SelectItem value={String(size)} label={String(size)}>{size}</SelectItem>
|
||||||
|
{/each}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<p class="text-muted-fg">
|
||||||
|
{firstItemIndex.toLocaleString()}–{lastItemIndex.toLocaleString()} of {totalLength.toLocaleString()}
|
||||||
|
</p>
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<SimpleTooltip label="First page">
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
disabled={!hasPreviousPage}
|
||||||
|
onclick={() => onPaging({ page: 1, pageSize })}
|
||||||
|
>
|
||||||
|
<ChevronFirst class="size-4" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</SimpleTooltip>
|
||||||
|
<SimpleTooltip label="Previous page">
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
disabled={!hasPreviousPage}
|
||||||
|
onclick={() => onPaging({ page: page - 1, pageSize })}
|
||||||
|
>
|
||||||
|
<ChevronLeft class="size-4" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</SimpleTooltip>
|
||||||
|
<SimpleTooltip label="Next page">
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
disabled={!hasNextPage}
|
||||||
|
onclick={() => onPaging({ page: page + 1, pageSize })}
|
||||||
|
>
|
||||||
|
<ChevronRight class="size-4" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</SimpleTooltip>
|
||||||
|
<SimpleTooltip label="Last page">
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
disabled={!hasNextPage}
|
||||||
|
onclick={() => onPaging({ page: Math.max(1, Math.ceil(totalLength / pageSize)), pageSize })}
|
||||||
|
>
|
||||||
|
<ChevronLast class="size-4" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</SimpleTooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { Select } from 'bits-ui';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, sideOffset = 4, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Select.Portal>
|
||||||
|
<Select.Content
|
||||||
|
bind:ref
|
||||||
|
{sideOffset}
|
||||||
|
class={cn(
|
||||||
|
'z-50 max-h-72 w-[var(--bits-select-anchor-width)] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</Select.Content>
|
||||||
|
</Select.Portal>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Select as SelectPrimitive } from 'bits-ui';
|
||||||
|
|
||||||
|
export const Select = SelectPrimitive.Root;
|
||||||
|
export const SelectValue = SelectPrimitive.Value;
|
||||||
|
|
||||||
|
export { default as SelectTrigger } from './trigger.svelte';
|
||||||
|
export { default as SelectContent } from './content.svelte';
|
||||||
|
export { default as SelectItem } from './item.svelte';
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<script>
|
||||||
|
import { Select } from 'bits-ui';
|
||||||
|
import { Check } from '@lucide/svelte';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, value, label, children: itemLabel, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Select.Item
|
||||||
|
bind:ref
|
||||||
|
{value}
|
||||||
|
{label}
|
||||||
|
class={cn(
|
||||||
|
'flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-highlighted:bg-surface-hover',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{#snippet children({ selected })}
|
||||||
|
{@render itemLabel?.()}
|
||||||
|
{#if selected}
|
||||||
|
<Check class="ml-auto size-4" />
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</Select.Item>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<script>
|
||||||
|
import { Select } from 'bits-ui';
|
||||||
|
import { ChevronDown } from '@lucide/svelte';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Select.Trigger
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
'flex h-9 items-center justify-between gap-2 rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
<ChevronDown class="size-4 opacity-60" />
|
||||||
|
</Select.Trigger>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { Tooltip } from 'bits-ui';
|
||||||
|
import { cn } from '$lib/utils/cn.js';
|
||||||
|
|
||||||
|
let { ref = $bindable(null), class: className, sideOffset = 6, children, ...restProps } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Tooltip.Portal>
|
||||||
|
<Tooltip.Content
|
||||||
|
bind:ref
|
||||||
|
{sideOffset}
|
||||||
|
class={cn(
|
||||||
|
'z-50 overflow-hidden rounded-md border border-border bg-surface px-3 py-1.5 text-xs text-fg shadow-md animate-in fade-in-0 zoom-in-95',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</Tooltip.Content>
|
||||||
|
</Tooltip.Portal>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { Tooltip as TooltipPrimitive } from 'bits-ui';
|
||||||
|
|
||||||
|
export const TooltipProvider = TooltipPrimitive.Provider;
|
||||||
|
|
||||||
|
export { default as SimpleTooltip } from './simple-tooltip.svelte';
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import { Tooltip } from 'bits-ui';
|
||||||
|
import TooltipContent from './content.svelte';
|
||||||
|
|
||||||
|
let { label, children } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Tooltip.Root>
|
||||||
|
<Tooltip.Trigger>
|
||||||
|
{#snippet child({ props })}
|
||||||
|
{@render children({ props })}
|
||||||
|
{/snippet}
|
||||||
|
</Tooltip.Trigger>
|
||||||
|
<TooltipContent>{label}</TooltipContent>
|
||||||
|
</Tooltip.Root>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<script>
|
||||||
|
import { createQuery } from '@tanstack/svelte-query';
|
||||||
|
import { fetchTechStack } from '$lib/api.js';
|
||||||
|
|
||||||
|
const FRONTEND_TECH_STACK = __FRONTEND_TECH_STACK__;
|
||||||
|
|
||||||
|
const techStackQuery = createQuery(() => ({
|
||||||
|
queryKey: ['TechStack'],
|
||||||
|
queryFn: fetchTechStack,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const techStack = $derived(techStackQuery.data);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#snippet infoRow(label, value)}
|
||||||
|
<div class="flex items-center justify-between gap-2 py-1 text-sm">
|
||||||
|
<span class="text-muted-fg">{label}</span>
|
||||||
|
<span class="font-mono text-xs text-fg">{value}</span>
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
<div class="rounded-lg border border-border bg-surface p-4">
|
||||||
|
<h3 class="mb-2 text-sm font-medium text-fg">Tech stack</h3>
|
||||||
|
|
||||||
|
{#if techStackQuery.isLoading}
|
||||||
|
<p class="text-sm text-muted-fg">Loading tech stack…</p>
|
||||||
|
{/if}
|
||||||
|
{#if techStackQuery.error}
|
||||||
|
<p class="text-sm text-danger">{techStackQuery.error.message}</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if techStack}
|
||||||
|
<div class="mt-3 grid gap-6 sm:grid-cols-2">
|
||||||
|
<div>
|
||||||
|
<h4 class="mb-1 text-xs font-medium uppercase text-muted-fg">Backend</h4>
|
||||||
|
{#each techStack.stack as entry (entry.label)}
|
||||||
|
{@render infoRow(entry.label, entry.value)}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 class="mb-1 text-xs font-medium uppercase text-muted-fg">Frontend</h4>
|
||||||
|
{#each FRONTEND_TECH_STACK as dep (dep.name)}
|
||||||
|
{@render infoRow(dep.name, dep.version)}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<script>
|
||||||
|
import { AlertTriangle, CheckCircle2, HelpCircle } from '@lucide/svelte';
|
||||||
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
DialogClose,
|
||||||
|
} from '$lib/components/ui/dialog';
|
||||||
|
import { SimpleTooltip } from '$lib/components/ui/tooltip';
|
||||||
|
import { createHealth } from './health.svelte.js';
|
||||||
|
|
||||||
|
const icons = { up: CheckCircle2, down: AlertTriangle, unknown: HelpCircle };
|
||||||
|
const statusColor = { up: 'text-success', down: 'text-danger', unknown: 'text-muted-fg' };
|
||||||
|
const statusLabel = { up: 'up', down: 'unreachable', unknown: 'checking…' };
|
||||||
|
|
||||||
|
const health = createHealth();
|
||||||
|
let open = $state(false);
|
||||||
|
|
||||||
|
const Icon = $derived(icons[health.status]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog bind:open>
|
||||||
|
<SimpleTooltip label={`CollabTable server is ${statusLabel[health.status]}`}>
|
||||||
|
{#snippet children({ props })}
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onclick={() => (open = true)}
|
||||||
|
class={statusColor[health.status]}
|
||||||
|
aria-label="Status"
|
||||||
|
>
|
||||||
|
<Icon class="size-5" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</SimpleTooltip>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Status: CollabTable server is {statusLabel[health.status]}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="flex items-center gap-2 text-sm">
|
||||||
|
<Icon class={`size-4 ${statusColor[health.status]}`} />
|
||||||
|
<span class="text-muted-fg">GET /health</span>
|
||||||
|
<span class={statusColor[health.status]}>{statusLabel[health.status]}</span>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose>
|
||||||
|
{#snippet child({ props })}
|
||||||
|
<Button variant="secondary" {...props}>Dismiss</Button>
|
||||||
|
{/snippet}
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { createQuery } from '@tanstack/svelte-query';
|
||||||
|
import { fetchHealth } from '$lib/api.js';
|
||||||
|
|
||||||
|
const pollIntervalMs = 10_000;
|
||||||
|
|
||||||
|
export function createHealth() {
|
||||||
|
const query = createQuery(() => ({
|
||||||
|
queryKey: ['Health'],
|
||||||
|
queryFn: fetchHealth,
|
||||||
|
refetchInterval: pollIntervalMs,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const status = $derived.by(() => {
|
||||||
|
if (query.error) return 'down';
|
||||||
|
if (!query.data) return 'unknown';
|
||||||
|
return query.data.up ? 'up' : 'down';
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
get status() {
|
||||||
|
return status;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import { Tooltip } from 'bits-ui';
|
||||||
|
import Header from '$lib/components/Header.svelte';
|
||||||
|
|
||||||
|
let { children } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Tooltip.Provider delayDuration={300}>
|
||||||
|
<div class="flex min-h-screen flex-col">
|
||||||
|
<Header />
|
||||||
|
<main class="flex min-w-0 flex-1 flex-col">
|
||||||
|
{@render children?.()}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</Tooltip.Provider>
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<script>
|
||||||
|
import { Moon, Sun, SunMoon } from '@lucide/svelte';
|
||||||
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '$lib/components/ui/dialog';
|
||||||
|
import { themeState } from '$lib/theme.svelte.js';
|
||||||
|
|
||||||
|
let { open = $bindable(false) } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog bind:open>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Settings</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div>
|
||||||
|
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||||
|
<div class="flex w-full rounded-md border border-border p-1">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||||
|
size="sm"
|
||||||
|
class="flex-1 gap-1.5"
|
||||||
|
onclick={() => themeState.setMode('light')}
|
||||||
|
>
|
||||||
|
<Sun class="size-4" />
|
||||||
|
Light
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||||
|
size="sm"
|
||||||
|
class="flex-1 gap-1.5"
|
||||||
|
onclick={() => themeState.setMode('dark')}
|
||||||
|
>
|
||||||
|
<Moon class="size-4" />
|
||||||
|
Dark
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||||
|
size="sm"
|
||||||
|
class="flex-1 gap-1.5"
|
||||||
|
onclick={() => themeState.setMode('system')}
|
||||||
|
>
|
||||||
|
<SunMoon class="size-4" />
|
||||||
|
System
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export function listFieldsFor(fields, listId) {
|
||||||
|
return fields.filter((f) => f.listId === listId && !f.isDeleted).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listItemsFor(items, listId) {
|
||||||
|
return items.filter((i) => i.listId === listId && !i.isDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function itemValuesFor(values, itemId) {
|
||||||
|
return values.filter((v) => v.itemId === itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function valueFor(values, itemId, fieldId) {
|
||||||
|
return values.find((v) => v.itemId === itemId && v.fieldId === fieldId)?.value ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fmtDate(v) {
|
||||||
|
if (v === null || v === undefined) return '—';
|
||||||
|
const d = new Date(v);
|
||||||
|
return Number.isNaN(d.getTime()) ? '—' : d.toLocaleString();
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { createQuery } from '@tanstack/svelte-query';
|
||||||
|
import { fetchOverview } from '$lib/api.js';
|
||||||
|
|
||||||
|
const pollIntervalMs = 5_000;
|
||||||
|
|
||||||
|
export function createOverviewData() {
|
||||||
|
const query = createQuery(() => ({
|
||||||
|
queryKey: ['Overview'],
|
||||||
|
queryFn: fetchOverview,
|
||||||
|
refetchInterval: pollIntervalMs,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const lists = $derived(query.data?.lists ?? []);
|
||||||
|
const fields = $derived(query.data?.fields ?? []);
|
||||||
|
const items = $derived(query.data?.items ?? []);
|
||||||
|
const values = $derived(query.data?.values ?? []);
|
||||||
|
const stats = $derived(query.data?.stats ?? { lists: 0, fields: 0, items: 0, values: 0 });
|
||||||
|
|
||||||
|
return {
|
||||||
|
get lists() {
|
||||||
|
return lists;
|
||||||
|
},
|
||||||
|
get fields() {
|
||||||
|
return fields;
|
||||||
|
},
|
||||||
|
get items() {
|
||||||
|
return items;
|
||||||
|
},
|
||||||
|
get values() {
|
||||||
|
return values;
|
||||||
|
},
|
||||||
|
get stats() {
|
||||||
|
return stats;
|
||||||
|
},
|
||||||
|
get isLoading() {
|
||||||
|
return query.isLoading;
|
||||||
|
},
|
||||||
|
get error() {
|
||||||
|
return query.error;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const STORAGE_KEY = 'collabtable-dashboard-view-mode';
|
||||||
|
|
||||||
|
function readStoredViewMode() {
|
||||||
|
if (typeof window === 'undefined') return 'grid';
|
||||||
|
return window.localStorage.getItem(STORAGE_KEY) === 'list' ? 'list' : 'grid';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createDashboardViewMode() {
|
||||||
|
let mode = $state(readStoredViewMode());
|
||||||
|
|
||||||
|
function setMode(value) {
|
||||||
|
window.localStorage.setItem(STORAGE_KEY, value);
|
||||||
|
mode = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
get mode() {
|
||||||
|
return mode;
|
||||||
|
},
|
||||||
|
setMode,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { QueryClient } from '@tanstack/svelte-query';
|
||||||
|
|
||||||
|
export const queryClient = new QueryClient({
|
||||||
|
defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } },
|
||||||
|
});
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export const searchState = $state({ query: '' });
|
||||||
|
|
||||||
|
export function filterListsBySearch(lists, query) {
|
||||||
|
if (!query || !query.trim()) return lists;
|
||||||
|
const needle = query.trim().toLowerCase();
|
||||||
|
return lists.filter((l) => l.name.toLowerCase().includes(needle));
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { browser } from '$app/environment';
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'collabtable-theme';
|
||||||
|
|
||||||
|
function prefersDarkMediaQuery() {
|
||||||
|
return browser && window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadInitialMode() {
|
||||||
|
if (!browser) return 'system';
|
||||||
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
|
return stored === 'light' || stored === 'dark' || stored === 'system' ? stored : 'system';
|
||||||
|
}
|
||||||
|
|
||||||
|
let mode = $state(loadInitialMode());
|
||||||
|
let systemPrefersDark = $state(prefersDarkMediaQuery()?.matches ?? false);
|
||||||
|
|
||||||
|
export const themeState = {
|
||||||
|
get mode() {
|
||||||
|
return mode;
|
||||||
|
},
|
||||||
|
get isDark() {
|
||||||
|
return mode === 'system' ? systemPrefersDark : mode === 'dark';
|
||||||
|
},
|
||||||
|
get value() {
|
||||||
|
return themeState.isDark ? 'dark' : 'light';
|
||||||
|
},
|
||||||
|
setMode(next) {
|
||||||
|
mode = next;
|
||||||
|
if (browser) localStorage.setItem(STORAGE_KEY, next);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (browser) {
|
||||||
|
$effect.root(() => {
|
||||||
|
$effect(() => {
|
||||||
|
document.documentElement.setAttribute('data-theme', themeState.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const mql = prefersDarkMediaQuery();
|
||||||
|
if (mql) {
|
||||||
|
mql.addEventListener('change', () => {
|
||||||
|
systemPrefersDark = mql.matches;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { clsx } from 'clsx';
|
||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
|
export function cn(...inputs) {
|
||||||
|
return twMerge(clsx(inputs));
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// Fully client-rendered SPA — the Express server only ever serves the static build plus
|
||||||
|
// its JSON/API routes, so there is no server to render against.
|
||||||
|
export const ssr = false;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import '../app.css';
|
||||||
|
import '$lib/theme.svelte.js';
|
||||||
|
import { QueryClientProvider } from '@tanstack/svelte-query';
|
||||||
|
import { queryClient } from '$lib/query/queryClient.js';
|
||||||
|
import AppShell from '$lib/features/layout/AppShell.svelte';
|
||||||
|
|
||||||
|
let { children } = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<AppShell>
|
||||||
|
{@render children()}
|
||||||
|
</AppShell>
|
||||||
|
</QueryClientProvider>
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
<script>
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
import { ArrowDown, ArrowUp, LayoutGrid, List, Search, X } from '@lucide/svelte';
|
||||||
|
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
||||||
|
import { searchState, filterListsBySearch } from '$lib/search.svelte.js';
|
||||||
|
import { createDashboardViewMode } from '$lib/preferences/viewMode.svelte.js';
|
||||||
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
|
||||||
|
import Paginator from '$lib/components/ui/paginator.svelte';
|
||||||
|
import ListsGrid from '$lib/components/lists/ListsGrid.svelte';
|
||||||
|
import ListsTable from '$lib/components/lists/ListsTable.svelte';
|
||||||
|
|
||||||
|
const SORT_FIELDS = [
|
||||||
|
{ field: 'name', label: 'Name' },
|
||||||
|
{ field: 'created', label: 'Created' },
|
||||||
|
{ field: 'updated', label: 'Updated' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const overview = createOverviewData();
|
||||||
|
const viewMode = createDashboardViewMode();
|
||||||
|
|
||||||
|
let sortField = $state('name');
|
||||||
|
let sortDir = $state('asc');
|
||||||
|
let page = $state(1);
|
||||||
|
let pageSize = $state(24);
|
||||||
|
|
||||||
|
function sortLists(lists, field, dir) {
|
||||||
|
const sorted = [...lists].sort((a, b) => {
|
||||||
|
if (field === 'name') return a.name.localeCompare(b.name);
|
||||||
|
if (field === 'created') return (a.createdAt ?? 0) - (b.createdAt ?? 0);
|
||||||
|
return (a.effectiveUpdatedAt ?? a.updatedAt ?? 0) - (b.effectiveUpdatedAt ?? b.updatedAt ?? 0);
|
||||||
|
});
|
||||||
|
return dir === 'desc' ? sorted.reverse() : sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
let searched = $derived(filterListsBySearch(overview.lists, searchState.query));
|
||||||
|
let sorted = $derived(sortLists(searched, sortField, sortDir));
|
||||||
|
let pageItems = $derived(sorted.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize));
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
void searchState.query;
|
||||||
|
void sortField;
|
||||||
|
void sortDir;
|
||||||
|
page = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
function goToList(list) {
|
||||||
|
void goto(resolve('/lists/[id]', { id: list.id }));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex-1 p-4">
|
||||||
|
<div class="mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4">
|
||||||
|
<div class="rounded-lg border border-border bg-surface p-3">
|
||||||
|
<div class="text-xs text-muted-fg">Lists</div>
|
||||||
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.lists}</div>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg border border-border bg-surface p-3">
|
||||||
|
<div class="text-xs text-muted-fg">Fields</div>
|
||||||
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.fields}</div>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg border border-border bg-surface p-3">
|
||||||
|
<div class="text-xs text-muted-fg">Items</div>
|
||||||
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.items}</div>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg border border-border bg-surface p-3">
|
||||||
|
<div class="text-xs text-muted-fg">Values</div>
|
||||||
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.values}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if overview.isLoading}
|
||||||
|
<div class="flex items-center gap-3 py-10 text-sm text-muted-fg">
|
||||||
|
<span class="inline-block h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"></span>
|
||||||
|
Loading lists…
|
||||||
|
</div>
|
||||||
|
{:else if overview.error}
|
||||||
|
<p class="text-sm text-danger">{overview.error.message}</p>
|
||||||
|
{:else}
|
||||||
|
<div class="mb-3 flex flex-wrap items-center gap-2">
|
||||||
|
<div class="relative min-w-0 flex-1 basis-full sm:basis-auto">
|
||||||
|
<Search class="pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-fg" />
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
bind:value={searchState.query}
|
||||||
|
placeholder="Search lists…"
|
||||||
|
autocapitalize="none"
|
||||||
|
class="h-9 w-full rounded-md border border-border bg-bg pl-8 pr-8 text-sm text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||||
|
/>
|
||||||
|
{#if searchState.query}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick={() => (searchState.query = '')}
|
||||||
|
title="Clear search"
|
||||||
|
class="absolute right-2 top-1/2 -translate-y-1/2 text-muted-fg hover:text-fg"
|
||||||
|
>
|
||||||
|
<X class="size-4" />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Select type="single" value={sortField} onValueChange={(field) => (sortField = field)}>
|
||||||
|
<SelectTrigger class="min-w-0 flex-1 sm:w-44 sm:flex-none">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{#each SORT_FIELDS as s (s.field)}
|
||||||
|
<SelectItem value={s.field} label={s.label}>{s.label}</SelectItem>
|
||||||
|
{/each}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
aria-label="Toggle sort direction"
|
||||||
|
onclick={() => (sortDir = sortDir === 'asc' ? 'desc' : 'asc')}
|
||||||
|
>
|
||||||
|
{#if sortDir === 'desc'}
|
||||||
|
<ArrowDown class="size-4" />
|
||||||
|
{:else}
|
||||||
|
<ArrowUp class="size-4" />
|
||||||
|
{/if}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
aria-label={viewMode.mode === 'grid' ? 'Switch to list view' : 'Switch to grid view'}
|
||||||
|
onclick={() => viewMode.setMode(viewMode.mode === 'grid' ? 'list' : 'grid')}
|
||||||
|
>
|
||||||
|
{#if viewMode.mode === 'grid'}
|
||||||
|
<LayoutGrid class="size-4" />
|
||||||
|
{:else}
|
||||||
|
<List class="size-4" />
|
||||||
|
{/if}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto rounded-lg border border-border bg-bg p-3">
|
||||||
|
{#if viewMode.mode === 'list'}
|
||||||
|
<ListsTable lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
||||||
|
{:else}
|
||||||
|
<ListsGrid lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Paginator
|
||||||
|
{page}
|
||||||
|
{pageSize}
|
||||||
|
pageLength={pageItems.length}
|
||||||
|
totalLength={sorted.length}
|
||||||
|
onPaging={(e) => {
|
||||||
|
page = e.page;
|
||||||
|
pageSize = e.pageSize;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
import { Table2 } from '@lucide/svelte';
|
||||||
|
import TechStackSection from '$lib/features/about/TechStackSection.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main class="flex-1 overflow-y-auto p-5">
|
||||||
|
<div class="mx-auto max-w-2xl">
|
||||||
|
<div class="mb-4 flex items-center gap-3">
|
||||||
|
<Table2 class="size-8 text-primary" />
|
||||||
|
<div>
|
||||||
|
<h1 class="text-xl font-semibold text-fg">CollabTable</h1>
|
||||||
|
<p class="text-sm text-muted-fg">Collaborative list management server.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<TechStackSection />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export const load = ({ params }) => {
|
||||||
|
return { id: params.id };
|
||||||
|
};
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
<script>
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
import { ArrowLeft, LoaderCircle } from '@lucide/svelte';
|
||||||
|
import Button from '$lib/components/ui/button.svelte';
|
||||||
|
import Paginator from '$lib/components/ui/paginator.svelte';
|
||||||
|
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
||||||
|
import { listFieldsFor, listItemsFor, itemValuesFor, valueFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||||
|
|
||||||
|
let { data } = $props();
|
||||||
|
|
||||||
|
function goBack() {
|
||||||
|
if (typeof window !== 'undefined' && window.history.length > 1) {
|
||||||
|
window.history.back();
|
||||||
|
} else {
|
||||||
|
void goto(resolve('/'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const overview = createOverviewData();
|
||||||
|
|
||||||
|
const list = $derived(overview.lists.find((l) => l.id === data.id));
|
||||||
|
const listFields = $derived(listFieldsFor(overview.fields, data.id));
|
||||||
|
const listItems = $derived(listItemsFor(overview.items, data.id));
|
||||||
|
|
||||||
|
let page = $state(1);
|
||||||
|
let pageSize = $state(24);
|
||||||
|
const pageItems = $derived(listItems.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="p-4">
|
||||||
|
<div class="mb-4 flex min-w-0 items-center gap-3">
|
||||||
|
<Button type="button" variant="secondary" size="sm" class="shrink-0" onclick={goBack}>
|
||||||
|
<ArrowLeft class="size-4" />
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
|
{#if list}
|
||||||
|
<h1 class="min-w-0 truncate text-lg font-semibold text-fg">{list.name}</h1>
|
||||||
|
{#if list.isDeleted}
|
||||||
|
<span class="shrink-0 rounded-full bg-danger/15 px-2 py-0.5 text-[11px] font-medium text-danger">Deleted</span>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if overview.isLoading}
|
||||||
|
<div class="rounded-lg border border-border bg-bg p-4">
|
||||||
|
<div class="flex flex-col items-center gap-3 py-12 text-center text-sm text-muted-fg">
|
||||||
|
<LoaderCircle class="size-8 animate-spin text-primary" />
|
||||||
|
Loading…
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else if !list}
|
||||||
|
<div class="rounded-lg border border-border bg-bg p-4">
|
||||||
|
<p class="py-8 text-center text-sm text-muted-fg">List not found.</p>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="rounded-lg border border-border bg-bg p-4">
|
||||||
|
<div class="mb-2 text-xs text-muted-fg">
|
||||||
|
Created {fmtDate(list.createdAt)} · Updated {fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<div class="mb-1.5 text-sm font-medium text-fg">Fields ({listFields.length})</div>
|
||||||
|
{#if listFields.length === 0}
|
||||||
|
<p class="text-sm text-muted-fg">No fields</p>
|
||||||
|
{:else}
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
{#each listFields as f (f.id)}
|
||||||
|
<span class="rounded-md bg-primary/10 px-2.5 py-1 text-xs font-medium text-primary">
|
||||||
|
{f.name} ({f.fieldType})
|
||||||
|
</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-1.5 text-sm font-medium text-fg">Items ({listItems.length})</div>
|
||||||
|
{#if listItems.length === 0}
|
||||||
|
<p class="text-sm text-muted-fg">No items</p>
|
||||||
|
{:else}
|
||||||
|
<div class="overflow-x-auto rounded-lg border border-border">
|
||||||
|
<table class="min-w-max w-full text-left text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-muted-fg">
|
||||||
|
<th class="py-2 pl-3 font-medium">Item ID</th>
|
||||||
|
{#each listFields as f (f.id)}
|
||||||
|
<th class="py-2 font-medium">{f.name}</th>
|
||||||
|
{/each}
|
||||||
|
<th class="py-2 pr-3 font-medium">Updated</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each pageItems as item (item.id)}
|
||||||
|
{@const itemValues = itemValuesFor(overview.values, item.id)}
|
||||||
|
<tr class="border-t border-border">
|
||||||
|
<td class="py-2 pl-3 font-mono text-xs text-muted-fg">{item.id.slice(0, 8)}…</td>
|
||||||
|
{#each listFields as f (f.id)}
|
||||||
|
<td class="py-2 text-fg">{valueFor(itemValues, item.id, f.id) ?? '—'}</td>
|
||||||
|
{/each}
|
||||||
|
<td class="py-2 pr-3 text-muted-fg">{fmtDate(item.updatedAt)}</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<Paginator
|
||||||
|
{page}
|
||||||
|
{pageSize}
|
||||||
|
pageLength={pageItems.length}
|
||||||
|
totalLength={listItems.length}
|
||||||
|
onPaging={(e) => {
|
||||||
|
page = e.page;
|
||||||
|
pageSize = e.pageSize;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<style>
|
||||||
|
svg { stroke: #2563eb; }
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
svg { stroke: #3b82f6; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<path d="M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 394 B |
@@ -0,0 +1,14 @@
|
|||||||
|
import adapter from '@sveltejs/adapter-static';
|
||||||
|
|
||||||
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
const config = {
|
||||||
|
kit: {
|
||||||
|
// Static SPA build: the Express server serves this output and falls back to
|
||||||
|
// index.html for any path so SvelteKit's client-side router can take over.
|
||||||
|
adapter: adapter({
|
||||||
|
fallback: 'index.html',
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import tailwindcss from '@tailwindcss/vite';
|
||||||
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
// Real installed frontend dependency versions for the About page, resolved from
|
||||||
|
// node_modules (not the package.json semver range) so it can't drift from what's bundled.
|
||||||
|
const FRONTEND_TECH_STACK_PACKAGES = [
|
||||||
|
{ name: 'Svelte', pkg: 'svelte' },
|
||||||
|
{ name: 'SvelteKit', pkg: '@sveltejs/kit' },
|
||||||
|
{ name: 'TanStack Query', pkg: '@tanstack/svelte-query' },
|
||||||
|
{ name: 'Tailwind CSS', pkg: 'tailwindcss' },
|
||||||
|
{ name: 'Vite', pkg: 'vite' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function readInstalledVersion(pkg) {
|
||||||
|
try {
|
||||||
|
const pkgJsonPath = path.resolve(import.meta.dirname, 'node_modules', pkg, 'package.json');
|
||||||
|
return JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')).version ?? null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const frontendTechStack = FRONTEND_TECH_STACK_PACKAGES.flatMap(({ name, pkg }) => {
|
||||||
|
const version = readInstalledVersion(pkg);
|
||||||
|
return version ? [{ name, version }] : [];
|
||||||
|
});
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [tailwindcss(), sveltekit()],
|
||||||
|
define: {
|
||||||
|
__FRONTEND_TECH_STACK__: JSON.stringify(frontendTechStack),
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
port: 5173,
|
||||||
|
proxy: {
|
||||||
|
'/web': 'http://localhost:3000',
|
||||||
|
'/health': 'http://localhost:3000',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -126,6 +126,7 @@ CollabTable/
|
|||||||
│ ├── models/ # Data models & database logic
|
│ ├── models/ # Data models & database logic
|
||||||
│ ├── routes/ # API endpoints
|
│ ├── routes/ # API endpoints
|
||||||
│ └── index.ts # Server entry point
|
│ └── index.ts # Server entry point
|
||||||
|
├── webui/ # SvelteKit web dashboard (read-only database viewer)
|
||||||
├── data/ # SQLite database storage
|
├── data/ # SQLite database storage
|
||||||
├── Dockerfile
|
├── Dockerfile
|
||||||
├── docker-compose.yml
|
├── docker-compose.yml
|
||||||
@@ -189,6 +190,11 @@ Authorization: Bearer your_password_here
|
|||||||
### Health
|
### Health
|
||||||
- `GET /health` - Server health check
|
- `GET /health` - Server health check
|
||||||
|
|
||||||
|
### Web UI
|
||||||
|
`/`, `/about`, and `/lists/:id` serve a SvelteKit dashboard (a single-page app with client-side routing) for browsing lists/fields/items read-only. It's unauthenticated, same as before this endpoint existed.
|
||||||
|
- `GET /web/data` - JSON snapshot of all lists, fields, items, and values, used by the dashboard
|
||||||
|
- `GET /web/info` - JSON tech stack info, shown on the dashboard's About page
|
||||||
|
|
||||||
See [Server README](CollabTableServer/README.md) for detailed API documentation.
|
See [Server README](CollabTableServer/README.md) for detailed API documentation.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|||||||
Reference in new issue
Block a user