Oberfläche: Einträge im Kalender aufziehen, Filter für Keys und Aufzeichnungen, ganztägige Wochentage
- Zeitplan: Zeitraum im Kalender aufziehen öffnet ein Overlay mit allen Einstellungen, vorbelegt mit Tag und Uhrzeit; Klick auf einen Eintrag zeigt Details und Entfernen; "Neuer Eintrag" für die Tastatur - Meine Keys: widerrufene ausblenden (standardmäßig an) - Aufzeichnungen: vergangene ausblenden (standardmäßig an) - Kontingent: "Grenzen gelten" über zwei Spalten; alle Wochentage vorausgewählt - Wochentage ohne Uhrzeit gelten ganztags (Weekly::whole_days) - start.sh --demo: realistische Fristen für Aufzeichnungen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
11dbc1c781
commit
8e61b77ffa
9 files changed
+332
-89
No files matched your search
+228
-76
@@ -153,11 +153,11 @@ function segmented(name, options, value, onchange) {
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** Wochentage zum Anklicken; liefert die Auswahl als "mo,mi" */
|
||||
function dayToggles(id) {
|
||||
/** Wochentage zum Anklicken, vorausgewählt `selected` (Kürzel); liefert die Auswahl als "mo,mi" */
|
||||
function dayToggles(id, selected = []) {
|
||||
const wrap = h('div', { class: 'days', id, role: 'group', 'aria-label': 'Wochentage' });
|
||||
for (const [code, label] of WEEKDAYS) {
|
||||
const b = h('button', { type: 'button', class: 'day', 'aria-pressed': 'false', 'data-day': code,
|
||||
const b = h('button', { type: 'button', class: 'day', 'aria-pressed': String(selected.includes(code)), 'data-day': code,
|
||||
onclick: () => b.setAttribute('aria-pressed', b.getAttribute('aria-pressed') === 'true' ? 'false' : 'true') }, label);
|
||||
wrap.append(b);
|
||||
}
|
||||
@@ -266,6 +266,7 @@ function head(section, title, sub, ...actions) {
|
||||
}
|
||||
|
||||
async function render() {
|
||||
closeOverlays();
|
||||
const { page, arg } = route();
|
||||
const def = PAGES[page] || PAGES[''];
|
||||
if (!state.me) {
|
||||
@@ -534,19 +535,30 @@ async function keysPage() {
|
||||
}
|
||||
|
||||
function keysManageCard(title, keys, own) {
|
||||
return h('section', { class: 'card' }, h('h2', {}, title),
|
||||
const hide = h('input', { type: 'checkbox', id: 'hide-revoked', checked: state.hideRevoked ?? true });
|
||||
const revoked = keys.filter((k) => k.revoked).length;
|
||||
const body = h('tbody', {});
|
||||
function update() {
|
||||
state.hideRevoked = hide.checked;
|
||||
body.replaceChildren(...keys.filter((k) => !hide.checked || !k.revoked).map((k) => h('tr', { class: k.revoked ? 'dim' : null },
|
||||
h('td', { class: 'mono' }, k.name), own ? null : h('td', { class: 'mono' }, k.owner || '–'),
|
||||
h('td', { class: 'mono muted' }, k.prefix + '…'), h('td', {}, quotaLabel(k)),
|
||||
h('td', { class: 'num' }, tokens(tok(k.usage.month))), h('td', { class: 'num' }, num(k.usage.month.requests)),
|
||||
h('td', {}, keyState(k)),
|
||||
h('td', {}, k.revoked ? null : h('div', { class: 'actions' },
|
||||
own && !k.recording ? h('button', { class: 'btn small', type: 'button', onclick: () => startRecording(k) }, 'Aufzeichnen') : null,
|
||||
own && k.recording ? h('button', { class: 'btn small', type: 'button', onclick: () => act(() => api('POST', '/recordings/stop', { key_id: k.id }), 'Aufzeichnung beendet; sie liegt jetzt zum Herunterladen bereit.') }, 'Aufzeichnung beenden') : null,
|
||||
h('button', { class: 'btn small danger', type: 'button', onclick: () => revokeKey(k) }, 'Widerrufen'))))));
|
||||
}
|
||||
hide.addEventListener('change', update);
|
||||
update();
|
||||
return h('section', { class: 'card' },
|
||||
h('div', { class: 'card-head' }, h('h2', {}, title),
|
||||
revoked ? h('label', { class: 'check', for: 'hide-revoked' }, hide, 'Widerrufene ausblenden (' + revoked + ')') : null),
|
||||
keys.length ? h('div', { class: 'table-wrap' }, h('table', {},
|
||||
h('thead', {}, h('tr', {}, h('th', {}, 'Name'), own ? null : h('th', {}, 'Inhaber'), h('th', {}, 'Key'), h('th', {}, 'Kontingent'),
|
||||
h('th', { class: 'num' }, 'Token (Monat)'), h('th', { class: 'num' }, 'Anfragen (Monat)'), h('th', {}, 'Status'), h('th', {}, h('span', { class: 'sr-only' }, 'Aktionen')))),
|
||||
h('tbody', {}, keys.map((k) => h('tr', { class: k.revoked ? 'dim' : null },
|
||||
h('td', { class: 'mono' }, k.name), own ? null : h('td', { class: 'mono' }, k.owner || '–'),
|
||||
h('td', { class: 'mono muted' }, k.prefix + '…'), h('td', {}, quotaLabel(k)),
|
||||
h('td', { class: 'num' }, tokens(tok(k.usage.month))), h('td', { class: 'num' }, num(k.usage.month.requests)),
|
||||
h('td', {}, keyState(k)),
|
||||
h('td', {}, k.revoked ? null : h('div', { class: 'actions' },
|
||||
own && !k.recording ? h('button', { class: 'btn small', type: 'button', onclick: () => startRecording(k) }, 'Aufzeichnen') : null,
|
||||
own && k.recording ? h('button', { class: 'btn small', type: 'button', onclick: () => act(() => api('POST', '/recordings/stop', { key_id: k.id }), 'Aufzeichnung beendet; sie liegt jetzt zum Herunterladen bereit.') }, 'Aufzeichnung beenden') : null,
|
||||
h('button', { class: 'btn small danger', type: 'button', onclick: () => revokeKey(k) }, 'Widerrufen'))))))))
|
||||
body))
|
||||
: h('p', { class: 'empty' }, 'Keine Keys.'));
|
||||
}
|
||||
|
||||
@@ -603,16 +615,33 @@ function recordingsCard(recordings, keys) {
|
||||
const k = keys.find((x) => x.id === id);
|
||||
return k ? [h('span', { class: 'mono' }, k.name), ' ', h('span', { class: 'mono muted' }, '(' + k.prefix + '…)')] : '#' + id;
|
||||
};
|
||||
// Vergangen: läuft nicht mehr und hat keine Daten mehr zum Herunterladen
|
||||
const past = (r) => !r.state.startsWith('zeichnet') && !r.state.startsWith('bereit');
|
||||
const pastCount = recordings.filter(past).length;
|
||||
const hide = h('input', { type: 'checkbox', id: 'hide-past-recordings', checked: state.hidePastRecordings ?? true });
|
||||
const body = h('tbody', {});
|
||||
const empty = h('p', { class: 'empty' });
|
||||
function update() {
|
||||
state.hidePastRecordings = hide.checked;
|
||||
const shown = recordings.slice().reverse().filter((r) => !hide.checked || !past(r));
|
||||
body.replaceChildren(...shown.map((r) => h('tr', { class: past(r) ? 'dim' : null },
|
||||
h('td', { class: 'mono' }, r.id), h('td', {}, keyLabel(r.key_id)), h('td', { class: 'num' }, r.written + ' / ' + r.count),
|
||||
h('td', {}, r.state), h('td', { class: 'muted' }, r.end_reason || '–'),
|
||||
h('td', {}, r.state.startsWith('bereit') ? h('a', { class: 'btn small primary', href: '/omega/api/recordings/' + r.id + '/download', download: 'aufzeichnung-' + r.id + '.jsonl', onclick: () => setTimeout(render, 1500) }, 'JSONL herunterladen') : null))));
|
||||
empty.hidden = shown.length > 0;
|
||||
empty.textContent = recordings.length ? 'Keine laufenden oder bereitliegenden Aufzeichnungen.' : 'Noch keine Aufzeichnungen. Starte eine über „Aufzeichnen“ bei einem deiner Keys.';
|
||||
table.hidden = !shown.length;
|
||||
}
|
||||
const table = h('div', { class: 'table-wrap' }, h('table', {},
|
||||
h('thead', {}, h('tr', {}, h('th', {}, 'Nr.'), h('th', {}, 'Key'), h('th', { class: 'num' }, 'Einträge'), h('th', {}, 'Stand'), h('th', {}, 'Ende'), h('th', {}, h('span', { class: 'sr-only' }, 'Aktionen')))),
|
||||
body));
|
||||
hide.addEventListener('change', update);
|
||||
update();
|
||||
return h('section', { class: 'card' },
|
||||
h('div', { class: 'card-head' }, h('h2', {}, 'Aufzeichnung für Debugging'),
|
||||
h('span', { class: 'muted' }, 'Verschlüsselt gespeichert, nur für dich abrufbar, eine Stunde bereit, nach dem Download gelöscht.')),
|
||||
recordings.length ? h('div', { class: 'table-wrap' }, h('table', {},
|
||||
h('thead', {}, h('tr', {}, h('th', {}, 'Nr.'), h('th', {}, 'Key'), h('th', { class: 'num' }, 'Einträge'), h('th', {}, 'Stand'), h('th', {}, 'Ende'), h('th', {}, h('span', { class: 'sr-only' }, 'Aktionen')))),
|
||||
h('tbody', {}, recordings.slice().reverse().map((r) => h('tr', {},
|
||||
h('td', { class: 'mono' }, r.id), h('td', {}, keyLabel(r.key_id)), h('td', { class: 'num' }, r.written + ' / ' + r.count),
|
||||
h('td', {}, r.state), h('td', { class: 'muted' }, r.end_reason || '–'),
|
||||
h('td', {}, r.state.startsWith('bereit') ? h('a', { class: 'btn small primary', href: '/omega/api/recordings/' + r.id + '/download', download: 'aufzeichnung-' + r.id + '.jsonl', onclick: () => setTimeout(render, 1500) }, 'JSONL herunterladen') : null))))))
|
||||
: h('p', { class: 'empty' }, 'Noch keine Aufzeichnungen. Starte eine über „Aufzeichnen“ bei einem deiner Keys.'));
|
||||
pastCount ? h('label', { class: 'check', for: 'hide-past-recordings' }, hide, 'Vergangene ausblenden (' + pastCount + ')') : null),
|
||||
h('span', { class: 'hint' }, 'Verschlüsselt gespeichert, nur für dich abrufbar, eine Stunde bereit, nach dem Download gelöscht.'),
|
||||
table, empty);
|
||||
}
|
||||
|
||||
function endpointsCard() {
|
||||
@@ -733,16 +762,15 @@ function quotasTable(quotas, showOwner) {
|
||||
: h('p', { class: 'empty' }, 'Noch keine Kontingente.');
|
||||
}
|
||||
|
||||
/** Formular für ein neues Kontingent, für eine feste Gruppe oder mit Auswahl */
|
||||
/** Formular für ein neues Kontingent, für eine feste Gruppe oder mit Auswahl */
|
||||
function quotaForm(groups, fixedGroup, models) {
|
||||
const limit = (name, label) => h('div', { class: 'field-group' }, h('label', { for: 'q-' + name }, label),
|
||||
h('input', { id: 'q-' + name, name, class: 'field mono', type: 'number', min: 1, inputmode: 'numeric', placeholder: 'unbegrenzt' }));
|
||||
const days = dayToggles('q-days');
|
||||
const days = dayToggles('q-days', WEEKDAYS.map(([code]) => code));
|
||||
const picker = h('div', { hidden: true }, modelPicker(models || [], 'q-model', true));
|
||||
const person = h('div', { class: 'field-group', hidden: true }, h('label', { for: 'q-username' }, 'Benutzername'),
|
||||
h('input', { id: 'q-username', name: 'username', class: 'field mono' }));
|
||||
const sharing = h('div', { class: 'field-group' }, h('span', { class: 'label' }, 'Grenzen gelten'),
|
||||
const sharing = h('div', { class: 'field-group wide' }, h('span', { class: 'label' }, 'Grenzen gelten'),
|
||||
segmented('q-shared', [['each', 'je Person'], ['shared', 'für die Gruppe gemeinsam']], 'each'));
|
||||
const target = fixedGroup ? null : h('select', { id: 'q-target', name: 'target', class: 'field', onchange: () => {
|
||||
person.hidden = target.value !== 'user';
|
||||
@@ -759,17 +787,18 @@ function quotaForm(groups, fixedGroup, models) {
|
||||
const chosen = checkedValues(form, 'q-model');
|
||||
if (restricted && !chosen.length) { state.flash = { kind: 'error', text: 'Bei begrenzten Modellen mindestens ein Modell auswählen.' }; return render(); }
|
||||
const weekly = days.value();
|
||||
if (!!weekly !== !!(d.time_start && d.time_end) && (weekly || d.time_start || d.time_end)) {
|
||||
state.flash = { kind: 'error', text: 'Für Nutzungszeiten Wochentage und Uhrzeit von–bis angeben.' };
|
||||
return render();
|
||||
}
|
||||
if (!weekly) { state.flash = { kind: 'error', text: 'Mindestens einen Wochentag auswählen.' }; return render(); }
|
||||
if (!d.time_start !== !d.time_end) { state.flash = { kind: 'error', text: 'Für die Uhrzeit Beginn und Ende angeben.' }; return render(); }
|
||||
const time = d.time_start ? d.time_start + '-' + d.time_end : undefined;
|
||||
// Alle Tage ohne Uhrzeit heißt: jederzeit
|
||||
const always = weekly.split(',').length === 7 && !time;
|
||||
const body = {
|
||||
name: d.name,
|
||||
tokens: { hour: optNum(d.tokens_hour), day: optNum(d.tokens_day), week: optNum(d.tokens_week), month: optNum(d.tokens_month), total: optNum(d.tokens_total) },
|
||||
requests: { hour: optNum(d.requests_hour), day: optNum(d.requests_day), week: optNum(d.requests_week), month: optNum(d.requests_month), total: optNum(d.requests_total) },
|
||||
models: restricted ? chosen : undefined,
|
||||
from: optional(d.valid_from), until: dayAfter(d.valid_until),
|
||||
weekly: weekly || undefined, time: weekly ? d.time_start + '-' + d.time_end : undefined, note: d.note,
|
||||
weekly: always ? undefined : weekly, time, note: d.note,
|
||||
};
|
||||
const t = fixedGroup || d.target;
|
||||
if (t.startsWith('group:')) {
|
||||
@@ -795,7 +824,7 @@ function quotaForm(groups, fixedGroup, models) {
|
||||
h('div', { class: 'fields' },
|
||||
h('div', { class: 'field-group' }, h('label', { for: 'q-time-start' }, 'von'), h('input', { id: 'q-time-start', name: 'time_start', type: 'time', class: 'field mono' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 'q-time-end' }, 'bis'), h('input', { id: 'q-time-end', name: 'time_end', type: 'time', class: 'field mono' }))),
|
||||
h('span', { class: 'hint' }, 'Ohne Auswahl jederzeit nutzbar. Endet die Zeit vor dem Beginn, reicht sie über Mitternacht.')),
|
||||
h('span', { class: 'hint' }, 'Ohne Uhrzeit ganztags. Endet die Uhrzeit vor dem Beginn, reicht sie über Mitternacht.')),
|
||||
h('fieldset', {}, h('legend', {}, 'Gültigkeit'),
|
||||
h('div', { class: 'fields' },
|
||||
h('div', { class: 'field-group' }, h('label', { for: 'q-valid-from' }, 'ab'), h('input', { id: 'q-valid-from', name: 'valid_from', type: 'date', class: 'field mono' })),
|
||||
@@ -984,9 +1013,11 @@ async function schedulePage() {
|
||||
+ new Date(weekEnd.getTime() - 1).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
const permanent = entries.filter((e) => !e.time.from && !e.time.until && !e.time.weekly);
|
||||
const shiftWeek = (d) => { state.week = d === 0 ? 0 : (state.week || 0) + d; render(); };
|
||||
const newEntry = (preset) => openOverlay('Neuer Eintrag', (close) => scheduleForm(models, groups, preset, close));
|
||||
|
||||
// Kalender: eine Spalte je Tag, eine Zeile je Stunde
|
||||
// Kalender: eine Spalte je Tag, eine Zeile je Stunde. Ziehen markiert einen Zeitraum, ein Klick eine Stunde.
|
||||
const HOUR = 22;
|
||||
const SLOT = 30;
|
||||
const grid = h('div', { class: 'cal' });
|
||||
grid.append(h('div', { class: 'cal-corner' }));
|
||||
for (let d = 0; d < 7; d++) {
|
||||
@@ -999,37 +1030,128 @@ async function schedulePage() {
|
||||
grid.append(hours);
|
||||
for (let d = 0; d < 7; d++) {
|
||||
const dayStart = new Date(weekStart.getTime() + d * 86400000);
|
||||
const col = h('div', { class: 'cal-col', style: { height: (24 * HOUR) + 'px' } });
|
||||
const col = h('div', { class: 'cal-col', style: { height: (24 * HOUR) + 'px' }, title: 'Zeitraum aufziehen, um einen Eintrag anzulegen' });
|
||||
let lane = 0;
|
||||
for (const e of entries) {
|
||||
if (permanent.includes(e)) continue;
|
||||
for (const [from, to] of occurrences(e, dayStart)) {
|
||||
const top = (from - dayStart) / 3600000 * HOUR;
|
||||
const height = Math.max(16, (to - from) / 3600000 * HOUR);
|
||||
col.append(h('div', { class: 'ev ' + e.kind.kind, style: { top: top + 'px', height: height + 'px', left: (4 + lane * 6) + 'px' }, title: e.subject + ' · ' + e.describe },
|
||||
h('span', { class: 'ev-kind' }, KIND_LABEL[e.kind.kind]), h('span', { class: 'mono' }, e.subject),
|
||||
e.note ? h('span', {}, e.note) : null, h('span', { class: 'mono' }, hhmm(from) + '–' + (to.getTime() === dayStart.getTime() + 86400000 ? '24:00' : hhmm(to)))));
|
||||
col.append(h('button', { type: 'button', class: 'ev ' + e.kind.kind, style: { top: top + 'px', height: height + 'px', left: (4 + lane * 6) + 'px' },
|
||||
title: e.subject + ' · ' + e.describe, onpointerdown: (ev) => ev.stopPropagation(), onclick: () => showEntry(e) },
|
||||
h('span', { class: 'ev-kind' }, KIND_LABEL[e.kind.kind]), h('span', { class: 'mono' }, e.subject),
|
||||
e.note ? h('span', {}, e.note) : null, h('span', { class: 'mono' }, hhmm(from) + '–' + (to.getTime() === dayStart.getTime() + 86400000 ? '24:00' : hhmm(to)))));
|
||||
lane = (lane + 1) % 3;
|
||||
}
|
||||
}
|
||||
// Minuten seit Tagesbeginn an der Zeigerposition, auf halbe Stunden gerastert
|
||||
const minutes = (ev, round) => {
|
||||
const y = ev.clientY - col.getBoundingClientRect().top;
|
||||
return Math.min(24 * 60, Math.max(0, round(y / HOUR * 60 / SLOT) * SLOT));
|
||||
};
|
||||
let drag = null;
|
||||
const sel = h('div', { class: 'cal-sel', hidden: true });
|
||||
col.append(sel);
|
||||
const show = () => {
|
||||
const [a, b] = [Math.min(drag.start, drag.end), Math.max(drag.start, drag.end)];
|
||||
Object.assign(sel.style, { top: (a / 60 * HOUR) + 'px', height: ((b - a) / 60 * HOUR) + 'px' });
|
||||
sel.textContent = mm(a) + '–' + mm(b);
|
||||
sel.hidden = false;
|
||||
};
|
||||
col.addEventListener('pointerdown', (ev) => {
|
||||
if (ev.button !== 0) return;
|
||||
ev.preventDefault();
|
||||
if (col.setPointerCapture && ev.pointerId !== undefined) col.setPointerCapture(ev.pointerId);
|
||||
const start = minutes(ev, Math.floor);
|
||||
drag = { start, end: Math.min(24 * 60, start + 60) };
|
||||
show();
|
||||
});
|
||||
col.addEventListener('pointermove', (ev) => {
|
||||
if (!drag) return;
|
||||
const m = minutes(ev, Math.ceil);
|
||||
// Nach oben gezogen: der Beginn rastet nach unten ab
|
||||
drag.end = m > drag.start ? m : Math.max(0, minutes(ev, Math.floor));
|
||||
if (drag.end === drag.start) drag.end = drag.start + SLOT;
|
||||
show();
|
||||
});
|
||||
col.addEventListener('pointerup', () => {
|
||||
if (!drag) return;
|
||||
const [a, b] = [Math.min(drag.start, drag.end), Math.max(drag.start, drag.end)];
|
||||
drag = null;
|
||||
newEntry({ day: dayStart, start: a, end: b });
|
||||
sel.hidden = true;
|
||||
});
|
||||
col.addEventListener('pointercancel', () => { drag = null; sel.hidden = true; });
|
||||
grid.append(col);
|
||||
}
|
||||
|
||||
// Formular wie im Mockup: Art, Gegenstand, Zeit und Wiederholung
|
||||
const kindBox = h('div', {});
|
||||
function showEntry(e) {
|
||||
openOverlay(KIND_LABEL[e.kind.kind] + ': ' + e.subject, (close) => h('div', { class: 'stack small' },
|
||||
h('dl', { class: 'facts' },
|
||||
h('dt', {}, 'Wann'), h('dd', {}, e.describe),
|
||||
h('dt', {}, 'Stand'), h('dd', {}, e.active ? 'gerade aktiv' : 'gerade nicht aktiv'),
|
||||
e.note ? [h('dt', {}, 'Anmerkung'), h('dd', {}, e.note)] : null),
|
||||
h('div', { class: 'actions' },
|
||||
h('button', { class: 'btn', type: 'button', onclick: close }, 'Schließen'),
|
||||
h('button', { class: 'btn danger', type: 'button', onclick: () => { close(); act(() => api('DELETE', '/schedule/' + e.id), 'Eintrag entfernt.'); } }, 'Entfernen'))));
|
||||
}
|
||||
|
||||
return h('div', { class: 'stack' },
|
||||
head('Administration', 'Zeitplan', 'Pins, exklusive Nutzung und Modellzeitfenster in einem gemeinsamen Plan. Zum Anlegen einen Zeitraum im Kalender aufziehen.',
|
||||
h('button', { class: 'btn icon', type: 'button', 'aria-label': 'Vorige Woche', onclick: () => shiftWeek(-1) }, '‹'),
|
||||
h('span', { class: 'mono' }, label),
|
||||
h('button', { class: 'btn icon', type: 'button', 'aria-label': 'Nächste Woche', onclick: () => shiftWeek(1) }, '›'),
|
||||
h('button', { class: 'btn', type: 'button', onclick: () => shiftWeek(0) }, 'Heute'),
|
||||
h('button', { class: 'btn primary', type: 'button', onclick: () => newEntry(null) }, 'Neuer Eintrag')),
|
||||
h('div', { class: 'toolbar' },
|
||||
h('span', { class: 'muted' }, 'Dauerhaft'),
|
||||
permanent.length ? permanent.map((e) => h('button', { type: 'button', class: 'chip ' + (e.kind.kind === 'pin' ? 'accent' : '') + ' mono', onclick: () => showEntry(e) }, KIND_LABEL[e.kind.kind] + ' · ' + e.subject)) : h('span', { class: 'muted' }, '–'),
|
||||
h('span', { class: 'legend' }, ['pin', 'exclusive', 'window'].map((k) => h('span', {}, h('span', { class: 'swatch ev-' + k }), KIND_LABEL[k])))),
|
||||
h('section', { class: 'card cal-card' }, grid),
|
||||
h('section', { class: 'card' }, h('h2', {}, 'Alle Einträge'),
|
||||
entries.length ? h('div', { class: 'table-wrap' }, h('table', {},
|
||||
h('thead', {}, h('tr', {}, h('th', {}, 'Art'), h('th', {}, 'Was'), h('th', {}, 'Wann'), h('th', {}, 'Stand'), h('th', {}, 'Anmerkung'), h('th', {}, h('span', { class: 'sr-only' }, 'Aktionen')))),
|
||||
h('tbody', {}, entries.map((e) => h('tr', {},
|
||||
h('td', {}, h('span', { class: 'chip' + (e.kind.kind === 'pin' ? ' accent' : '') }, KIND_LABEL[e.kind.kind] || e.kind.kind)),
|
||||
h('td', { class: 'mono wrap' }, e.subject), h('td', { class: 'wrap' }, e.describe),
|
||||
h('td', {}, e.active ? h('span', { class: 'status' }, h('span', { class: 'dot good' }), 'aktiv') : h('span', { class: 'muted' }, 'inaktiv')),
|
||||
h('td', { class: 'wrap' }, e.note),
|
||||
h('td', {}, h('button', { class: 'btn small danger', type: 'button', onclick: () => act(() => api('DELETE', '/schedule/' + e.id), 'Eintrag entfernt.') }, 'Entfernen')))))))
|
||||
: h('p', { class: 'empty' }, 'Der Zeitplan ist leer.')));
|
||||
}
|
||||
|
||||
const mm = (m) => String(Math.floor(m / 60)).padStart(2, '0') + ':' + String(m % 60).padStart(2, '0');
|
||||
|
||||
/** Datum und Minuten seit Tagesbeginn als Wert für ein datetime-local-Feld */
|
||||
function localValue(day, minutes) {
|
||||
const d = new Date(day.getFullYear(), day.getMonth(), day.getDate(), 0, minutes);
|
||||
const p = (n) => String(n).padStart(2, '0');
|
||||
return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + 'T' + p(d.getHours()) + ':' + p(d.getMinutes());
|
||||
}
|
||||
|
||||
/** Formular für einen Zeitplaneintrag; `preset` ist der im Kalender markierte Zeitraum */
|
||||
function scheduleForm(models, groups, preset, close) {
|
||||
const error = h('div', { class: 'notice error', role: 'alert', hidden: true });
|
||||
const fail = (text) => { error.textContent = text; error.hidden = false; };
|
||||
const subject = h('div', { class: 'stack small' });
|
||||
const repeat = h('select', { id: 's-repeat', name: 'repeat', class: 'field', onchange: () => showTime() },
|
||||
h('option', { value: 'once' }, 'einmalig'), h('option', { value: 'weekly' }, 'wöchentlich'), h('option', { value: 'permanent' }, 'dauerhaft'));
|
||||
const days = dayToggles('s-days');
|
||||
const weekday = preset ? WEEKDAYS[(preset.day.getDay() + 6) % 7][0] : null;
|
||||
const days = dayToggles('s-days', weekday ? [weekday] : []);
|
||||
const once = h('div', { class: 'fields' },
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-from' }, 'Beginn'), h('input', { id: 's-from', name: 'from', type: 'datetime-local', class: 'field mono' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-until' }, 'Ende'), h('input', { id: 's-until', name: 'until', type: 'datetime-local', class: 'field mono' })));
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-from' }, 'Beginn'),
|
||||
h('input', { id: 's-from', name: 'from', type: 'datetime-local', class: 'field mono', value: preset ? localValue(preset.day, preset.start) : '' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-until' }, 'Ende'),
|
||||
h('input', { id: 's-until', name: 'until', type: 'datetime-local', class: 'field mono', value: preset ? localValue(preset.day, preset.end) : '' })));
|
||||
const weekly = h('div', { class: 'stack small' }, days,
|
||||
h('div', { class: 'fields' },
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-time-start' }, 'von'), h('input', { id: 's-time-start', name: 'time_start', type: 'time', class: 'field mono' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-time-end' }, 'bis'), h('input', { id: 's-time-end', name: 'time_end', type: 'time', class: 'field mono' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-time-start' }, 'von'),
|
||||
h('input', { id: 's-time-start', name: 'time_start', type: 'time', class: 'field mono', value: preset ? mm(preset.start) : '' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-time-end' }, 'bis'),
|
||||
h('input', { id: 's-time-end', name: 'time_end', type: 'time', class: 'field mono', value: preset ? mm(preset.end % (24 * 60)) : '' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-valid-from' }, 'erstmals am'), h('input', { id: 's-valid-from', name: 'valid_from', type: 'date', class: 'field mono' })),
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-valid-until' }, 'letztmals am'), h('input', { id: 's-valid-until', name: 'valid_until', type: 'date', class: 'field mono' }))));
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-valid-until' }, 'letztmals am'), h('input', { id: 's-valid-until', name: 'valid_until', type: 'date', class: 'field mono' }))),
|
||||
h('span', { class: 'hint' }, 'Ohne Uhrzeit ganztags.'));
|
||||
function showTime() {
|
||||
once.hidden = repeat.value !== 'once';
|
||||
weekly.hidden = repeat.value !== 'weekly';
|
||||
@@ -1043,59 +1165,89 @@ async function schedulePage() {
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-users' }, 'Personen (Benutzernamen)'), h('input', { id: 's-users', name: 'users', class: 'field mono', placeholder: 'hofmannol, mueller' })));
|
||||
if (kind === 'window') subject.replaceChildren(h('span', { class: 'label' }, 'Nur diese Modelle'), modelPicker(models, 's-model', true));
|
||||
}
|
||||
kindBox.append(segmented('s-kind', [['pin', 'Pinnen'], ['exclusive', 'Exklusiv'], ['window', 'Zeitfenster']], 'pin', (v) => { kind = v; showSubject(); }));
|
||||
showSubject();
|
||||
showTime();
|
||||
const form = h('form', {
|
||||
class: 'card cal-form',
|
||||
onsubmit: (ev) => {
|
||||
class: 'stack small',
|
||||
onsubmit: async (ev) => {
|
||||
ev.preventDefault();
|
||||
error.hidden = true;
|
||||
const d = formData(form);
|
||||
const body = { kind, note: d.note };
|
||||
if (kind === 'pin') {
|
||||
const m = checkedValues(form, 's-model')[0];
|
||||
if (!m) { state.flash = { kind: 'error', text: 'Ein Modell auswählen.' }; return render(); }
|
||||
if (!m) return fail('Ein Modell auswählen.');
|
||||
body.model = m;
|
||||
const nodes = (models.find((x) => x.id === m) || { nodes: [] }).nodes;
|
||||
if (nodes.length > 1) body.node = d.node || nodes[0];
|
||||
if (nodes.length > 1) body.node = nodes[0];
|
||||
}
|
||||
if (kind === 'exclusive') Object.assign(body, { groups: checkedValues(form, 's-group'), users: list(d.users) });
|
||||
if (kind === 'window') body.models = checkedValues(form, 's-model');
|
||||
if (d.repeat === 'once') Object.assign(body, { from: apiTime(d.from), until: apiTime(d.until) });
|
||||
if (d.repeat === 'weekly') Object.assign(body, { weekly: days.value(), time: d.time_start + '-' + d.time_end, from: optional(d.valid_from), until: dayAfter(d.valid_until) });
|
||||
act(() => api('POST', '/schedule', body), (e2) => 'Eintrag angelegt: ' + e2.subject + ', ' + e2.describe);
|
||||
if (kind === 'window') {
|
||||
body.models = checkedValues(form, 's-model');
|
||||
if (!body.models.length) return fail('Mindestens ein Modell auswählen.');
|
||||
}
|
||||
if (d.repeat === 'once') {
|
||||
if (!d.from || !d.until) return fail('Beginn und Ende angeben.');
|
||||
Object.assign(body, { from: apiTime(d.from), until: apiTime(d.until) });
|
||||
}
|
||||
if (d.repeat === 'weekly') {
|
||||
if (!days.value()) return fail('Mindestens einen Wochentag auswählen.');
|
||||
if (!d.time_start !== !d.time_end) return fail('Für die Uhrzeit Beginn und Ende angeben.');
|
||||
Object.assign(body, { weekly: days.value(), time: d.time_start ? d.time_start + '-' + d.time_end : undefined, from: optional(d.valid_from), until: dayAfter(d.valid_until) });
|
||||
}
|
||||
// Fehler bleiben im Overlay, damit die Eingaben erhalten bleiben
|
||||
try {
|
||||
const created = await api('POST', '/schedule', body);
|
||||
close();
|
||||
state.flash = { kind: 'ok', text: 'Eintrag angelegt: ' + created.subject + ', ' + created.describe };
|
||||
render();
|
||||
} catch (e) {
|
||||
fail(e.message);
|
||||
}
|
||||
},
|
||||
},
|
||||
h('h2', {}, 'Eintrag anlegen'),
|
||||
h('div', { class: 'field-group' }, h('span', { class: 'label' }, 'Art des Eintrags'), kindBox),
|
||||
h('div', { class: 'field-group' }, h('span', { class: 'label' }, 'Art des Eintrags'),
|
||||
segmented('s-kind', [['pin', 'Pinnen'], ['exclusive', 'Exklusiv'], ['window', 'Zeitfenster']], 'pin', (v) => { kind = v; showSubject(); })),
|
||||
subject,
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-repeat' }, 'Wiederholung'), repeat),
|
||||
once, weekly,
|
||||
h('div', { class: 'field-group' }, h('label', { for: 's-note' }, 'Anmerkung'), h('input', { id: 's-note', name: 'note', class: 'field', placeholder: 'z. B. Vorlesung KI' })),
|
||||
h('span', { class: 'hint' }, 'Der Proxy lehnt Einträge ab, die nicht in den Speicher passen oder sich widersprechen, und nennt den Grund.'),
|
||||
h('div', { class: 'actions' }, h('button', { class: 'btn primary', type: 'submit' }, 'Speichern')));
|
||||
error,
|
||||
h('div', { class: 'actions' },
|
||||
h('button', { class: 'btn', type: 'button', onclick: close }, 'Abbrechen'),
|
||||
h('button', { class: 'btn primary', type: 'submit' }, 'Speichern')));
|
||||
return form;
|
||||
}
|
||||
|
||||
return h('div', { class: 'stack' },
|
||||
head('Administration', 'Zeitplan', 'Pins, exklusive Nutzung und Modellzeitfenster in einem gemeinsamen Plan.',
|
||||
h('button', { class: 'btn icon', type: 'button', 'aria-label': 'Vorige Woche', onclick: () => shiftWeek(-1) }, '‹'),
|
||||
h('span', { class: 'mono' }, label),
|
||||
h('button', { class: 'btn icon', type: 'button', 'aria-label': 'Nächste Woche', onclick: () => shiftWeek(1) }, '›'),
|
||||
h('button', { class: 'btn', type: 'button', onclick: () => shiftWeek(0) }, 'Heute')),
|
||||
h('div', { class: 'toolbar' },
|
||||
h('span', { class: 'muted' }, 'Dauerhaft'),
|
||||
permanent.length ? permanent.map((e) => h('span', { class: 'chip ' + (e.kind.kind === 'pin' ? 'accent' : '') + ' mono' }, KIND_LABEL[e.kind.kind] + ' · ' + e.subject)) : h('span', { class: 'muted' }, '–'),
|
||||
h('span', { class: 'legend' }, ['pin', 'exclusive', 'window'].map((k) => h('span', {}, h('span', { class: 'swatch ev-' + k }), KIND_LABEL[k])))),
|
||||
h('div', { class: 'row top' }, h('section', { class: 'card cal-card' }, grid), form),
|
||||
h('section', { class: 'card' }, h('h2', {}, 'Alle Einträge'),
|
||||
entries.length ? h('div', { class: 'table-wrap' }, h('table', {},
|
||||
h('thead', {}, h('tr', {}, h('th', {}, 'Art'), h('th', {}, 'Was'), h('th', {}, 'Wann'), h('th', {}, 'Stand'), h('th', {}, 'Anmerkung'), h('th', {}, h('span', { class: 'sr-only' }, 'Aktionen')))),
|
||||
h('tbody', {}, entries.map((e) => h('tr', {},
|
||||
h('td', {}, h('span', { class: 'chip' + (e.kind.kind === 'pin' ? ' accent' : '') }, KIND_LABEL[e.kind.kind] || e.kind.kind)),
|
||||
h('td', { class: 'mono wrap' }, e.subject), h('td', { class: 'wrap' }, e.describe),
|
||||
h('td', {}, e.active ? h('span', { class: 'status' }, h('span', { class: 'dot good' }), 'aktiv') : h('span', { class: 'muted' }, 'inaktiv')),
|
||||
h('td', { class: 'wrap' }, e.note),
|
||||
h('td', {}, h('button', { class: 'btn small danger', type: 'button', onclick: () => act(() => api('DELETE', '/schedule/' + e.id), 'Eintrag entfernt.') }, 'Entfernen')))))))
|
||||
: h('p', { class: 'empty' }, 'Der Zeitplan ist leer.')));
|
||||
/** Overlay über der Seite; schließt mit Escape, Klick daneben oder close() */
|
||||
function openOverlay(title, content) {
|
||||
closeOverlays();
|
||||
const previous = document.activeElement;
|
||||
const titleId = 'overlay-title';
|
||||
const backdrop = h('div', { class: 'overlay' });
|
||||
const close = () => {
|
||||
backdrop.remove();
|
||||
document.removeEventListener('keydown', onKey);
|
||||
if (previous && previous.focus) previous.focus();
|
||||
};
|
||||
const onKey = (e) => { if (e.key === 'Escape') close(); };
|
||||
const dialog = h('div', { class: 'dialog card', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': titleId },
|
||||
h('div', { class: 'card-head' }, h('h2', { id: titleId }, title),
|
||||
h('button', { class: 'btn icon', type: 'button', 'aria-label': 'Schließen', onclick: close }, '×')),
|
||||
content(close));
|
||||
backdrop.append(dialog);
|
||||
backdrop.addEventListener('pointerdown', (e) => { if (e.target === backdrop) close(); });
|
||||
document.addEventListener('keydown', onKey);
|
||||
backdrop.close = close;
|
||||
document.body.append(backdrop);
|
||||
const first = dialog.querySelector('input:not([type=hidden]), select, textarea, button:not(.icon)');
|
||||
if (first) first.focus();
|
||||
return close;
|
||||
}
|
||||
|
||||
function closeOverlays() {
|
||||
for (const o of document.querySelectorAll('.overlay')) o.close();
|
||||
}
|
||||
|
||||
// ---------- Benutzer ----------
|
||||
|
||||
Reference in new issue
Block a user