Some checks failed
CI / OCR Service Tests (push) Successful in 29s
CI / Backend Unit Tests (push) Failing after 1m21s
CI / Unit & Component Tests (push) Failing after 2m37s
CI / Unit & Component Tests (pull_request) Failing after 2m27s
CI / OCR Service Tests (pull_request) Successful in 30s
CI / Backend Unit Tests (pull_request) Failing after 1m21s
- +layout.svelte: Upload button in header (authenticated users only) - +page.server.ts: call /api/dashboard/resume, /pulse, /activity; remove deprecated /api/documents/incomplete and /recent-activity - +page.svelte: 2-col grid layout (main + 320px sidebar), greeting, DashboardFamilyPulse + DashboardActivityFeed in sidebar - DashboardResumeStrip: refactored to use server data (resumeDoc prop), SVG thumbnail, progress bar with aria-*, empty state, CTA - DashboardFamilyPulse: new component — weekly stats from audit_log - DashboardActivityFeed: new component — activity feed with "für dich" badge - Update specs for new data shapes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
184 lines
6.6 KiB
TypeScript
184 lines
6.6 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import { createApiClient } from '$lib/api.server';
|
|
import type { components } from '$lib/generated/api';
|
|
|
|
type StatsDTO = components['schemas']['StatsDTO'];
|
|
type Document = components['schemas']['Document'];
|
|
type SearchMatchData = components['schemas']['SearchMatchData'];
|
|
type TranscriptionQueueItemDTO = components['schemas']['TranscriptionQueueItemDTO'];
|
|
type TranscriptionWeeklyStatsDTO = components['schemas']['TranscriptionWeeklyStatsDTO'];
|
|
type DashboardResumeDTO = components['schemas']['DashboardResumeDTO'];
|
|
type DashboardPulseDTO = components['schemas']['DashboardPulseDTO'];
|
|
type ActivityFeedItemDTO = components['schemas']['ActivityFeedItemDTO'];
|
|
|
|
export async function load({ url, fetch }) {
|
|
const q = url.searchParams.get('q') || '';
|
|
const from = url.searchParams.get('from') || '';
|
|
const to = url.searchParams.get('to') || '';
|
|
const senderId = url.searchParams.get('senderId') || '';
|
|
const receiverId = url.searchParams.get('receiverId') || '';
|
|
const tags = url.searchParams.getAll('tag');
|
|
const VALID_SORTS = ['DATE', 'TITLE', 'SENDER', 'RECEIVER', 'UPLOAD_DATE'] as const;
|
|
type ValidSort = (typeof VALID_SORTS)[number];
|
|
const rawSort = url.searchParams.get('sort') ?? 'DATE';
|
|
const sort: ValidSort = (VALID_SORTS as readonly string[]).includes(rawSort)
|
|
? (rawSort as ValidSort)
|
|
: 'DATE';
|
|
const VALID_DIRS = ['asc', 'desc'] as const;
|
|
type ValidDir = (typeof VALID_DIRS)[number];
|
|
const rawDir = url.searchParams.get('dir') ?? 'desc';
|
|
const dir: ValidDir = (VALID_DIRS as readonly string[]).includes(rawDir)
|
|
? (rawDir as ValidDir)
|
|
: 'desc';
|
|
const tagQ = url.searchParams.get('tagQ') || '';
|
|
const tagOp = url.searchParams.get('tagOp') === 'OR' ? 'OR' : 'AND';
|
|
|
|
const isDashboard = !q && !from && !to && !senderId && !receiverId && !tags.length && !tagQ;
|
|
|
|
const api = createApiClient(fetch);
|
|
|
|
try {
|
|
const [docsResult, personsResult] = await Promise.all([
|
|
isDashboard
|
|
? Promise.resolve(null)
|
|
: api.GET('/api/documents/search', {
|
|
params: {
|
|
query: {
|
|
q: q || undefined,
|
|
from: from || undefined,
|
|
to: to || undefined,
|
|
senderId: senderId || undefined,
|
|
receiverId: receiverId || undefined,
|
|
tag: tags.length ? tags : undefined,
|
|
tagQ: tagQ && !tags.length ? tagQ : undefined,
|
|
tagOp: tagOp === 'OR' ? 'OR' : undefined,
|
|
sort,
|
|
dir: dir || undefined
|
|
}
|
|
}
|
|
}),
|
|
api.GET('/api/persons')
|
|
]);
|
|
|
|
if (personsResult.response.status === 401) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
if (docsResult && docsResult.response.status === 401) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
const searchResult = docsResult?.data as {
|
|
documents?: Document[];
|
|
total?: number;
|
|
matchData?: Record<string, SearchMatchData>;
|
|
} | null;
|
|
const documents: Document[] = searchResult?.documents ?? [];
|
|
const total: number = searchResult?.total ?? 0;
|
|
const matchData: Record<string, SearchMatchData> = searchResult?.matchData ?? {};
|
|
const allPersons = (personsResult.data ?? []) as {
|
|
id: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
}[];
|
|
|
|
const senderObj = allPersons.find((p) => p.id === senderId);
|
|
const receiverObj = allPersons.find((p) => p.id === receiverId);
|
|
|
|
let stats: StatsDTO | null = null;
|
|
let resumeDoc: DashboardResumeDTO | null = null;
|
|
let pulse: DashboardPulseDTO | null = null;
|
|
let activityFeed: ActivityFeedItemDTO[] = [];
|
|
let segmentationDocs: TranscriptionQueueItemDTO[] = [];
|
|
let transcriptionDocs: TranscriptionQueueItemDTO[] = [];
|
|
let readyDocs: TranscriptionQueueItemDTO[] = [];
|
|
let weeklyStats: TranscriptionWeeklyStatsDTO | null = null;
|
|
|
|
if (isDashboard) {
|
|
const [
|
|
statsResult,
|
|
resumeResult,
|
|
pulseResult,
|
|
activityResult,
|
|
segmentationResult,
|
|
transcriptionResult,
|
|
readyResult,
|
|
weeklyStatsResult
|
|
] = await Promise.allSettled([
|
|
api.GET('/api/stats'),
|
|
api.GET('/api/dashboard/resume'),
|
|
api.GET('/api/dashboard/pulse'),
|
|
api.GET('/api/dashboard/activity', { params: { query: { limit: 7 } } }),
|
|
api.GET('/api/transcription/segmentation-queue'),
|
|
api.GET('/api/transcription/transcription-queue'),
|
|
api.GET('/api/transcription/ready-to-read'),
|
|
api.GET('/api/transcription/weekly-stats')
|
|
]);
|
|
|
|
if (statsResult.status === 'fulfilled' && statsResult.value.response.ok) {
|
|
stats = statsResult.value.data ?? null;
|
|
}
|
|
if (resumeResult.status === 'fulfilled' && resumeResult.value.response.ok) {
|
|
resumeDoc = (resumeResult.value.data as DashboardResumeDTO) ?? null;
|
|
}
|
|
if (pulseResult.status === 'fulfilled' && pulseResult.value.response.ok) {
|
|
pulse = (pulseResult.value.data as DashboardPulseDTO) ?? null;
|
|
}
|
|
if (activityResult.status === 'fulfilled' && activityResult.value.response.ok) {
|
|
activityFeed = (activityResult.value.data as ActivityFeedItemDTO[]) ?? [];
|
|
}
|
|
if (segmentationResult.status === 'fulfilled' && segmentationResult.value.response.ok) {
|
|
segmentationDocs = (segmentationResult.value.data ?? []) as TranscriptionQueueItemDTO[];
|
|
}
|
|
if (transcriptionResult.status === 'fulfilled' && transcriptionResult.value.response.ok) {
|
|
transcriptionDocs = (transcriptionResult.value.data ?? []) as TranscriptionQueueItemDTO[];
|
|
}
|
|
if (readyResult.status === 'fulfilled' && readyResult.value.response.ok) {
|
|
readyDocs = (readyResult.value.data ?? []) as TranscriptionQueueItemDTO[];
|
|
}
|
|
if (weeklyStatsResult.status === 'fulfilled' && weeklyStatsResult.value.response.ok) {
|
|
weeklyStats = weeklyStatsResult.value.data ?? null;
|
|
}
|
|
}
|
|
|
|
return {
|
|
isDashboard,
|
|
documents,
|
|
total,
|
|
matchData,
|
|
stats,
|
|
resumeDoc,
|
|
pulse,
|
|
activityFeed,
|
|
segmentationDocs,
|
|
transcriptionDocs,
|
|
readyDocs,
|
|
weeklyStats,
|
|
initialValues: {
|
|
senderName: senderObj ? `${senderObj.firstName} ${senderObj.lastName}`.trim() : '',
|
|
receiverName: receiverObj ? `${receiverObj.firstName} ${receiverObj.lastName}`.trim() : ''
|
|
},
|
|
filters: { q, from, to, senderId, receiverId, tags, sort, dir, tagQ, tagOp },
|
|
error: null as string | null
|
|
};
|
|
} catch (e) {
|
|
if ((e as { status?: number }).status) throw e;
|
|
console.error('Error loading data:', e);
|
|
return {
|
|
isDashboard,
|
|
documents: [],
|
|
total: 0,
|
|
matchData: {} as Record<string, SearchMatchData>,
|
|
stats: null,
|
|
resumeDoc: null,
|
|
pulse: null,
|
|
activityFeed: [],
|
|
segmentationDocs: [],
|
|
transcriptionDocs: [],
|
|
readyDocs: [],
|
|
weeklyStats: null,
|
|
initialValues: { senderName: '', receiverName: '' },
|
|
filters: { q, from, to, senderId, receiverId, tags, sort, dir, tagQ, tagOp },
|
|
error: 'Daten konnten nicht geladen werden.' as string | null
|
|
};
|
|
}
|
|
}
|