diff --git a/lib/polar_web/live/root_live.ex b/lib/polar_web/live/root_live.ex index 77263e1..eb114b7 100644 --- a/lib/polar_web/live/root_live.ex +++ b/lib/polar_web/live/root_live.ex @@ -13,6 +13,14 @@ defmodule PolarWeb.RootLive do "inline-flex items-center rounded-full bg-cyan-100 px-2 py-1 text-xs font-medium text-cyan-700" } + @os_colors %{ + "alpine" => "h-1.5 w-1.5 fill-cyan-500", + "debian" => "h-1.5 w-1.5 fill-red-500", + "ubuntu" => "h-1.5 w-1.5 fill-amber-500" + } + + attr :filter, :map, default: %{} + def render(assigns) do ~H"""
@@ -31,8 +39,18 @@ defmodule PolarWeb.RootLive do <%= gettext("opsmaru-images") %> <%= gettext("repository.") %> + <%= gettext("Click on an os to filter.") %>

+
+ <.link + :if={!Enum.empty?(@filter)} + patch={~p"/"} + class="block rounded-md bg-indigo-600 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" + > + <%= gettext("Clear filter") %> + +
@@ -59,6 +77,9 @@ defmodule PolarWeb.RootLive do <%= gettext("Arch") %> + + <%= gettext("Variant") %> + <%= gettext("Published At") %> @@ -78,16 +99,38 @@ defmodule PolarWeb.RootLive do <%= version.serial %> - <%= version.product.os %> + <.link patch={~p"/?os=#{version.product.os}"}> + + + <%= Phoenix.Naming.humanize(version.product.os) %> + + <%= version.product.release %> - + <%= version.product.arch %> + + <%= version.product.variant %> + <%= Calendar.strftime( version.inserted_at, @@ -107,6 +150,41 @@ defmodule PolarWeb.RootLive do end def mount(_params, _session, socket) do + socket = + socket + |> assign(:versions, []) + |> assign(:page_title, gettext("OpsMaru Images")) + |> assign(:current_path, ~p"/") + |> assign(:arch_colors, @arch_colors) + |> assign(:os_colors, @os_colors) + |> assign(:filter, %{}) + + {:ok, socket} + end + + def handle_params(%{"os" => os} = params, _uri, socket) do + versions = + from( + v in Version, + join: p in assoc(v, :product), + where: v.current_state == ^"active" and p.os == ^os, + preload: [{:product, p}], + order_by: [asc: [p.os]], + order_by: [desc: [p.release]] + ) + |> Repo.all() + + filter = Map.take(params, ["os"]) + + socket = + socket + |> assign(:versions, versions) + |> assign(:filter, filter) + + {:noreply, socket} + end + + def handle_params(_, _uri, socket) do versions = from( v in Version, @@ -121,10 +199,8 @@ defmodule PolarWeb.RootLive do socket = socket |> assign(:versions, versions) - |> assign(:page_title, gettext("OpsMaru Images")) - |> assign(:current_path, ~p"/") - |> assign(:arch_colors, @arch_colors) + |> assign(:filter, %{}) - {:ok, socket} + {:noreply, socket} end end