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-16 17:11:00 +02:00
|
|
|
alias Freedive.Api.Service
|
2024-05-15 22:18:55 +02:00
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
~H"""
|
2024-05-16 05:15:32 +02:00
|
|
|
<.page name="Services" filters={@filters} details={@details}>
|
2024-05-16 03:56:54 +02:00
|
|
|
<FreediveWeb.ServiceLive.Components.items_block
|
|
|
|
items={@items}
|
|
|
|
selected_item={@selected_item}
|
|
|
|
details={@details}
|
|
|
|
/>
|
2024-05-16 02:27:59 +02:00
|
|
|
</.page>
|
2024-05-15 22:18:55 +02:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2024-05-15 23:59:20 +02:00
|
|
|
def items() do
|
2024-05-16 17:11:00 +02:00
|
|
|
Service.list()
|
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
|
|
|
|
|
2024-05-16 05:01:40 +02:00
|
|
|
def search(items, query) do
|
|
|
|
items
|
|
|
|
|> Enum.filter(fn {name, _item} ->
|
|
|
|
String.contains?(String.downcase(name), String.downcase(query))
|
2024-05-16 01:37:36 +02:00
|
|
|
end)
|
2024-05-16 05:01:40 +02:00
|
|
|
|> Enum.into(%{}, fn {name, item} -> {name, item} end)
|
2024-05-16 01:37:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-16 03:56:54 +02:00
|
|
|
defmodule FreediveWeb.ServiceLive.Components do
|
2024-05-16 01:37:36 +02:00
|
|
|
use Liliform.Component
|
|
|
|
import Liliform.Icon
|
2024-05-16 03:56:54 +02:00
|
|
|
import Liliform.Panel
|
|
|
|
import Liliform.Title
|
2024-05-16 01:37:36 +02:00
|
|
|
|
|
|
|
@doc """
|
2024-05-16 02:27:59 +02:00
|
|
|
Returns items as panel-blocks.
|
2024-05-16 01:37:36 +02:00
|
|
|
"""
|
|
|
|
attr :items, :list, default: [], doc: "items"
|
2024-05-16 03:56:54 +02:00
|
|
|
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}
|
|
|
|
>
|
|
|
|
<span class="panel-icon">
|
|
|
|
<.icon for="arrow-left" aria-hidden="true" has-text-dark />
|
|
|
|
</span>
|
|
|
|
<div class="mt-2 ml-2">Back</div>
|
|
|
|
</.link>
|
|
|
|
|
2024-05-16 12:44:28 +02:00
|
|
|
<.panel_media>
|
|
|
|
<:icon>
|
|
|
|
<.icon_raw for={@selected_item.icon} color="auto" size="3rem" aria-hidden="true" />
|
|
|
|
<%!-- <Lucideicons.accessibility height="2rem" width="2rem" /> --%>
|
|
|
|
</:icon>
|
|
|
|
|
|
|
|
<.title is-4>
|
|
|
|
<%= @selected_item.name %>
|
|
|
|
</.title>
|
|
|
|
<.subtitle>
|
|
|
|
<%= @selected_item.description %>
|
|
|
|
</.subtitle>
|
|
|
|
|
|
|
|
<:actions>
|
|
|
|
<div class="columns">
|
|
|
|
<div class="column is-narrow">
|
|
|
|
<.icon for="running" color="auto" aria-hidden="true" />
|
|
|
|
<.icon for="enabled" color="auto" aria-hidden="true" />
|
|
|
|
</div>
|
2024-05-16 05:01:40 +02:00
|
|
|
</div>
|
2024-05-16 12:44:28 +02:00
|
|
|
</:actions>
|
|
|
|
</.panel_media>
|
2024-05-16 03:56:54 +02:00
|
|
|
"""
|
|
|
|
end
|
2024-05-16 01:37:36 +02:00
|
|
|
|
2024-05-16 01:47:37 +02:00
|
|
|
def items_block(assigns) do
|
2024-05-16 01:37:36 +02:00
|
|
|
~H"""
|
2024-05-16 03:56:54 +02:00
|
|
|
<%= 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}
|
|
|
|
>
|
2024-05-16 01:37:36 +02:00
|
|
|
<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
|