2023-02-28 22:08:49 +08:00
|
|
|
defmodule LivebookWeb.AppHelpers do
|
|
|
|
use LivebookWeb, :html
|
|
|
|
|
2023-05-20 01:40:56 +08:00
|
|
|
@doc """
|
|
|
|
Renders page placeholder on unauthenticated dead render.
|
|
|
|
"""
|
|
|
|
def auth_placeholder(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="flex justify-center items-center h-screen w-screen">
|
|
|
|
<img src={~p"/images/logo.png"} height="128" width="128" alt="livebook" class="animate-pulse" />
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2023-02-28 22:08:49 +08:00
|
|
|
@doc """
|
|
|
|
Renders app status with indicator.
|
|
|
|
"""
|
|
|
|
attr :status, :atom, required: true
|
2023-03-29 07:02:07 +08:00
|
|
|
attr :show_label, :boolean, default: true
|
2023-02-28 22:08:49 +08:00
|
|
|
|
2023-05-20 01:40:56 +08:00
|
|
|
def app_status(%{status: :executing} = assigns) do
|
2023-02-28 22:08:49 +08:00
|
|
|
~H"""
|
2023-05-20 01:40:56 +08:00
|
|
|
<.app_status_indicator text={@show_label && "Executing"} variant={:progressing} />
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2023-05-20 01:40:56 +08:00
|
|
|
def app_status(%{status: :executed} = assigns) do
|
2023-02-28 22:08:49 +08:00
|
|
|
~H"""
|
2023-05-20 01:40:56 +08:00
|
|
|
<.app_status_indicator text={@show_label && "Executed"} variant={:success} />
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_status(%{status: :error} = assigns) do
|
|
|
|
~H"""
|
2023-03-29 07:02:07 +08:00
|
|
|
<.app_status_indicator text={@show_label && "Error"} variant={:error} />
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_status(%{status: :shutting_down} = assigns) do
|
|
|
|
~H"""
|
2023-03-29 07:02:07 +08:00
|
|
|
<.app_status_indicator text={@show_label && "Shutting down"} variant={:inactive} />
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2023-05-20 01:40:56 +08:00
|
|
|
def app_status(%{status: :deactivated} = assigns) do
|
2023-02-28 22:08:49 +08:00
|
|
|
~H"""
|
2023-05-20 01:40:56 +08:00
|
|
|
<.app_status_indicator text={@show_label && "Deactivated"} variant={:inactive} />
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
defp app_status_indicator(assigns) do
|
|
|
|
~H"""
|
2023-04-13 04:16:43 +08:00
|
|
|
<span class="flex items-center space-x-2">
|
|
|
|
<span :if={@text}><%= @text %></span>
|
2023-02-28 22:08:49 +08:00
|
|
|
<.status_indicator variant={@variant} />
|
2023-04-13 04:16:43 +08:00
|
|
|
</span>
|
2023-02-28 22:08:49 +08:00
|
|
|
"""
|
|
|
|
end
|
2023-05-20 01:40:56 +08:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Shows a confirmation modal and closes the app on confirm.
|
|
|
|
"""
|
|
|
|
def confirm_app_termination(socket, app_pid) do
|
|
|
|
on_confirm = fn socket ->
|
|
|
|
Livebook.App.close(app_pid)
|
|
|
|
socket
|
|
|
|
end
|
|
|
|
|
|
|
|
confirm(socket, on_confirm,
|
|
|
|
title: "Terminate app",
|
|
|
|
description: "All app sessions will be immediately terminated.",
|
|
|
|
confirm_text: "Terminate",
|
|
|
|
confirm_icon: "delete-bin-6-line"
|
|
|
|
)
|
|
|
|
end
|
2023-02-28 22:08:49 +08:00
|
|
|
end
|