From 5203104fef6319479e790d316f602d98e3f5c694 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 13 Apr 2026 22:44:58 -0400 Subject: [PATCH] refactor(badges): move hide toggle + print count editor to individual badge view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hide/Unhide and print count edit belong on the per-badge page (print controls staff section), not the search list — the list was getting too crowded. - ae_comp__badge_obj_li: removed hide toggle, print count input, and the ae_api/events_func imports that were only there to support them - ae_comp__badge_print_controls: added Hide Badge button (Trusted, top of staff section) and Print Count editor (Admin+, below hide); both reuse the existing save_field/field_save_status pattern for consistent spinner/done/error feedback Co-Authored-By: Claude Sonnet 4.6 --- .../ae_comp__badge_print_controls.svelte | 67 +++++++++++++++ .../badges/ae_comp__badge_obj_li.svelte | 85 +------------------ 2 files changed, 69 insertions(+), 83 deletions(-) diff --git a/src/routes/events/[event_id]/(badges)/badges/[badge_id]/ae_comp__badge_print_controls.svelte b/src/routes/events/[event_id]/(badges)/badges/[badge_id]/ae_comp__badge_print_controls.svelte index 490c8fc6..3f20a474 100644 --- a/src/routes/events/[event_id]/(badges)/badges/[badge_id]/ae_comp__badge_print_controls.svelte +++ b/src/routes/events/[event_id]/(badges)/badges/[badge_id]/ae_comp__badge_print_controls.svelte @@ -112,6 +112,7 @@ let is_auth = $derived($ae_loc.authenticated_access === true); // This component NEVER writes to $ae_loc.edit_mode. Read-only usage only: // — used here to allow reprinting an already-printed badge when global edit mode is active. let is_global_edit_mode = $derived($ae_loc.edit_mode === true); +let is_admin = $derived($ae_loc.administrator_access === true); // --- Per-template controls config --- // Stored in event_badge_template.other_json as { controls_cfg: { shown?, auth_editable? } }. @@ -1554,6 +1555,72 @@ let allow_tracking_open = $derived(
+ +
+ +
+ + + {#if is_admin} +
+

+ Print Count + Admin · timestamps unchanged +

+
+ { + const v = Math.max(0, Math.round(Number((e.currentTarget as HTMLInputElement).value))); + if (v !== print_count) save_field('print_count', { print_count: v }); + }} + onkeydown={(e) => { if (e.key === 'Enter') (e.currentTarget as HTMLInputElement).blur(); }} + disabled={field_save_status['print_count'] === 'saving'} + class="input input-sm w-20 text-center font-mono" /> + {#if field_save_status['print_count'] === 'saving'} + + {:else if field_save_status['print_count'] === 'done'} + + {/if} +
+
+ {/if} +
diff --git a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte index cb31ad11..eaa52937 100644 --- a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte +++ b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_obj_li.svelte @@ -19,11 +19,10 @@ let { hide_badge_type = false }: Props = $props(); -import { ae_loc, ae_api } from '$lib/stores/ae_stores'; +import { ae_loc } from '$lib/stores/ae_stores'; import { events_loc } from '$lib/stores/ae_events_stores'; import { badges_loc } from '$lib/stores/ae_events_stores__badges.svelte'; import { ae_util } from '$lib/ae_utils/ae_utils'; -import { events_func } from '$lib/ae_events/ae_events_functions'; import { Check, Eye, @@ -42,55 +41,9 @@ let copy_status: Record = $state({}); // Access level shortcuts let is_trusted = $derived($ae_loc.trusted_access === true); -let is_admin = $derived($ae_loc.administrator_access === true); let is_public = $derived($ae_loc.public_access === true); // public passcode or higher — may print first prints let is_edit_mode = $derived($ae_loc.edit_mode === true); -// Per-badge async action states -let hide_status: Record = $state({}); -let print_count_status: Record = $state({}); - -async function toggle_badge_hide(badge_obj: any) { - const id = badge_obj.event_badge_id; - if (!id || hide_status[id] === 'loading') return; - hide_status[id] = 'loading'; - try { - await events_func.update_ae_obj__event_badge({ - api_cfg: $ae_api, - event_id: badge_obj.event_id, - event_badge_id: id, - data_kv: { hide: !badge_obj.hide }, - log_lvl - }); - } catch (e) { - console.error('Failed to toggle hide:', e); - } - hide_status[id] = 'idle'; -} - -// Admin-only: edit the raw print count. Does NOT touch timestamps — those are -// only set by the actual print action. This is a correction tool (e.g. "badge -// was printed offline, count needs to match reality"). -async function save_print_count(badge_obj: any, new_count: number) { - const id = badge_obj.event_badge_id; - if (!id || print_count_status[id] === 'saving') return; - const count = Math.max(0, Math.round(new_count)); - if (count === (badge_obj.print_count ?? 0)) return; // no-op - print_count_status[id] = 'saving'; - try { - await events_func.update_ae_obj__event_badge({ - api_cfg: $ae_api, - event_id: badge_obj.event_id, - event_badge_id: id, - data_kv: { print_count: count }, - log_lvl - }); - } catch (e) { - console.error('Failed to update print count:', e); - } - print_count_status[id] = 'idle'; -} - /** * Obscures an email address for display to non-trusted users. * e.g. john.doe@example.com → joh***@example.com @@ -320,25 +273,6 @@ let visible_badge_obj_li = $derived( {/if} - - {#if is_trusted && is_edit_mode} - - {/if} - {#if is_trusted && is_edit_mode} PC: - {#if is_admin} - save_print_count(event_badge_obj, Number((e.currentTarget as HTMLInputElement).value))} - onkeydown={(e) => { if (e.key === 'Enter') (e.currentTarget as HTMLInputElement).blur(); }} - disabled={print_count_status[event_badge_obj.event_badge_id] === 'saving'} - class="w-14 rounded border border-surface-300 bg-surface-100 px-1 text-center font-mono text-[10px] dark:border-surface-700 dark:bg-surface-800" - title="Edit print count (Admin+). Does not change timestamps." /> - {#if print_count_status[event_badge_obj.event_badge_id] === 'saving'} - - {/if} - {:else} - {print_count} - {/if} + {print_count} FP: