feat: live SSE stage, phone view and presenter control
- proxy Go /api/stream through Nitro; drive /stage, /live, /plan and /forecast from scenario events - fall back to 5 s polling after SSE failures or heartbeat silence; show Live/Polling/Offline - authenticate /control and POST /api/scenario in Nitro with server-side control credentials - add big-screen stage with local QR and a no-login phone recommendation view - add SSE unit tests and a live smoke test; refresh README/Makefile
This commit is contained in:
1 parent
7181562e0f
commit
233fdbf66c
24 files changed
+2757
-49
No files matched your search
+3
-3
@@ -8,7 +8,7 @@ useHead({ title: 'About the data and limits — PulseCast' })
|
||||
const { data: meta } = await useFetch<MetaResponse>('/api/meta')
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const usingMock = computed(() => Boolean(config.public.useMock))
|
||||
const usingMock = computed(() => ['1', 'true'].includes(String(config.public.useMock).toLowerCase()))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -87,7 +87,7 @@ const usingMock = computed(() => Boolean(config.public.useMock))
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Context version</th><td class="mono">{{ meta?.context_version ?? '—' }}</td></tr>
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Coverage</th><td>{{ meta ? `${formatDate(meta.coverage.from)} → ${formatDate(meta.coverage.to)}` : '—' }}</td></tr>
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Validation</th><td>{{ meta ? `WAPE ${formatPercent(meta.metrics.wape, 1)} · baseline ${formatPercent(meta.metrics.baseline_wape, 1)} · R² ${meta.metrics.r2}` : '—' }}</td></tr>
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Weather source</th><td>Open-Meteo archive + forecast via `/api/context`</td></tr>
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Weather source</th><td>Open-Meteo archive + forecast via /api/context</td></tr>
|
||||
<tr><th scope="row" style="text-align: left; font-weight: 600">Holidays</th><td>Baden-Württemberg 2025–2026 public holidays</td></tr>
|
||||
</OnyxTable>
|
||||
<p class="small muted table-note">Meta comes from Go <code>/api/meta</code> through the Nitro proxy.</p>
|
||||
@@ -139,7 +139,7 @@ const usingMock = computed(() => Boolean(config.public.useMock))
|
||||
service; the plan heuristic is the shared implementation in <code>shared/staffing.ts</code>.
|
||||
</p>
|
||||
<p v-else class="small muted" style="margin-top: 0">
|
||||
The browser only talks to this Nuxt origin. Nitro proxies `/api/*` to the Go API at
|
||||
The browser only talks to this Nuxt origin. Nitro proxies /api/* to the Go API at
|
||||
<code>NUXT_API_INTERNAL_BASE</code>; forecast, context and meta are served from there.
|
||||
</p>
|
||||
<p class="small muted" style="margin: 0">
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
iconArrowRight,
|
||||
iconCircleCheck,
|
||||
iconCircleX,
|
||||
iconPresentionBoard,
|
||||
iconSync,
|
||||
iconTriangleWarning,
|
||||
} from '@sit-onyx/icons'
|
||||
import { scenarioLabel } from '#shared/live'
|
||||
import type { ScenarioPreset, ScenarioState } from '#shared/types'
|
||||
import { apiErrorMessage } from '~/utils/api-error'
|
||||
import { formatDateTime } from '~/utils/format'
|
||||
|
||||
useHead({ title: 'Presenter control — PulseCast' })
|
||||
|
||||
const { data: initialScenario } = await useFetch<ScenarioState>('/api/scenario')
|
||||
const { data: presets, error: presetsError } = await useFetch<ScenarioPreset[]>('/api/scenarios')
|
||||
|
||||
const live = useLiveScenario(initialScenario.value)
|
||||
const submitted = ref<ScenarioState | null>(null)
|
||||
const busy = ref('')
|
||||
const message = ref('')
|
||||
const errorMessage = ref('')
|
||||
|
||||
const current = computed(() => submitted.value ?? live.scenario ?? initialScenario.value ?? null)
|
||||
const activeId = computed(() => current.value?.scenario.scenario ?? '')
|
||||
const presetList = computed(() => presets.value ?? [])
|
||||
|
||||
function applyBody(preset: ScenarioPreset) {
|
||||
return {
|
||||
scenario: preset.id,
|
||||
weather: preset.weather ?? {},
|
||||
event: preset.event,
|
||||
}
|
||||
}
|
||||
|
||||
async function apply(preset: ScenarioPreset) {
|
||||
if (busy.value) return
|
||||
busy.value = preset.id
|
||||
message.value = ''
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const response = await $fetch<ScenarioState>('/api/scenario', {
|
||||
method: 'POST',
|
||||
body: applyBody(preset),
|
||||
})
|
||||
submitted.value = response
|
||||
message.value = `${preset.label} is now live · version ${response.version}.`
|
||||
} catch (error) {
|
||||
errorMessage.value =
|
||||
apiErrorMessage(error, 'The scenario change failed. Check the Go API and control credentials.') +
|
||||
(String((error as { status?: number }).status) === '401'
|
||||
? ' Reload this page to sign in again.'
|
||||
: '')
|
||||
} finally {
|
||||
busy.value = ''
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page-stack control-page">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Presenter control · not linked in public navigation</p>
|
||||
<OnyxHeadline is="h1">Change the scenario once. Every screen follows.</OnyxHeadline>
|
||||
<p class="lede">
|
||||
Each button POSTs to this Nuxt origin. Nitro attaches the Go control credentials server-side; the browser
|
||||
never sees them. <NuxtLink to="/stage">Stage</NuxtLink> and <NuxtLink to="/live">Live</NuxtLink> update through
|
||||
SSE, with a 5-second polling fallback.
|
||||
</p>
|
||||
</div>
|
||||
<div class="hero-actions">
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" />
|
||||
<OnyxBadge v-if="current" color="neutral" density="compact">v{{ current.version }}</OnyxBadge>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="errorMessage" class="callout callout--warning" role="alert">
|
||||
<OnyxIcon :icon="iconCircleX" size="16px" color="danger" />
|
||||
<span>{{ errorMessage }}</span>
|
||||
</div>
|
||||
<div v-if="message" class="callout" role="status">
|
||||
<OnyxIcon :icon="iconCircleCheck" size="16px" color="success" />
|
||||
<span>{{ message }}</span>
|
||||
</div>
|
||||
|
||||
<div class="split-grid">
|
||||
<div class="card-stack">
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
<OnyxHeadline is="h2">Scenario presets</OnyxHeadline>
|
||||
<p class="small muted" style="margin: 0">
|
||||
The enum is fixed by CONTRACT.md. Weather and event values match the demo narrative.
|
||||
</p>
|
||||
</div>
|
||||
<OnyxBadge color="info" density="compact">server proxy</OnyxBadge>
|
||||
</div>
|
||||
|
||||
<div v-if="presetList.length" class="scenario-grid">
|
||||
<button
|
||||
v-for="preset in presetList"
|
||||
:key="preset.id"
|
||||
type="button"
|
||||
class="scenario-button"
|
||||
:class="{ 'scenario-button--active': preset.id === activeId }"
|
||||
:disabled="Boolean(busy)"
|
||||
:aria-pressed="preset.id === activeId"
|
||||
@click="apply(preset)"
|
||||
>
|
||||
<span class="scenario-button__head">
|
||||
<strong>{{ preset.label }}</strong>
|
||||
<OnyxBadge v-if="preset.id === activeId" color="success" density="compact">on stage</OnyxBadge>
|
||||
<OnyxBadge v-else color="neutral" density="compact">{{ preset.short }}</OnyxBadge>
|
||||
</span>
|
||||
<span class="small muted">{{ preset.description }}</span>
|
||||
<span v-if="busy === preset.id" class="scenario-button__busy">
|
||||
<OnyxIcon :icon="iconSync" size="16px" color="primary" class="spin" />
|
||||
Broadcasting…
|
||||
</span>
|
||||
<span v-else class="scenario-button__action">
|
||||
Apply
|
||||
<OnyxIcon :icon="iconArrowRight" size="16px" color="primary" />
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else class="callout callout--warning">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="16px" color="warning" />
|
||||
Scenario presets could not be loaded.
|
||||
<span v-if="presetsError" class="muted">{{ presetsError.statusMessage }}</span>
|
||||
</div>
|
||||
</OnyxCard>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h2">Open the audience views</OnyxHeadline>
|
||||
<OnyxIcon :icon="iconPresentionBoard" size="24px" color="primary" />
|
||||
</div>
|
||||
<div class="hero-actions">
|
||||
<OnyxButton label="Open /stage" link="/stage" color="primary" />
|
||||
<OnyxButton label="Open /live" link="/live" mode="outline" />
|
||||
<OnyxButton label="Open /plan" link="/plan" mode="outline" />
|
||||
</div>
|
||||
<p class="small muted table-note">
|
||||
Put <code>/stage</code> on the projector and let the audience scan the QR code. <code>/live</code> needs no
|
||||
login and keeps the last known plan if the stream drops.
|
||||
</p>
|
||||
</OnyxCard>
|
||||
</div>
|
||||
|
||||
<aside class="card-stack">
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h2">Current scenario</OnyxHeadline>
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" compact />
|
||||
</div>
|
||||
<p class="control-current">{{ current ? scenarioLabel(current.scenario.scenario) : 'Unavailable' }}</p>
|
||||
<dl class="metric-list">
|
||||
<div><dt>Version</dt><dd>{{ current?.version ?? '—' }}</dd></div>
|
||||
<div><dt>Broadcast at</dt><dd>{{ current ? formatDateTime(current.at) : '—' }}</dd></div>
|
||||
<div><dt>Last SSE event</dt><dd>{{ live.lastEventAt ? formatDateTime(live.lastEventAt) : '—' }}</dd></div>
|
||||
<div><dt>Transport</dt><dd>{{ live.statusLabel }}</dd></div>
|
||||
</dl>
|
||||
<p v-if="live.error" class="small muted table-note">{{ live.error }}</p>
|
||||
</OnyxCard>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<OnyxHeadline is="h3">What the presenter says</OnyxHeadline>
|
||||
</div>
|
||||
<ul class="why-list">
|
||||
<li><span><strong>Base week</strong> — normal weather, no event uplift.</span></li>
|
||||
<li><span><strong>Sunny Saturday + market</strong> — the Saturday plan should add staff.</span></li>
|
||||
<li><span><strong>Rainy Saturday</strong> — the Saturday plan should shed staff.</span></li>
|
||||
<li><span><strong>Wednesday event</strong> — the weekday evening block should rise.</span></li>
|
||||
</ul>
|
||||
<p class="small muted table-note">
|
||||
If the numbers do not move on stage, check the <code>cached</code> badge: Go may be serving its last good
|
||||
forecast because the ML service is down.
|
||||
</p>
|
||||
</OnyxCard>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.control-current {
|
||||
margin: 0 0 var(--onyx-density-md);
|
||||
color: var(--onyx-color-text-icons-primary-intense);
|
||||
font-size: clamp(1.6rem, 3vw, 2.4rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.scenario-button {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--onyx-density-xs);
|
||||
width: 100%;
|
||||
padding: var(--onyx-density-md);
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: var(--onyx-color-base-neutral-100);
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.scenario-button:hover:not(:disabled),
|
||||
.scenario-button:focus-visible {
|
||||
border-color: var(--onyx-color-base-primary-500);
|
||||
outline: 2px solid var(--onyx-color-base-primary-300);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.scenario-button:disabled {
|
||||
cursor: progress;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.scenario-button--active {
|
||||
border-color: var(--onyx-color-base-primary-600);
|
||||
background: var(--onyx-color-base-primary-100);
|
||||
}
|
||||
|
||||
.scenario-button__head,
|
||||
.scenario-button__action,
|
||||
.scenario-button__busy {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--onyx-density-xs);
|
||||
}
|
||||
|
||||
.scenario-button__action,
|
||||
.scenario-button__busy {
|
||||
justify-content: flex-start;
|
||||
margin-top: var(--onyx-density-xs);
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
.spin {
|
||||
animation: spin 0.9s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.spin {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+57
-17
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { iconCalendar, iconChart } from '@sit-onyx/icons'
|
||||
import { iconCalendar, iconChart, iconTriangleWarning } from '@sit-onyx/icons'
|
||||
import { dailyWeather } from '#shared/insights'
|
||||
import { berlinParts, planWeekStart, STANDARD_VISITORS_PER_STAFF_HOUR } from '#shared/staffing'
|
||||
import type { ContextResponse, ForecastResponse, MetaResponse, Point, Scenario, ScenarioPreset, Sensor } from '#shared/types'
|
||||
import type { ContextResponse, ForecastResponse, MetaResponse, Point, Scenario, ScenarioPreset, ScenarioState, Sensor } from '#shared/types'
|
||||
import { formatDate, formatNumber, formatPercent, formatShortDate, formatWeekday, formatWeekdayShort, weekLabel } from '~/utils/format'
|
||||
|
||||
useHead({ title: 'Forecast — PulseCast' })
|
||||
@@ -21,16 +21,31 @@ const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
|
||||
const { data: context } = await useFetch<ContextResponse>('/api/context')
|
||||
const { data: meta } = await useFetch<MetaResponse>('/api/meta')
|
||||
const { data: presets } = await useFetch<ScenarioPreset[]>('/api/scenarios')
|
||||
const { data: liveScenarioState } = await useFetch<ScenarioState>('/api/scenario')
|
||||
const live = useLiveScenario(liveScenarioState.value)
|
||||
scenario.value = live.scenarioId
|
||||
|
||||
sensorId.value =
|
||||
sensors.value?.find((sensor) => sensor.id === 'hn-stadtgalerie-01')?.id ??
|
||||
sensors.value?.[0]?.id ??
|
||||
sensorId.value
|
||||
|
||||
const { data: forecast } = await useFetch<ForecastResponse>('/api/forecast', {
|
||||
const {
|
||||
data: forecast,
|
||||
error: forecastError,
|
||||
refresh: refreshForecast,
|
||||
} = await useFetch<ForecastResponse>('/api/forecast', {
|
||||
query: computed(() => ({ sensor: sensorId.value, horizon: '7d', scenario: scenario.value })),
|
||||
})
|
||||
|
||||
watch(
|
||||
() => live.revision,
|
||||
() => {
|
||||
if (live.scenarioId !== scenario.value) scenario.value = live.scenarioId
|
||||
else void refreshForecast()
|
||||
},
|
||||
)
|
||||
|
||||
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
|
||||
const sensorOptions = computed(() =>
|
||||
(sensors.value ?? []).map((sensor) => ({ value: sensor.id, label: sensor.name })),
|
||||
@@ -81,9 +96,14 @@ const weekPeak = computed(() =>
|
||||
days.value.length ? days.value.reduce((best, day) => (day.peak > best.peak ? day : best)) : undefined,
|
||||
)
|
||||
const dayMax = computed(() => Math.max(...days.value.map((day) => day.peak), 1))
|
||||
// The API 7-day window starts at the current hour, so it spans up to eight
|
||||
// calendar days. Label the real window instead of the Monday plan week.
|
||||
const forecastStart = computed(() => days.value[0]?.date ?? weekStart)
|
||||
const forecastEnd = computed(() => days.value.at(-1)?.date ?? weekEnd)
|
||||
const forecastWindow = computed(() => weekLabel(forecastStart.value, forecastEnd.value))
|
||||
const weekWeather = computed(() =>
|
||||
Object.values(dailyWeather(context.value?.weather.forecast ?? []))
|
||||
.filter((day) => day.date >= weekStart && day.date <= weekEnd)
|
||||
.filter((day) => day.date >= forecastStart.value && day.date <= forecastEnd.value)
|
||||
.sort((a, b) => a.date.localeCompare(b.date)),
|
||||
)
|
||||
const total = computed(() => days.value.reduce((sum, day) => sum + day.mean, 0))
|
||||
@@ -93,24 +113,37 @@ const total = computed(() => days.value.reduce((sum, day) => sum + day.mean, 0))
|
||||
<div class="page page-stack">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Forecast · {{ weekLabel(weekStart, weekEnd) }}</p>
|
||||
<p class="eyebrow">Forecast · {{ forecastWindow }}</p>
|
||||
<OnyxHeadline is="h1">Next week peaks on {{ weekPeak ? formatWeekday(weekPeak.date) : '—' }}.</OnyxHeadline>
|
||||
<p class="lede">
|
||||
A 168-hour forecast for <strong>{{ activeSensor?.name ?? 'the selected store' }}</strong>, aggregated by
|
||||
day. The decision, shift blocks and hourly coverage are on <NuxtLink to="/plan">Plan</NuxtLink>.
|
||||
</p>
|
||||
</div>
|
||||
<div style="min-width: 14rem">
|
||||
<OnyxSelect
|
||||
v-model="sensorId"
|
||||
label="Sensor"
|
||||
list-label="Inner-city sensors"
|
||||
:options="sensorOptions"
|
||||
density="compact"
|
||||
/>
|
||||
<div class="forecast-header-controls">
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" />
|
||||
<div style="min-width: 14rem">
|
||||
<OnyxSelect
|
||||
v-model="sensorId"
|
||||
label="Sensor"
|
||||
list-label="Inner-city sensors"
|
||||
:options="sensorOptions"
|
||||
density="compact"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="forecastError" class="callout callout--warning" role="alert">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="16px" color="warning" />
|
||||
The forecast could not be loaded. <span class="muted">{{ forecastError.statusMessage }}</span>
|
||||
<OnyxButton label="Retry" mode="plain" density="compact" @click="refreshForecast()" />
|
||||
</div>
|
||||
<div v-else-if="forecast && !days.length" class="callout callout--warning" role="status">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="16px" color="warning" />
|
||||
No forecast points are available for this store yet. Try another sensor.
|
||||
</div>
|
||||
|
||||
<OnyxCard>
|
||||
<div class="card-header">
|
||||
<div>
|
||||
@@ -216,8 +249,7 @@ const total = computed(() => days.value.reduce((sum, day) => sum + day.mean, 0))
|
||||
<li>
|
||||
<OnyxIcon :icon="iconCalendar" size="16px" color="primary" />
|
||||
<span>
|
||||
Forecast covers {{ formatDate(days[0]?.date ?? weekStart) }} →
|
||||
{{ formatDate(days[days.length - 1]?.date ?? weekEnd) }} in Europe/Berlin.
|
||||
Forecast covers {{ formatDate(forecastStart) }} → {{ formatDate(forecastEnd) }} in Europe/Berlin.
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -230,7 +262,7 @@ const total = computed(() => days.value.reduce((sum, day) => sum + day.mean, 0))
|
||||
<style scoped>
|
||||
.forecast-bars {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, minmax(0, 1fr));
|
||||
grid-template-columns: repeat(auto-fit, minmax(4.5rem, 1fr));
|
||||
gap: var(--onyx-density-xs);
|
||||
align-items: end;
|
||||
min-height: 13rem;
|
||||
@@ -264,9 +296,17 @@ const total = computed(() => days.value.reduce((sum, day) => sum + day.mean, 0))
|
||||
background: var(--onyx-color-base-primary-500);
|
||||
}
|
||||
|
||||
.forecast-header-controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
@media (max-width: 576px) {
|
||||
.forecast-bars {
|
||||
gap: 2px;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: var(--onyx-density-2xs);
|
||||
}
|
||||
|
||||
.forecast-bar strong {
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
iconArrowRight,
|
||||
iconCircleInformation,
|
||||
iconMobileSignal,
|
||||
iconSync,
|
||||
iconTriangleWarning,
|
||||
iconUserGroup,
|
||||
} from '@sit-onyx/icons'
|
||||
import { scenarioLabel } from '#shared/live'
|
||||
import type { ScenarioState, Sensor, Shift, StaffingResponse } from '#shared/types'
|
||||
import { formatDateTime, formatEuro, formatNumber, formatPercent, formatShortDate, formatWeekday } from '~/utils/format'
|
||||
|
||||
useHead({ title: 'Live recommendation — PulseCast' })
|
||||
|
||||
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,
|
||||
status: planStatus,
|
||||
error: planError,
|
||||
refresh: refreshPlan,
|
||||
} = await useFetch<StaffingResponse>('/api/staffing', {
|
||||
query: computed(() => ({
|
||||
sensor: sensorId.value,
|
||||
scenario: live.scenarioId,
|
||||
standard: 'standard',
|
||||
})),
|
||||
})
|
||||
|
||||
let lastScenarioId = live.scenarioId
|
||||
watch(
|
||||
() => live.revision,
|
||||
() => {
|
||||
if (live.scenarioId === lastScenarioId) void refreshPlan()
|
||||
lastScenarioId = live.scenarioId
|
||||
},
|
||||
)
|
||||
|
||||
const plan = computed(() => planData.value ?? null)
|
||||
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
|
||||
|
||||
function maxOf<T>(items: T[], score: (item: T) => number): T | undefined {
|
||||
let best: T | undefined
|
||||
for (const item of items) if (!best || score(item) > score(best)) best = item
|
||||
return best
|
||||
}
|
||||
|
||||
const peakShift = computed<Shift | undefined>(() =>
|
||||
plan.value ? maxOf(plan.value.shifts, (shift) => shift.staff) : undefined,
|
||||
)
|
||||
const peakStaff = computed(() => peakShift.value?.staff ?? 0)
|
||||
const totalStaffHours = computed(() =>
|
||||
plan.value ? plan.value.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0) : 0,
|
||||
)
|
||||
const currentReason = computed(() => plan.value?.why[0] ?? '')
|
||||
const lastUpdate = computed(() => {
|
||||
if (live.scenarioAt) return live.scenarioAt
|
||||
return plan.value?.context_version ?? ''
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page-stack live-page">
|
||||
<header class="live-header">
|
||||
<div>
|
||||
<p class="eyebrow">Live · no login</p>
|
||||
<OnyxHeadline is="h1">The plan on your phone.</OnyxHeadline>
|
||||
<p class="lede">
|
||||
{{ activeSensor?.name ?? 'Stadtgalerie' }} · {{ scenarioLabel(live.scenarioId) }}. Updates arrive over SSE;
|
||||
if the stream drops, this page polls every 5 seconds.
|
||||
</p>
|
||||
</div>
|
||||
<div class="live-header__status">
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" />
|
||||
<OnyxBadge color="neutral" density="compact">v{{ live.version || '—' }}</OnyxBadge>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="planError" class="callout callout--warning" role="alert">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="18px" color="warning" />
|
||||
<div>
|
||||
<strong>The live plan is unavailable.</strong>
|
||||
<span class="muted"> {{ planError.statusMessage ?? 'The API did not answer.' }}</span>
|
||||
</div>
|
||||
<OnyxButton label="Retry" mode="outline" density="compact" :icon="iconSync" @click="refreshPlan()" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="planStatus === 'pending' && !plan" class="callout">
|
||||
<OnyxIcon :icon="iconSync" size="18px" color="primary" />
|
||||
<span>Loading the current recommendation…</span>
|
||||
</div>
|
||||
|
||||
<div v-else-if="plan && !plan.shifts.length" class="callout callout--warning" role="status">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="18px" color="warning" />
|
||||
<span>No shift blocks are available yet. The presenter may still be preparing the plan.</span>
|
||||
</div>
|
||||
|
||||
<section class="live-hero" aria-labelledby="live-decision">
|
||||
<p class="live-hero__kicker"><OnyxIcon :icon="iconUserGroup" size="18px" color="primary" /> Current recommendation</p>
|
||||
<p id="live-decision" class="live-hero__value">
|
||||
<template v-if="plan">{{ peakStaff }} staff</template>
|
||||
<template v-else>No plan yet</template>
|
||||
</p>
|
||||
<p class="live-hero__shift">
|
||||
<template v-if="peakShift">
|
||||
<strong>{{ formatWeekday(peakShift.date) }} {{ formatShortDate(peakShift.date) }}</strong><br />
|
||||
{{ peakShift.start }}–{{ peakShift.end }} · peak shift
|
||||
</template>
|
||||
<template v-else>Waiting for the peak shift</template>
|
||||
</p>
|
||||
<p v-if="currentReason" class="live-hero__why">
|
||||
<OnyxIcon :icon="iconCircleInformation" size="16px" color="primary" />
|
||||
<span>{{ currentReason }}</span>
|
||||
</p>
|
||||
<OnyxButton
|
||||
label="Open the full plan"
|
||||
:link="`/plan?scenario=${live.scenarioId}`"
|
||||
color="primary"
|
||||
:icon="iconArrowRight"
|
||||
icon-position="right"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section class="live-metrics" aria-label="Plan at a glance">
|
||||
<div class="live-metric">
|
||||
<p class="live-metric__label">Staff-hours</p>
|
||||
<p class="live-metric__value">{{ plan ? formatNumber(totalStaffHours) : '—' }}</p>
|
||||
</div>
|
||||
<div class="live-metric">
|
||||
<p class="live-metric__label">Labour cost</p>
|
||||
<p class="live-metric__value">{{ plan ? formatEuro(plan.summary.cost_eur) : '—' }}</p>
|
||||
</div>
|
||||
<div class="live-metric">
|
||||
<p class="live-metric__label">Coverage</p>
|
||||
<p class="live-metric__value">{{ plan ? formatPercent(plan.summary.coverage_pct, 1) : '—' }}</p>
|
||||
</div>
|
||||
<div class="live-metric">
|
||||
<p class="live-metric__label">Understaffed</p>
|
||||
<p class="live-metric__value">{{ plan ? `${plan.summary.understaffed_hours} h` : '—' }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="live-status-card">
|
||||
<div class="live-status-card__row">
|
||||
<span class="live-status-card__label">Scenario</span>
|
||||
<strong>{{ scenarioLabel(live.scenarioId) }}</strong>
|
||||
</div>
|
||||
<div class="live-status-card__row">
|
||||
<span class="live-status-card__label">Version</span>
|
||||
<span>{{ live.version || '—' }}</span>
|
||||
</div>
|
||||
<div class="live-status-card__row">
|
||||
<span class="live-status-card__label">Last update</span>
|
||||
<span>{{ lastUpdate ? formatDateTime(lastUpdate) : '—' }}</span>
|
||||
</div>
|
||||
<div class="live-status-card__row">
|
||||
<span class="live-status-card__label">Transport</span>
|
||||
<span>{{ live.statusLabel }}<template v-if="live.status === 'polling'"> · 5 s</template></span>
|
||||
</div>
|
||||
<p v-if="live.error" class="small muted table-note">{{ live.error }}</p>
|
||||
</section>
|
||||
|
||||
<footer class="live-footer">
|
||||
<p>
|
||||
<strong>Decision support, not an optimizer.</strong> The plan uses
|
||||
{{ plan?.assumptions.visitors_per_staff_hour ?? 25 }} visitors per staff-hour,
|
||||
×{{ plan?.assumptions.safety_factor ?? 1.15 }} safety, {{ plan?.assumptions.shift_length_h ?? 4 }} h shift
|
||||
blocks and €{{ plan?.assumptions.labor_cost_eur_h ?? 16 }}/h.
|
||||
</p>
|
||||
<p class="muted">
|
||||
Estimated devices, not people · {{ sensors?.length ?? 8 }} sensors in a 580 m cluster · no POS, sales or
|
||||
payroll data.
|
||||
</p>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.live-page {
|
||||
max-width: 44rem;
|
||||
gap: clamp(0.85rem, 2vw, 1.25rem);
|
||||
}
|
||||
|
||||
.live-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
.live-header h1 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.live-header__status {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--onyx-density-xs);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.live-hero {
|
||||
padding: clamp(1.1rem, 3vw, 1.75rem);
|
||||
border: 1px solid var(--onyx-color-base-primary-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background:
|
||||
radial-gradient(circle at 100% 0%, var(--onyx-color-base-primary-200), transparent 48%),
|
||||
linear-gradient(135deg, var(--onyx-color-base-primary-100), var(--onyx-color-base-neutral-100) 72%);
|
||||
}
|
||||
|
||||
.live-hero__kicker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin: 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.live-hero__value {
|
||||
margin: var(--onyx-density-xs) 0 0;
|
||||
font-size: clamp(3rem, 16vw, 5.5rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.04em;
|
||||
line-height: 0.95;
|
||||
color: var(--onyx-color-text-icons-primary-intense);
|
||||
}
|
||||
|
||||
.live-hero__shift {
|
||||
margin: var(--onyx-density-sm) 0 0;
|
||||
font-size: clamp(1rem, 3.5vw, 1.25rem);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.live-hero__why {
|
||||
display: flex;
|
||||
gap: var(--onyx-density-xs);
|
||||
align-items: flex-start;
|
||||
margin: var(--onyx-density-md) 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.live-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
.live-metric {
|
||||
min-width: 0;
|
||||
padding: var(--onyx-density-md);
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: var(--onyx-color-base-neutral-100);
|
||||
}
|
||||
|
||||
.live-metric__label {
|
||||
margin: 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.78rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.live-metric__value {
|
||||
margin: var(--onyx-density-xs) 0 0;
|
||||
font-size: clamp(1.35rem, 6vw, 1.9rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.live-status-card {
|
||||
display: grid;
|
||||
gap: var(--onyx-density-xs);
|
||||
padding: var(--onyx-density-md);
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: var(--onyx-color-base-neutral-100);
|
||||
}
|
||||
|
||||
.live-status-card__row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
.live-status-card__label {
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.live-footer {
|
||||
padding-top: var(--onyx-density-sm);
|
||||
border-top: 1px solid var(--onyx-color-base-neutral-300);
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.live-footer p {
|
||||
margin: 0 0 var(--onyx-density-xs);
|
||||
}
|
||||
|
||||
@media (min-width: 577px) {
|
||||
.live-metrics {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+25
-5
@@ -24,6 +24,7 @@ import type {
|
||||
MetaResponse,
|
||||
Scenario,
|
||||
ScenarioPreset,
|
||||
ScenarioState,
|
||||
Sensor,
|
||||
Shift,
|
||||
StaffingHour,
|
||||
@@ -68,9 +69,13 @@ const { data: sensors } = await useFetch<Sensor[]>('/api/sensors')
|
||||
const { data: context } = await useFetch<ContextResponse>('/api/context')
|
||||
const { data: meta } = await useFetch<MetaResponse>('/api/meta')
|
||||
const { data: presets } = await useFetch<ScenarioPreset[]>('/api/scenarios')
|
||||
const { data: liveScenarioState } = await useFetch<ScenarioState>('/api/scenario')
|
||||
const live = useLiveScenario(liveScenarioState.value)
|
||||
|
||||
const sensorId = ref(preferredSensor(sensors.value))
|
||||
const scenario = ref<Scenario>(initialScenario())
|
||||
// The stage scenario wins unless the URL explicitly asks for another one.
|
||||
if (!route.query.scenario) scenario.value = live.scenarioId
|
||||
const standard = ref<Standard>('standard')
|
||||
const approved = ref(false)
|
||||
const generating = ref(false)
|
||||
@@ -128,6 +133,16 @@ watch(
|
||||
},
|
||||
)
|
||||
|
||||
// A scenario event changes the plan. If the enum is unchanged (same scenario,
|
||||
// new override/version), the query string does not move, so refresh it here.
|
||||
watch(
|
||||
() => live.revision,
|
||||
() => {
|
||||
if (live.scenarioId !== scenario.value) scenario.value = live.scenarioId
|
||||
else void refresh()
|
||||
},
|
||||
)
|
||||
|
||||
const apiPlan = computed(() => apiPlanData.value ?? EMPTY_PLAN)
|
||||
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
|
||||
const activeScenario = computed(() => presets.value?.find((preset) => preset.id === scenario.value))
|
||||
@@ -383,6 +398,7 @@ function exportPlan() {
|
||||
@click="approved = !approved"
|
||||
/>
|
||||
<OnyxButton label="Export CSV" :icon="iconDownload" mode="outline" @click="exportPlan" />
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" />
|
||||
<OnyxBadge v-if="approved" color="success">Approved · demo</OnyxBadge>
|
||||
<span v-else class="small muted">Draft for manager review</span>
|
||||
</div>
|
||||
@@ -392,8 +408,8 @@ function exportPlan() {
|
||||
Local preview · the Go API plan is unchanged.
|
||||
</template>
|
||||
<template v-else>
|
||||
Go `/api/staffing` · updated {{ context ? formatDateTime(context.updated_at) : '—' }} · no POS, sales
|
||||
or labour-cost feed.
|
||||
Go /api/staffing · scenario v{{ live.version }} · broadcast
|
||||
{{ live.scenarioAt ? formatDateTime(live.scenarioAt) : '—' }} · no POS, sales or labour-cost feed.
|
||||
</template>
|
||||
</p>
|
||||
</div>
|
||||
@@ -426,6 +442,10 @@ function exportPlan() {
|
||||
The staffing API could not be loaded. Check that the Go API is running and that NUXT_API_INTERNAL_BASE points
|
||||
to it. <span v-if="error" class="muted">{{ error.statusMessage }}</span>
|
||||
</div>
|
||||
<div v-else-if="status === 'success' && !apiPlan.hours.length" class="callout callout--warning">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="16px" color="warning" />
|
||||
No open hours are available for this store and scenario yet. Pick another sensor or check the data window.
|
||||
</div>
|
||||
|
||||
<section class="summary-grid" aria-label="Plan summary">
|
||||
<MetricCard
|
||||
@@ -463,7 +483,7 @@ function exportPlan() {
|
||||
<div>
|
||||
<OnyxHeadline is="h2">Plan inputs</OnyxHeadline>
|
||||
<p class="small muted" style="margin: 0">
|
||||
Store, service standard and scenario are sent to Go `/api/staffing`. Local assumption edits render a
|
||||
Store, service standard and scenario are sent to Go /api/staffing. Local assumption edits render a
|
||||
preview from the API forecast.
|
||||
</p>
|
||||
</div>
|
||||
@@ -555,7 +575,7 @@ function exportPlan() {
|
||||
message="Assumption only. No payroll or POS data exists."
|
||||
/>
|
||||
<p class="small muted" style="grid-column: 1 / -1; margin: 0">
|
||||
These four values are not query inputs of Go `/api/staffing`. Changing them shows a local preview;
|
||||
These four values are not query inputs of Go /api/staffing. Changing them shows a local preview;
|
||||
“Use API plan” restores the server values.
|
||||
</p>
|
||||
<div class="form-actions" style="grid-column: 1 / -1">
|
||||
@@ -720,7 +740,7 @@ function exportPlan() {
|
||||
<p class="stat-label" style="margin-bottom: var(--onyx-density-xs)">Weather during the plan week</p>
|
||||
<WeatherStrip :days="weekWeather" />
|
||||
<p v-if="!weekWeather.length" class="small muted table-note">
|
||||
The weather forecast from `/api/context` does not cover this plan window yet.
|
||||
The weather forecast from /api/context does not cover this plan window yet.
|
||||
</p>
|
||||
<p class="small muted table-note">
|
||||
{{ activeScenario?.description ?? 'Base scenario uses the API forecast weather.' }}
|
||||
|
||||
@@ -136,8 +136,9 @@ const days = computed(() =>
|
||||
|
||||
<div class="callout">
|
||||
<OnyxIcon :icon="iconCircleInformation" size="16px" color="primary" />
|
||||
The base and scenario plans are generated by Go `/api/staffing`. SSE broadcast to <code>/stage</code> and
|
||||
phones is the next slice; this page makes the recommendation change visible on one screen.
|
||||
The base and scenario plans are generated by Go /api/staffing. The presenter broadcasts from
|
||||
<NuxtLink to="/control">/control</NuxtLink>; <NuxtLink to="/stage">/stage</NuxtLink> and
|
||||
<NuxtLink to="/live">/live</NuxtLink> follow the scenario over SSE with a 5 s polling fallback.
|
||||
</div>
|
||||
|
||||
<div class="split-grid">
|
||||
@@ -246,7 +247,7 @@ const days = computed(() =>
|
||||
</ul>
|
||||
<p class="small muted table-note">
|
||||
Scenario perturbations are produced by the Go/ML stack. This page reads the base and scenario plans from
|
||||
`/api/staffing`; it does not invent its own multipliers.
|
||||
/api/staffing; it does not invent its own multipliers.
|
||||
</p>
|
||||
</OnyxCard>
|
||||
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
iconArrowRight,
|
||||
iconCalendar,
|
||||
iconCheck,
|
||||
iconMobileSignal,
|
||||
iconQrCode,
|
||||
iconSync,
|
||||
iconTriangleWarning,
|
||||
iconUserGroup,
|
||||
} from '@sit-onyx/icons'
|
||||
import { scenarioLabel } from '#shared/live'
|
||||
import type {
|
||||
ForecastResponse,
|
||||
ScenarioState,
|
||||
Sensor,
|
||||
Shift,
|
||||
StaffingHour,
|
||||
StaffingResponse,
|
||||
} from '#shared/types'
|
||||
import { formatDateTime, formatEuro, formatPercent, formatShortDate, formatWeekday } from '~/utils/format'
|
||||
|
||||
useHead({ title: 'Stage — PulseCast live decision' })
|
||||
|
||||
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,
|
||||
status: planStatus,
|
||||
error: planError,
|
||||
refresh: refreshPlan,
|
||||
} = await useFetch<StaffingResponse>('/api/staffing', {
|
||||
query: computed(() => ({
|
||||
sensor: sensorId.value,
|
||||
scenario: live.scenarioId,
|
||||
standard: 'standard',
|
||||
})),
|
||||
})
|
||||
|
||||
const {
|
||||
data: forecastData,
|
||||
error: forecastError,
|
||||
refresh: refreshForecast,
|
||||
} = await useFetch<ForecastResponse>('/api/forecast', {
|
||||
query: computed(() => ({
|
||||
sensor: sensorId.value,
|
||||
horizon: '7d',
|
||||
scenario: live.scenarioId,
|
||||
})),
|
||||
})
|
||||
|
||||
// A new version of the same scenario (new weather/event values) does not
|
||||
// change the query string, so refresh explicitly. A different scenario id
|
||||
// already triggers useFetch's own query watcher.
|
||||
let lastScenarioId = live.scenarioId
|
||||
watch(
|
||||
() => live.revision,
|
||||
() => {
|
||||
if (live.scenarioId === lastScenarioId) {
|
||||
void refreshPlan()
|
||||
void refreshForecast()
|
||||
}
|
||||
lastScenarioId = live.scenarioId
|
||||
},
|
||||
)
|
||||
|
||||
const plan = computed<StaffingResponse | null>(() => planData.value ?? null)
|
||||
const activeSensor = computed(() => sensors.value?.find((sensor) => sensor.id === sensorId.value))
|
||||
|
||||
function maxOf<T>(items: T[], score: (item: T) => number): T | undefined {
|
||||
let best: T | undefined
|
||||
for (const item of items) if (!best || score(item) > score(best)) best = item
|
||||
return best
|
||||
}
|
||||
|
||||
const peakShift = computed<Shift | undefined>(() =>
|
||||
plan.value ? maxOf(plan.value.shifts, (shift) => shift.staff) : undefined,
|
||||
)
|
||||
const peakHour = computed<StaffingHour | undefined>(() =>
|
||||
plan.value ? maxOf(plan.value.hours, (hour) => hour.required_staff) : undefined,
|
||||
)
|
||||
const peakStaff = computed(() => peakShift.value?.staff ?? peakHour.value?.required_staff ?? 0)
|
||||
const totalStaffHours = computed(() =>
|
||||
plan.value ? plan.value.hours.reduce((sum, hour) => sum + hour.scheduled_staff, 0) : 0,
|
||||
)
|
||||
const forecastPeak = computed(() => {
|
||||
const points = forecastData.value?.points ?? []
|
||||
return points.length ? Math.max(...points.map((point) => point.v)) : 0
|
||||
})
|
||||
const saving = computed(() =>
|
||||
plan.value ? Math.max(0, plan.value.summary.flat_schedule_cost_eur - plan.value.summary.cost_eur) : 0,
|
||||
)
|
||||
|
||||
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 headline = computed(() => {
|
||||
if (!plan.value) return 'Waiting for the next staffing plan.'
|
||||
const shift = peakShift.value
|
||||
if (!shift) return 'Next week has no shift blocks yet.'
|
||||
return `${formatWeekday(shift.date)} peak: ${shift.staff} staff, ${shift.start}–${shift.end}.`
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page page-stack stage-page">
|
||||
<header class="stage-hero">
|
||||
<div class="stage-hero__copy">
|
||||
<div class="stage-kicker">
|
||||
<OnyxBadge color="neutral" density="compact">PulseCast stage</OnyxBadge>
|
||||
<LiveStatusBadge :status="live.status" :last-event-at="live.lastEventAt" />
|
||||
<OnyxBadge v-if="plan?.cached" color="warning" density="compact">cached forecast</OnyxBadge>
|
||||
</div>
|
||||
<h1 class="stage-headline">{{ headline }}</h1>
|
||||
<p class="stage-sub">
|
||||
{{ activeSensor?.name ?? 'Stadtgalerie' }} · {{ scenarioLabel(live.scenarioId) }} ·
|
||||
{{ plan ? `${totalStaffHours} staff-hours` : 'waiting for the API' }} · updates live via SSE
|
||||
</p>
|
||||
<div class="stage-scenario">
|
||||
<OnyxIcon :icon="iconCalendar" size="18px" color="primary" />
|
||||
<span>
|
||||
<strong>Scenario version {{ live.version || '—' }}</strong>
|
||||
<template v-if="live.scenarioAt"> · broadcast {{ formatDateTime(live.scenarioAt) }}</template>
|
||||
</span>
|
||||
</div>
|
||||
</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">
|
||||
<OnyxIcon :icon="iconQrCode" size="16px" color="primary" />
|
||||
Scan for the phone view
|
||||
</p>
|
||||
<p class="stage-qr__url mono">{{ liveUrl }}</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="planError" class="callout callout--warning" role="alert">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="18px" color="warning" />
|
||||
<div>
|
||||
<strong>The plan is unavailable.</strong>
|
||||
<span class="muted"> {{ planError.statusMessage ?? 'Check the Go API and ML service.' }}</span>
|
||||
</div>
|
||||
<OnyxButton label="Retry" mode="outline" density="compact" :icon="iconSync" @click="refreshPlan()" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="planStatus === 'pending' && !plan" class="callout">
|
||||
<OnyxIcon :icon="iconSync" size="18px" color="primary" class="spin-slow" />
|
||||
<span>Loading the current staffing plan…</span>
|
||||
</div>
|
||||
|
||||
<div v-else-if="plan && !plan.hours.length" class="callout callout--warning" role="status">
|
||||
<OnyxIcon :icon="iconTriangleWarning" size="18px" color="warning" />
|
||||
<span>No open hours are available for this sensor yet. Check the data window or pick another store.</span>
|
||||
</div>
|
||||
|
||||
<section class="stage-metrics" aria-label="Decision summary">
|
||||
<div class="stage-metric stage-metric--primary">
|
||||
<p class="stage-metric__label"><OnyxIcon :icon="iconUserGroup" size="18px" color="primary" /> Peak staff</p>
|
||||
<p class="stage-metric__value">{{ plan ? peakStaff : '—' }}</p>
|
||||
<p class="stage-metric__hint">
|
||||
<template v-if="peakShift">{{ formatWeekday(peakShift.date) }} {{ peakShift.start }}–{{ peakShift.end }}</template>
|
||||
<template v-else>Per shift block</template>
|
||||
</p>
|
||||
</div>
|
||||
<div class="stage-metric">
|
||||
<p class="stage-metric__label">Labour cost</p>
|
||||
<p class="stage-metric__value">{{ plan ? formatEuro(plan.summary.cost_eur) : '—' }}</p>
|
||||
<p class="stage-metric__hint">{{ plan ? `€${plan.assumptions.labor_cost_eur_h}/h assumption` : '—' }}</p>
|
||||
</div>
|
||||
<div class="stage-metric">
|
||||
<p class="stage-metric__label">Coverage</p>
|
||||
<p class="stage-metric__value">{{ plan ? formatPercent(plan.summary.coverage_pct, 1) : '—' }}</p>
|
||||
<p class="stage-metric__hint">
|
||||
{{ plan ? `${plan.summary.understaffed_hours} h under` : '—' }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="stage-metric">
|
||||
<p class="stage-metric__label">Forecast peak</p>
|
||||
<p class="stage-metric__value">{{ forecastPeak ? Math.round(forecastPeak) : '—' }}</p>
|
||||
<p class="stage-metric__hint">estimated devices/hour</p>
|
||||
</div>
|
||||
<div class="stage-metric">
|
||||
<p class="stage-metric__label">vs flat schedule</p>
|
||||
<p class="stage-metric__value">−{{ plan ? formatEuro(saving) : '—' }}</p>
|
||||
<p class="stage-metric__hint">same coverage, fewer hours</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="stage-grid">
|
||||
<section class="stage-panel" aria-labelledby="stage-decision">
|
||||
<div class="stage-panel__head">
|
||||
<OnyxHeadline id="stage-decision" is="h2">The decision on stage</OnyxHeadline>
|
||||
<OnyxBadge color="success" density="compact">{{ scenarioLabel(live.scenarioId) }}</OnyxBadge>
|
||||
</div>
|
||||
<p class="stage-decision">
|
||||
<template v-if="peakShift">
|
||||
Put <strong>{{ peakShift.staff }} staff</strong> on {{ formatWeekday(peakShift.date) }}
|
||||
{{ formatShortDate(peakShift.date) }}, {{ peakShift.start }}–{{ peakShift.end }}.
|
||||
</template>
|
||||
<template v-else>Pick a store and scenario; the recommendation appears here.</template>
|
||||
</p>
|
||||
<p class="stage-why">
|
||||
<OnyxIcon :icon="iconCheck" size="18px" color="success" />
|
||||
<template v-if="plan">
|
||||
{{ plan.summary.understaffed_hours === 0 ? 'Every open hour is covered by the block plan.' : `${plan.summary.understaffed_hours} hours are below requirement.` }}
|
||||
{{ plan.summary.overstaffed_hours }} hours are intentionally over requirement.
|
||||
</template>
|
||||
<template v-else>Nothing to approve yet.</template>
|
||||
</p>
|
||||
<div class="stage-actions">
|
||||
<OnyxButton label="Presenter control" link="/control" color="primary" :icon="iconArrowRight" icon-position="right" />
|
||||
<OnyxButton label="Open full plan" link="/plan" mode="outline" />
|
||||
<OnyxButton label="Refresh" mode="plain" :icon="iconSync" @click="refreshPlan()" />
|
||||
</div>
|
||||
<p v-if="forecastError" class="small muted">
|
||||
Forecast refresh failed: {{ forecastError.statusMessage }}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<aside class="stage-panel stage-panel--aside">
|
||||
<div class="stage-panel__head">
|
||||
<OnyxHeadline is="h2">On every phone</OnyxHeadline>
|
||||
<OnyxBadge color="info" density="compact">no login</OnyxBadge>
|
||||
</div>
|
||||
<div class="stage-phone">
|
||||
<div class="stage-phone__screen">
|
||||
<p class="stage-phone__kicker"><OnyxIcon :icon="iconMobileSignal" size="14px" color="primary" /> LIVE</p>
|
||||
<p class="stage-phone__value">{{ plan ? peakStaff : '—' }} staff</p>
|
||||
<p class="stage-phone__label">
|
||||
<template v-if="peakShift">{{ formatWeekday(peakShift.date) }} · {{ peakShift.start }}–{{ peakShift.end }}</template>
|
||||
<template v-else>Waiting for the plan</template>
|
||||
</p>
|
||||
<p class="stage-phone__scenario">{{ scenarioLabel(live.scenarioId) }} · v{{ live.version || '—' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p class="small muted">
|
||||
The audience scans the QR code. The same scenario event refreshes the phone view and this screen within
|
||||
the SSE round trip.
|
||||
</p>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<footer class="stage-footer">
|
||||
<span>
|
||||
<strong>Assumptions:</strong> {{ plan?.assumptions.visitors_per_staff_hour ?? 25 }} visitors per staff-hour,
|
||||
×{{ plan?.assumptions.safety_factor ?? 1.15 }} safety, {{ plan?.assumptions.shift_length_h ?? 4 }} h blocks,
|
||||
store hours {{ plan?.assumptions.store_hours.open ?? '10:00' }}–{{ plan?.assumptions.store_hours.close ?? '20:00' }}.
|
||||
</span>
|
||||
<span class="muted">
|
||||
Estimated devices, not people · 8 sensors in a 580 m cluster · no POS or payroll feed ·
|
||||
last update {{ plan ? formatDateTime(live.scenarioAt || plan.context_version) : '—' }}
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.stage-page {
|
||||
gap: clamp(1rem, 2vw, 1.75rem);
|
||||
}
|
||||
|
||||
.stage-hero {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: clamp(1rem, 3vw, 2.5rem);
|
||||
align-items: center;
|
||||
padding: clamp(1.25rem, 2.5vw, 2.5rem);
|
||||
border: 1px solid var(--onyx-color-base-primary-200);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background:
|
||||
radial-gradient(circle at 100% 0%, var(--onyx-color-base-primary-200), transparent 45%),
|
||||
linear-gradient(135deg, var(--onyx-color-base-primary-100), var(--onyx-color-base-neutral-100) 70%);
|
||||
}
|
||||
|
||||
.stage-kicker,
|
||||
.stage-scenario,
|
||||
.stage-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
.stage-headline {
|
||||
max-width: 24ch;
|
||||
margin: var(--onyx-density-sm) 0 0;
|
||||
font-size: clamp(2.1rem, 4.8vw, 4.5rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.03em;
|
||||
line-height: 1.02;
|
||||
color: var(--onyx-color-text-icons-primary-intense);
|
||||
}
|
||||
|
||||
.stage-sub {
|
||||
max-width: 70ch;
|
||||
margin: var(--onyx-density-sm) 0 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: clamp(0.95rem, 1.5vw, 1.15rem);
|
||||
}
|
||||
|
||||
.stage-scenario {
|
||||
margin-top: var(--onyx-density-md);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.stage-qr {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--onyx-density-xs);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stage-qr__frame {
|
||||
padding: 0.65rem;
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: #fff;
|
||||
box-shadow: var(--onyx-shadow-soft-bottom);
|
||||
}
|
||||
|
||||
.stage-qr__frame img {
|
||||
display: block;
|
||||
width: min(220px, 32vw);
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.stage-qr__label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stage-qr__url {
|
||||
max-width: 18rem;
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
}
|
||||
|
||||
.stage-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
gap: var(--onyx-density-sm);
|
||||
}
|
||||
|
||||
.stage-metric {
|
||||
min-width: 0;
|
||||
padding: var(--onyx-density-md);
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: var(--onyx-color-base-neutral-100);
|
||||
}
|
||||
|
||||
.stage-metric--primary {
|
||||
border-color: var(--onyx-color-base-primary-400);
|
||||
background: var(--onyx-color-base-primary-100);
|
||||
}
|
||||
|
||||
.stage-metric__label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin: 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stage-metric__value {
|
||||
margin: var(--onyx-density-xs) 0 0;
|
||||
font-size: clamp(1.5rem, 2.6vw, 2.5rem);
|
||||
font-weight: 800;
|
||||
line-height: 1.05;
|
||||
}
|
||||
|
||||
.stage-metric__hint {
|
||||
margin: var(--onyx-density-2xs) 0 0;
|
||||
color: var(--onyx-color-text-icons-neutral-soft);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.stage-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.65fr) minmax(16rem, 1fr);
|
||||
gap: var(--onyx-density-lg);
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.stage-panel {
|
||||
min-width: 0;
|
||||
padding: clamp(1rem, 2vw, 1.75rem);
|
||||
border: 1px solid var(--onyx-color-base-neutral-300);
|
||||
border-radius: var(--onyx-radius-component-container-soft);
|
||||
background: var(--onyx-color-base-neutral-100);
|
||||
}
|
||||
|
||||
.stage-panel--aside {
|
||||
background: var(--onyx-color-base-neutral-200);
|
||||
}
|
||||
|
||||
.stage-panel__head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--onyx-density-xs);
|
||||
}
|
||||
|
||||
.stage-panel__head h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.stage-decision {
|
||||
margin: var(--onyx-density-md) 0 0;
|
||||
font-size: clamp(1.1rem, 2vw, 1.5rem);
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.stage-why {
|
||||
display: flex;
|
||||
gap: var(--onyx-density-xs);
|
||||
align-items: flex-start;
|
||||
margin: var(--onyx-density-sm) 0 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
}
|
||||
|
||||
.stage-actions {
|
||||
margin-top: var(--onyx-density-lg);
|
||||
}
|
||||
|
||||
.stage-phone {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-block: var(--onyx-density-md);
|
||||
}
|
||||
|
||||
.stage-phone__screen {
|
||||
width: min(15rem, 100%);
|
||||
padding: var(--onyx-density-md);
|
||||
border: 6px solid #1e293b;
|
||||
border-radius: 1.5rem;
|
||||
background: #fff;
|
||||
box-shadow: var(--onyx-shadow-soft-bottom);
|
||||
}
|
||||
|
||||
.stage-phone__kicker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
margin: 0;
|
||||
color: var(--onyx-color-text-icons-primary-intense);
|
||||
font-size: 0.7rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.stage-phone__value {
|
||||
margin: 0.35rem 0 0;
|
||||
font-size: 2.2rem;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.stage-phone__label {
|
||||
margin: 0.25rem 0 0;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.stage-phone__scenario {
|
||||
margin: 0.75rem 0 0;
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
.stage-footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: var(--onyx-density-sm);
|
||||
padding-top: var(--onyx-density-sm);
|
||||
border-top: 1px solid var(--onyx-color-base-neutral-300);
|
||||
color: var(--onyx-color-text-icons-neutral-medium);
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.stage-footer span {
|
||||
max-width: 75ch;
|
||||
}
|
||||
|
||||
.spin-slow {
|
||||
animation: spin 1.4s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.spin-slow {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.stage-metrics {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.stage-hero,
|
||||
.stage-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.stage-qr {
|
||||
align-items: flex-start;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.stage-qr__frame img {
|
||||
width: min(180px, 50vw);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 576px) {
|
||||
.stage-metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.stage-headline {
|
||||
font-size: clamp(1.8rem, 8vw, 2.6rem);
|
||||
}
|
||||
|
||||
.stage-footnote {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user