freedive/lib/freedive_web/live/service_live.ex

98 lines
2 KiB
Elixir
Raw Normal View History

2024-05-15 22:18:55 +02:00
defmodule FreediveWeb.ServiceLive do
2024-05-16 01:37:36 +02:00
use FreediveWeb.LiliformLive
2024-05-15 22:18:55 +02:00
def render(assigns) do
~H"""
2024-05-16 01:37:36 +02:00
<.block class="px-2 py-4">
2024-05-16 01:47:37 +02:00
<.page name="Services" filters={@filters}>
<FreediveWeb.ServiceLive.Item.items_block items={@items} />
2024-05-16 01:37:36 +02:00
</.page>
</.block>
2024-05-15 22:18:55 +02:00
"""
end
def items() do
[
%{
name: "sshd",
2024-05-16 01:37:36 +02:00
path: "/services/ssh",
icon: "blocks",
description: "Secure Shell Daemon",
enabled: true,
running: true
},
%{
name: "pf",
2024-05-16 01:37:36 +02:00
path: "/services/pf",
icon: "shield",
description: "Packet Filter",
enabled: true,
running: true
},
%{
name: "ntpdate",
2024-05-16 01:37:36 +02:00
path: "/services/ntp",
icon: "clock",
description: "Network Time Protocol Daemon",
enabled: true,
running: false
},
%{
name: "httpd",
2024-05-16 01:37:36 +02:00
path: "/services/httpd",
icon: "globe",
description: "Hypertext Transfer Protocol Daemon",
enabled: false,
running: false
}
]
2024-05-15 22:18:55 +02:00
end
2024-05-16 01:37:36 +02:00
def filters() do
[
%{
title: "Running",
2024-05-16 02:22:56 +02:00
key: :running,
2024-05-16 01:37:36 +02:00
icon: "circle-play",
active: true
},
%{
title: "Enabled",
2024-05-16 02:22:56 +02:00
key: :enabled,
2024-05-16 01:37:36 +02:00
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.Item do
use Liliform.Component
import Liliform.Icon
@doc """
Returns a list of items.
"""
attr :items, :list, default: [], doc: "items"
2024-05-16 01:47:37 +02:00
def items_block(assigns) do
2024-05-16 01:37:36 +02:00
~H"""
<%= for item <- @items do %>
<.link patch={item.path} class="panel-block pt-1">
<span class="panel-icon">
<.icon for={item.icon} color="auto" aria-hidden="true" />
</span>
<div class="mt-2 ml-2"><%= item.name %></div>
</.link>
<% end %>
"""
end
2024-05-15 22:18:55 +02:00
end