chore(badges): remove legacy badge_id_only_search; sync remote badges config into badges_loc; docs update

This commit is contained in:
Scott Idem
2026-04-02 18:03:23 -04:00
parent 0ab8b936ce
commit c198ca2454
12 changed files with 254 additions and 86 deletions

View File

@@ -2,6 +2,8 @@ import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api';
import { pres_mgmt_loc } from '$lib/stores/ae_events_stores__pres_mgmt.svelte';
import type { PressMgmtRemoteCfg } from '$lib/stores/ae_events_stores__pres_mgmt_defaults';
import { badges_loc } from '$lib/stores/ae_events_stores__badges.svelte';
import type { BadgesRemoteCfg } from '$lib/stores/ae_events_stores__badges_defaults';
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
import { db_events } from '$lib/ae_events/db_events';
@@ -1060,3 +1062,43 @@ export function sync_config__event_pres_mgmt({
pres_mgmt_cfg_remote?.limit__options ?? false;
}
}
/**
* sync_config__event_badges
*
* Mirror a subset of server-side `mod_badges_json` into the local persisted
* `badges_loc.current` store so the UI can read a fast local copy of
* authoritative feature flags (search mode, QR enable, mass-print, etc.).
*
* Called reactively from badge-related pages when the event object changes.
*/
export function sync_config__event_badges({
badges_cfg_remote,
log_lvl = 0
}: {
badges_cfg_remote: Partial<BadgesRemoteCfg>;
log_lvl?: number;
}) {
if (log_lvl) {
console.log(
`*** sync_config__event_badges() *** remote:`,
badges_cfg_remote
);
}
const loc = badges_loc.current;
// Always-sync: feature flags and simple values
loc.enable_mass_print = badges_cfg_remote?.enable_mass_print ?? true;
loc.enable_add_badge_btn = badges_cfg_remote?.enable_add_badge_btn ?? true;
loc.enable_upload_badge_li_btn = badges_cfg_remote?.enable_upload_badge_li_btn ?? true;
loc.enable_search_qr = badges_cfg_remote?.enable_search_qr ?? true;
loc.qr_type = badges_cfg_remote?.qr_type ?? null;
// Passcodes and permissions (may be null)
loc.trusted_passcode = badges_cfg_remote?.trusted_passcode ?? null;
loc.administrator_passcode = badges_cfg_remote?.administrator_passcode ?? null;
loc.edit_permissions = badges_cfg_remote?.edit_permissions ?? null;
loc.remote_cfg_last_synced_on = new Date().toISOString();
}

View File

@@ -47,6 +47,7 @@ const export_obj = {
delete_ae_obj_id__event: event.delete_ae_obj_id__event,
update_ae_obj__event: event.update_ae_obj__event,
sync_config__event_pres_mgmt: event.sync_config__event_pres_mgmt,
sync_config__event_badges: event.sync_config__event_badges,
// Event Person
create_ae_obj__event_person: create_ae_obj__event_person,

View File

@@ -0,0 +1,18 @@
/**
* ae_events_stores__badges.svelte.ts
*
* Svelte 5 PersistedState store for Badge module local config.
* Replaces the `events_loc.badges` sub-object from the Svelte 4 persisted store.
*
* localStorage key: 'ae_badges_loc'
* Version gate: AE_BADGES_LOC_VERSION in store_versions.ts
*
* Usage:
* import { badges_loc } from '$lib/stores/ae_events_stores__badges.svelte';
* badges_loc.current.fulltext_search_qry_str // read
* badges_loc.current.search_version++ // write
*/
import { PersistedState } from 'runed';
import { badges_loc_defaults } from './ae_events_stores__badges_defaults';
export const badges_loc = new PersistedState('ae_badges_loc', badges_loc_defaults);

View File

@@ -1,11 +1,89 @@
/**
* ae_events_stores__badges_defaults.ts
*
* Default state for the badges (badge printing) section of ae_events_stores.ts.
* badges_loc_defaults → events_loc.badges (persisted to localStorage)
* badges_sess_defaults → events_sess.badges (in-memory, resets on page load)
* Type definitions and defaults for the Badges stores.
*
* BadgesRemoteCfg → shape of event.mod_badges_json (server-side admin config)
* BadgesLocState → badges_loc (PersistedState, localStorage key 'ae_badges_loc')
* BadgesSessState → events_sess.badges (in-memory, resets on page load)
*/
// ---------------------------------------------------------------------------
// Remote config — shape of event.mod_badges_json
// This is the admin-controlled, server-side config for an event.
// ---------------------------------------------------------------------------
export interface BadgesRemoteCfg {
// Search & UI behaviour
enable_mass_print: boolean; // show the mass-print controls
enable_add_badge_btn: boolean; // show the "Add Badge" button
enable_upload_badge_li_btn: boolean; // show the "Upload Badge List" button
enable_search_qr: boolean; // enable QR scan search
// QR code configuration
qr_type: string | null; // QR payload format (e.g. 'badge_id', 'url')
// Access control — passcodes for attendee / staff tiered access.
// Only expose to administrator_access. Never render for lower access levels.
trusted_passcode: string | null;
administrator_passcode: string | null;
// Field-level edit permissions per access tier.
// can_edit is a string[] of field keys, or '*' for all fields.
edit_permissions: {
authenticated?: { can_edit: string[] | '*' };
trusted?: { can_edit: string[] | '*' };
administrator?: { can_edit: string[] | '*' };
};
}
// Default field lists — used when edit_permissions is absent from mod_badges_json.
export const default_authenticated_can_edit: string[] = [
'pronouns_override',
'full_name_override',
'professional_title_override',
'affiliations_override',
'phone_override',
'location_override',
'allow_tracking',
'agree_to_tc'
];
export const default_trusted_can_edit: string[] = [
'pronouns_override',
'full_name_override',
'professional_title_override',
'affiliations_override',
'email_override',
'phone_override',
'location_override',
'badge_type_code_override',
'registration_type_code_override',
'other_1_code',
'other_2_code',
'other_3_code',
'other_4_code',
'other_5_code',
'other_6_code',
'other_7_code',
'other_8_code',
'ticket_1_code',
'ticket_2_code',
'ticket_3_code',
'ticket_4_code',
'ticket_5_code',
'ticket_6_code',
'ticket_7_code',
'ticket_8_code',
'allow_tracking',
'agree_to_tc',
'hide',
'priority',
'notes'
];
// ---------------------------------------------------------------------------
// Local state — persisted to localStorage via PersistedState ('ae_badges_loc')
// ---------------------------------------------------------------------------
export interface BadgesLocState {
auto_view: boolean;
show_hidden: boolean;
@@ -26,6 +104,21 @@ export interface BadgesLocState {
search_status: string | null;
search_complete: boolean;
classes__form: string;
// Server-mirrored flags (copied from event.mod_badges_json)
enable_mass_print: boolean;
enable_add_badge_btn: boolean;
enable_upload_badge_li_btn: boolean;
enable_search_qr: boolean;
qr_type: string | null;
trusted_passcode: string | null;
administrator_passcode: string | null;
edit_permissions: {
authenticated?: { can_edit: string[] | '*' };
trusted?: { can_edit: string[] | '*' };
administrator?: { can_edit: string[] | '*' };
} | null;
// Timestamp when the remote config was last mirrored locally
remote_cfg_last_synced_on: string | null;
}
export interface BadgesSessState {
@@ -43,6 +136,7 @@ export interface BadgesSessState {
}
// Persisted badge UI state — survives browser sessions.
// Stored in localStorage as 'ae_badges_loc' via PersistedState (runed).
export const badges_loc_defaults: BadgesLocState = {
auto_view: true,
@@ -73,6 +167,17 @@ export const badges_loc_defaults: BadgesLocState = {
search_complete: false,
classes__form: 'border border-surface-200 p-4 space-y-4 rounded-container'
,
// Default values for server-mirrored flags
enable_mass_print: true,
enable_add_badge_btn: true,
enable_upload_badge_li_btn: true,
enable_search_qr: true,
qr_type: null,
trusted_passcode: null,
administrator_passcode: null,
edit_permissions: null,
remote_cfg_last_synced_on: null
};
// In-memory badge state — resets on page load.

View File

@@ -34,6 +34,7 @@ export const AE_LOC_VERSION = 2; // Bumped 2026-03-30: force-clear stale site_cf
export const AE_EVENTS_LOC_VERSION = 1;
export const AE_IDAA_LOC_VERSION = 1; // Added 2026-03-30: was missing, no wipe mechanism existed
export const AE_PRES_MGMT_LOC_VERSION = 1; // Added 2026-04-02: new standalone PersistedState store
export const AE_BADGES_LOC_VERSION = 1; // Added 2026-04-02: promoted from events_loc.badges
// Version check side-effect: runs on import, before any persisted() call.
// Guard presence of `localStorage` and its functions for safety (SSR, Node flags).