From faac6c4835b25c1db668ce534feb65edd35db584 Mon Sep 17 00:00:00 2001 From: Elin Olsson Date: Thu, 5 Dec 2024 07:35:03 +0100 Subject: [PATCH 1/2] Put audit log feed in component --- .../components/audit_log_feed.ex | 34 +++++++++++++++++++ lib/nerves_hub_web/live/deployments/show.ex | 2 ++ .../live/deployments/show.html.heex | 2 +- lib/nerves_hub_web/live/devices/show.ex | 1 + .../live/devices/show.html.heex | 2 +- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/nerves_hub_web/components/audit_log_feed.ex diff --git a/lib/nerves_hub_web/components/audit_log_feed.ex b/lib/nerves_hub_web/components/audit_log_feed.ex new file mode 100644 index 000000000..35a220cce --- /dev/null +++ b/lib/nerves_hub_web/components/audit_log_feed.ex @@ -0,0 +1,34 @@ +defmodule NervesHubWeb.Components.AuditLogFeed do + use NervesHubWeb, :component + + import NervesHubWeb.LayoutView, only: [pagination_links: 1] + + alias NervesHubWeb.LayoutView.DateTimeFormat + + attr(:audit_logs, :list) + attr(:audit_pager, :map) + + def render(assigns) do + ~H""" +
+ <%= if Enum.empty?(@audit_logs) do %> +
+

No activity

+
+ <% else %> +
+
+
+

<%= audit_log.description %>

+
+ <%= DateTimeFormat.from_now(audit_log.inserted_at) %> at <%= audit_log.inserted_at %> + <%= if audit_log.reference_id, do: "(Ref: #{audit_log.reference_id})" %> +
+
+
+ <%= pagination_links(@audit_pager) %> + <% end %> +
+ """ + end +end diff --git a/lib/nerves_hub_web/live/deployments/show.ex b/lib/nerves_hub_web/live/deployments/show.ex index 43903563f..0888dd8ad 100644 --- a/lib/nerves_hub_web/live/deployments/show.ex +++ b/lib/nerves_hub_web/live/deployments/show.ex @@ -8,6 +8,8 @@ defmodule NervesHubWeb.Live.Deployments.Show do alias NervesHub.Firmwares.Firmware alias NervesHub.Repo + alias NervesHubWeb.Components.AuditLogFeed + @impl Phoenix.LiveView def mount(params, _session, socket) do %{"name" => name} = params diff --git a/lib/nerves_hub_web/live/deployments/show.html.heex b/lib/nerves_hub_web/live/deployments/show.html.heex index bedf474ee..50087fa63 100644 --- a/lib/nerves_hub_web/live/deployments/show.html.heex +++ b/lib/nerves_hub_web/live/deployments/show.html.heex @@ -205,5 +205,5 @@

Latest Activity

- <%= render(NervesHubWeb.AuditLogView, "_audit_log_feed.html", assigns) %> +
diff --git a/lib/nerves_hub_web/live/devices/show.ex b/lib/nerves_hub_web/live/devices/show.ex index 2e2f11823..54d9e5dc7 100644 --- a/lib/nerves_hub_web/live/devices/show.ex +++ b/lib/nerves_hub_web/live/devices/show.ex @@ -11,6 +11,7 @@ defmodule NervesHubWeb.Live.Devices.Show do alias NervesHub.Firmwares alias NervesHub.Tracker + alias NervesHubWeb.Components.AuditLogFeed alias NervesHubWeb.Components.DeviceHeader alias NervesHubWeb.Components.FwupProgress alias NervesHubWeb.Components.DeviceLocation diff --git a/lib/nerves_hub_web/live/devices/show.html.heex b/lib/nerves_hub_web/live/devices/show.html.heex index 62a431d25..b7df9ad62 100644 --- a/lib/nerves_hub_web/live/devices/show.html.heex +++ b/lib/nerves_hub_web/live/devices/show.html.heex @@ -263,7 +263,7 @@ - <%= render(NervesHubWeb.AuditLogView, "_audit_log_feed.html", assigns) %> + From f135c2a6dd40a85def1c1ec64b271b9bf706e90e Mon Sep 17 00:00:00 2001 From: Elin Olsson Date: Thu, 5 Dec 2024 09:19:36 +0100 Subject: [PATCH 2/2] Remove deprecated files --- .../audit_log/_audit_log_feed.html.heex | 23 -------- lib/nerves_hub_web/views/audit_log_view.ex | 56 ------------------- 2 files changed, 79 deletions(-) delete mode 100644 lib/nerves_hub_web/templates/audit_log/_audit_log_feed.html.heex delete mode 100644 lib/nerves_hub_web/views/audit_log_view.ex diff --git a/lib/nerves_hub_web/templates/audit_log/_audit_log_feed.html.heex b/lib/nerves_hub_web/templates/audit_log/_audit_log_feed.html.heex deleted file mode 100644 index 90ff63ee4..000000000 --- a/lib/nerves_hub_web/templates/audit_log/_audit_log_feed.html.heex +++ /dev/null @@ -1,23 +0,0 @@ -
- <%= if Enum.empty?(@audit_logs) do %> -
-

No activity

-
- <% else %> - <%= for audit_log <- @audit_logs do %> -
-
-
-

<%= audit_log.description %>

-
- <%= DateTimeFormat.from_now(audit_log.inserted_at) %> at <%= audit_log.inserted_at %> - <%= if audit_log.reference_id do %> - (Ref: <%= audit_log.reference_id %>) - <% end %> -
-
-
- <% end %> - <%= pagination_links(@audit_pager) %> - <% end %> -
diff --git a/lib/nerves_hub_web/views/audit_log_view.ex b/lib/nerves_hub_web/views/audit_log_view.ex deleted file mode 100644 index 18a9d574b..000000000 --- a/lib/nerves_hub_web/views/audit_log_view.ex +++ /dev/null @@ -1,56 +0,0 @@ -defmodule NervesHubWeb.AuditLogView do - use NervesHubWeb, :view - - alias NervesHubWeb.LayoutView.DateTimeFormat - import NervesHubWeb.LayoutView, only: [pagination_links: 1] - - def actor_link(%{actor_id: id, actor_type: type}, current_id) do - link_to_resource(type, id, current_id, "audit-log-actor") - end - - def resource_link(%{resource_id: id, resource_type: type}, current_id) do - link_to_resource(type, id, current_id, "audit-log-resource") - end - - defp feed_type(type) do - to_string(type) - |> String.downcase() - |> String.split(".") - |> Enum.at(-1) - end - - defp link_to_resource(type, id, current_id, class) do - simple_type = feed_type(type) - - if id == current_id do - # no need to link to yourself - simple_type - else - link("#{simple_type} [#{id}]", to: path_for(simple_type, id), class: class) - end - end - - def path_for("deployment", _id) do - # TODO: handle lookup product id - "/products" - end - - def path_for("device", _id) do - # TODO: handle product id lookup - "/products" - end - - def path_for("firmware", _id) do - # TODO: handle product id lookup - "/products" - end - - def path_for("user", _id) do - # TODO: Add route for user#show instead of settings - "" - end - - def path_for(simple_type, id) do - apply(Routes, :"#{simple_type}_path", [Endpoint, :show, id]) - end -end