Migrate Event Badges to V3 and implement Core Management pages
- Completed V3 migration for Event Badge CRUD operations - Implemented User module V3 logic and editable fields - Created management routes for Accounts, Sites, Users, and Lookups - Updated Site Domain logic to use 'fqdn' and show 'access_key' - Modernized Core Dashboard with navigation cards - Restored Dexie User table definition
This commit is contained in:
130
src/routes/core/accounts/+page.svelte
Normal file
130
src/routes/core/accounts/+page.svelte
Normal file
@@ -0,0 +1,130 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { load_ae_obj_li__account, create_ae_obj__account } from '$lib/ae_core/ae_core__account';
|
||||
import { ae_api, ae_loc, slct } from '$lib/stores/ae_stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { FileText, Plus, Search, Building } from 'lucide-svelte';
|
||||
|
||||
let account_li: any[] = $state([]);
|
||||
let loading = $state(true);
|
||||
let qry_enabled = $state('all');
|
||||
let qry_hidden = $state('all');
|
||||
|
||||
async function load_accounts() {
|
||||
loading = true;
|
||||
account_li = await load_ae_obj_li__account({
|
||||
api_cfg: $ae_api,
|
||||
enabled: qry_enabled as any,
|
||||
hidden: qry_hidden as any,
|
||||
log_lvl: 1
|
||||
});
|
||||
loading = false;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
load_accounts();
|
||||
});
|
||||
|
||||
async function handle_add_account() {
|
||||
const name = prompt('Enter new account name:');
|
||||
if (!name) return;
|
||||
|
||||
const code = prompt('Enter account code (optional):');
|
||||
|
||||
const new_acct = await create_ae_obj__account({
|
||||
api_cfg: $ae_api,
|
||||
data_kv: {
|
||||
name,
|
||||
code: code || undefined,
|
||||
enable: true
|
||||
},
|
||||
log_lvl: 1
|
||||
});
|
||||
|
||||
if (new_acct) {
|
||||
load_accounts();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container mx-auto p-4 space-y-4">
|
||||
<header class="flex justify-between items-center">
|
||||
<div class="flex items-center gap-2">
|
||||
<Building size={24} />
|
||||
<h1 class="h2">Account Management</h1>
|
||||
</div>
|
||||
<button class="btn variant-filled-primary" onclick={handle_add_account}>
|
||||
<Plus size={16} class="mr-2" /> Add Account
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div class="card p-4 variant-soft flex flex-wrap gap-4 items-end">
|
||||
<label class="label">
|
||||
<span>Enabled Status</span>
|
||||
<select class="select" bind:value={qry_enabled} onchange={load_accounts}>
|
||||
<option value="all">All</option>
|
||||
<option value="enabled">Enabled Only</option>
|
||||
<option value="not_enabled">Disabled Only</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Hidden Status</span>
|
||||
<select class="select" bind:value={qry_hidden} onchange={load_accounts}>
|
||||
<option value="all">All</option>
|
||||
<option value="not_hidden">Not Hidden Only</option>
|
||||
<option value="hidden">Hidden Only</option>
|
||||
</select>
|
||||
</label>
|
||||
<button class="btn variant-filled-secondary" onclick={load_accounts} disabled={loading}>
|
||||
<Search size={16} class="mr-2" /> Refresh
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center p-12">
|
||||
<div class="placeholder animate-pulse w-full h-32"></div>
|
||||
</div>
|
||||
{:else if account_li.length === 0}
|
||||
<div class="card p-8 text-center">
|
||||
<p>No accounts found matching your filters.</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Code</th>
|
||||
<th>Created</th>
|
||||
<th>Status</th>
|
||||
<th class="text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each account_li as acct}
|
||||
<tr>
|
||||
<td>{acct.name}</td>
|
||||
<td><code class="code">{acct.code || '--'}</code></td>
|
||||
<td>{new Date(acct.created_on).toLocaleDateString()}</td>
|
||||
<td>
|
||||
{#if acct.enable}
|
||||
<span class="badge variant-filled-success">Enabled</span>
|
||||
{:else}
|
||||
<span class="badge variant-filled-error">Disabled</span>
|
||||
{/if}
|
||||
{#if acct.hide}
|
||||
<span class="badge variant-filled-warning">Hidden</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<button class="btn btn-sm variant-soft-primary" onclick={() => goto(`/core/accounts/${acct.account_id_random}`)}>
|
||||
Manage
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
14
src/routes/core/accounts/+page.ts
Normal file
14
src/routes/core/accounts/+page.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { PageLoad } from './$types';
|
||||
import { load_ae_obj_li__account } from '$lib/ae_core/ae_core__account';
|
||||
import { get } from 'svelte/store';
|
||||
import { ae_api } from '$lib/stores/ae_stores';
|
||||
|
||||
export const load: PageLoad = async ({ parent }) => {
|
||||
// Ensure we have parent data if needed, but for listing accounts we mostly need the api_cfg
|
||||
const parentData = await parent();
|
||||
|
||||
return {
|
||||
// We could pre-load here, but listing accounts might be better handled in the component
|
||||
// to support interactive filtering/pagination more easily.
|
||||
};
|
||||
};
|
||||
149
src/routes/core/accounts/[account_id]/+page.svelte
Normal file
149
src/routes/core/accounts/[account_id]/+page.svelte
Normal file
@@ -0,0 +1,149 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { load_ae_obj_id__account, update_ae_obj__account, delete_ae_obj_id__account } from '$lib/ae_core/ae_core__account';
|
||||
import { editable_fields__account } from '$lib/ae_core/ae_core__account.editable_fields';
|
||||
import { ae_api, ae_loc } from '$lib/stores/ae_stores';
|
||||
import { goto } from '$app/navigation';
|
||||
import { Save, Trash2, ArrowLeft, Building } from 'lucide-svelte';
|
||||
|
||||
let account_id = $page.params.account_id;
|
||||
let account: any = $state(null);
|
||||
let loading = $state(true);
|
||||
let saving = $state(false);
|
||||
|
||||
async function load_account() {
|
||||
loading = true;
|
||||
account = await load_ae_obj_id__account({
|
||||
api_cfg: $ae_api,
|
||||
account_id,
|
||||
log_lvl: 1
|
||||
});
|
||||
loading = false;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!$ae_loc.manager_access) {
|
||||
goto('/core');
|
||||
return;
|
||||
}
|
||||
load_account();
|
||||
});
|
||||
|
||||
async function handle_save() {
|
||||
saving = true;
|
||||
// Filter fields to only include editable ones
|
||||
const data_kv: any = {};
|
||||
editable_fields__account.forEach(field => {
|
||||
if (account[field] !== undefined) {
|
||||
data_kv[field] = account[field];
|
||||
}
|
||||
});
|
||||
|
||||
const result = await update_ae_obj__account({
|
||||
api_cfg: $ae_api,
|
||||
account_id,
|
||||
data_kv,
|
||||
log_lvl: 1
|
||||
});
|
||||
|
||||
if (result) {
|
||||
alert('Account updated successfully');
|
||||
}
|
||||
saving = false;
|
||||
}
|
||||
|
||||
async function handle_delete() {
|
||||
if (!confirm('Are you sure you want to disable this account?')) return;
|
||||
|
||||
const result = await delete_ae_obj_id__account({
|
||||
api_cfg: $ae_api,
|
||||
account_id,
|
||||
method: 'disable',
|
||||
log_lvl: 1
|
||||
});
|
||||
|
||||
if (result) {
|
||||
goto('/core/accounts');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="container mx-auto p-4 space-y-6">
|
||||
<header class="flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<button class="btn btn-sm variant-soft" onclick={() => goto('/core/accounts')}>
|
||||
<ArrowLeft size={16} />
|
||||
</button>
|
||||
<div class="flex items-center gap-2">
|
||||
<Building size={24} />
|
||||
<h1 class="h2">{account?.name ?? 'Loading Account...'}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button class="btn variant-filled-error" onclick={handle_delete} disabled={loading || saving}>
|
||||
<Trash2 size={16} class="mr-2" /> Disable
|
||||
</button>
|
||||
<button class="btn variant-filled-primary" onclick={handle_save} disabled={loading || saving}>
|
||||
<Save size={16} class="mr-2" /> Save Changes
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{#if loading}
|
||||
<div class="placeholder animate-pulse w-full h-64"></div>
|
||||
{:else if account}
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div class="card p-4 space-y-4">
|
||||
<h3 class="h4 border-b border-surface-500/30 pb-2">Basic Information</h3>
|
||||
<label class="label">
|
||||
<span>Account Name</span>
|
||||
<input class="input" type="text" bind:value={account.name} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Short Name</span>
|
||||
<input class="input" type="text" bind:value={account.short_name} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Account Code</span>
|
||||
<input class="input" type="text" bind:value={account.code} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Description</span>
|
||||
<textarea class="textarea" rows="3" bind:value={account.description}></textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="card p-4 space-y-4">
|
||||
<h3 class="h4 border-b border-surface-500/30 pb-2">Settings & Status</h3>
|
||||
<div class="flex flex-col gap-4">
|
||||
<label class="flex items-center space-x-2">
|
||||
<input class="checkbox" type="checkbox" bind:checked={account.enable} />
|
||||
<p>Enabled</p>
|
||||
</label>
|
||||
<label class="flex items-center space-x-2">
|
||||
<input class="checkbox" type="checkbox" bind:checked={account.hide} />
|
||||
<p>Hidden</p>
|
||||
</label>
|
||||
<label class="flex items-center space-x-2">
|
||||
<input class="checkbox" type="checkbox" bind:checked={account.priority} />
|
||||
<p>Priority Account</p>
|
||||
</label>
|
||||
</div>
|
||||
<label class="label">
|
||||
<span>Group</span>
|
||||
<input class="input" type="text" bind:value={account.group} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Sort Order</span>
|
||||
<input class="input" type="number" bind:value={account.sort} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="card p-4 space-y-4 md:col-span-2">
|
||||
<h3 class="h4 border-b border-surface-500/30 pb-2">Internal Notes</h3>
|
||||
<textarea class="textarea" rows="4" bind:value={account.notes} placeholder="Private notes for staff..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
Reference in New Issue
Block a user