defmodule LivebookWeb.SettingsLive do
use LivebookWeb, :live_view
import LivebookWeb.UserHelpers
alias LivebookWeb.{SidebarHelpers, PageHelpers}
@impl true
def mount(_params, _session, socket) do
file_systems = Livebook.Config.file_systems()
file_systems_env = Livebook.Config.file_systems_as_env(file_systems)
{:ok,
assign(socket,
file_systems: file_systems,
file_systems_env: file_systems_env,
page_title: "Livebook - Settings"
)}
end
@impl true
def render(assigns) do
~H"""
Here you can change global Livebook configuration. Keep in mind
that this configuration is not persisted and gets discarded as
soon as you stop the application.
<%= live_redirect "Dashboard",
to: Routes.home_path(@socket, :page),
class: "button-base button-blue"%>
File systems
<%= @file_systems_env %>
User settings
The configuration in this section changes only your Livebook
experience and is saved in your browser.
Code editor
<.switch_checkbox
name="editor_auto_completion"
label="Show completion list while typing"
checked={false} />
<.switch_checkbox
name="editor_auto_signature"
label="Show function signature while typing"
checked={false} />
<%= if @live_action == :user do %>
<.current_user_modal
return_to={Routes.settings_path(@socket, :page)}
current_user={@current_user} />
<% end %>
<%= if @live_action == :add_file_system do %>
<.modal class="w-full max-w-3xl" return_to={Routes.settings_path(@socket, :page)}>
<.live_component module={LivebookWeb.SettingsLive.AddFileSystemComponent}
id="add-file-system"
return_to={Routes.settings_path(@socket, :page)} />
<% end %>
<%= if @live_action == :detach_file_system do %>
<.modal class="w-full max-w-xl" return_to={Routes.settings_path(@socket, :page)}>
<.live_component module={LivebookWeb.SettingsLive.RemoveFileSystemComponent}
id="detach-file-system"
return_to={Routes.settings_path(@socket, :page)}
file_system={@file_system} />
<% end %>
"""
end
@impl true
def handle_params(%{"file_system_index" => index}, _url, socket) do
index = String.to_integer(index)
file_system = Enum.at(socket.assigns.file_systems, index)
{:noreply, assign(socket, :file_system, file_system)}
end
def handle_params(_params, _url, socket), do: {:noreply, socket}
@impl true
def handle_info({:file_systems_updated, file_systems}, socket) do
file_systems_env = Livebook.Config.file_systems_as_env(file_systems)
{:noreply, assign(socket, file_systems: file_systems, file_systems_env: file_systems_env)}
end
def handle_info(_message, socket), do: {:noreply, socket}
end