Site Filtering
The topbar is the single source of truth for site selection across the entire application. The URL path includes the site code, and all pages react to site changes via a shared event system.
URL Structure
Section titled “URL Structure”All pages follow the pattern /central/{site_code}/{page}. The site code in the URL is the primary source of truth:
https://fjzippin.com/central/elior-stmicrocrolles/homehttps://fjzippin.com/central/elior-stmicrocrolles/operationsGlobal State
Section titled “Global State”| Variable / Key | Description |
|---|---|
window.FJ.sites | Array of all site objects fetched from /api/sites on page load |
window.FJ.selectedSite | Current site code (e.g. “elior-stmicrocrolles”), updated on every site change |
localStorage[“fj-topbar-site”] | Persisted selected site code (survives page reloads) |
Cookie fj-site | HTTP cookie with 1-year expiry (SameSite=Lax), used for server-side awareness |
Site Resolution (on page load)
Section titled “Site Resolution (on page load)”The site is resolved in this priority order:
- URL path — extract site code from
/central/{site_code}/{page} - localStorage — fallback to
fj-topbar-site - First available site — default if nothing is set
If the URL site code is invalid, the user is redirected to /central/select-site.
Event System
Section titled “Event System”When the site is resolved (or changed), a fj:site-change CustomEvent is dispatched on document:
Page Navigation
Section titled “Page Navigation”All sidebar links use the pageUrl() helper to preserve site context:
export function pageUrl(page) { const site = window.FJ.selectedSite || _urlSite || 'default'; return `/central/${site}/${page}`;}Site Filtering in Pages
Section titled “Site Filtering in Pages”Pages filter content by matching the selected site’s rpi_ids array against device data:
function filterRpisBySite(rpis) { const site = window.FJ?.selectedSite; if (!site || site === 'all') return rpis; const siteObj = window.FJ?.sites?.find(s => s.site_code === site); if (!siteObj?.rpi_ids) return rpis; const rpiIds = new Set( Array.isArray(siteObj.rpi_ids) ? siteObj.rpi_ids : JSON.parse(siteObj.rpi_ids || '[]') ); return rpis.filter(rpi => rpiIds.has(rpi.rpi_id));}