diff options
| author | zwlucas <lucas.fariamo08@gmail.com> | 2026-05-29 20:21:48 +0000 |
|---|---|---|
| committer | zwlucas <lucas.fariamo08@gmail.com> | 2026-05-29 20:21:48 +0000 |
| commit | d186a989b6808ff39fcd43a9f0b478aebc4aa346 (patch) | |
| tree | abf32684ea56e6066d8584e0378227ffc397ace2 /frontend/src/routes/+page.ts | |
| parent | 6cc0bfd1d79074df790272b8091b1f0226d14283 (diff) | |
| download | yaum-d186a989b6808ff39fcd43a9f0b478aebc4aa346.tar.gz yaum-d186a989b6808ff39fcd43a9f0b478aebc4aa346.zip | |
feat: enhance maintenance management and heartbeat history features
- Updated Store interface to include methods for managing maintenances.
- Modified API functions to support pagination for heartbeat history and added CRUD operations for maintenances.
- Enhanced types to include paginated responses and initial log entries.
- Implemented maintenance management UI in the admin panel with create, edit, and delete functionalities.
- Updated service detail page to display paginated heartbeat history and improved chart rendering.
- Refactored status page to accommodate new data structures and ensure consistent data handling.
Signed-off-by: Lucas Faria Mendes <lucas.fariamo08@gmail.com>
Diffstat (limited to 'frontend/src/routes/+page.ts')
| -rw-r--r-- | frontend/src/routes/+page.ts | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/frontend/src/routes/+page.ts b/frontend/src/routes/+page.ts index ba70169..4f8b3f9 100644 --- a/frontend/src/routes/+page.ts +++ b/frontend/src/routes/+page.ts @@ -4,9 +4,19 @@ export interface EnhancedService extends Service { heartbeats: Heartbeat[]; } +export interface InitialLogEntry { + kind: 'check' | 'created' | 'deleted' | 'transition'; + serviceName: string; + serviceUrl: string; + timestamp: Date; + hb?: Heartbeat; + wasUp?: boolean; +} + export async function load({ fetch }) { let services: EnhancedService[] = []; let error = ''; + let initialLog: InitialLogEntry[] = []; try { const res = await fetch('/api/services'); @@ -18,16 +28,46 @@ export async function load({ fetch }) { try { const hres = await fetch(`/api/services/${svc.id}/history`); if (!hres.ok) throw new Error(`HTTP ${hres.status}`); - const heartbeats: Heartbeat[] = await hres.json(); + const json = await hres.json(); + const heartbeats: Heartbeat[] = Array.isArray(json) ? json : (json.data ?? []); return { ...svc, heartbeats }; } catch { return { ...svc, heartbeats: [] }; } }) ); + + initialLog = []; + for (const svc of services) { + const hbs = svc.heartbeats; + if (hbs.length === 0) continue; + const last = hbs[hbs.length - 1]; + initialLog.push({ + kind: 'check', + serviceName: svc.name, + serviceUrl: svc.url, + timestamp: new Date(last.tested_at), + hb: last + }); + if (hbs.length >= 2) { + const prev = hbs[hbs.length - 2]; + if (prev.is_up !== last.is_up) { + initialLog.push({ + kind: 'transition', + serviceName: svc.name, + serviceUrl: svc.url, + timestamp: new Date(last.tested_at), + hb: last, + wasUp: prev.is_up + }); + } + } + } + initialLog.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime()); + initialLog = initialLog.slice(0, 50); } catch (e) { error = 'Não foi possível conectar ao servidor'; } - return { services, error }; + return { services, error, initialLog }; } |