2021-04-01 18:56:19 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.IndicatorsComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2022-04-04 18:19:11 +08:00
|
|
|
<div class="flex flex-col items-center space-y-2" data-el-notebook-indicators>
|
2022-04-15 03:17:19 +08:00
|
|
|
<.code_zen_indicator />
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= if @file do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<%= if @dirty do %>
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= if @autosave_interval_s do %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Autosave pending">
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-blue-400 hover:bg-blue-50 focus:bg-blue-50",
|
|
|
|
aria_label: "autosave pending, click to open file settings" do %>
|
2021-08-14 03:17:43 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-blue-500" />
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="No autosave configured, make sure to save manually">
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2022-01-17 21:19:20 +08:00
|
|
|
class: "icon-button icon-outlined-button border-yellow-bright-200 hover:bg-red-50 focus:bg-red-50",
|
2021-11-02 01:20:56 +08:00
|
|
|
aria_label: "no autosave configured, click to open file settings" do %>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-yellow-bright-300" />
|
2021-08-14 03:17:43 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
2021-04-01 18:56:19 +08:00
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Notebook saved">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2022-01-17 21:19:20 +08:00
|
|
|
class: "icon-button icon-outlined-button border-green-bright-300 hover:bg-green-bright-50 focus:bg-green-bright-50",
|
2021-11-02 01:20:56 +08:00
|
|
|
aria_label: "notebook saved, click to open file settings" do %>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-green-bright-400" />
|
2021-04-22 05:02:09 +08:00
|
|
|
<% end %>
|
2021-04-01 18:56:19 +08:00
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Choose a file to save the notebook">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-gray-200 hover:bg-gray-100 focus:bg-gray-100",
|
|
|
|
aria_label: "choose a file to save the notebook" do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-gray-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
|
2022-04-02 02:13:37 +08:00
|
|
|
<%= if Livebook.Runtime.connected?(@runtime) do %>
|
2021-11-01 20:15:21 +08:00
|
|
|
<.global_status
|
|
|
|
status={elem(@global_status, 0)}
|
|
|
|
cell_id={elem(@global_status, 1)} />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Choose a runtime to run the notebook in">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :runtime_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-gray-200 hover:bg-gray-100 focus:bg-gray-100",
|
|
|
|
aria_label: "choose a runtime to run the notebook in" do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
<%# Note: this indicator is shown/hidden using CSS based on the current mode %>
|
2022-04-04 18:19:11 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Insert mode" data-el-insert-mode-indicator>
|
2021-10-25 01:38:57 +08:00
|
|
|
<span class="text-sm font-medium text-gray-400 cursor-default">
|
2021-04-01 18:56:19 +08:00
|
|
|
ins
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2022-04-15 03:17:19 +08:00
|
|
|
defp code_zen_indicator(assigns) do
|
|
|
|
~H"""
|
|
|
|
<span class="tooltip left" data-tooltip="Enter code zen (z)" data-el-code-zen-enable>
|
|
|
|
<button class="icon-button icon-outlined-button border-gray-200 hover:bg-gray-100 focus:bg-gray-100"
|
|
|
|
aria-label="enter code zen"
|
|
|
|
data-el-code-zen-enable-button>
|
|
|
|
<.remix_icon icon="code-line" class="text-xl text-gray-400" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<div data-el-focus-mode-options>
|
|
|
|
<.menu id="focus-mode-menu" position="top-right">
|
|
|
|
<:toggle>
|
|
|
|
<button class="icon-button icon-outlined-button border-green-bright-300 hover:bg-green-bright-50 focus:bg-green-bright-50"
|
|
|
|
aria-label="code zen options">
|
|
|
|
<.remix_icon icon="code-line" class="text-xl text-green-bright-400" />
|
|
|
|
</button>
|
|
|
|
</:toggle>
|
|
|
|
<:content>
|
|
|
|
<button class="menu-item text-gray-500"
|
|
|
|
role="menuitem"
|
|
|
|
data-el-code-zen-outputs-toggle>
|
|
|
|
<.remix_icon icon="layout-bottom-2-line" />
|
2022-05-02 21:29:42 +08:00
|
|
|
<span class="font-medium" data-label-show>Show outputs</span>
|
|
|
|
<span class="font-medium" data-label-hide>Hide outputs</span>
|
2022-04-15 03:17:19 +08:00
|
|
|
</button>
|
|
|
|
<button class="menu-item text-gray-500"
|
|
|
|
role="menuitem"
|
|
|
|
data-el-code-zen-disable-button>
|
|
|
|
<.remix_icon icon="close-line" />
|
|
|
|
<span class="font-medium">Exit code zen</span>
|
|
|
|
</button>
|
|
|
|
</:content>
|
|
|
|
</.menu>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :evaluating} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to evaluating cell">
|
2021-10-25 01:38:57 +08:00
|
|
|
<button class="border-blue-400 icon-button icon-outlined-button hover:bg-blue-50 focus:bg-blue-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to evaluating cell"
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-focus-cell-button
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-blue-500 animate-spin" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :evaluated} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to last evaluated cell">
|
2022-01-17 21:19:20 +08:00
|
|
|
<button class="border-green-bright-300 icon-button icon-outlined-button hover:bg-green-bright-50 focus:bg-green-bright-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to last evaluated cell"
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-focus-cell-button
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-green-bright-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :stale} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to first stale cell">
|
2022-01-17 21:19:20 +08:00
|
|
|
<button class="border-yellow-bright-200 icon-button icon-outlined-button hover:bg-yellow-bright-50 focus:bg-yellow-bright-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to first stale cell"
|
2022-04-04 18:19:11 +08:00
|
|
|
data-el-focus-cell-button
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-yellow-bright-300" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :fresh} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Ready to evaluate">
|
|
|
|
<div class="border-gray-200 icon-button icon-outlined-button hover:bg-gray-100 focus:bg-gray-100"
|
|
|
|
aria-label="ready to evaluate">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
|
2021-11-02 01:20:56 +08:00
|
|
|
</div>
|
2021-04-01 18:56:19 +08:00
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|