Standort: locations.parent_id, eine Ebene. Neu "Shop" mit sechs Shops (Shop W17, Shop Wodo, Shop Parndorf, Shop Donaupark, Shop W1, Shop Wien Hauptbahnhof). Personen sitzen nur auf Standorten ohne Unterstandorte; zwei Trigger halten das auch fuer Import und Nachtlauf fest. Einstellung, Externe und Versetzung zeigen bei "Shop" eine zweite Auswahl (StandortAuswahl). Filter in Liste und Berichten und die Importliste bieten "Shop" selbst nicht an; der Import nennt bei "Shop" die Shops. rauchtest.sql und vertragsangaben.sql waehlen einen zuweisbaren Standort. C-Level: ueberall nur der Code (Formular, Akte, Zusammenfassung, Historie, Berichte, Import). Export ohne Spalte "C-Level Bezeichnung". Angehoerige und Notfallkontakte im Import wie im Formular: Auswahl als feste Liste und daneben "Verhaeltnis (Sonstige)" fuer den eigenen Text. Gespeichert wird bei "Sonstige" der Text; ein Text ohne "Sonstige" ist ein Fehler. Der Download teilt einen eigenen Text in beide Spalten. Geprueft: lint, tsc, types:check, npm test, waechter; Migrationen auf leerer Datenbank zweimal (Nichts anzuwenden), rauchtest.sql, vertragsangaben.sql; als alpenwerk_app: Einstellung auf "Shop" abgewiesen, auf "Shop W17" angenommen, Wechsel auf "Shop" abgewiesen, auf "Shop Wodo" angenommen, Unterstandort unter einem Shop abgewiesen.
35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
// Standorte mit Unterstandorten (Migration 20261123140000): „Shop" fasst die
|
|
// einzelnen Shops zusammen. Eine Person sitzt nur auf einem Standort ohne
|
|
// Unterstandorte; die Auswahl zeigt zuerst die oberste Ebene und bei einem
|
|
// zusammenfassenden Standort eine zweite Liste.
|
|
|
|
export type StandortEintrag = { id: string; name: string; parent_id?: string | null };
|
|
|
|
/** Standorte der obersten Ebene, wie die erste Auswahl sie zeigt. */
|
|
export function oberstandorte<T extends StandortEintrag>(alle: readonly T[]): T[] {
|
|
return alle.filter((s) => !s.parent_id);
|
|
}
|
|
|
|
/** Die Unterstandorte eines Standorts, leer bei einem gewöhnlichen. */
|
|
export function unterstandorte<T extends StandortEintrag>(alle: readonly T[], id: string): T[] {
|
|
return id ? alle.filter((s) => s.parent_id === id) : [];
|
|
}
|
|
|
|
/** Standorte, auf denen eine Person sitzen kann — für Filter und Importlisten. */
|
|
export function zuweisbareStandorte<T extends StandortEintrag>(alle: readonly T[]): T[] {
|
|
const gruppen = new Set(alle.map((s) => s.parent_id).filter(Boolean));
|
|
return alle.filter((s) => !gruppen.has(s.id));
|
|
}
|
|
|
|
/** Welcher Eintrag der ersten Auswahl zu einem gespeicherten Standort gehört. */
|
|
export function oberstandortVon(alle: readonly StandortEintrag[], id: string): string {
|
|
const s = alle.find((x) => x.id === id);
|
|
return s ? (s.parent_id ?? s.id) : "";
|
|
}
|
|
|
|
/** „Shop W17" unter „Shop" zeigt die zweite Auswahl als „W17". */
|
|
export function kurzname(unter: StandortEintrag, ober: StandortEintrag | undefined): string {
|
|
const praefix = ober ? `${ober.name} ` : "";
|
|
return praefix && unter.name.startsWith(praefix) ? unter.name.slice(praefix.length) : unter.name;
|
|
}
|