/* ============================================================ Views: Dashboard, Drivers, Trucks ============================================================ */ function driverById(ctx, id) { return ctx.drivers.find(d => d.id === id); } function truckById(ctx, id) { return ctx.trucks.find(t => t.id === id); } /* =================== DASHBOARD =================== */ function DashboardView({ ctx }) { const k = Engine.kpis(ctx.schedule); const activeDrivers = ctx.drivers.filter(d => d.status === 'Active').length; // current-week legs, full week, by date (outbound before backhaul same day) const snapshot = [...ctx.schedule] .filter(l => !l.carryover) .sort((a, b) => { if (a.date !== b.date) return a.date < b.date ? -1 : 1; return a.leg === 'outbound' ? -1 : 1; }); const util = Engine.utilization(ctx.schedule, ctx.trucks, Engine.scheduleDates(ctx.schedule)); // activity feed (most recent completed / in transit) const feed = [...ctx.schedule] .filter(l => l.status !== 'scheduled') .sort((a, b) => (a.date < b.date ? 1 : -1)) .slice(0, 6); return (
{/* KPIs */}
{activeDrivers} active this week} /> Fleet in rotation} /> {k.total} legs scheduled} /> On the road now} /> {k.delayed} delayed returns} />
{/* Weekly control panel */}

Weekly Control Panel

Generate & manage this week's dispatch cycle
ctx.setWeekStart(e.target.value)} />
{/* schedule snapshot */}

This Week's Dispatch

ctx.setView('board')}>Open board →
{snapshot.map(l => { const drv = driverById(ctx, l.driverId); const trk = truckById(ctx, l.truckId); return ( ); })}
DateDriverTruckRouteLegStatus
{Engine.fmtLong(l.date)} {drv ? drv.name : '—'} {trk ? trk.code : '—'} {l.leg === 'outbound' ? 'Outbound' : 'Backhaul'}
{/* right stack */}

Truck Utilization

{util.map(u => (
{u.truck.name}
{u.days}/{u.span} days
{u.pct}%
))}

Recent Activity

{feed.length === 0 &&
No live activity yet — run the sim.
} {feed.map(l => { const drv = driverById(ctx, l.driverId); const isDone = l.status === 'completed'; return (
{drv ? drv.name : 'Driver'} {isDone ? 'completed' : 'started'} {l.leg} {l.from}→{l.to}
{Engine.fmtLong(l.date)}
); })}
); } /* =================== DRIVERS =================== */ function DriversView({ ctx }) { const [editing, setEditing] = useState(null); // driver obj or {new:true} return (
{ctx.drivers.length} Drivers
{ctx.drivers.filter(d => d.status === 'Active').length} active · {ctx.drivers.filter(d => d.status !== 'Active').length} off duty
{ctx.drivers.map(d => { const trk = truckById(ctx, d.assignedTruck); return ( ); })}
IDDriverPhoneAssigned TruckStatusActions
{d.id}
{d.name}
{d.license || 'CDL-A'}
{d.phone || '—'} {trk ? {trk.name} : Unassigned} {d.status}
{editing && setEditing(null)} />}
); } function DriverModal({ ctx, editing, close }) { const [form, setForm] = useState({ name: editing.name || '', phone: editing.phone || '', license: editing.license || 'CDL-A', assignedTruck: editing.assignedTruck || (ctx.trucks[0] && ctx.trucks[0].id) || null, status: editing.status || 'Active', }); const set = (k, v) => setForm(f => ({ ...f, [k]: v })); const save = () => { if (!form.name.trim()) return; if (editing.new) ctx.addDriver(form); else ctx.updateDriver(editing.id, form); close(); }; return ( }>
set('name', e.target.value)} placeholder="e.g. Marcus Bell" />
set('phone', e.target.value)} placeholder="(704) 555-0142" />
set('license', e.target.value)} />
); } /* =================== TRUCKS =================== */ function TrucksView({ ctx }) { const [editing, setEditing] = useState(null); const dates = Engine.scheduleDates(ctx.schedule); const util = Engine.utilization(ctx.schedule, ctx.trucks, dates); return (
{ctx.trucks.length} Trucks
Fleet rotation & utilization
{ctx.trucks.map(t => { const drivers = ctx.drivers.filter(d => d.assignedTruck === t.id); const u = util.find(x => x.truck.id === t.id) || { pct: 0, days: 0, span: dates.length }; return (
{t.name}
{t.code} · {t.plate}
Utilization
{u.days}/{u.span} days
{u.pct}%
Assigned Drivers
{drivers.length === 0 &&
No drivers assigned
}
{drivers.map(d => ( {d.id} {d.name} ))}
); })}
{editing && setEditing(null)} />}
); } function TruckModal({ ctx, editing, close }) { const [form, setForm] = useState({ name: editing.name || '', code: editing.code || '', plate: editing.plate || '', }); const set = (k, v) => setForm(f => ({ ...f, [k]: v })); const save = () => { if (!form.name.trim()) return; if (editing.new) ctx.addTruck(form); else ctx.updateTruck(editing.id, form); close(); }; return ( }>
set('name', e.target.value)} placeholder="e.g. Truck 4 — Freightliner" />
set('code', e.target.value)} placeholder="T-04" />
set('plate', e.target.value)} placeholder="NC ABC-1234" />
); } Object.assign(window, { DashboardView, DriversView, TrucksView });