feat(stammbaum): person edit Stammbaum & Beziehungen card
New StammbaumCard rendered below the Namensverlauf card on
/persons/{id}/edit:
- Header with "Als Familienmitglied" toggle (form action
toggleFamilyMember → PATCH /api/persons/{id}/family-member).
- "Erscheint im Stammbaum" banner with deep-link to
/stammbaum?focus={id} when familyMember is true.
- Direct relationships list grouped by type, then year. Chip text is
direction-aware: storage subject reads "Elternteil von", storage
object reads "Kind von" (new relation_child_of i18n key in all 3
locales). Symmetric and non-family types use their own keys.
- + Beziehung hinzufügen reveals an inline form with type select
(grouped Familie / Sozial), a PersonTypeahead with the new
excludePersonId prop (self-rel prevention, Elicit blocker 1), and
Von / Bis year fields.
- Year validation lives client-side via $derived: empty/empty is OK,
Bis < Von shows a red text-red-700 error wired with aria-describedby
and disables submit (Sara blocker 3).
- Self-rel inline error mirrors the typeahead exclusion in case the
user submits the personId regardless.
- Abgeleitete Beziehungen section (top 5) collapsed by default.
+page.server.ts loads relationships + inferred relationships in the
existing parallel fetch and adds three actions: toggleFamilyMember,
addRelationship (with year-range guard), deleteRelationship.
Refs #358.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,9 +17,11 @@ export async function load({ params, fetch, locals }) {
|
||||
|
||||
const { id } = params;
|
||||
const api = createApiClient(fetch);
|
||||
const [result, aliasesResult] = await Promise.all([
|
||||
const [result, aliasesResult, relsResult, inferredResult] = await Promise.all([
|
||||
api.GET('/api/persons/{id}', { params: { path: { id } } }),
|
||||
api.GET('/api/persons/{id}/aliases', { params: { path: { id } } })
|
||||
api.GET('/api/persons/{id}/aliases', { params: { path: { id } } }),
|
||||
api.GET('/api/persons/{id}/relationships', { params: { path: { id } } }),
|
||||
api.GET('/api/persons/{id}/inferred-relationships', { params: { path: { id } } })
|
||||
]);
|
||||
|
||||
if (!result.response.ok) {
|
||||
@@ -29,7 +31,12 @@ export async function load({ params, fetch, locals }) {
|
||||
|
||||
const person = result.data!;
|
||||
const personType = normalizePersonType(person.personType);
|
||||
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
|
||||
return {
|
||||
person: { ...person, personType },
|
||||
aliases: aliasesResult.data ?? [],
|
||||
relationships: relsResult.data ?? [],
|
||||
inferredRelationships: inferredResult.data ?? []
|
||||
};
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
@@ -146,5 +153,86 @@ export const actions = {
|
||||
}
|
||||
|
||||
return { aliasSuccess: true };
|
||||
},
|
||||
|
||||
toggleFamilyMember: async ({ request, params, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const value = formData.get('familyMember')?.toString() === 'true';
|
||||
|
||||
const api = createApiClient(fetch);
|
||||
const result = await api.PATCH('/api/persons/{id}/family-member', {
|
||||
params: { path: { id: params.id } },
|
||||
body: { familyMember: value }
|
||||
});
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
||||
}
|
||||
return { relationshipSuccess: true };
|
||||
},
|
||||
|
||||
addRelationship: async ({ request, params, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const relatedPersonId = formData.get('relatedPersonId')?.toString();
|
||||
const relationType = formData.get('relationType')?.toString();
|
||||
const fromYearRaw = formData.get('fromYear')?.toString().trim();
|
||||
const toYearRaw = formData.get('toYear')?.toString().trim();
|
||||
const notes = formData.get('notes')?.toString().trim() || undefined;
|
||||
|
||||
if (!relatedPersonId || !relationType) {
|
||||
return fail(400, { relationshipError: getErrorMessage('VALIDATION_ERROR') });
|
||||
}
|
||||
if (relatedPersonId === params.id) {
|
||||
return fail(400, { relationshipError: getErrorMessage('VALIDATION_ERROR') });
|
||||
}
|
||||
const fromYear = fromYearRaw ? parseInt(fromYearRaw, 10) : undefined;
|
||||
const toYear = toYearRaw ? parseInt(toYearRaw, 10) : undefined;
|
||||
if (
|
||||
fromYear !== undefined &&
|
||||
toYear !== undefined &&
|
||||
!Number.isNaN(fromYear) &&
|
||||
!Number.isNaN(toYear) &&
|
||||
toYear < fromYear
|
||||
) {
|
||||
return fail(400, { relationshipError: getErrorMessage('VALIDATION_ERROR') });
|
||||
}
|
||||
|
||||
const api = createApiClient(fetch);
|
||||
const result = await api.POST('/api/persons/{id}/relationships', {
|
||||
params: { path: { id: params.id } },
|
||||
body: {
|
||||
relatedPersonId,
|
||||
relationType,
|
||||
...(fromYear !== undefined && !Number.isNaN(fromYear) ? { fromYear } : {}),
|
||||
...(toYear !== undefined && !Number.isNaN(toYear) ? { toYear } : {}),
|
||||
...(notes ? { notes } : {})
|
||||
}
|
||||
});
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
||||
}
|
||||
return { relationshipSuccess: true };
|
||||
},
|
||||
|
||||
deleteRelationship: async ({ request, params, fetch }) => {
|
||||
const formData = await request.formData();
|
||||
const relId = formData.get('relId')?.toString();
|
||||
if (!relId) {
|
||||
return fail(400, { relationshipError: getErrorMessage('VALIDATION_ERROR') });
|
||||
}
|
||||
|
||||
const api = createApiClient(fetch);
|
||||
const result = await api.DELETE('/api/persons/{id}/relationships/{relId}', {
|
||||
params: { path: { id: params.id, relId } }
|
||||
});
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
return fail(result.response.status, { relationshipError: getErrorMessage(code) });
|
||||
}
|
||||
return { relationshipSuccess: true };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import PersonEditForm from './PersonEditForm.svelte';
|
||||
import PersonEditSaveBar from './PersonEditSaveBar.svelte';
|
||||
import NameHistoryEditCard from './NameHistoryEditCard.svelte';
|
||||
import PersonMergePanel from '../PersonMergePanel.svelte';
|
||||
import StammbaumCard from '$lib/components/StammbaumCard.svelte';
|
||||
|
||||
let { data, form } = $props();
|
||||
const person = $derived(data.person);
|
||||
@@ -35,6 +36,15 @@ const person = $derived(data.person);
|
||||
|
||||
<NameHistoryEditCard aliases={data.aliases} canWrite={true} aliasError={form?.aliasError} />
|
||||
|
||||
<StammbaumCard
|
||||
personId={person.id}
|
||||
familyMember={person.familyMember ?? false}
|
||||
relationships={data.relationships}
|
||||
inferredRelationships={data.inferredRelationships}
|
||||
canWrite={true}
|
||||
relationshipError={form?.relationshipError}
|
||||
/>
|
||||
|
||||
{#key person.id}
|
||||
<PersonMergePanel person={person} form={form} />
|
||||
{/key}
|
||||
|
||||
Reference in New Issue
Block a user