2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.RuntimeComponent do
|
|
|
|
use LivebookWeb, :live_component
|
2021-02-11 19:42:17 +08:00
|
|
|
|
2021-11-10 01:37:22 +08:00
|
|
|
alias Livebook.Runtime
|
2021-02-11 19:42:17 +08:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def mount(socket) do
|
2021-03-20 21:10:15 +08:00
|
|
|
{:ok, assign(socket, type: nil)}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def update(assigns, socket) do
|
|
|
|
assigns =
|
|
|
|
if socket.assigns.type == nil do
|
2022-04-02 02:13:37 +08:00
|
|
|
type = runtime_type(assigns.runtime)
|
2021-03-20 21:10:15 +08:00
|
|
|
Map.put(assigns, :type, type)
|
|
|
|
else
|
|
|
|
assigns
|
|
|
|
end
|
|
|
|
|
|
|
|
{:ok, assign(socket, assigns)}
|
2021-02-11 19:42:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-10 01:37:22 +08:00
|
|
|
<div class="p-6 pb-4 max-w-4xl flex flex-col space-y-5">
|
2021-04-22 05:02:09 +08:00
|
|
|
<h3 class="text-2xl font-semibold text-gray-800">
|
2021-11-11 01:50:39 +08:00
|
|
|
Runtime settings
|
2021-04-22 05:02:09 +08:00
|
|
|
</h3>
|
|
|
|
<div class="w-full flex-col space-y-5">
|
|
|
|
<div class="flex space-x-4">
|
2022-04-04 18:20:36 +08:00
|
|
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.ElixirStandalone) do %>
|
|
|
|
<.choice_button
|
|
|
|
active={@type == "elixir_standalone"}
|
|
|
|
phx-click="set_runtime_type"
|
|
|
|
phx-value-type="elixir_standalone"
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-target={@myself}
|
|
|
|
>
|
2022-04-04 18:20:36 +08:00
|
|
|
Elixir standalone
|
|
|
|
</.choice_button>
|
|
|
|
<% end %>
|
|
|
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.MixStandalone) do %>
|
|
|
|
<.choice_button
|
|
|
|
active={@type == "mix_standalone"}
|
|
|
|
phx-click="set_runtime_type"
|
|
|
|
phx-value-type="mix_standalone"
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-target={@myself}
|
|
|
|
>
|
2022-04-04 18:20:36 +08:00
|
|
|
Mix standalone
|
|
|
|
</.choice_button>
|
|
|
|
<% end %>
|
|
|
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Attached) do %>
|
|
|
|
<.choice_button
|
|
|
|
active={@type == "attached"}
|
|
|
|
phx-click="set_runtime_type"
|
|
|
|
phx-value-type="attached"
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-target={@myself}
|
|
|
|
>
|
2022-04-04 18:20:36 +08:00
|
|
|
Attached node
|
|
|
|
</.choice_button>
|
|
|
|
<% end %>
|
|
|
|
<%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Embedded) do %>
|
|
|
|
<.choice_button
|
|
|
|
active={@type == "embedded"}
|
|
|
|
phx-click="set_runtime_type"
|
|
|
|
phx-value-type="embedded"
|
2022-08-02 21:51:02 +08:00
|
|
|
phx-target={@myself}
|
|
|
|
>
|
2022-04-04 18:20:36 +08:00
|
|
|
Embedded
|
|
|
|
</.choice_button>
|
|
|
|
<% end %>
|
2021-04-22 05:02:09 +08:00
|
|
|
</div>
|
|
|
|
<div>
|
2022-08-02 21:51:02 +08:00
|
|
|
<%= live_render(@socket, live_view_for_type(@type),
|
|
|
|
id: "runtime-config-#{@type}",
|
|
|
|
session: %{"session" => @session, "current_runtime" => @runtime}
|
|
|
|
) %>
|
2021-04-22 05:02:09 +08:00
|
|
|
</div>
|
2021-02-11 19:42:17 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-03-20 21:10:15 +08:00
|
|
|
defp runtime_type(%Runtime.ElixirStandalone{}), do: "elixir_standalone"
|
|
|
|
defp runtime_type(%Runtime.MixStandalone{}), do: "mix_standalone"
|
|
|
|
defp runtime_type(%Runtime.Attached{}), do: "attached"
|
2021-05-10 20:37:38 +08:00
|
|
|
defp runtime_type(%Runtime.Embedded{}), do: "embedded"
|
2021-03-20 21:10:15 +08:00
|
|
|
|
2021-07-07 20:32:49 +08:00
|
|
|
defp live_view_for_type("elixir_standalone"), do: LivebookWeb.SessionLive.ElixirStandaloneLive
|
|
|
|
defp live_view_for_type("mix_standalone"), do: LivebookWeb.SessionLive.MixStandaloneLive
|
|
|
|
defp live_view_for_type("attached"), do: LivebookWeb.SessionLive.AttachedLive
|
|
|
|
defp live_view_for_type("embedded"), do: LivebookWeb.SessionLive.EmbeddedLive
|
|
|
|
|
2021-02-11 19:42:17 +08:00
|
|
|
@impl true
|
2021-02-27 03:53:29 +08:00
|
|
|
def handle_event("set_runtime_type", %{"type" => type}, socket) do
|
|
|
|
{:noreply, assign(socket, type: type)}
|
|
|
|
end
|
2021-02-11 19:42:17 +08:00
|
|
|
end
|