fix tests and better async results
This commit is contained in:
		
							parent
							
								
									707cb0d636
								
							
						
					
					
						commit
						78051bb796
					
				
					 6 changed files with 44 additions and 34 deletions
				
			
		| 
						 | 
				
			
			@ -15,11 +15,19 @@
 | 
			
		|||
        v<%= Application.spec(:prymn, :vsn) %>
 | 
			
		||||
      </p>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="flex items-center border-r border-l border-zinc-300 text-zinc-900 hover:bg-white">
 | 
			
		||||
      <.link class="px-3 py-4" href={~p"/users/settings"}>
 | 
			
		||||
    <div class="flex items-center text-zinc-900">
 | 
			
		||||
      <.link class="border-r border-l px-3 py-4 hover:bg-white" href={~p"/users/settings"}>
 | 
			
		||||
        <.icon name="hero-user" />
 | 
			
		||||
        <.icon name="hero-chevron-down" />
 | 
			
		||||
      </.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>
 | 
			
		||||
</header>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,46 +18,48 @@ defmodule PrymnWeb.SystemInfo do
 | 
			
		|||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def render(assigns) do
 | 
			
		||||
    %{result: unwrapped_info} = assigns.sys_info
 | 
			
		||||
    assigns = assign(assigns, unwrapped_info: unwrapped_info)
 | 
			
		||||
 | 
			
		||||
    ~H"""
 | 
			
		||||
    <div>
 | 
			
		||||
      <div :if={@sys_info.ok?} class="flex justify-between rounded bg-gray-800 p-5 text-white">
 | 
			
		||||
    <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>
 | 
			
		||||
            <.spinner class="h-5 w-5" />
 | 
			
		||||
            <p class="text-xl">Loading system statistics...</p>
 | 
			
		||||
          </div>
 | 
			
		||||
        </:loading>
 | 
			
		||||
        <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>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="ml-4">
 | 
			
		||||
          <p class="text-xl"><%= Enum.count(@unwrapped_info.cpus || []) %></p>
 | 
			
		||||
        <div>
 | 
			
		||||
          <p class="text-xl"><%= Enum.count(sys_info.cpus || []) %></p>
 | 
			
		||||
          <p class="text-sm">CPUs</p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="ml-4">
 | 
			
		||||
          <p class="text-xl"><%= calculate_cpu_usage(@unwrapped_info.cpus) %></p>
 | 
			
		||||
        <div>
 | 
			
		||||
          <p class="text-xl"><%= calculate_cpu_usage(sys_info.cpus) %></p>
 | 
			
		||||
          <p class="text-sm">CPU%</p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="ml-4">
 | 
			
		||||
        <div>
 | 
			
		||||
          <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>
 | 
			
		||||
            <%= bytes_to_gigabytes(@unwrapped_info.mem_total_bytes) %>
 | 
			
		||||
            <%= bytes_to_gigabytes(sys_info.mem_total_bytes) %>
 | 
			
		||||
            <span>GiB</span>
 | 
			
		||||
          </p>
 | 
			
		||||
          <p class="text-sm">Memory</p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="ml-4">
 | 
			
		||||
        <div>
 | 
			
		||||
          <p class="text-xl">
 | 
			
		||||
            <%= calculate_disk_used_percent(@unwrapped_info.disks) %>
 | 
			
		||||
            <%= calculate_disk_used_percent(sys_info.disks) %>
 | 
			
		||||
            <span>%</span>
 | 
			
		||||
          </p>
 | 
			
		||||
          <p class="text-sm">Used Disk</p>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
      </.async_result>
 | 
			
		||||
    </div>
 | 
			
		||||
    """
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def handle_async(:get_sys_info, {:ok, {:ok, sys_info}}, socket) do
 | 
			
		||||
    %{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))}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def handle_async(:get_sys_info, {:exit, reason}, socket) do
 | 
			
		||||
    # dbg(reason)
 | 
			
		||||
  def handle_async(:get_sys_info, {:exit, _reason}, socket) do
 | 
			
		||||
    {:noreply, socket}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,25 +9,30 @@ defmodule PrymnWeb.DashboardLive do
 | 
			
		|||
        <h1 class="text-3xl font-bold leading-snug">Good morning, <%= @current_user.email %>!</h1>
 | 
			
		||||
        <h2 class="text-lg font-medium">Your overview</h2>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <div class="flex gap-2">
 | 
			
		||||
        <div class="basis-6/12 rounded-lg p-3 shadow-md">
 | 
			
		||||
      <div class="flex flex-wrap justify-around gap-2">
 | 
			
		||||
        <div class="basis-4/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>
 | 
			
		||||
          <h2 class="mt-5 font-medium leading-snug text-gray-600">Total Servers</h2>
 | 
			
		||||
          <.link class="text-sm text-blue-600" navigate={~p"/servers"}>
 | 
			
		||||
            <.icon class="h-3 w-4" name="hero-arrow-right" /> View your servers
 | 
			
		||||
          </.link>
 | 
			
		||||
        </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>
 | 
			
		||||
          <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
 | 
			
		||||
          </.link>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="mx-auto mt-7 max-w-6xl">
 | 
			
		||||
      <div class="flex items-center justify-between">
 | 
			
		||||
        <div class="space-x-6 text-sm text-blue-600">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@ defmodule PrymnWeb.ServerLive.Show do
 | 
			
		|||
     |> assign(:registration_command, Servers.create_setup_command(server))}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  @impl true
 | 
			
		||||
  def handle_info(%PrymnProto.Prymn.SysUpdateResponse{} = response, socket) do
 | 
			
		||||
    output = String.split(response.output, "\n")
 | 
			
		||||
    socket = assign(socket, :update_output, output)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,12 +39,6 @@ defmodule PrymnWeb.UserRegistrationLiveTest do
 | 
			
		|||
      conn = follow_trigger_action(form, conn)
 | 
			
		||||
 | 
			
		||||
      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
 | 
			
		||||
 | 
			
		||||
    test "renders errors for duplicated email", %{conn: conn} do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								mix.exs
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								mix.exs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -9,6 +9,7 @@ defmodule Prymn.MixProject do
 | 
			
		|||
      compilers: [:proto | Mix.compilers()],
 | 
			
		||||
      elixirc_paths: elixirc_paths(Mix.env()),
 | 
			
		||||
      config_path: Path.expand("app/config/config.exs", __DIR__),
 | 
			
		||||
      test_paths: ["app/test"],
 | 
			
		||||
      start_permanent: Mix.env() == :prod,
 | 
			
		||||
      aliases: aliases(),
 | 
			
		||||
      deps: deps()
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +65,7 @@ defmodule Prymn.MixProject do
 | 
			
		|||
      {:tailwind_formatter, "~> 0.3.6", runtime: Mix.env() == :dev},
 | 
			
		||||
      {:phoenix_live_reload, "~> 1.2", only: :dev},
 | 
			
		||||
      {: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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue