Skip to content

Commit

Permalink
Put audit log feed in component (#1677)
Browse files Browse the repository at this point in the history
* Put audit log feed in component

* Remove deprecated files
  • Loading branch information
elinol authored Dec 5, 2024
1 parent ab42170 commit 963a702
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 81 deletions.
34 changes: 34 additions & 0 deletions lib/nerves_hub_web/components/audit_log_feed.ex
Original file line number Diff line number Diff line change
@@ -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"""
<div id="audit-log-feed">
<%= if Enum.empty?(@audit_logs) do %>
<div class="audit-log-item">
<p class="text-muted">No activity</p>
</div>
<% else %>
<div :for={audit_log <- @audit_logs} class="audit-log-item" id={audit_log.id}>
<div class="audit-action-icon icon-update"></div>
<div>
<p class="audit-description"><%= audit_log.description %></p>
<div class="help-text">
<%= DateTimeFormat.from_now(audit_log.inserted_at) %><small> at <%= audit_log.inserted_at %></small>
<%= if audit_log.reference_id, do: "(Ref: #{audit_log.reference_id})" %>
</div>
</div>
</div>
<%= pagination_links(@audit_pager) %>
<% end %>
</div>
"""
end
end
2 changes: 2 additions & 0 deletions lib/nerves_hub_web/live/deployments/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/deployments/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,5 @@
<div>
<h3 id="latest-activity" class="mb-2">Latest Activity</h3>

<%= render(NervesHubWeb.AuditLogView, "_audit_log_feed.html", assigns) %>
<AuditLogFeed.render audit_logs={@audit_logs} audit_pager={@audit_pager} />
</div>
1 change: 1 addition & 0 deletions lib/nerves_hub_web/live/devices/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/live/devices/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
</a>
</div>

<%= render(NervesHubWeb.AuditLogView, "_audit_log_feed.html", assigns) %>
<AuditLogFeed.render audit_logs={@audit_logs} audit_pager={@audit_pager} />
</div>
</div>
</div>
23 changes: 0 additions & 23 deletions lib/nerves_hub_web/templates/audit_log/_audit_log_feed.html.heex

This file was deleted.

56 changes: 0 additions & 56 deletions lib/nerves_hub_web/views/audit_log_view.ex

This file was deleted.

0 comments on commit 963a702

Please sign in to comment.