defmodule FreediveWeb.ServiceLive do use FreediveWeb.LiliformLive def render(assigns) do ~H""" <.page name="Services" filters={@filters}> """ end def items() do %{ "sshd" => %{ name: "sshd", path: "/services/ssh", icon: "blocks", 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(query) do items() |> Enum.filter(fn item -> String.contains?(String.downcase(item.name), String.downcase(query)) 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_block_div>
<.title class="column"> <%= @selected_item.name %> <.subtitle class="column"> <%= @selected_item.description %>
""" 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