From 07479f17a84224779e224bc008ec7d05adcdfae3 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 7 Jan 2026 12:20:52 -0500 Subject: [PATCH] Implement Activity Log management and Person activity integration - Updated qry__activity_log to support filtering by person_id - Created /core/activity_logs standalone page for monitoring system actions - Enhanced Person detail page with 'Recent Activity' column showing real data - Added 'Activity Logs' card to the Core Management dashboard --- src/lib/ae_core/core__activity_log.ts | 64 ++++++- src/routes/core/+page.svelte | 14 +- src/routes/core/activity_logs/+page.svelte | 179 ++++++++++++++++++ src/routes/core/activity_logs/+page.ts | 5 + .../core/people/[person_id]/+page.svelte | 57 +++++- 5 files changed, 307 insertions(+), 12 deletions(-) create mode 100644 src/routes/core/activity_logs/+page.svelte create mode 100644 src/routes/core/activity_logs/+page.ts diff --git a/src/lib/ae_core/core__activity_log.ts b/src/lib/ae_core/core__activity_log.ts index ce5e9fd3..6c740de5 100644 --- a/src/lib/ae_core/core__activity_log.ts +++ b/src/lib/ae_core/core__activity_log.ts @@ -181,52 +181,112 @@ export async function update_ae_obj__activity_log({ return ae_promises.update__activity_log_obj; } -// Updated 2026-01-06 +// Updated 2026-01-07 + export async function qry__activity_log({ + api_cfg, + account_id, + qry_str, + + qry_person_id = null, + enabled = 'enabled', + hidden = 'not_hidden', + view = 'default', + limit = 50, + offset = 0, + order_by_li = { created_on: 'DESC' }, + log_lvl = 0 + }: { + api_cfg: any; + account_id: string; + qry_str?: string; + + qry_person_id?: string | null; + enabled?: 'enabled' | 'all' | 'not_enabled'; + hidden?: 'hidden' | 'all' | 'not_hidden'; + view?: string; + limit?: number; + offset?: number; + order_by_li?: Record; + log_lvl?: number; + }) { + const search_query: any = { and: [] }; + + if (account_id) { + search_query.and.push({ field: 'account_id_random', op: 'eq', value: account_id }); + } + + if (qry_str) { + search_query.q = qry_str; + } + + + if (qry_person_id) { + + search_query.and.push({ field: 'person_id_random', op: 'eq', value: qry_person_id }); + + } + + + ae_promises.load__activity_log_obj_li = await api.search_ae_obj_v3({ + api_cfg, + obj_type: 'activity_log', + search_query, + enabled, + hidden, + view, + limit, + offset, + order_by_li, + log_lvl + }); + + return ae_promises.load__activity_log_obj_li; -} \ No newline at end of file + +} diff --git a/src/routes/core/+page.svelte b/src/routes/core/+page.svelte index ab65194e..aa107ce1 100644 --- a/src/routes/core/+page.svelte +++ b/src/routes/core/+page.svelte @@ -1,5 +1,5 @@ + +
+
+
+ +

Activity Logs

+
+
+ + +
+
+ + + + + +
+
+ + {#if loading} +
+
+
+ {:else if log_li.length === 0} +
+

No activity logs found for this account matching your criteria.

+
+ {:else} +
+ + + + + + + + + + + + {#each log_li as log} + + + + + + + + + + + + + + + + + {/each} + +
Date/TimeUser/PersonActionContextSummary
+
+ {ae_util.iso_datetime_formatter(log.created_on, 'date_short')} + {ae_util.iso_datetime_formatter(log.created_on, 'time_12_short')} +
+
+
+ {#if log.person_full_name || log.person_id_random} + + + {log.person_full_name || 'Person'} + + {log.person_id_random || '--'} + {:else if log.name} + {log.name} + {:else} + -- + {/if} +
+
+ + {log.action} + + {#if log.action_with} + via {log.action_with} + {/if} + + {#if log.object_type} +
+ + + {log.object_type} + + {#if log.external_client_id} + {log.external_client_id} + {/if} +
+ {:else} + -- + {/if} +
+
+ {#if log.summary} + {log.summary} + {/if} + {#if log.description} +

{log.description}

+ {/if} + {#if !log.summary && !log.description} + No detail provided + {/if} +
+
+
+ {/if} +
diff --git a/src/routes/core/activity_logs/+page.ts b/src/routes/core/activity_logs/+page.ts new file mode 100644 index 00000000..fcde8af2 --- /dev/null +++ b/src/routes/core/activity_logs/+page.ts @@ -0,0 +1,5 @@ +/** @type {import('./$types').PageLoad} */ +export async function load({ parent }) { + const data = await parent(); + return data; +} diff --git a/src/routes/core/people/[person_id]/+page.svelte b/src/routes/core/people/[person_id]/+page.svelte index d888a12b..733f74cf 100644 --- a/src/routes/core/people/[person_id]/+page.svelte +++ b/src/routes/core/people/[person_id]/+page.svelte @@ -31,7 +31,8 @@ import { update_ae_obj__person } from '$lib/ae_core/ae_core__person'; import { qry_ae_obj_li__event } from '$lib/ae_events/ae_events__event'; import { qry__post } from '$lib/ae_posts/ae_posts__post'; - import { Users, Link, Unlink, UserPlus, ShieldCheck, User, Calendar, MessageSquare, History } from 'lucide-svelte'; + import { qry__activity_log } from '$lib/ae_core/core__activity_log'; + import { Users, Link, Unlink, UserPlus, ShieldCheck, User, Calendar, MessageSquare, History, Activity } from 'lucide-svelte'; interface Props { data: any; @@ -59,6 +60,7 @@ let related_events: any[] = $state([]); let related_posts: any[] = $state([]); + let related_activity_logs: any[] = $state([]); let loading_activity = $state(false); async function load_activity() { @@ -66,7 +68,7 @@ loading_activity = true; // Load related data using search queries - const [events, posts] = await Promise.all([ + const [events, posts, logs] = await Promise.all([ qry_ae_obj_li__event({ api_cfg: $ae_api, for_obj_id: $ae_loc.account_id, @@ -78,11 +80,19 @@ account_id: $ae_loc.account_id, qry_person_id: $slct.person_id, log_lvl: 1 + }), + qry__activity_log({ + api_cfg: $ae_api, + account_id: $ae_loc.account_id, + qry_person_id: $slct.person_id, + limit: 10, + log_lvl: 1 }) ]); related_events = events || []; related_posts = posts || []; + related_activity_logs = logs || []; loading_activity = false; } @@ -294,7 +304,7 @@ Linked Activity & Content -
+

@@ -308,8 +318,8 @@ @@ -328,17 +338,46 @@ {:else} + + +
+

+ Recent Activity +

+ {#if loading_activity} +
+ {:else if related_activity_logs.length === 0} +

No recent activity logs.

+ {:else} +
+ {#each related_activity_logs as log} +
+
+ {log.action} + {new Date(log.created_on).toLocaleDateString()} +
+ {#if log.summary} + {log.summary} + {/if} +
+ {/each} + + View All Activity + +
+ {/if} +

{/if}