Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,12 @@ async function loadDashboardSettings(): Promise<void> {
applyDashboardSettings(await response.json() as DashboardSettings);
}

function parseTickerText(text: string): string[] {
return text
.split(/[\n,]+/)
.map((item) => item.trim())
.filter(Boolean);
}

function focusSettingsEditor(focus?: 'tickers'): void {
const editor = document.getElementById('settingsEditor');
if (!editor) return;
const tickers = editor.querySelector<HTMLTextAreaElement>('#settingsTickers');
const tickers = editor.querySelector<HTMLInputElement>('#tickerInput');
if (focus === 'tickers' && tickers) {
tickers.focus();
tickers.select();
return;
}
editor.querySelector<HTMLInputElement>('input[name="machine"]')?.focus();
Expand All @@ -68,19 +60,46 @@ function openSettingsEditor(focus?: 'tickers'): void {
overlay.className = 'links-editor-modal settings-editor-modal';
overlay.id = 'settingsEditor';
const panels = dashboardSettings.panels;
overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock/crypto tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label for="settingsTickers">Tickers</label><textarea id="settingsTickers" spellcheck="false" placeholder="MSFT, NVDA, BTC-USD"></textarea><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`;
overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock/crypto tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, BTC-USD"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Yahoo Finance symbols · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`;
document.body.appendChild(overlay);
const form = overlay.querySelector<HTMLFormElement>('form')!;
const textarea = overlay.querySelector<HTMLTextAreaElement>('#settingsTickers')!;
textarea.value = (dashboardSettings.tickers || []).join('\n');
const chipsEl = overlay.querySelector<HTMLElement>('#tickerChips')!;
const input = overlay.querySelector<HTMLInputElement>('#tickerInput')!;
const editTickers = (dashboardSettings.tickers || []).slice();
const renderChips = (): void => {
chipsEl.innerHTML = editTickers.length
? editTickers.map((sym, i) => `<span class="ticker-chip">${escapeHtml(sym)}<button type="button" data-remove-ticker="${i}" title="Remove ${escapeHtml(sym)}" aria-label="Remove ${escapeHtml(sym)}">×</button></span>`).join('')
: '<span class="muted ticker-empty-chip">No tickers yet — add one below</span>';
};
const addTicker = (): void => {
const sym = input.value.trim().toUpperCase().replace(/[^A-Z0-9.\-_=^]/g, '').slice(0, 24);
input.value = '';
if (!sym) return;
if (editTickers.includes(sym)) { toast(`${sym} already added`); return; }
if (editTickers.length >= 16) { toast('Max 16 tickers'); return; }
editTickers.push(sym);
renderChips();
input.focus();
};
renderChips();
chipsEl.addEventListener('click', (event: MouseEvent) => {
const btn = (event.target as HTMLElement).closest<HTMLButtonElement>('[data-remove-ticker]');
if (!btn) return;
Comment on lines +85 to +87
editTickers.splice(Number(btn.dataset.removeTicker), 1);
renderChips();
});
input.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.key === 'Enter' || event.key === ',') { event.preventDefault(); addTicker(); }
});
overlay.querySelector('#addTickerBtn')?.addEventListener('click', addTicker);
const close = (): void => overlay.remove();
overlay.querySelector('[data-close-settings]')?.addEventListener('click', close);
overlay.addEventListener('mousedown', (event: MouseEvent) => { if (event.target === overlay) close(); });
form.addEventListener('submit', (event: Event) => {
event.preventDefault();
const data = new FormData(form);
saveDashboardSettings({
tickers: parseTickerText(textarea.value),
tickers: editTickers,
panels: {
machine: data.has('machine'),
machineSensors: data.has('machineSensors'),
Expand Down
55 changes: 43 additions & 12 deletions public/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ async function loadDashboardSettings() {
return;
applyDashboardSettings(await response.json());
}
function parseTickerText(text) {
return text
.split(/[\n,]+/)
.map((item) => item.trim())
.filter(Boolean);
}
function focusSettingsEditor(focus) {
const editor = document.getElementById('settingsEditor');
if (!editor)
return;
const tickers = editor.querySelector('#settingsTickers');
const tickers = editor.querySelector('#tickerInput');
if (focus === 'tickers' && tickers) {
tickers.focus();
tickers.select();
return;
}
editor.querySelector('input[name="machine"]')?.focus();
Expand All @@ -67,11 +60,49 @@ function openSettingsEditor(focus) {
overlay.className = 'links-editor-modal settings-editor-modal';
overlay.id = 'settingsEditor';
const panels = dashboardSettings.panels;
overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock/crypto tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label for="settingsTickers">Tickers</label><textarea id="settingsTickers" spellcheck="false" placeholder="MSFT, NVDA, BTC-USD"></textarea><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`;
overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock/crypto tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, BTC-USD"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Yahoo Finance symbols · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`;
document.body.appendChild(overlay);
const form = overlay.querySelector('form');
const textarea = overlay.querySelector('#settingsTickers');
textarea.value = (dashboardSettings.tickers || []).join('\n');
const chipsEl = overlay.querySelector('#tickerChips');
const input = overlay.querySelector('#tickerInput');
const editTickers = (dashboardSettings.tickers || []).slice();
const renderChips = () => {
chipsEl.innerHTML = editTickers.length
? editTickers.map((sym, i) => `<span class="ticker-chip">${escapeHtml(sym)}<button type="button" data-remove-ticker="${i}" title="Remove ${escapeHtml(sym)}" aria-label="Remove ${escapeHtml(sym)}">×</button></span>`).join('')
: '<span class="muted ticker-empty-chip">No tickers yet — add one below</span>';
};
const addTicker = () => {
const sym = input.value.trim().toUpperCase().replace(/[^A-Z0-9.\-_=^]/g, '').slice(0, 24);
input.value = '';
if (!sym)
return;
if (editTickers.includes(sym)) {
toast(`${sym} already added`);
return;
}
if (editTickers.length >= 16) {
toast('Max 16 tickers');
return;
}
editTickers.push(sym);
renderChips();
input.focus();
};
renderChips();
chipsEl.addEventListener('click', (event) => {
const btn = event.target.closest('[data-remove-ticker]');
if (!btn)
return;
Comment on lines +92 to +95
editTickers.splice(Number(btn.dataset.removeTicker), 1);
renderChips();
Comment on lines +96 to +97
});
input.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ',') {
event.preventDefault();
addTicker();
}
});
overlay.querySelector('#addTickerBtn')?.addEventListener('click', addTicker);
const close = () => overlay.remove();
overlay.querySelector('[data-close-settings]')?.addEventListener('click', close);
overlay.addEventListener('mousedown', (event) => { if (event.target === overlay)
Expand All @@ -80,7 +111,7 @@ function openSettingsEditor(focus) {
event.preventDefault();
const data = new FormData(form);
saveDashboardSettings({
tickers: parseTickerText(textarea.value),
tickers: editTickers,
panels: {
machine: data.has('machine'),
machineSensors: data.has('machineSensors'),
Expand Down
12 changes: 12 additions & 0 deletions public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ body.preview-fullscreen-open{overflow:hidden}
.settings-grid label{display:flex;align-items:center;gap:8px;margin:0;color:var(--text);font-size:13px}
.settings-grid .settings-subsetting{color:var(--muted);padding-left:18px}
.settings-grid input{width:auto;min-height:0}
.ticker-editor{margin:6px 0 4px}
.ticker-chips{display:flex;flex-wrap:wrap;gap:6px;min-height:30px;padding:6px;border:1px solid rgba(255,255,255,.1);border-radius:8px;background:rgba(7,16,23,.5)}
.ticker-chip{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-variant-numeric:tabular-nums;background:rgba(139,246,255,.1);border:1px solid rgba(139,246,255,.22);color:#c9fff3;border-radius:999px;padding:2px 4px 2px 9px}
.ticker-chip button{border:0;background:rgba(255,255,255,.06);color:var(--muted);border-radius:999px;width:17px;height:17px;line-height:15px;padding:0;cursor:pointer;font-size:13px}
.ticker-chip button:hover{background:rgba(255,106,122,.25);color:#ffd0d6}
.ticker-empty-chip{font-size:12px;align-self:center;padding:2px 4px}
.ticker-add{display:flex;gap:7px;margin-top:7px}
.ticker-add input{flex:1;min-width:0;text-transform:uppercase}
.ticker-add input::placeholder{text-transform:none}
.ticker-add button{flex:0 0 auto;display:inline-flex;align-items:center;gap:4px;padding:6px 12px}
.ticker-add-plus{font-size:15px;line-height:1}
.ticker-hint{font-size:11px;margin:5px 0 0}
/* Button legend */
.legend{margin:0 0 8px;border:1px solid rgba(139,246,255,.18);border-radius:8px;background:#0b121a;font-size:12.5px}
.legend>summary{cursor:pointer;padding:8px 10px;color:var(--muted);font-weight:600;list-style:none}
Expand Down