/* global React, Card, StatCard, StatusBadge, StatusGlyph, STATUS_META, Ic, Button, VS */ function Dashboard({ onOpenRecent }) { const [data, setData] = React.useState(null); const [recent, setRecent] = React.useState(null); const [err, setErr] = React.useState(''); React.useEffect(() => { (async () => { try { const [d, r] = await Promise.all([VS.dashboard(), VS.recentSessions(12)]); setData(d); setRecent(r); } catch (e) { setErr(e.message); } })(); }, []); const now = new Date(); const dayStr = now.toLocaleDateString('pl-PL', { weekday: 'long' }); const fullDate = now.toLocaleDateString('pl-PL', { day: 'numeric', month: 'long', year: 'numeric' }); if (err) return ; if (!data) return ; const okPct = data.total_machines ? Math.round((data.machines_ok / data.total_machines) * 100) : 0; const warn = data.machines_warn || 0; const alarm = data.machines_alarm || 0; const needAttention = warn + alarm; return (
{dayStr}, {fullDate}

Dzień dobry, {VS.getUsername() || 'inżynierze'}.

System monitoruje {fmtInt(data.total_machines)} maszyn w {fmtInt(data.total_sites)} zakładach. {needAttention > 0 ? ( <> {needAttention} maszyn wymaga uwagi. ) : ( <> wszystko w normie. )}
{data.daily_stats?.length > 0 && (

Puls systemu

ostatnie {data.daily_stats.length} dni · pomiary / ostrzeżenia / alarmy
OK Ostrz. Alarm
)}

Ostatnie pomiary

{recent ? `${recent.length} sesji` : '…'}
{recent && recent.length === 0 &&
Brak pomiarów.
} {recent && recent.map((r, i) => { const st = statusFromAlarm(r.max_alarm); return (
onOpenRecent && onOpenRecent(r)} style={{ display: 'grid', gridTemplateColumns: '72px 1fr 80px 100px', gap: 12, padding: '10px 16px', borderBottom: i < recent.length - 1 ? '1px solid var(--hairline)' : 'none', alignItems: 'center', fontSize: 12, cursor: onOpenRecent ? 'pointer' : 'default', }} onMouseEnter={(e) => { e.currentTarget.style.background = 'var(--bg-sunken)'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; }} > {r.time_start || '—'} {r.machine_name} {r.point_count} pkt
); })}
Wskazówka dnia
Porównuj wartości VEL RMS (prędkości drgań w mm/s) z normą ISO 10816-3 dla danej klasy maszyny. Wartości w strefie C (powyżej 4,5 mm/s dla maszyn klasy II) oznaczają, że praca długoterminowa jest niedopuszczalna — zaplanuj serwis.
ISO 10816-3 · Klasa II < 15 kW
); } function DailyBars({ days }) { const max = Math.max(...days.map(d => d.sessions || 0), 1); return (
{days.map((d, i) => { const total = d.sessions || 0; const alarms = d.alarms || 0; const warns = d.warnings || 0; const ok = Math.max(0, total - alarms - warns); const pct = (v) => (v / max) * 100; const label = d.date ? d.date.slice(5) : ''; return (
{total}
{ok > 0 &&
} {warns > 0 &&
} {alarms > 0 &&
}
{label}
); })}
); } function LoadingState() { return
Ładowanie…
; } function ErrorState({ message }) { return (
{message}
); } function fmtInt(n) { return (n || 0).toLocaleString('pl-PL'); } function statusFromAlarm(level) { if (!level && level !== 0) return 'idle'; if (level >= 3) return 'alarm'; if (level >= 2) return 'warn'; return 'ok'; } Object.assign(window, { Dashboard, LoadingState, ErrorState, statusFromAlarm, fmtInt });