@props(['charities', 'sortBy' => 'rating', 'sortDir' => 'desc', 'lens' => '', 'barMaxima' => [], 'openRows' => []]) @php // Columns are rows in `column_tooltips`, not cases in a switch. The // service hands back the visible ones and knows the select alias each // column's compiled formula landed under. $columnService = app(\App\Services\HomepageColumns::class); $columns = $columnService->visible(); // ── Rating group pinned to the right ───────────────────────────────────── // The appraisal is the column every other number is read against, so it is // moved to the end regardless of the admin's sort_order and stuck to the // right edge below. Relative order within each part is preserved. $tailKeys = ['rating', 'stars']; $columns = $columns->reject(fn ($c) => in_array($c->column_key, $tailKeys, true)) ->concat($columns->filter(fn ($c) => in_array($c->column_key, $tailKeys, true))) ->values(); // ── Column lenses ──────────────────────────────────────────────────────── // Admin-defined named subsets (Content → Column Lenses). Every visible // column is rendered; the lens only decides which ones start hidden, so a // visitor can switch on a column outside the lens without a round trip. // charity-list-expand.js reads data-lens-columns off the wrapper. $lensMenu = \App\Models\ColumnLens::menu(); $activeLens = \App\Models\ColumnLens::resolve($lens === '' ? null : $lens); $activeSlug = $activeLens?->slug ?? \App\Models\ColumnLens::ALL_SLUG; $lensKeys = $activeLens ? array_values(array_intersect($activeLens->keys(), $columns->pluck('column_key')->all())) : $columns->pluck('column_key')->all(); // Determine which group columns (rating/stars — pink bracket) need border-left/right. // border-left → first visible group col that has other cols before it. // border-right → last visible group col that has other cols after it. $groupKeys = ['rating', 'stars']; $groupStartKey = null; $groupStartIdx = null; $groupEndKey = null; $groupEndIdx = null; $colCount = $columns->count(); foreach ($columns as $i => $col) { if (in_array($col->column_key, $groupKeys)) { if ($groupStartKey === null) { $groupStartKey = $col->column_key; $groupStartIdx = $i; } $groupEndKey = $col->column_key; $groupEndIdx = $i; } } $borderStartKey = ($groupStartKey !== null && $groupStartIdx > 0) ? $groupStartKey : null; $borderEndKey = ($groupEndKey !== null && $groupEndIdx < $colCount - 1) ? $groupEndKey : null; // ── Pinned columns ─────────────────────────────────────────────────────── // Once enough columns are switched on the table scrolls sideways. Sticking // the charity name to the left edge and the appraisal to the right keeps // every number attached to a name and a verdict, which is what makes // horizontal scrolling survivable at all. The tail move above guarantees // the rating group sits at the right edge to be pinned. $pinLeftKey = optional($columns->first())->column_key === 'name' ? 'name' : null; $pinRightKeys = $columns->pluck('column_key')->intersect($tailKeys)->values()->all(); // Never pin every column: with nothing unpinned there is nothing to scroll. if (count($pinRightKeys) >= $columns->count()) $pinRightKeys = []; // ── In-cell magnitude bars ─────────────────────────────────────────────── // Scaled against the largest value currently on screen, so the comparison // is between the charities the visitor is actually looking at. // Every column's value for every row on screen, read off the aliased // select expressions MySQL evaluated. Done once here so the row component // does not have to know how a value is produced. $values = []; foreach ($charities as $listedCharity) { $listedKey = $listedCharity->id ?? $listedCharity->registration_number ?? $listedCharity->ein; foreach ($columns as $col) { $values[$listedKey][$col->column_key] = $columnService->raw($listedCharity, $col->column_key); } } // $barMaxima arrives from the page component, which measures it over the // whole filtered set. Deriving it from $charities would tie the scale to // however many rows happen to be loaded, and every "show more" would // silently redraw the bars above it. $tooltips = \App\Models\ColumnTooltip::where('is_enabled', true) ->where('is_visible', true) ->whereNotNull('tooltip')->where('tooltip', '!=', '') ->pluck('tooltip', 'column_key'); // Header cell class follows the renderer, and sortability the column's own // flag — both used to be a per-key lookup that had to be edited by hand // whenever a column was added. $thClasses = [ 'name' => 'col-name', 'figure' => 'col-num', 'text' => 'col-text', 'link' => 'col-link', 'score' => 'col-score', 'composite' => 'col-composite', 'stars' => 'col-stars', ]; $sortableKeys = $columnService->sortableKeys(); // ── Feature switches ───────────────────────────────────────────────────── // Admin-controlled removals (Customizer → Features). Not styling: the // markup is simply not rendered, so there is nothing for a visitor to find // in the DOM and nothing for the JavaScript to re-enable. $settings = app(\App\Services\SiteSettings::class); $barsControl = $settings->enabled(\App\Services\SiteSettings::BARS_TOGGLE); $rowDetail = $settings->enabled(\App\Services\SiteSettings::ROW_DETAIL); $colPicker = $settings->enabled(\App\Services\SiteSettings::COLUMN_PICKER); $columnMeta = $columns->mapWithKeys(fn ($col) => [$col->column_key => [ 'th_class' => $thClasses[$col->renderer] ?? 'col-num', 'sortable' => in_array($col->column_key, $sortableKeys, true), ]])->all(); // Weight badges hang off the 4R sub-score a column shows, not off its key, // so renaming or duplicating a score column keeps its badge. // Percentages mirror CharityScoreCalculator's composite weights. $weightPercent = ['revenue' => '50%', 'religious' => '20%', 'recipient' => '15%', 'results' => '15%']; $weightBadges = $columns ->filter(fn ($col) => $col->renderer === 'score' && isset($weightPercent[$col->score_key])) ->mapWithKeys(fn ($col) => [$col->column_key => [ 'weight_key' => $col->score_key, 'percent' => $weightPercent[$col->score_key], ]]) ->all(); // A closure, not a named function: a Blade view can be rendered more than // once in a request, and a `function` declaration in one would then be a // fatal redeclaration. The other helpers here are closures for the same // reason. $sortIcon = function (string $col, string $sortBy, string $sortDir): string { if ($sortBy !== $col) { return ''; } return $sortDir === 'asc' ? '' : ''; }; $pinClass = function (string $key) use ($pinLeftKey, $pinRightKeys): string { if ($key === $pinLeftKey) return ' col-pin-l'; if (in_array($key, $pinRightKeys, true)) return ' col-pin-r'; return ''; }; @endphp
{{-- data-bars-control and data-column-picker mirror the controls above: with no control on the page a visitor has no preference to honour, and charity-list-expand.js reads the attribute rather than looking for the button, so the customizer can preview the removal without taking the markup out from under Livewire. --}}| has($key)) data-tooltip="{{ $tooltips[$key] }}" @endif> {{ $col->label }} @if($meta['sortable']) {!! $sortIcon($key, $sortBy, $sortDir) !!} @endif @if($tooltips->has($key)) ⓘ @endif | @endforeach
|---|
| @if($weight) {{ $weight['percent'] }} @elseif(!$weightLabelRendered) Weights / significance @php $weightLabelRendered = true; @endphp @endif | @endforeach