Files
web-nuxt/app/pages/stage.vue
T
Noel Sabia 836e71c5f4 feat(web): replace UI with greenfield Stitch sensing-engine hero
Rebuild the web frontend around the Stitch hero design: new app shell header with responsive navigation and a single / page preserving the Stitch main/footer copy. Remove the legacy Onyx pages, components, composables and CSS. Add bundled Tailwind 3.4.17 and @nuxt/icon with a locally bundled Material Symbols collection; no icon CDN at runtime. Include design notes for claims to reconcile before the pitch and verification screenshots.
2026-11-14 17:06:35 +01:00

678 lines
16 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { iconSync, iconTriangleWarning } from '@sit-onyx/icons'
import { addDays, berlinParts, planWeekStart } from '#shared/staffing'
import { scenarioLabel } from '#shared/live'
import type { ScenarioState, Sensor, StaffingResponse } from '#shared/types'
import {
formatDateTime,
formatEuro,
formatNumber,
formatPercent,
formatShortDate,
formatTime,
formatWeekday,
weekLabel,
} from '~/utils/format'
import {
peakHourOf,
peakShiftOf,
planDays,
planPulsePoints,
savingOf,
totalStaffHoursOf,
} from '~/utils/plan'
const config = useRuntimeConfig()
const demoNow = String(config.public.demoNow)
const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
const { data: initialScenario } = await useFetch<ScenarioState>('/api/scenario')
const sensorId = ref(
sensors.value?.find((sensor) => sensor.id === 'hn-stadtgalerie-01')?.id ??
sensors.value?.[0]?.id ??
'hn-stadtgalerie-01',
)
const live = useLiveScenario(initialScenario.value)
const {
data: planData,
error: planError,
refresh: refreshPlan,
} = await useFetch<StaffingResponse>('/api/staffing', {
query: computed(() => ({
sensor: sensorId.value,
scenario: live.scenarioId,
standard: 'standard',
})),
})
const {
error: forecastError,
refresh: refreshForecast,
} = await useFetch('/api/forecast', {
query: computed(() => ({
sensor: sensorId.value,
horizon: '7d',
scenario: live.scenarioId,
})),
})
let lastScenarioId = live.scenarioId
watch(
() => live.revision,
() => {
if (live.scenarioId === lastScenarioId) {
void refreshPlan()
void refreshForecast()
}
lastScenarioId = live.scenarioId
},
)
const plan = computed(() => planData.value ?? null)
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
const peakShift = computed(() => peakShiftOf(plan.value))
const peakHour = computed(() => peakHourOf(plan.value))
const totalStaffHours = computed(() => totalStaffHoursOf(plan.value))
const savingEur = computed(() => savingOf(plan.value))
const daySummaries = computed(() => planDays(plan.value))
const pulsePoints = computed(() => planPulsePoints(plan.value))
const weekStart = computed(() => {
const first = plan.value?.hours[0]
return first ? berlinParts(first.t).date : planWeekStart(demoNow)
})
const weekEnd = computed(() => addDays(weekStart.value, 6))
const today = computed(() => berlinParts(demoNow).date)
const windowTag = computed(() => {
if (!plan.value) return 'No plan'
return weekStart.value <= today.value && today.value <= weekEnd.value ? 'Today–Friday' : 'Seven days'
})
const windowLabel = computed(() => (plan.value ? weekLabel(weekStart.value, weekEnd.value) : 'Window unavailable'))
const freshness = computed(() => live.lastEventAt || live.scenarioAt || plan.value?.context_version || '')
const scenarioName = computed(() => scenarioLabel(live.scenarioId))
const reason = computed(() => {
if (peakHour.value) {
return `Peak forecast ${formatNumber(peakHour.value.footfall)} est. devices/hour at ${formatTime(peakHour.value.t)}.`
}
return plan.value?.why[0] ?? 'Waiting for the forecast.'
})
const requestUrl = useRequestURL()
const liveUrl = computed(() => {
const origin = import.meta.client ? window.location.origin : requestUrl.origin
return `${origin}/live`
})
const qrSrc = computed(() => `/api/qr?text=${encodeURIComponent(liveUrl.value)}`)
const changed = ref(false)
let changedTimer: ReturnType<typeof setTimeout> | undefined
let mounted = false
watch(
() => live.revision,
() => {
if (!mounted) return
changed.value = true
if (changedTimer) clearTimeout(changedTimer)
changedTimer = setTimeout(() => {
changed.value = false
}, 8000)
},
)
onMounted(() => {
mounted = true
})
onBeforeUnmount(() => {
if (changedTimer) clearTimeout(changedTimer)
})
useHead({
title: 'Stage — PulseCast live decision',
meta: [{ name: 'theme-color', content: '#0e100e' }],
})
</script>
<template>
<div class="pc-dark stage">
<header class="stage__top">
<div class="stage__brand">
<span class="stage__mark" aria-hidden="true" />
<span>PulseCast</span>
</div>
<div class="stage__context">
<span>{{ scenarioName }}</span>
<span class="stage__sep" aria-hidden="true">/</span>
<span>{{ windowLabel }}</span>
<span class="pc-tag pc-tag--dark">{{ windowTag }}</span>
</div>
<div class="stage__status">
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" dark />
<span class="stage__version">v{{ live.version || '—' }}</span>
</div>
</header>
<section v-if="planError" class="stage__error" role="alert">
<OnyxIcon :icon="iconTriangleWarning" size="28px" color="warning" />
<div>
<h1 class="stage__error-title">The plan is unavailable.</h1>
<p>The plan service did not answer. Retry when the connection is back.</p>
<p v-if="forecastError" class="stage__muted">The forecast refresh also failed.</p>
</div>
<OnyxButton label="Retry" mode="outline" :icon="iconSync" @click="refreshPlan()" />
</section>
<main v-else-if="plan" class="stage__main">
<section class="stage__decision" aria-labelledby="stage-title">
<p class="stage__day">
<template v-if="peakShift">{{ formatWeekday(peakShift.date) }} {{ formatShortDate(peakShift.date) }}</template>
<template v-else>The week</template>
</p>
<h1 id="stage-title" class="stage__number">
<template v-if="peakShift">{{ peakShift.staff }}<span class="stage__unit">staff</span></template>
<template v-else>—</template>
</h1>
<p class="stage__shift">
<template v-if="peakShift">{{ peakShift.start }}–{{ peakShift.end }}</template>
<template v-else>No shift blocks</template>
</p>
<p class="stage__reason">{{ reason }}</p>
<p v-if="changed" class="pc-tag pc-tag--signal stage__changed" role="status">Plan updated</p>
<p class="stage__updated">
Updated {{ freshness ? formatDateTime(freshness) : '—' }} · {{ activeSensor?.name ?? 'Stadtgalerie' }}
</p>
</section>
<section class="stage__board" aria-labelledby="stage-week-title">
<div class="stage__board-head">
<h2 id="stage-week-title" class="pc-label">The week · forecast above, staff below</h2>
<span>{{ windowLabel }} · {{ windowTag }}</span>
</div>
<PulseLine
:points="pulsePoints"
:height="58"
label="Forecast footfall across the plan window, with the peak marked"
/>
<WeekBoard
:days="daySummaries"
:peak-date="peakShift?.date"
large
dark
label="Weekly shift board"
/>
</section>
<aside class="stage__side">
<div class="stage__receipt" aria-label="The week, costed">
<p class="stage__receipt-label">The week, costed</p>
<p class="stage__receipt-value">{{ formatEuro(plan.summary.cost_eur) }}</p>
<div class="stage__receipt-row">
<span>Staff-hours</span>
<strong>{{ totalStaffHours }}</strong>
</div>
<div class="stage__receipt-row">
<span>Flat schedule</span>
<strong>{{ formatEuro(plan.summary.flat_schedule_cost_eur) }}</strong>
</div>
<div class="stage__receipt-row">
<span>Saved</span>
<strong class="stage__green">{{ formatEuro(savingEur) }}</strong>
</div>
<div class="stage__receipt-row">
<span>Coverage</span>
<strong>{{ formatPercent(plan.summary.coverage_pct, 1) }}</strong>
</div>
<div class="stage__receipt-row">
<span>Under requirement</span>
<strong>{{ plan.summary.understaffed_hours }} h</strong>
</div>
<div class="stage__receipt-row">
<span>Over requirement</span>
<strong>{{ plan.summary.overstaffed_hours }} h</strong>
</div>
<p class="stage__receipt-note">Trade-off is visible. Overstaffed hours are not hidden.</p>
</div>
<div class="stage__qr">
<div class="stage__qr-frame">
<img :src="qrSrc" width="220" height="220" :alt="`QR code to ${liveUrl}`" />
</div>
<p class="stage__qr-label">Scan for the live plan</p>
<p class="stage__qr-url">{{ liveUrl }}</p>
</div>
</aside>
</main>
<main v-else class="stage__loading" aria-busy="true">
<div class="pc-skeleton pc-skeleton--dark" style="width: 24rem; height: 2rem" />
<div class="pc-skeleton pc-skeleton--dark" style="width: 34rem; height: 12rem; margin-top: 1.5rem" />
<div class="pc-skeleton pc-skeleton--dark" style="width: 100%; height: 18rem; margin-top: 2rem" />
<p>Building the week…</p>
</main>
<footer class="stage__footer">
<span><strong>Measured</strong> footfall → <strong>modelled</strong> forecast → <strong>declared</strong> assumptions.</span>
<span v-if="plan">
{{ plan.assumptions.visitors_per_staff_hour }} visitors/staff-h ·
×{{ plan.assumptions.safety_factor }} safety ·
{{ plan.assumptions.shift_length_h }} h blocks ·
€{{ plan.assumptions.labor_cost_eur_h }}/h ·
8 sensors in 580 m · no POS data
</span>
<span v-else>No plan data · 8 sensors in 580 m · no POS data</span>
<span>Decision support, not an optimizer.</span>
</footer>
</div>
</template>
<style scoped>
.stage {
display: grid;
min-height: 100dvh;
grid-template-rows: auto 1fr auto;
gap: 1.1rem;
padding: clamp(1.2rem, 2.6vw, 2.6rem) clamp(1.2rem, 3vw, 3.5rem) clamp(1rem, 1.6vw, 1.5rem);
}
.stage__top {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding-bottom: 0.8rem;
border-bottom: 1px solid var(--pc-dark-line);
}
.stage__brand {
display: inline-flex;
align-items: center;
gap: 0.55rem;
color: var(--pc-paper);
font-size: 0.95rem;
font-weight: 800;
letter-spacing: -0.02em;
}
.stage__mark {
display: block;
width: 0.55rem;
height: 1.5rem;
background: var(--pc-signal-bright);
}
.stage__context {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
color: var(--pc-dark-muted);
font-size: 0.74rem;
font-variant-numeric: tabular-nums;
letter-spacing: 0.02em;
}
.stage__sep {
color: var(--pc-dark-line);
}
.stage__status {
display: flex;
align-items: center;
gap: 0.7rem;
}
.stage__version {
color: var(--pc-dark-muted);
font-size: 0.7rem;
font-variant-numeric: tabular-nums;
}
.stage__main {
display: grid;
grid-template-columns: minmax(24rem, 0.9fr) minmax(0, 1.5fr) minmax(17rem, 0.62fr);
gap: clamp(1.5rem, 3vw, 3.2rem);
align-items: center;
min-height: 0;
}
.stage__decision {
display: flex;
min-width: 0;
flex-direction: column;
align-items: flex-start;
gap: 0.2rem;
}
.stage__day {
margin: 0;
color: var(--pc-dark-muted);
font-size: clamp(1.1rem, 1.5vw, 1.55rem);
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage__number {
display: flex;
align-items: baseline;
gap: 0.65rem;
margin: 0.1rem 0 0;
color: var(--pc-signal-bright);
font-size: clamp(10rem, 18vw, 19rem);
font-stretch: 72%;
font-weight: 850;
line-height: 0.76;
letter-spacing: -0.04em;
font-variant-numeric: tabular-nums;
}
.stage__unit {
color: var(--pc-paper);
font-size: clamp(1.4rem, 2.2vw, 2.2rem);
font-stretch: 100%;
font-weight: 700;
letter-spacing: 0;
text-transform: uppercase;
}
.stage__shift {
margin: 0.4rem 0 0;
color: var(--pc-paper);
font-size: clamp(2.4rem, 4.4vw, 4.6rem);
font-weight: 800;
letter-spacing: -0.035em;
line-height: 0.9;
font-variant-numeric: tabular-nums;
}
.stage__reason {
max-width: 30ch;
margin: 0.9rem 0 0;
color: var(--pc-dark-muted);
font-size: clamp(0.95rem, 1.3vw, 1.25rem);
line-height: 1.4;
}
.stage__changed {
margin-top: 0.75rem;
}
.stage__updated {
margin: 0.85rem 0 0;
color: var(--pc-dark-muted);
font-size: clamp(0.68rem, 0.95vw, 0.82rem);
font-variant-numeric: tabular-nums;
letter-spacing: 0.02em;
}
.stage__board {
display: flex;
min-width: 0;
flex-direction: column;
gap: 0.55rem;
}
.stage__board-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 0.5rem;
color: var(--pc-dark-muted);
font-size: 0.72rem;
font-variant-numeric: tabular-nums;
}
.stage__board-head .pc-label {
color: var(--pc-dark-muted);
}
.stage__board :deep(.pc-pulse) {
--pc-pulse-color: var(--pc-dark-line);
}
.stage__side {
display: flex;
min-width: 0;
flex-direction: column;
justify-content: center;
gap: clamp(1.2rem, 2vw, 2rem);
}
.stage__receipt {
padding-top: 0.5rem;
border-top: 3px solid var(--pc-paper);
}
.stage__receipt-label {
margin: 0;
color: var(--pc-dark-muted);
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stage__receipt-value {
margin: 0.25rem 0 0.5rem;
color: var(--pc-paper);
font-size: clamp(2.4rem, 3.4vw, 3.6rem);
font-stretch: 84%;
font-weight: 850;
line-height: 0.9;
letter-spacing: -0.03em;
font-variant-numeric: tabular-nums;
}
.stage__receipt-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 0.6rem;
padding-block: 0.3rem;
border-bottom: 1px solid var(--pc-dark-line);
}
.stage__receipt-row span {
color: var(--pc-dark-muted);
font-size: 0.72rem;
letter-spacing: 0.03em;
}
.stage__receipt-row strong {
color: var(--pc-paper);
font-size: 0.92rem;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.stage__green {
color: var(--pc-green-bright) !important;
}
.stage__receipt-note {
margin: 0.5rem 0 0;
color: var(--pc-dark-muted);
font-size: 0.65rem;
line-height: 1.4;
}
.stage__qr {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.35rem;
}
.stage__qr-frame {
padding: 0.5rem;
background: var(--pc-paper);
}
.stage__qr-frame img {
display: block;
width: clamp(9rem, 11vw, 13rem);
height: auto;
}
.stage__qr-label {
margin: 0.2rem 0 0;
color: var(--pc-paper);
font-size: clamp(1rem, 1.15vw, 1.2rem);
font-weight: 700;
}
.stage__qr-url {
margin: 0;
color: var(--pc-dark-muted);
font-size: 0.66rem;
overflow-wrap: anywhere;
}
.stage__footer {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 0.7rem;
padding-top: 0.65rem;
border-top: 1px solid var(--pc-dark-line);
color: var(--pc-dark-muted);
font-size: 0.66rem;
line-height: 1.4;
}
.stage__footer strong {
color: var(--pc-paper);
font-weight: 700;
}
.stage__error,
.stage__loading {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 1.2rem;
align-self: center;
justify-self: center;
max-width: 60rem;
color: var(--pc-paper);
}
.stage__error {
flex-direction: column;
align-items: flex-start;
gap: 0.7rem;
}
.stage__error-title {
margin: 0;
color: var(--pc-paper);
font-size: clamp(2.5rem, 4vw, 4rem);
font-stretch: 80%;
font-weight: 850;
letter-spacing: -0.03em;
}
.stage__error p {
margin: 0.4rem 0;
color: var(--pc-dark-muted);
}
.stage__muted {
color: var(--pc-dark-muted);
}
.stage__loading {
flex-direction: column;
align-items: flex-start;
}
.stage__loading p {
margin: 0;
color: var(--pc-dark-muted);
}
@media (max-width: 1500px) {
.stage__main {
grid-template-columns: minmax(20rem, 0.9fr) minmax(0, 1.4fr) minmax(15rem, 0.6fr);
gap: 1.5rem;
}
.stage__number {
font-size: clamp(8rem, 15vw, 14rem);
}
.stage__shift {
font-size: clamp(2rem, 3.5vw, 3.6rem);
}
}
@media (max-width: 1100px) {
.stage__main {
grid-template-columns: minmax(0, 1fr);
gap: 1.5rem;
}
.stage__side {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: end;
}
.stage__number {
font-size: clamp(7rem, 25vw, 14rem);
}
.stage__qr {
align-items: flex-end;
}
.stage__qr-frame img {
width: 9rem;
}
}
@media (max-width: 640px) {
.stage {
padding: 0.9rem;
}
.stage__top {
align-items: flex-start;
}
.stage__context {
order: 3;
width: 100%;
}
.stage__main {
gap: 1rem;
}
.stage__number {
font-size: 7.5rem;
}
.stage__shift {
font-size: 2.2rem;
}
.stage__side {
grid-template-columns: minmax(0, 1fr);
}
.stage__qr {
align-items: flex-start;
}
.stage__footer {
flex-direction: column;
}
}
</style>