livebook/lib/livebook_web/live/app_helpers.ex

77 lines
1.9 KiB
Elixir
Raw Normal View History

2023-02-28 22:08:49 +08:00
defmodule LivebookWeb.AppHelpers do
use LivebookWeb, :html
@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
attr :show_label, :boolean, default: true
2023-02-28 22:08:49 +08:00
def app_status(%{status: :executing} = assigns) do
2023-02-28 22:08:49 +08:00
~H"""
<.app_status_indicator text={@show_label && "Executing"} variant={:progressing} />
2023-02-28 22:08:49 +08:00
"""
end
def app_status(%{status: :executed} = assigns) do
2023-02-28 22:08:49 +08:00
~H"""
<.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"""
<.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"""
<.app_status_indicator text={@show_label && "Shutting down"} variant={:inactive} />
2023-02-28 22:08:49 +08:00
"""
end
def app_status(%{status: :deactivated} = assigns) do
2023-02-28 22:08:49 +08:00
~H"""
<.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"""
<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} />
</span>
2023-02-28 22:08:49 +08:00
"""
end
@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