Refactor service live for clarity
This commit is contained in:
parent
a0eb9cd518
commit
0881246d57
3 changed files with 110 additions and 62 deletions
|
@ -81,9 +81,7 @@ defmodule Freedive.Api.Service do
|
|||
broadcast(:stdlog, %{name: name, log: std_to_log(reason)})
|
||||
end
|
||||
|
||||
if command in ["start", "stop", "restart"] do
|
||||
broadcast(:refreshed, service_details(name))
|
||||
end
|
||||
|
||||
{:noreply, state}
|
||||
end
|
||||
|
|
|
@ -107,8 +107,7 @@ defmodule FreediveWeb.ServiceLive do
|
|||
socket
|
||||
|> assign(:selected_item, %{
|
||||
socket.assigns.selected_item
|
||||
| log: socket.assigns.selected_item.log ++ payload.log,
|
||||
busy: false
|
||||
| log: socket.assigns.selected_item.log ++ payload.log
|
||||
})
|
||||
else
|
||||
socket
|
||||
|
@ -137,6 +136,24 @@ defmodule FreediveWeb.ServiceLive.Components do
|
|||
attr :details, :string, default: nil, doc: "details"
|
||||
|
||||
def items_block(%{details: true} = assigns) do
|
||||
~H"""
|
||||
<.back_link selected_item={@selected_item} />
|
||||
<.service_header selected_item={@selected_item} />
|
||||
<.std_log selected_item={@selected_item} />
|
||||
<.basic_commands selected_item={@selected_item} />
|
||||
<.extra_commands selected_item={@selected_item} />
|
||||
"""
|
||||
end
|
||||
|
||||
def items_block(assigns) do
|
||||
~H"""
|
||||
<%= for {_name, item} <- @items do %>
|
||||
<.service_preview item={item} selected_item={@selected_item} />
|
||||
<% end %>
|
||||
"""
|
||||
end
|
||||
|
||||
def back_link(assigns) do
|
||||
~H"""
|
||||
<.link
|
||||
class="panel-block pt-1 has-background-light"
|
||||
|
@ -148,9 +165,12 @@ defmodule FreediveWeb.ServiceLive.Components do
|
|||
</span>
|
||||
<div class="mt-2 ml-2">Back</div>
|
||||
</.link>
|
||||
"""
|
||||
end
|
||||
|
||||
def service_header(assigns) do
|
||||
~H"""
|
||||
<.panel_block>
|
||||
<%!-- <.icon_raw for={@selected_item.icon} color="auto" size="3rem" class="" aria-hidden="true" /> --%>
|
||||
<.icon_raw for={@selected_item.icon} color="auto" size="3rem" aria-hidden="true" />
|
||||
<div class="column">
|
||||
<.title is-4>
|
||||
|
@ -171,13 +191,39 @@ defmodule FreediveWeb.ServiceLive.Components do
|
|||
</.subtitle>
|
||||
</div>
|
||||
</.panel_block>
|
||||
"""
|
||||
end
|
||||
|
||||
<%= if Map.has_key?(@selected_item, :log) and @selected_item.log != [] do %>
|
||||
<.panel_block>
|
||||
<pre><code><%= Enum.join(@selected_item.log, "\n") %></code></pre>
|
||||
</.panel_block>
|
||||
def service_preview(assigns) do
|
||||
~H"""
|
||||
<.panel_block
|
||||
class={"#{if @selected_item != nil and @selected_item.name == @item.name, do: "pt-2 has-background-info-light", else: "pt-2"}"}
|
||||
phx-click="tap"
|
||||
phx-value-name={@item.name}
|
||||
>
|
||||
|
||||
<.icon_raw for={@item.icon} color="auto" size="1.8rem" aria-hidden="true" />
|
||||
|
||||
<span class="is-size-5 px-4">
|
||||
<%= @item.name %>
|
||||
</span>
|
||||
|
||||
<%= if @item.running do %>
|
||||
<.icon for="circle-play" size="1rem" color="lightgreen" aria-hidden="true" />
|
||||
<% else %>
|
||||
<.icon for="circle-stop" size="1rem" color="gray" aria-hidden="true" />
|
||||
<% end %>
|
||||
<%= if @item.enabled do %>
|
||||
<.icon for="circle-check" size="1rem" color="lightgreen" aria-hidden="true" />
|
||||
<% else %>
|
||||
<.icon for="circle-x" size="1rem" color="gray" aria-hidden="true" />
|
||||
<% end %>
|
||||
</.panel_block>
|
||||
"""
|
||||
end
|
||||
|
||||
def basic_commands(assigns) do
|
||||
~H"""
|
||||
<.panel_block_div>
|
||||
<%= if @selected_item.running do %>
|
||||
<.icon_raw for="power" color="lightgreen" size="2rem" class="ml-2 mr-5" aria-hidden="true" />
|
||||
|
@ -214,9 +260,20 @@ defmodule FreediveWeb.ServiceLive.Components do
|
|||
<% end %>
|
||||
</div>
|
||||
</.panel_block_div>
|
||||
"""
|
||||
end
|
||||
|
||||
def extra_commands(assigns) do
|
||||
~H"""
|
||||
<%= if @selected_item.commands != [] and @selected_item.commands != nil do %>
|
||||
<.panel_block_div>
|
||||
<.icon_raw for="inspection-panel" color="auto" size="2rem" class="ml-1 mr-5" aria-hidden="true" />
|
||||
<.icon_raw
|
||||
for="inspection-panel"
|
||||
color="auto"
|
||||
size="2rem"
|
||||
class="ml-1 mr-5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="columns is-fullwidth mr-4">
|
||||
<%= for command <- @selected_item.commands do %>
|
||||
<button
|
||||
|
@ -234,23 +291,10 @@ defmodule FreediveWeb.ServiceLive.Components do
|
|||
"""
|
||||
end
|
||||
|
||||
def items_block(assigns) do
|
||||
def std_log(assigns) do
|
||||
~H"""
|
||||
<%= for {_name, item} <- @items do %>
|
||||
<div>
|
||||
<.panel_block
|
||||
class={"panel-block pt-3 #{if @selected_item != nil and @selected_item.name == item.name, do: "has-background-info-light"}"}
|
||||
phx-click="tap"
|
||||
phx-value-name={item.name}
|
||||
>
|
||||
<.icon_raw for={item.icon} color="auto" size="1.8rem" aria-hidden="true" />
|
||||
<%!-- <div class="mt-2 ml-2"> --%>
|
||||
<.subtitle class="ml-3">
|
||||
<%= item.name %>
|
||||
</.subtitle>
|
||||
<%!-- </div> --%>
|
||||
</.panel_block>
|
||||
</div>
|
||||
<%= if Map.has_key?(@selected_item, :log) and @selected_item.log != [] do %>
|
||||
<pre class="panel-block is-fullwidth"><code><%= Enum.join(@selected_item.log, "\n") %></code></pre>
|
||||
<% end %>
|
||||
"""
|
||||
end
|
||||
|
|
|
@ -37,7 +37,9 @@ defmodule Liliform.Page do
|
|||
phx-click="filter"
|
||||
phx-value-key={filter.key}
|
||||
>
|
||||
<span class="is-size-5">
|
||||
<%= filter.title %>
|
||||
</span>
|
||||
</a>
|
||||
<% end %>
|
||||
</.panel_tabs>
|
||||
|
@ -50,7 +52,11 @@ defmodule Liliform.Page do
|
|||
phx-click="filter"
|
||||
phx-value-key={filter.key}
|
||||
>
|
||||
<.icon for={filter.icon} color={if filter.active, do: "gray", else: "auto"} />
|
||||
<.icon_raw
|
||||
for={filter.icon}
|
||||
size="2rem"
|
||||
color={if filter.active, do: "gray", else: "auto"}
|
||||
/>
|
||||
</a>
|
||||
<% end %>
|
||||
</.panel_tabs>
|
||||
|
|
Loading…
Reference in a new issue