fix tests and better async results

This commit is contained in:
Nikos Papadakis 2023-11-20 18:50:08 +02:00
parent 707cb0d636
commit 78051bb796
Signed by untrusted user who does not match committer: nikos
GPG key ID: 78871F9905ADFF02
6 changed files with 44 additions and 34 deletions

View file

@ -15,11 +15,19 @@
v<%= Application.spec(:prymn, :vsn) %> v<%= Application.spec(:prymn, :vsn) %>
</p> </p>
</div> </div>
<div class="flex items-center border-r border-l border-zinc-300 text-zinc-900 hover:bg-white"> <div class="flex items-center text-zinc-900">
<.link class="px-3 py-4" href={~p"/users/settings"}> <.link class="border-r border-l px-3 py-4 hover:bg-white" href={~p"/users/settings"}>
<.icon name="hero-user" /> <.icon name="hero-user" />
<.icon name="hero-chevron-down" /> <.icon name="hero-chevron-down" />
</.link> </.link>
<.link
title="Log out"
class="border-r px-3 py-4 hover:bg-white"
method="DELETE"
href={~p"/auth/log_out"}
>
<.icon name="hero-x-mark" />
</.link>
</div> </div>
</div> </div>
</header> </header>

View file

@ -18,46 +18,48 @@ defmodule PrymnWeb.SystemInfo do
@impl true @impl true
def render(assigns) do def render(assigns) do
%{result: unwrapped_info} = assigns.sys_info
assigns = assign(assigns, unwrapped_info: unwrapped_info)
~H""" ~H"""
<div class="flex justify-between space-x-4 rounded bg-gray-800 p-5 text-white">
<.async_result :let={sys_info} assign={@sys_info}>
<:loading>
<div> <div>
<div :if={@sys_info.ok?} class="flex justify-between rounded bg-gray-800 p-5 text-white"> <.spinner class="h-5 w-5" />
<p class="text-xl">Loading system statistics...</p>
</div>
</:loading>
<div> <div>
<p class="text-xl"><%= @unwrapped_info.uptime || "" %>s</p> <p class="text-xl"><%= sys_info.uptime || "" %>s</p>
<p class="text-sm">Uptime</p> <p class="text-sm">Uptime</p>
</div> </div>
<div class="ml-4"> <div>
<p class="text-xl"><%= Enum.count(@unwrapped_info.cpus || []) %></p> <p class="text-xl"><%= Enum.count(sys_info.cpus || []) %></p>
<p class="text-sm">CPUs</p> <p class="text-sm">CPUs</p>
</div> </div>
<div class="ml-4"> <div>
<p class="text-xl"><%= calculate_cpu_usage(@unwrapped_info.cpus) %></p> <p class="text-xl"><%= calculate_cpu_usage(sys_info.cpus) %></p>
<p class="text-sm">CPU%</p> <p class="text-sm">CPU%</p>
</div> </div>
<div class="ml-4"> <div>
<p class="text-xl"> <p class="text-xl">
<%= bytes_to_gigabytes(@unwrapped_info.mem_total_bytes - @unwrapped_info.mem_avail_bytes) %> <%= bytes_to_gigabytes(sys_info.mem_total_bytes - sys_info.mem_avail_bytes) %>
<span>/</span> <span>/</span>
<%= bytes_to_gigabytes(@unwrapped_info.mem_total_bytes) %> <%= bytes_to_gigabytes(sys_info.mem_total_bytes) %>
<span>GiB</span> <span>GiB</span>
</p> </p>
<p class="text-sm">Memory</p> <p class="text-sm">Memory</p>
</div> </div>
<div class="ml-4"> <div>
<p class="text-xl"> <p class="text-xl">
<%= calculate_disk_used_percent(@unwrapped_info.disks) %> <%= calculate_disk_used_percent(sys_info.disks) %>
<span>%</span> <span>%</span>
</p> </p>
<p class="text-sm">Used Disk</p> <p class="text-sm">Used Disk</p>
</div> </div>
</div> </.async_result>
</div> </div>
""" """
end end
@impl true
def handle_async(:get_sys_info, {:ok, {:ok, sys_info}}, socket) do def handle_async(:get_sys_info, {:ok, {:ok, sys_info}}, socket) do
%{sys_info: sys_info_result, ip: host_address} = socket.assigns %{sys_info: sys_info_result, ip: host_address} = socket.assigns
@ -81,8 +83,7 @@ defmodule PrymnWeb.SystemInfo do
|> assign(:sys_info, AsyncResult.failed(sys_info_result, grpc_error))} |> assign(:sys_info, AsyncResult.failed(sys_info_result, grpc_error))}
end end
def handle_async(:get_sys_info, {:exit, reason}, socket) do def handle_async(:get_sys_info, {:exit, _reason}, socket) do
# dbg(reason)
{:noreply, socket} {:noreply, socket}
end end

View file

@ -9,25 +9,30 @@ defmodule PrymnWeb.DashboardLive do
<h1 class="text-3xl font-bold leading-snug">Good morning, <%= @current_user.email %>!</h1> <h1 class="text-3xl font-bold leading-snug">Good morning, <%= @current_user.email %>!</h1>
<h2 class="text-lg font-medium">Your overview</h2> <h2 class="text-lg font-medium">Your overview</h2>
</div> </div>
<div class="flex flex-wrap justify-around gap-2">
<div class="flex gap-2"> <div class="basis-4/12 rounded-lg p-3 shadow-md">
<div class="basis-6/12 rounded-lg p-3 shadow-md"> <span class="text-7xl font-medium">0</span>
<h2 class="mt-5 font-medium leading-snug text-gray-600">Projects</h2>
<.link class="text-sm text-blue-600">
<.icon class="h-3 w-4" name="hero-arrow-right" /> Manage your projects
</.link>
</div>
<div class="basis-4/12 rounded-lg p-3 shadow-md">
<span class="text-7xl font-medium">0</span> <span class="text-7xl font-medium">0</span>
<h2 class="mt-5 font-medium leading-snug text-gray-600">Total Servers</h2> <h2 class="mt-5 font-medium leading-snug text-gray-600">Total Servers</h2>
<.link class="text-sm text-blue-600" navigate={~p"/servers"}> <.link class="text-sm text-blue-600" navigate={~p"/servers"}>
<.icon class="h-3 w-4" name="hero-arrow-right" /> View your servers <.icon class="h-3 w-4" name="hero-arrow-right" /> View your servers
</.link> </.link>
</div> </div>
<div class="basis-6/12 rounded-lg p-3 shadow-md"> <div class="basis-3/12 rounded-lg p-3 shadow-md">
<span class="text-7xl font-medium">0</span> <span class="text-7xl font-medium">0</span>
<h2 class="mt-5 font-medium leading-snug text-gray-600">Apps</h2> <h2 class="mt-5 font-medium leading-snug text-gray-600">Apps</h2>
<.link class="text-sm text-blue-600"> <.link class="text-sm text-blue-600" navigate={~p"/apps"}>
<.icon class="h-3 w-4" name="hero-arrow-right" /> View your apps <.icon class="h-3 w-4" name="hero-arrow-right" /> View your apps
</.link> </.link>
</div> </div>
</div> </div>
</div> </div>
<div class="mx-auto mt-7 max-w-6xl"> <div class="mx-auto mt-7 max-w-6xl">
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div class="space-x-6 text-sm text-blue-600"> <div class="space-x-6 text-sm text-blue-600">

View file

@ -31,6 +31,7 @@ defmodule PrymnWeb.ServerLive.Show do
|> assign(:registration_command, Servers.create_setup_command(server))} |> assign(:registration_command, Servers.create_setup_command(server))}
end end
@impl true
def handle_info(%PrymnProto.Prymn.SysUpdateResponse{} = response, socket) do def handle_info(%PrymnProto.Prymn.SysUpdateResponse{} = response, socket) do
output = String.split(response.output, "\n") output = String.split(response.output, "\n")
socket = assign(socket, :update_output, output) socket = assign(socket, :update_output, output)

View file

@ -39,12 +39,6 @@ defmodule PrymnWeb.UserRegistrationLiveTest do
conn = follow_trigger_action(form, conn) conn = follow_trigger_action(form, conn)
assert redirected_to(conn) == ~p"/" assert redirected_to(conn) == ~p"/"
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
response = html_response(conn, 200)
assert response =~ email
assert response =~ "Welcome"
end end
test "renders errors for duplicated email", %{conn: conn} do test "renders errors for duplicated email", %{conn: conn} do

View file

@ -9,6 +9,7 @@ defmodule Prymn.MixProject do
compilers: [:proto | Mix.compilers()], compilers: [:proto | Mix.compilers()],
elixirc_paths: elixirc_paths(Mix.env()), elixirc_paths: elixirc_paths(Mix.env()),
config_path: Path.expand("app/config/config.exs", __DIR__), config_path: Path.expand("app/config/config.exs", __DIR__),
test_paths: ["app/test"],
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,
aliases: aliases(), aliases: aliases(),
deps: deps() deps: deps()
@ -64,7 +65,7 @@ defmodule Prymn.MixProject do
{:tailwind_formatter, "~> 0.3.6", runtime: Mix.env() == :dev}, {:tailwind_formatter, "~> 0.3.6", runtime: Mix.env() == :dev},
{:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_reload, "~> 1.2", only: :dev},
{:dialyxir, "~> 1.4", only: [:dev], runtime: false}, {:dialyxir, "~> 1.4", only: [:dev], runtime: false},
{:prymn_proto_compiler, path: "./proto_compiler", only: :dev, runtime: false} {:prymn_proto_compiler, path: "proto_compiler", runtime: false}
] ]
end end