defmodule FreediveWeb.ServiceLive do use FreediveWeb.LiliformLive def render(assigns) do ~H""" <.page name="Services" filters={@filters} details={@details}> """ end def items() do %{ "sshd" => %{ name: "sshd", path: "/services/ssh", icon: "lock", description: "Secure Shell Daemon", enabled: true, running: true }, "pf" => %{ name: "pf", path: "/services/pf", icon: "shield", description: "Packet Filter", enabled: true, running: true }, "ntpdate" => %{ name: "ntpdate", path: "/services/ntp", icon: "clock", description: "Network Time Protocol Daemon", enabled: true, running: false }, "httpd" => %{ name: "httpd", path: "/services/httpd", icon: "globe", description: "Hypertext Transfer Protocol Daemon", enabled: false, running: false } } end def filters() do [ %{ title: "Running", key: :running, icon: "circle-play", active: true }, %{ title: "Enabled", key: :enabled, icon: "circle-check", active: false } ] end def search(items, query) do items |> Enum.filter(fn {name, _item} -> String.contains?(String.downcase(name), String.downcase(query)) end) |> Enum.into(%{}, fn {name, item} -> {name, item} end) end end defmodule FreediveWeb.ServiceLive.Components do use Liliform.Component import Liliform.Icon import Liliform.Panel import Liliform.Title @doc """ Returns items as panel-blocks. """ attr :items, :list, default: [], doc: "items" attr :selected_item, :string, default: nil, doc: "selected item" attr :details, :string, default: nil, doc: "details" def items_block(%{details: true} = assigns) do ~H""" <.link class="panel-block pt-1 has-background-light" phx-click="tap" phx-value-name={@selected_item.name} > <.icon for="arrow-left" aria-hidden="true" has-text-dark />
Back
<.panel_media> <:icon> <.icon_raw for={@selected_item.icon} color="auto" size="3rem" aria-hidden="true" /> <%!-- --%> <.title is-4> <%= @selected_item.name %> <.subtitle> <%= @selected_item.description %> <:actions>
<.icon for="running" color="auto" aria-hidden="true" /> <.icon for="enabled" color="auto" aria-hidden="true" />
""" end def items_block(assigns) do ~H""" <%= for {_name, item} <- @items do %> <.link class={"panel-block pt-1 #{if @selected_item != nil and @selected_item.name == item.name, do: "has-background-info-light"}"} phx-click="tap" phx-value-name={item.name} > <.icon for={item.icon} color="auto" aria-hidden="true" />
<%= item.name %>
<% end %> """ end end