Startseite mit Aufgaben, Warnungen und wer macht was; Aufgaben aus V70 übernehmen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
Claude
2026-10-19 19:01:50 +00:00
parent aedd86a29b
commit 8a4fbafa65
10 changed files with 363 additions and 17 deletions

85
src/domain/uebersicht.ts Normal file
View File

@@ -0,0 +1,85 @@
// Startseite (Ü3, Ü7, Ü8): Aufgaben wie in V70 gruppiert, Warnungen und wer was wann wo macht.
import { type Datum, plusTage, wochentag } from "./datum.js";
import { type Arbeitswoche, istArbeitstag } from "./kalender.js";
import { type Besetzung, wer } from "./einsatz.js";
export interface Aufgabe {
id: string;
text: string;
faellig_am?: Datum | null;
langfristig?: boolean;
erledigt_am?: string | null;
}
/** V70: „Diese Woche“ (fällig bis Sonntag), „Noch nicht abgearbeitet“ (überfällig), „Langfristig“ (später oder ohne Datum). */
export function aufgabenGruppen<T extends Aufgabe>(aufgaben: T[], heute: Datum) {
const sonntag = plusTage(heute, (7 - wochentag(heute)) % 7);
const g = { dieseWoche: [] as T[], ueberfaellig: [] as T[], langfristig: [] as T[] };
for (const a of aufgaben) {
if (a.erledigt_am) continue;
const d = a.faellig_am;
if (d && d < heute) g.ueberfaellig.push(a);
else if (d && d <= sonntag && !a.langfristig) g.dieseWoche.push(a);
else g.langfristig.push(a);
}
const nachDatum = (a: T, b: T) => (a.faellig_am ?? "9999") < (b.faellig_am ?? "9999") ? -1 : (a.faellig_am ?? "9999") > (b.faellig_am ?? "9999") ? 1 : a.text.localeCompare(b.text, "de");
g.dieseWoche.sort(nachDatum);
g.ueberfaellig.sort(nachDatum);
g.langfristig.sort(nachDatum);
return g;
}
export interface UeVorgang {
id: string;
name: string;
anfang: Datum;
ende: Datum;
projekt: string;
}
export interface UeBesetzung extends Besetzung {
anzeige: string;
kurz: string;
}
/** Arbeitstage ab heute, so viele wie gewünscht (Freitag ist Reserve und fehlt deshalb). */
export function naechsteArbeitstage(heute: Datum, anzahl: number, woche: Arbeitswoche): Datum[] {
const aus: Datum[] = [];
for (let d = heute; aus.length < anzahl; d = plusTage(d, 1)) if (istArbeitstag(d, woche)) aus.push(d);
return aus;
}
export interface Einsatzzeile {
wer: string;
anzeige: string;
/** je Tag die Vorgänge dieser Person */
tage: { vorgang: string; name: string; projekt: string; vorgemerkt: boolean }[][];
}
/** Ü8: je Person (und Platzhalter) die Vorgänge an den nächsten Arbeitstagen; dazu Vorgänge ohne Besetzung. */
export function einsatzMatrix(vorgaenge: UeVorgang[], besetzungen: UeBesetzung[], tage: Datum[]): { zeilen: Einsatzzeile[]; ohne: Einsatzzeile } {
const zeilen = new Map<string, Einsatzzeile>();
const ohne: Einsatzzeile = { wer: "", anzeige: "Noch nicht besetzt", tage: tage.map(() => []) };
for (const v of vorgaenge) {
const idx = tage.map((d, i) => (d >= v.anfang && d <= v.ende ? i : -1)).filter((i) => i >= 0);
if (!idx.length) continue;
const bs = besetzungen.filter((b) => b.vorgang_id === v.id);
const eintrag = (vorgemerkt: boolean) => ({ vorgang: v.id, name: v.name, projekt: v.projekt, vorgemerkt });
if (!bs.length) idx.forEach((i) => ohne.tage[i]!.push(eintrag(false)));
for (const b of bs) {
const w = wer(b) ?? `nn:${b.anzeige}`;
const z = zeilen.get(w) ?? { wer: w, anzeige: b.anzeige, tage: tage.map(() => []) };
idx.forEach((i) => z.tage[i]!.push(eintrag(!b.freigegeben)));
zeilen.set(w, z);
}
}
return { zeilen: [...zeilen.values()].sort((a, b) => a.anzeige.localeCompare(b.anzeige, "de")), ohne };
}
export interface Warnung {
art: "ueberschneidung" | "unbesetzt" | "freigabe" | "aufgabe" | "kontostand";
text: string;
/** Sprungziel in der App, z. B. "terminplan" */
ziel: string;
}