{{-- Goal metric readout — RA planbar language: filled progress + striped remaining, quarter score marks, a position marker at the current value, start/goal anchored under the bar's ends, and an explicit "N to go". The number IS the input (RA inline pattern): blur-when-changed hx-posts to goalProgress/updateValue, which re-renders this partial into #gvReadout. Expects: $canvasItem (id, metricType, startValue, currentValue, endValue, setting, description). Shared by the dialog and the HxController. --}} @php $roType = $canvasItem['metricType'] ?: 'number'; $roStart = (float) ($canvasItem['startValue'] ?? 0); $roCur = (float) ($canvasItem['currentValue'] ?? 0); $roGoal = (float) ($canvasItem['endValue'] ?? 0); $roHasRange = ($roGoal - $roStart) != 0; $roPct = $roHasRange ? max(0, min(100, (($roCur - $roStart) / ($roGoal - $roStart)) * 100)) : 0; $roFmt = function ($v) use ($roType) { $v = (float) $v; if ($roType === 'percent') { return rtrim(rtrim(number_format($v, 2), '0'), '.').'%'; } if ($roType === 'currency') { return '$'.number_format($v, $v == floor($v) ? 0 : 2); } return rtrim(rtrim(number_format($v, 2), '0'), '.'); }; $roReached = $roHasRange && $roPct >= 100; // Works for decreasing goals too (goal < start): distance left to travel. $roRemaining = abs($roGoal - $roCur); // linkAndReport current values are computed from children; viewers can't // write — both render the number as static text instead of an input. $roEditable = $login::userIsAtLeast($roles::$editor) && ($canvasItem['setting'] ?? '') !== 'linkAndReport'; // Inline blur-save needs a PERSISTED goal: on the create form (id empty) // an hx-post with itemId=0 would swap the readout back to zeros and wipe // the value the user just typed — new goals get a plain input that // submits with the create form instead. $roLive = (int) ($canvasItem['id'] ?? 0) > 0; @endphp
{{-- WHAT is being measured — without it the tab is a bare number. --}} @if (trim((string) ($canvasItem['description'] ?? '')) !== '')
{{ $canvasItem['description'] }}
@endif
@if ($roEditable && $roLive) @elseif ($roEditable) {{-- New goal: same editable number, no HTMX — the value rides the create form's own submit. --}} @else {{ $roFmt($roCur) }} {{-- Static readout (linkAndReport / viewer) submits no currentValue, and EditCanvasItem defaults an absent one to '' — which would blank the stored metric when the user saves other fields. Round the stored value back through the form to preserve it. --}} @endif {{-- How far away it ISN'T — the missing half of every progress bar. --}} @if ($roHasRange) @if ($roReached) {{ __('goalcanvas.goal_reached') }} @else {{ sprintf(__('goalcanvas.to_go'), $roFmt($roRemaining)) }} @endif @endif
{{-- Scored track (RA planbar language) + resolved % — the % column width/gap matches the milestone rows so both right edges align. --}}
{{-- The totals live where they ARE on the scale: start under the left end, the goal under the right end. --}}
{{ $roFmt($roStart) }}{{ $roFmt($roGoal) }}
{{ (int) round($roPct) }}%