feat(events): reorganize badge admin tools and enhance dependency tracking

- Migrated 'Add New Badge' and 'Upload Badge List' to centralized Event Settings hub.
- Secured Admin Tools visibility with Administrator access and Edit Mode requirements.
- Restored and modernized Badge Template management route with Svelte 5 runes.
- Patched 'Archive' and 'Session' database interfaces to resolve compiler errors.
- Added project-wide dependency comments to key interfaces (Archive, Badge, Session) to prevent cascading change regressions.
- Fixed duplicate import errors in the Settings page.
This commit is contained in:
Scott Idem
2026-02-04 14:04:44 -05:00
parent 49f0a888b0
commit bc30724628
19 changed files with 299 additions and 276 deletions

View File

@@ -58,7 +58,9 @@ export interface Archive {
tmp_sort_2?: null | string;
// Additional fields for convenience (database views)
// archive_content_count?: number;
topic_id?: null | string;
topic_name?: null | string;
archive_content_count?: number;
// archive_content_kv?: null|key_val;
// archive_content_li?: null|[];
}

View File

@@ -48,17 +48,17 @@ export async function load_ae_obj_id__event({
const cached_event = await db_events.event.get(event_id);
if (cached_event) {
if (log_lvl) console.log('EVENT LOAD: Cache hit. Returning stale data immediately.');
// Trigger background refresh
_refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl: 0
_refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl: 0
});
// Still handle nested loads for the cached version to ensure UI richness
return await _handle_nested_loads(cached_event, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl
return await _handle_nested_loads(cached_event, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl
});
}
} catch (e) {
@@ -67,20 +67,20 @@ export async function load_ae_obj_id__event({
}
// 2. SLOW PATH: Wait for API if cache is empty or try_cache is false
return await _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl
return await _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl
});
}
/**
* Internal helper to perform the actual API fetch and cache update for events
*/
async function _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl
async function _refresh_event_v3_background({
api_cfg, event_id, view, try_cache,
inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li,
log_lvl
}: any) {
// Check if offline
if (typeof navigator !== 'undefined' && !navigator.onLine) {
@@ -113,9 +113,9 @@ async function _refresh_event_v3_background({
log_lvl: log_lvl
});
}
return await _handle_nested_loads(processed_obj, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl
return await _handle_nested_loads(processed_obj, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl
});
}
} catch (error: any) {
@@ -128,6 +128,7 @@ async function _refresh_event_v3_background({
* Shared logic for loading nested child collections
*/
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl }: any) {
if (log_lvl) console.log(`Loading nested collections for event: ${event_obj.event_id} (Devices: ${inc_device_li}, Files: ${inc_file_li}, Locations: ${inc_location_li}, Sessions: ${inc_session_li}, Templates: ${inc_template_li})`);
// String-Only ID Vision: the '_id' field IS the string ID
const current_event_id = event_obj.id || event_obj.event_id;
@@ -177,7 +178,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
}
if (tasks.length > 0) await Promise.all(tasks);
return event_obj;
}

View File

@@ -10,9 +10,17 @@ import { load_ae_obj_id__event_badge_template } from '$lib/ae_events/ae_events__
const ae_promises: key_val = {};
// Updated 2026-01-02
/**
* load_ae_obj_id__event_badge - Load a single event badge by ID
* Related Files:
* - src/lib/ae_events/db_events.ts (Dexie Interface)
* - src/routes/events/[event_id]/(badges)/badges/[badge_id]/+page.svelte (View)
* - src/routes/events/[event_id]/settings/+page.svelte (Admin Operations)
*/
export async function load_ae_obj_id__event_badge({
api_cfg,
event_badge_id,
event_id, // This event_id should not be needed here... 2026-02-04
view = 'base',
inc_template = true,
try_cache = true,
@@ -20,6 +28,7 @@ export async function load_ae_obj_id__event_badge({
}: {
api_cfg: any;
event_badge_id: string;
event_id?: string;
view?: string;
inc_template?: boolean;
try_cache?: boolean;
@@ -41,8 +50,12 @@ export async function load_ae_obj_id__event_badge({
if (ae_promises.load__event_badge_obj) {
if (try_cache) {
// In theory we should be able to use the event_id found in the Badge load object. 2026-02-04
// This keeps coming up as undefined: ae_promises.load__event_badge_obj.event_id_random
if (log_lvl) console.log(`Saving to local cache... Event ID: ${event_id} or ${ae_promises.load__event_badge_obj.event_id_random}`);
const processed_obj_li = await process_ae_obj__event_badge_props({
obj_li: [ae_promises.load__event_badge_obj],
event_id: event_id || ae_promises.load__event_badge_obj.event_id_random,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
@@ -603,6 +616,9 @@ export async function process_ae_obj__event_badge_props({
obj_type: 'event_badge',
log_lvl,
specific_processor: (obj) => {
if (log_lvl) {
console.log(`*** process_ae_obj__event_badge_props() *** event_id=${event_id}`);
}
if (event_id) {
if (!obj.event_id) obj.event_id = event_id;
if (!obj.event_id_random) obj.event_id_random = event_id;

View File

@@ -97,7 +97,13 @@ export interface Event {
event_file_id_li_json?: null | string;
}
// Updated 2025-10-06
/**
* Badge - An event badge
* Related Files:
* - src/lib/ae_events/ae_events__event_badge.ts (API)
* - src/routes/events/[event_id]/(badges)/badges/[badge_id]/+page.svelte (View)
* - src/routes/events/[event_id]/settings/+page.svelte (Admin)
*/
export interface Badge {
id: string;
// id_random: string;
@@ -757,6 +763,7 @@ export interface Session {
tmp_sort_2?: null | string;
// Additional fields for convenience (database views)
default_qry_str?: null | string;
file_count?: null | number; // Only files directly under a session
file_count_all?: null | number; // All files under a session
internal_use_count?: null | number; // Files marked for internal use

View File

@@ -779,6 +779,9 @@ export interface ae_Page extends ae_BaseObj {
/**
* Archive - A collection of archival content
* Related Files:
* - src/lib/ae_archives/db_archives.ts (Dexie Interface)
* - src/routes/idaa/(idaa)/archives/[archive_id]/+page.svelte (View)
*/
export interface ae_Archive extends ae_BaseObj {
archive_id: string;

View File

@@ -262,38 +262,6 @@
}
</script>
{#if show_create_badge_modal}
<Modal bind:open={show_create_badge_modal}>
<div class="card p-4">
<h3 class="h3">Create New Badge</h3>
<Comp_badge_create_form
event_id={$events_slct?.event_id ?? ''}
on:success={() => {
show_create_badge_modal = false;
$events_loc.badges.search_version++;
}}
on:cancel={() => (show_create_badge_modal = false)}
/>
</div>
</Modal>
{/if}
{#if show_upload_badge_modal}
<Modal bind:open={show_upload_badge_modal}>
<div class="card p-4">
<h3 class="h3">Upload Badges (CSV)</h3>
<Comp_badge_upload_form
event_id={$events_slct?.event_id ?? ''}
on:success={() => {
show_upload_badge_modal = false;
$events_loc.badges.search_version++;
}}
on:cancel={() => (show_upload_badge_modal = false)}
/>
</div>
</Modal>
{/if}
<svelte:head>
<title>
Badges -
@@ -307,50 +275,6 @@
log_lvl={1}
></Comp_badge_search>
{#if $ae_loc.trusted_access}
<div class="mt-4 text-center">
<button type="button" class="btn btn-primary" onclick={() => (show_create_badge_modal = true)}>
<span class="fas fa-plus mr-2"></span> Add New Badge
</button>
<button type="button" class="btn btn-primary ml-2" onclick={() => (show_upload_badge_modal = true)}>
<span class="fas fa-upload mr-2"></span> Upload Badge List
</button>
</div>
<div class="mt-4 text-center p-4 border rounded-md">
<h4 class="h4">Mass Print Options</h4>
<div class="flex flex-wrap justify-center gap-2">
<a
href={`/events/${$events_slct?.event_id ?? ''}/badges/print_list?printed_status=not_printed`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print All Unprinted
</a>
<a
href={`/events/${$events_slct?.event_id ?? ''}/badges/print_list?badge_type_code=guest&printed_status=not_printed`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print Unprinted Guests
</a>
<a
href={`/events/${$events_slct?.event_id ?? ''}/badges/print_list`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print All
</a>
</div>
</div>
<div class="mt-4 text-center">
<a
href={`/events/${$events_slct?.event_id ?? ''}/badges/templates`}
class="btn btn-tertiary"
>
<span class="fas fa-file-alt mr-2"></span> Manage Badge Templates
</a>
</div>
{/if}
{#if $events_sess?.badges?.search_status === 'loading' && event_badge_id_li.length === 0}
<div class="flex flex-col items-center justify-center p-10 opacity-50 text-center">
<LoaderCircle size="3em" class="animate-spin mb-4 mx-auto" />

View File

@@ -0,0 +1,34 @@
/** @type {import('./$types').PageLoad} */
console.log(`Events - Badges [badge_id] +page.ts start`);
import { browser } from '$app/environment';
import { events_func } from '$lib/ae_events_functions';
// This file needs to load the Event Badge ID. It should also include the associated Event Badge Template for the specific badge ID.
export async function load({ params, parent, url }) {
const log_lvl: number = 2;
const parent_data = await parent();
const account_id = parent_data.account_id;
const ae_acct = parent_data[account_id];
if (browser) {
if (log_lvl) console.log(`ae_events +page.ts (Non-Blocking Refresh)`);
const event_id = params.event_id;
const event_badge_id = params.badge_id;
if (event_badge_id) {
// Refresh the specific selected Event Badge ID
events_func.load_ae_obj_id__event_badge({
api_cfg: ae_acct.api,
event_badge_id: event_badge_id,
event_id: event_id, // This event_id should not be needed here... 2026-02-04
inc_template: true,
log_lvl: log_lvl
});
}
}
}

View File

@@ -292,7 +292,7 @@
}
});
$effect(async () => {
$effect(() => {
if (browser && $lq__event_badge_obj?.event_badge_id) {
console.log('Generating QR code...');
qr_error_message = '';

View File

@@ -85,13 +85,11 @@
</button>
</div>
{#await lq__badge_templates}
<p>Loading badge templates...</p>
{:then templates}
{#if templates.length > 0}
{#if $lq__badge_templates}
{#if $lq__badge_templates.length > 0}
<div class="card p-4">
<ul class="list-group">
{#each templates as template (template.event_badge_template_id_random)}
{#each $lq__badge_templates as template (template.event_badge_template_id_random)}
<li class="list-group-item flex justify-between items-center">
<span>{template.name}</span>
<div>
@@ -117,31 +115,31 @@
{:else}
<p>No badge templates found for this event. Click "Add New Template" to create one.</p>
{/if}
{:catch error}
<p class="text-error-500">Error loading templates: {error.message}</p>
{/await}
{:else}
<p>Loading badge templates...</p>
{/if}
</section>
{#if show_create_template_modal}
<Modal bind:show={show_create_template_modal}>
<Modal bind:open={show_create_template_modal}>
<div class="card p-4">
<Comp_badge_template_form
{event_id}
on:success={handle_create_success}
on:cancel={handle_cancel}
onsuccess={handle_create_success}
oncancel={handle_cancel}
/>
</div>
</Modal>
{/if}
{#if show_edit_template_modal}
<Modal bind:show={show_edit_template_modal}>
<Modal bind:open={show_edit_template_modal}>
<div class="card p-4">
<Comp_badge_template_form
{event_id}
template_id={selected_template_id}
on:success={handle_edit_success}
on:cancel={handle_cancel}
onsuccess={handle_edit_success}
oncancel={handle_cancel}
/>
</div>
</Modal>

View File

@@ -49,11 +49,11 @@ export async function load({ params, parent, url }) {
events_func.load_ae_obj_id__event({
api_cfg: ae_acct.api,
event_id: event_id,
inc_file_li: true,
inc_location_li: true,
inc_file_li: false, // Changing from true 2026-02-04
inc_location_li: false, // Changing from true 2026-02-04
inc_session_li: true,
inc_template_li: true,
log_lvl: 0 // Keep background quiet unless debugging
log_lvl: 1 // Keep background quiet unless debugging
});
}

View File

@@ -1,64 +1,5 @@
/** @type {import('./$types').PageLoad} */
console.log(`Events - [event_id] +page.ts start`);
// import { error } from '@sveltejs/kit';
// import { browser } from '$app/environment';
// import { events_func } from '$lib/ae_events_functions';
export async function load({ params, parent }) {
// route
// let log_lvl: number = 0;
// let data = await parent();
// // console.log(`ae events_pres_mgmt event [event_id] +page.ts data:`, data);
// data.log_lvl = log_lvl;
// let account_id = data.account_id;
// let ae_acct = data[account_id];
// // console.log(`ae_acct = `, ae_acct);
// // if (!account_id) {
// // console.log(`events_pres_mgmt_event [event_id] +page.ts: The account_id was not found in the data!!!`);
// // return false;
// // }
// // data.ae_events_pres_mgmt_event_event_id_page_ts = true;
// let event_id = params.event_id;
// if (!event_id) {
// console.log(`ae Events - [event_id] +page.ts: The event_id was not found in the params.event_id!!!`);
// error(404, {
// message: 'Event ID not found'
// });
// }
// // ae_acct.slct.event_id = event_id;
// // let load_event_obj = events_func.handle_load_ae_obj_id__event({
// // api_cfg: ae_acct.api, event_id: event_id, try_cache: true
// // });
// // ae_acct.slct.event_obj = await load_event_obj;
// if (browser) {
// let load_event_obj = events_func.handle_load_ae_obj_id__event({
// api_cfg: ae_acct.api, event_id: event_id, try_cache: true
// });
// console.log(`load_event_obj = `, load_event_obj);
// ae_acct.slct.event_obj = load_event_obj;
// let load_event_session_obj_li = events_func.load_ae_obj_li__event_session({
// api_cfg: ae_acct.api,
// for_obj_type: 'event',
// for_obj_id: event_id,
// params: {qry__enabled: 'enabled', qry__hidden: 'all', qry__limit: 200},
// try_cache: true,
// log_lvl: 1
// });
// console.log(`load_event_session_obj_li = `, load_event_session_obj_li);
// ae_acct.slct.event_session_obj_li = load_event_session_obj_li;
// let load_event_location_obj_li = events_func.load_ae_obj_li__event_location({
// api_cfg: ae_acct.api,
// for_obj_type: 'event',
// for_obj_id: event_id,
// params: {qry__enabled: 'enabled', qry__hidden: 'all', qry__limit: 200},
// try_cache: true,
// log_lvl: 1
// });
// console.log(`load_event_location_obj_li = `, load_event_location_obj_li);
// ae_acct.slct.event_location_obj_li = load_event_location_obj_li;
// }
// // WARNING: Precaution against shared data between sites and sessions.
// data[account_id] = ae_acct;
// return data;
}
// export async function load({ params, parent }) {
// }

View File

@@ -50,6 +50,7 @@
ae_core={$ae_loc.administrator_access}
events__locations={$ae_loc.administrator_access}
events__reports={$ae_loc.trusted_access}
events__settings={$ae_loc.edit_mode && $ae_loc.administrator_access}
/>
<span

View File

@@ -1,16 +1,21 @@
<script lang="ts">
import { page } from '$app/state';
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { liveQuery } from 'dexie';
import { db_events, type Event } from '$lib/ae_events/db_events';
import { onMount } from 'svelte';
import { events_func } from '$lib/ae_events_functions';
import { ae_api } from '$lib/stores/ae_stores';
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
import AE_Comp_Editor_CodeMirror from '$lib/elements/AE_Comp_Editor_CodeMirror.svelte';
import Ae_comp_event_settings_form from './ae_comp__event_settings_form.svelte';
import Ae_comp_event_settings_pres_mgmt_form from './ae_comp__event_settings_pres_mgmt_form.svelte';
import Ae_comp_event_settings_basic_form from './ae_comp__event_settings_basic_form.svelte';
import Ae_comp_event_settings_badges_form from './ae_comp__event_settings_badges_form.svelte';
import Ae_comp_event_settings_abstracts_form from './ae_comp__event_settings_abstracts_form.svelte';
import { Modal } from 'flowbite-svelte';
import Comp_badge_create_form from '../(badges)/badges/ae_comp__badge_create_form.svelte';
import Comp_badge_upload_form from '../(badges)/badges/ae_comp__badge_upload_form.svelte';
let event_id = page.params.event_id as string;
let event_obj: Event | undefined | null = $state(null);
@@ -19,6 +24,17 @@
let badges_json_view = $state('form');
let abstracts_json_view = $state('form');
let show_create_badge_modal: boolean = $state(false);
let show_upload_badge_modal: boolean = $state(false);
// Guard: Only allow administrators in edit mode
if (!$ae_loc.administrator_access || !$ae_loc.edit_mode) {
if (browser) {
alert('Access Denied: Administrative privileges and Edit Mode required.');
goto(`/events/${event_id}`);
}
}
onMount(() => {
const observable = liveQuery(() => db_events.event.get(event_id));
const subscription = observable.subscribe((value) => {
@@ -60,6 +76,62 @@
{#if event_obj}
<div class="space-y-4">
<details class="details" open>
<summary class="summary font-bold text-error-500">Admin Tools</summary>
<div class="p-4 space-y-4">
<div class="card p-4 border rounded-md text-center">
<h4 class="h4">Badge Operations</h4>
<div class="flex flex-wrap justify-center gap-2 mt-2">
<button type="button" class="btn btn-primary" onclick={() => (show_create_badge_modal = true)}>
<span class="fas fa-plus mr-2"></span> Add New Badge
</button>
<button type="button" class="btn btn-primary ml-2" onclick={() => (show_upload_badge_modal = true)}>
<span class="fas fa-upload mr-2"></span> Upload Badge List
</button>
</div>
</div>
<div class="card p-4 border rounded-md text-center">
<h4 class="h4">Mass Print Options</h4>
<div class="flex flex-wrap justify-center gap-2 mt-2">
<a
href={`/events/${event_id}/badges/print_list?printed_status=not_printed`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print All Unprinted
</a>
<a
href={`/events/${event_id}/badges/print_list?badge_type_code=guest&printed_status=not_printed`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print Unprinted Guests
</a>
<a
href={`/events/${event_id}/badges/print_list`}
class="btn variant-filled-secondary"
>
<span class="fas fa-print mr-2"></span> Print All
</a>
</div>
</div>
<div class="flex flex-wrap justify-center gap-4 mt-4">
<a
href={`/events/${event_id}/templates`}
class="btn btn-tertiary"
>
<span class="fas fa-file-alt mr-2"></span> Manage Badge Templates
</a>
<a
href={`/events/${event_id}/badges/stats`}
class="btn btn-tertiary"
>
<span class="fas fa-chart-bar mr-2"></span> Badge Printing Stats
</a>
</div>
</div>
</details>
<details class="details">
<summary class="summary">Basic Info</summary>
<div class="p-4">
<Ae_comp_event_settings_basic_form
@@ -252,3 +324,33 @@
{:else}
<p>Loading event data...</p>
{/if}
{#if show_create_badge_modal}
<Modal bind:open={show_create_badge_modal}>
<div class="card p-4">
<h3 class="h3">Create New Badge</h3>
<Comp_badge_create_form
event_id={event_id}
on:success={() => {
show_create_badge_modal = false;
}}
on:cancel={() => (show_create_badge_modal = false)}
/>
</div>
</Modal>
{/if}
{#if show_upload_badge_modal}
<Modal bind:open={show_upload_badge_modal}>
<div class="card p-4">
<h3 class="h3">Upload Badges (CSV)</h3>
<Comp_badge_upload_form
event_id={event_id}
on:success={() => {
show_upload_badge_modal = false;
}}
on:cancel={() => (show_upload_badge_modal = false)}
/>
</div>
</Modal>
{/if}

View File

@@ -19,6 +19,7 @@
events__locations?: boolean; // event_id
// export let events__presenter_id: null|string = null; // event_presenter_id
events__reports?: boolean; // event_id
events__settings?: boolean; // event_id
events__session_id?: null | string; // event_session_id
events__session_search?: boolean; // event_id
}
@@ -31,6 +32,7 @@
events__location_id = null,
events__locations = false,
events__reports = false,
events__settings = false,
events__session_id = null,
events__session_search = false
}: Props = $props();
@@ -66,6 +68,14 @@
<span class="fas fa-map-marked-alt m-1"></span>
Locations
</a>
<a
href="/events/{event_id}/settings"
class="btn btn-sm mx-1 ae_btn_warning"
class:hidden={!events__settings}
>
<span class="fas fa-tools m-1"></span>
Admin Tools
</a>
</span>
<span

View File

@@ -20,7 +20,7 @@
// import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { db_archives } from '$lib/ae_archives/db_archives';
import { db_archives, type Archive } from '$lib/ae_archives/db_archives';
import {
ae_snip,
ae_loc,

View File

@@ -229,32 +229,6 @@ Middle-click to open in new tab`}
</a>
{:else}
<!-- Edit Journal button. Creates a modal to edit the journal. -->
<!-- <button type="button"
onclick={() => {
tmp_journal_obj = {
name: $lq__journal_obj?.name,
description: $lq__journal_obj?.description,
type_code: $lq__journal_obj?.type_code,
passcode: $lq__journal_obj?.passcode,
passcode_timeout: $lq__journal_obj?.passcode_timeout,
auth_key: $lq__journal_obj?.auth_key,
cfg_json: $lq__journal_obj?.cfg_json
};
$journals_sess.show__modal_edit__journal_obj = true;
}}
class:hidden={!$ae_loc.edit_mode}
class="
btn btn-sm
variant-ghost-warning
hover:variant-filled-warning
transition
"
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})">
<Pencil />
<span class="hidden md:inline">
Edit Journal
</span>
</button> -->
<Journal_entry_obj_qry {log_lvl} {lq__journal_obj} />
{/if}

View File

@@ -193,7 +193,8 @@
{#if !$journals_sess?.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified}
<div class="flex gap-1">
<input
type="password"
autocomplete="off"
type="text"
bind:value={typed_journal_passcode}
placeholder="Passcode"
class="input input-sm variant-form-material w-32"