clean up
This commit is contained in:
@@ -150,7 +150,6 @@ async function getAccountId(cookie: any, headers: any): Promise<{ accountId: str
|
||||
// monitor_order - full list of monitor IDs in DOM order (every row, not just checked)
|
||||
// monitor_ids - only the *checked* IDs, also in DOM order
|
||||
// display_name[<id>] - optional per-page name override
|
||||
// display_mode[<id>] - '', 'compact', or 'expanded'
|
||||
// Bun's body parser surfaces bracket-keyed fields either as nested objects
|
||||
// (`b.display_name = { id: value }`) or as flat string keys
|
||||
// (`b['display_name[id]'] = value`) depending on parser version, so handle both.
|
||||
@@ -172,7 +171,7 @@ function pickMap(b: any, prefix: string): Record<string, string> {
|
||||
|
||||
function parseStatusPageForm(b: any): {
|
||||
groupsForApi: Array<{ name: string; position: number }>;
|
||||
monitorsForApi: Array<{ monitor_id: string; position: number; group_index: number | null; display_name: string | null; display_mode: string | null }>;
|
||||
monitorsForApi: Array<{ monitor_id: string; position: number; group_index: number | null; display_name: string | null }>;
|
||||
} {
|
||||
// Parse groups from form (ordered array of names)
|
||||
const groupNames: string[] = Array.isArray(b.group_names) ? b.group_names : (b.group_names ? [b.group_names] : []);
|
||||
@@ -184,11 +183,10 @@ function parseStatusPageForm(b: any): {
|
||||
const checked: string[] = Array.isArray(b.monitor_ids) ? b.monitor_ids : (b.monitor_ids ? [b.monitor_ids] : []);
|
||||
const checkedSet = new Set(checked);
|
||||
const displayNames = pickMap(b, "display_name");
|
||||
const displayModes = pickMap(b, "display_mode");
|
||||
const monitorGroupMap = pickMap(b, "monitor_group");
|
||||
|
||||
const seen = new Set<string>();
|
||||
const monitorsForApi: Array<{ monitor_id: string; position: number; group_index: number | null; display_name: string | null; display_mode: string | null }> = [];
|
||||
const monitorsForApi: Array<{ monitor_id: string; position: number; group_index: number | null; display_name: string | null }> = [];
|
||||
|
||||
function addMonitor(id: string) {
|
||||
if (seen.has(id)) return;
|
||||
@@ -200,7 +198,6 @@ function parseStatusPageForm(b: any): {
|
||||
position: monitorsForApi.length,
|
||||
group_index: (groupIndex !== null && groupIndex >= 0 && groupIndex < groupsForApi.length) ? groupIndex : null,
|
||||
display_name: displayNames[id] ?? null,
|
||||
display_mode: (displayModes[id] === "compact" || displayModes[id] === "expanded") ? displayModes[id]! : null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -708,7 +705,7 @@ export const dashboard = new Elysia()
|
||||
`;
|
||||
if (!page) return redirect("/dashboard/status-pages");
|
||||
const [monitors, groups, allMonitors] = await Promise.all([
|
||||
sql`SELECT monitor_id, display_name, display_mode, group_id FROM status_page_monitors WHERE status_page_id = ${params.id} ORDER BY position ASC`,
|
||||
sql`SELECT monitor_id, display_name, group_id FROM status_page_monitors WHERE status_page_id = ${params.id} ORDER BY position ASC`,
|
||||
sql`SELECT id, name, position FROM status_page_groups WHERE status_page_id = ${params.id} ORDER BY position ASC`,
|
||||
sql`SELECT id, name FROM monitors WHERE account_id = ${resolved.accountId} ORDER BY created_at DESC`,
|
||||
]);
|
||||
@@ -734,7 +731,7 @@ export const dashboard = new Elysia()
|
||||
description: b.description || null,
|
||||
theme: b.theme || "auto",
|
||||
|
||||
display_mode: b.display_mode || "expanded",
|
||||
|
||||
bar_frequency: b.bar_frequency || "daily",
|
||||
bar_count: Number(b.bar_count) || 90,
|
||||
show_response_time: !!b.show_response_time,
|
||||
@@ -767,7 +764,6 @@ export const dashboard = new Elysia()
|
||||
title: b.title,
|
||||
description: b.description || null,
|
||||
theme: b.theme || "auto",
|
||||
display_mode: b.display_mode || "expanded",
|
||||
bar_frequency: b.bar_frequency || "daily",
|
||||
bar_count: Number(b.bar_count) || 90,
|
||||
show_response_time: !!b.show_response_time,
|
||||
|
||||
@@ -293,7 +293,7 @@ Content-Type: application/json
|
||||
<tr><td>description</td><td>string?</td><td>Shown below the title (up to 2000 chars).</td></tr>
|
||||
<tr><td>theme</td><td>string?</td><td><code>auto</code>, <code>light</code>, or <code>dark</code>. Default <code>auto</code>.</td></tr>
|
||||
<tr><td>password</td><td>string?</td><td>Plain text, hashed at write time. Pass <code>null</code> to clear.</td></tr>
|
||||
<tr><td>display_mode</td><td>string?</td><td><code>compact</code> or <code>expanded</code>. Default <code>expanded</code>.</td></tr>
|
||||
|
||||
<tr><td>bar_frequency</td><td>string?</td><td><code>hourly</code> or <code>daily</code>. Default <code>daily</code>.</td></tr>
|
||||
<tr><td>bar_count</td><td>number?</td><td>How many bars to show (1-180). Default 90.</td></tr>
|
||||
<tr><td>auto_refresh_s</td><td>number?</td><td>Auto-refresh interval in seconds (10-3600). Default 60.</td></tr>
|
||||
@@ -318,7 +318,6 @@ Content-Type: application/json
|
||||
<tr><td>monitor_id</td><td>string</td><td>ID of a monitor you own.</td></tr>
|
||||
<tr><td>group_index</td><td>number?</td><td>Index into the <code>groups</code> array (0-based). Omit for ungrouped.</td></tr>
|
||||
<tr><td>display_name</td><td>string?</td><td>Override the monitor's name on this page.</td></tr>
|
||||
<tr><td>display_mode</td><td>string?</td><td><code>compact</code> or <code>expanded</code>. Overrides the page default for this monitor.</td></tr>
|
||||
<tr><td>position</td><td>number?</td><td>Sort order within the group.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
const attached = new Set(attachedRows.map(m => m.monitor_id));
|
||||
// monitor_id -> existing per-page overrides
|
||||
const displayNames = {};
|
||||
const displayModes = {};
|
||||
const monitorGroups = {};
|
||||
for (const r of attachedRows) {
|
||||
displayNames[r.monitor_id] = r.display_name || '';
|
||||
displayModes[r.monitor_id] = r.display_mode || '';
|
||||
monitorGroups[r.monitor_id] = r.group_id || '';
|
||||
}
|
||||
// Map group UUID -> index for the form
|
||||
@@ -67,14 +65,6 @@
|
||||
<% }) %>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<label class="block text-sm text-gray-400 mb-1.5">Display mode</label>
|
||||
<select name="display_mode" class="w-full bg-surface-solid border border-border-subtle rounded-lg px-4 py-2.5 text-gray-100 focus:outline-none focus:border-blue-500">
|
||||
<% [['expanded','Expanded - show full detail per monitor'],['compact','Compact - one line per monitor, click to expand']].forEach(function([v, label]) { %>
|
||||
<option value="<%= v %>" <%= (p.display_mode || 'expanded') === v ? 'selected' : '' %>><%= label %></option>
|
||||
<% }) %>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4">
|
||||
@@ -125,7 +115,6 @@
|
||||
<% orderedMonitors.forEach(function(m) {
|
||||
const isAttached = attached.has(m.id);
|
||||
const displayName = displayNames[m.id] || '';
|
||||
const displayMode = displayModes[m.id] || '';
|
||||
const groupIdx = groupIdToIndex[monitorGroups[m.id]] || '';
|
||||
%>
|
||||
<div class="monitor-edit-row flex items-center gap-3 bg-gray-900 border border-gray-800 rounded-lg px-3 py-2" draggable="true" data-monitor-id="<%= m.id %>">
|
||||
@@ -141,12 +130,6 @@
|
||||
<option value="<%= i %>" <%= groupIdx === String(i) ? 'selected' : '' %>><%= g.name %></option>
|
||||
<% }) %>
|
||||
</select>
|
||||
<select name="display_mode[<%= m.id %>]"
|
||||
class="text-xs bg-gray-950 border border-gray-800 rounded px-2 py-1 text-gray-200 focus:outline-none focus:border-blue-500 shrink-0">
|
||||
<option value="" <%= displayMode === '' ? 'selected' : '' %>>Default</option>
|
||||
<option value="expanded" <%= displayMode === 'expanded' ? 'selected' : '' %>>Expanded</option>
|
||||
<option value="compact" <%= displayMode === 'compact' ? 'selected' : '' %>>Compact</option>
|
||||
</select>
|
||||
<input type="text" name="display_name[<%= m.id %>]" value="<%= displayName %>" placeholder="Show as"
|
||||
class="text-xs bg-gray-950 border border-gray-800 rounded px-2 py-1 text-gray-200 placeholder-gray-600 focus:outline-none focus:border-blue-500 w-36 shrink-0">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user