Skip to content

Commit

Permalink
Merge branch 'main' into distributed-deployment-orchestrator
Browse files Browse the repository at this point in the history
  • Loading branch information
joshk committed Feb 14, 2025
2 parents 48fc68a + 6b93041 commit 2d88b84
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 139 deletions.
27 changes: 0 additions & 27 deletions assets/ui-rework/hooks/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ export default {
}, 300)
)

const chatBody = document.getElementById("chat-body")
const chatMessage = document.getElementById("chat-message")

channel
.join()
.receive("ok", () => {
console.log("JOINED")
// This will be the same for everyone, the first time it should be used
// and there after it will be ignored as a noop by erlang
channel.push("window_size", { height: term.rows, width: term.cols })
channel.push("message", { event: "loaded the console" })
})
.receive("error", () => {
console.log("ERROR")
Expand All @@ -109,25 +104,6 @@ export default {
term.write(payload.data)
})

channel.on("message", payload => {
if (payload.text) {
chatBody.append(`${payload.name}: ${payload.text}\n`)
} else if (payload.event) {
chatBody.append(`${payload.name} ${payload.event}\n`)
}
chatBody.scrollTop = chatBody.scrollHeight
})

chatBody.addEventListener("click", () => {
chatMessage.focus()
})
chatMessage.addEventListener("keypress", e => {
if (e.key == "Enter") {
channel.push("message", { text: chatMessage.value })
chatMessage.value = ""
}
})

// store version outside of callback closure to set
// dropzone's dropEffect later on
let metadata = {}
Expand Down Expand Up @@ -195,7 +171,6 @@ export default {
})

channel.onClose(() => {
console.log("CLOSED")
term.blur()
term.setOption("cursorBlink", false)
term.write("DISCONNECTED")
Expand Down Expand Up @@ -224,12 +199,10 @@ export default {
const reader = file.stream().getReader()

channel.push("file-data/start", { filename: file.name })
channel.push("message", { event: `starting to upload ${file.name}` })

reader.read().then(function process({ done, value }) {
if (done) {
channel.push("file-data/stop", { filename: file.name })
channel.push("message", { event: `uploaded ${file.name}` })
return
}

Expand Down
5 changes: 5 additions & 0 deletions lib/nerves_hub/audit_logs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ defmodule NervesHub.AuditLogs do

{:ok, count}
end

# used in some tests
def with_description(desc) do
where(AuditLog, [a], like(a.description, ^desc))
end
end
6 changes: 3 additions & 3 deletions lib/nerves_hub/deployments/deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ defmodule NervesHub.Deployments.Deployment do
:connecting_code,
:total_updating_devices,
:current_updated_devices,
:recalculation_type,
:orchestrator_strategy
]

Expand Down Expand Up @@ -69,8 +68,9 @@ defmodule NervesHub.Deployments.Deployment do
field(:total_updating_devices, :integer, default: 0)
field(:current_updated_devices, :integer, default: 0)
field(:inflight_update_expiration_minutes, :integer, default: 60)
# TODO: (nshoes) this column is unused, remove after Managed Deploys is done
field(:recalculation_type, Ecto.Enum, values: [:device, :calculator_queue], default: :device)

# TODO: (nshoes) this column is unused, remove after 1st March
# field(:recalculation_type, Ecto.Enum, values: [:device, :calculator_queue], default: :device)

field(:device_count, :integer, virtual: true)

Expand Down
12 changes: 12 additions & 0 deletions lib/nerves_hub/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ defmodule NervesHub.Devices do
|> Repo.all()
end

defp sort_devices(query, {:asc, :connection_established_at}) do
order_by(query, [latest_connection: latest_connection],
desc_nulls_last: latest_connection.established_at
)
end

defp sort_devices(query, {:desc, :connection_established_at}) do
order_by(query, [latest_connection: latest_connection],
asc_nulls_first: latest_connection.established_at
)
end

defp sort_devices(query, {:asc, :connection_last_seen_at}) do
order_by(query, [latest_connection: latest_connection],
desc_nulls_last: latest_connection.last_seen_at
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub_web/components/deployment_page/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule NervesHubWeb.Components.DeploymentPage.Summary do
>
<span class="text-xs text-zinc-300 tracking-tight">{@deployment.archive.version} ({String.slice(@deployment.archive.uuid, 0..7)})</span>
</.link>
<span class="pl-1 text-xs text-nerves-gray-500">No archive configured</span>
<span :if={is_nil(@deployment.archive)} class="pl-1 text-xs text-nerves-gray-500">No archive configured</span>
</div>
</div>
Expand Down
42 changes: 3 additions & 39 deletions lib/nerves_hub_web/components/device_page/console.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,40 @@ defmodule NervesHubWeb.Components.DevicePage.Console do
<div class="size-full">
<div :if={authorized?(:"device:console", @org_user) && @console_active?} class="flex flex-col size-full items-start justify-between">
<div id="console-and-chat" class="size-full flex gap-4 p-6" phx-update="ignore">
<div class="flex flex-col w-9/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex flex-col w-full bg-zinc-900 border border-zinc-700 rounded">
<div class="flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div id="console-title" class="text-base text-neutral-50 font-medium">Console</div>
</div>
<div id="dropzone" class="grow flex p-6 gap-6">
<div id="console" phx-hook="Console" data-user-token={@user_token} data-device-id={@device.id} class="w-full h-full"></div>
</div>
</div>
<div class="flex flex-col w-3/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div class="text-base text-neutral-50 font-medium">Chat</div>
</div>
<div class="flex-1 flex justify-between items-center h-14 p-4 border-b border-zinc-700">
<pre id="chat-body" class="h-full leading-loose text-xs"></pre>
</div>
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-900 bg-zinc-900">
<input id="chat-message" type="text" class="py-1.5 px-2 block w-full border-0 text-zinc-400 bg-zinc-900 ring-0 focus:ring-0 sm:text-sm" />
</div>
</div>
</div>
</div>
<div :if={authorized?(:"device:console", @org_user) && !@console_active?} class="flex flex-col size-full items-start justify-between">
<div id="console-and-chat" class="size-full flex gap-4 p-6" phx-update="ignore">
<div class="flex flex-col w-9/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex flex-col w-full bg-zinc-900 border border-zinc-700 rounded">
<div class="flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div class="text-base text-neutral-50 font-medium">Console</div>
</div>
<div class="grow flex justify-center items-center p-6 gap-6 text-medium">
The device console isn't currently available.
</div>
</div>
<div class="flex flex-col w-3/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div class="text-base text-neutral-50 font-medium">Chat</div>
</div>
<div class="flex-1 flex justify-between items-center h-14 p-4 border-b border-zinc-700">
<pre id="chat-body" class="h-full leading-loose text-xs"></pre>
</div>
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-900 bg-zinc-900">
<input id="chat-message" type="text" class="py-1.5 px-2 block w-full border-0 text-zinc-400 bg-zinc-900 ring-0 focus:ring-0 sm:text-sm" />
</div>
</div>
</div>
</div>
<div :if={!authorized?(:"device:console", @org_user)} class="flex flex-col size-full items-start justify-between">
<div id="console-and-chat" class="size-full flex gap-4 p-6" phx-update="ignore">
<div class="flex flex-col w-9/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex flex-col w-full bg-zinc-900 border border-zinc-700 rounded">
<div class="flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div class="text-base text-neutral-50 font-medium">Console</div>
</div>
<div class="grow flex justify-center items-center p-6 gap-6 text-medium text-red-500">
You don't have the required permissions to access a Device console.
</div>
</div>
<div class="flex flex-col w-3/12 bg-zinc-900 border border-zinc-700 rounded">
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-700">
<div class="text-base text-neutral-50 font-medium">Chat</div>
</div>
<div class="flex-1 flex justify-between items-center h-14 p-4 border-b border-zinc-700">
<pre id="chat-body" class="h-full leading-loose text-xs"></pre>
</div>
<div class="flex-none flex justify-between items-center h-14 px-4 border-b border-zinc-900 bg-zinc-900">
<input id="chat-message" type="text" class="py-1.5 px-2 block w-full border-0 text-zinc-400 bg-zinc-900 ring-0 focus:ring-0 sm:text-sm" />
</div>
</div>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions lib/nerves_hub_web/live/devices/index-new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
</th>
<th>Firmware</th>
<th>Platform</th>
<th phx-click="sort" phx-value-sort="connection_last_seen_at" class="cursor-pointer">
<Sorting.sort_icon text="Seen" field="connection_last_seen_at" selected_field={@current_sort} selected_direction={@sort_direction} />
<th phx-click="sort" phx-value-sort="connection_established_at" class="cursor-pointer">
<Sorting.sort_icon text="Uptime" field="connection_established_at" selected_field={@current_sort} selected_direction={@sort_direction} />
</th>
<th phx-click="sort" phx-value-sort="tags" class="cursor-pointer">
<Sorting.sort_icon text="Tags" field="tags" selected_field={@current_sort} selected_direction={@sort_direction} />
Expand Down Expand Up @@ -119,7 +119,7 @@
</td>
<td>
<div class="flex gap-[8px] items-center">
<span title={last_seen_at_status(device.latest_connection)}>
<span title={connection_established_at_status(device.latest_connection)}>
<%= if @device_statuses[device.identifier] == "online" do %>
<svg xmlns="http://www.w3.org/2000/svg" width="6" height="6" viewBox="0 0 6 6" fill="none">
<circle cx="3" cy="3" r="3" fill="#10B981" />
Expand Down Expand Up @@ -206,8 +206,8 @@
</td>

<td>
<div :if={device.latest_connection} title={last_seen_at(device.latest_connection)}>
{last_seen_at(device.latest_connection)}
<div :if={device.latest_connection} title={connection_established_at(device.latest_connection)}>
{connection_established_at(device.latest_connection)}
</div>
</td>

Expand Down
16 changes: 16 additions & 0 deletions lib/nerves_hub_web/live/devices/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,22 @@ defmodule NervesHubWeb.Live.Devices.Index do
"""
end

defp connection_established_at_status(nil), do: "Not seen yet"

defp connection_established_at_status(latest_connection),
do: "Last connected at #{connection_established_at_formatted(latest_connection)}"

defp connection_established_at(nil), do: ""

defp connection_established_at(latest_connection),
do: connection_established_at_formatted(latest_connection)

defp connection_established_at_formatted(latest_connection) do
latest_connection
|> Map.get(:established_at)
|> DateTimeFormat.from_now()
end

defp last_seen_at_status(nil), do: "Not seen yet"

defp last_seen_at_status(latest_connection),
Expand Down
Loading

0 comments on commit 2d88b84

Please sign in to comment.