2026-02-18 21:23:15 +00:00
|
|
|
defmodule BerrypodWeb.AdminLayoutHook do
|
2026-02-12 08:35:22 +00:00
|
|
|
@moduledoc """
|
2026-02-20 23:53:42 +00:00
|
|
|
LiveView on_mount hook that assigns the current path for admin sidebar navigation
|
|
|
|
|
and loads theme settings for the admin layout.
|
2026-02-12 08:35:22 +00:00
|
|
|
"""
|
|
|
|
|
import Phoenix.Component
|
|
|
|
|
|
add activity log with order timeline and global feed
Single activity_log table powering two views: chronological timeline
on each order detail page (replacing the old fulfilment card) and a
global feed at /admin/activity with tabs, category filters, search,
and pagination. Real-time via PubSub — new entries appear instantly,
nav badge updates across all admin pages.
Instrumented across all event points: Stripe webhooks, order notifier,
submission worker, fulfilment status worker, product sync worker, and
Oban exhausted-job telemetry. Contextual action buttons (retry
submission, retry sync, dismiss) with Oban unique constraints to
prevent double-enqueue. 90-day pruning via cron.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 15:09:08 +00:00
|
|
|
alias Berrypod.{ActivityLog, Settings}
|
2026-02-20 23:53:42 +00:00
|
|
|
alias Berrypod.Theme.{CSSCache, CSSGenerator}
|
|
|
|
|
|
2026-02-12 08:35:22 +00:00
|
|
|
def on_mount(:assign_current_path, _params, _session, socket) do
|
2026-02-20 23:53:42 +00:00
|
|
|
theme_settings = Settings.get_theme_settings()
|
|
|
|
|
|
|
|
|
|
generated_css =
|
|
|
|
|
case CSSCache.get() do
|
|
|
|
|
{:ok, css} ->
|
|
|
|
|
css
|
|
|
|
|
|
|
|
|
|
:miss ->
|
|
|
|
|
css = CSSGenerator.generate(theme_settings, &BerrypodWeb.Endpoint.static_path/1)
|
|
|
|
|
CSSCache.put(css)
|
|
|
|
|
css
|
|
|
|
|
end
|
|
|
|
|
|
add activity log with order timeline and global feed
Single activity_log table powering two views: chronological timeline
on each order detail page (replacing the old fulfilment card) and a
global feed at /admin/activity with tabs, category filters, search,
and pagination. Real-time via PubSub — new entries appear instantly,
nav badge updates across all admin pages.
Instrumented across all event points: Stripe webhooks, order notifier,
submission worker, fulfilment status worker, product sync worker, and
Oban exhausted-job telemetry. Contextual action buttons (retry
submission, retry sync, dismiss) with Oban unique constraints to
prevent double-enqueue. 90-day pruning via cron.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 15:09:08 +00:00
|
|
|
if Phoenix.LiveView.connected?(socket), do: ActivityLog.subscribe()
|
|
|
|
|
|
2026-02-12 08:35:22 +00:00
|
|
|
socket =
|
|
|
|
|
socket
|
|
|
|
|
|> assign(:current_path, "")
|
2026-02-20 23:53:42 +00:00
|
|
|
|> assign(:site_live, Settings.site_live?())
|
|
|
|
|
|> assign(:theme_settings, theme_settings)
|
2026-03-03 14:52:31 +00:00
|
|
|
|> assign(:site_name, Settings.site_name())
|
|
|
|
|
|> assign(:site_description, Settings.site_description())
|
2026-02-20 23:53:42 +00:00
|
|
|
|> assign(:generated_css, generated_css)
|
add activity log with order timeline and global feed
Single activity_log table powering two views: chronological timeline
on each order detail page (replacing the old fulfilment card) and a
global feed at /admin/activity with tabs, category filters, search,
and pagination. Real-time via PubSub — new entries appear instantly,
nav badge updates across all admin pages.
Instrumented across all event points: Stripe webhooks, order notifier,
submission worker, fulfilment status worker, product sync worker, and
Oban exhausted-job telemetry. Contextual action buttons (retry
submission, retry sync, dismiss) with Oban unique constraints to
prevent double-enqueue. 90-day pruning via cron.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 15:09:08 +00:00
|
|
|
|> assign(:attention_count, ActivityLog.count_needing_attention())
|
2026-02-12 08:35:22 +00:00
|
|
|
|> Phoenix.LiveView.attach_hook(:set_current_path, :handle_params, fn _params,
|
|
|
|
|
uri,
|
|
|
|
|
socket ->
|
2026-02-18 23:55:42 +00:00
|
|
|
{:cont,
|
|
|
|
|
socket
|
|
|
|
|
|> assign(:current_path, URI.parse(uri).path)
|
2026-02-20 23:53:42 +00:00
|
|
|
|> assign(:site_live, Settings.site_live?())}
|
2026-02-12 08:35:22 +00:00
|
|
|
end)
|
add activity log with order timeline and global feed
Single activity_log table powering two views: chronological timeline
on each order detail page (replacing the old fulfilment card) and a
global feed at /admin/activity with tabs, category filters, search,
and pagination. Real-time via PubSub — new entries appear instantly,
nav badge updates across all admin pages.
Instrumented across all event points: Stripe webhooks, order notifier,
submission worker, fulfilment status worker, product sync worker, and
Oban exhausted-job telemetry. Contextual action buttons (retry
submission, retry sync, dismiss) with Oban unique constraints to
prevent double-enqueue. 90-day pruning via cron.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 15:09:08 +00:00
|
|
|
|> Phoenix.LiveView.attach_hook(:update_attention_count, :handle_info, fn
|
|
|
|
|
{:new_activity, _entry}, socket ->
|
|
|
|
|
{:cont, assign(socket, :attention_count, ActivityLog.count_needing_attention())}
|
|
|
|
|
|
|
|
|
|
_other, socket ->
|
|
|
|
|
{:cont, socket}
|
|
|
|
|
end)
|
2026-02-12 08:35:22 +00:00
|
|
|
|
|
|
|
|
{:cont, socket}
|
|
|
|
|
end
|
|
|
|
|
end
|