Skip to content

Commit

Permalink
Clean up root page table
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Feb 28, 2024
1 parent 01a1750 commit e9628b3
Showing 1 changed file with 89 additions and 79 deletions.
168 changes: 89 additions & 79 deletions lib/polar_web/live/root_live.ex
Original file line number Diff line number Diff line change
@@ -1,102 +1,112 @@
defmodule PolarWeb.RootLive do
use PolarWeb, :live_view

alias Polar.Repo
alias Polar.Streams
alias Polar.Streams.Version

import Ecto.Query, only: [from: 2]

def render(assigns) do
~H"""
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-base font-semibold leading-6 text-white">
<%= gettext("Active Images") %>
</h1>
<p class="mt-2 text-sm text-slate-300">
<%= gettext("If you need something not available here please create an issue at the") %>
<a
href="https://github.com/upmaru/opsmaru-images"
class="font-semibold text-brand hover:underline"
target="_blank"
>
<%= gettext("opsmaru-images") %>
</a>
<%= gettext("repository.") %>
</p>
<div class="px-4 sm:px-0">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-base font-semibold leading-6 text-white">
<%= gettext("Active Images") %>
</h1>
<p class="mt-2 text-sm text-slate-300">
<%= gettext("If you need something not available here please create an issue at the") %>
<a
href="https://github.com/upmaru/opsmaru-images"
class="font-semibold text-brand hover:underline"
target="_blank"
>
<%= gettext("opsmaru-images") %>
</a>
<%= gettext("repository.") %>
</p>
</div>
</div>
</div>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<table class="min-w-full divide-y divide-slate-700">
<thead>
<tr>
<th
scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-white sm:pl-0"
>
<%= gettext("Aliases") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-white">
<%= gettext("Arch") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-white">
<%= gettext("Variant") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-white">
<%= gettext("Published At") %>
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-900">
<%= for {{os, release}, products} <- @grouped_products do %>
<tr class="border-t border-slate-800">
<th
colspan="5"
scope="colgroup"
class="bg-slate-900 py-2 pl-4 pr-3 text-left text-sm font-semibold text-slate-50 sm:pl-3"
>
<%= Phoenix.Naming.humanize(os) %> - <%= release %>
</th>
</tr>
<%= for product <- products do %>
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 sm:rounded-lg">
<table class="min-w-full divide-y divide-slate-300">
<thead class="bg-gray-50">
<tr>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-white sm:pl-0">
<%= for alias <- product.aliases do %>
<span class="inline-flex items-center rounded-md bg-green-500/10 px-2 py-1 text-xs font-medium text-green-400 ring-1 ring-inset ring-green-500/20">
<%= alias %>
</span>
<% end %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-slate-300">
<%= product.arch %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-slate-300">
<%= product.variant %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-slate-300">
<%= Calendar.strftime(
product.latest_version.inserted_at,
"%B %d, %Y %H:%M:%S"
) %>
</td>
<th
scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6"
>
<%= gettext("Aliases") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<%= gettext("Serial") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<%= gettext("OS") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<%= gettext("Arch") %>
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
<%= gettext("Published At") %>
</th>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<%= for version <- @versions do %>
<tr>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
<%= for alias <- version.product.aliases do %>
<span class="inline-flex items-center rounded-md bg-indigo-100 px-2 py-1 text-xs font-medium text-indigo-700">
<%= alias %>
</span>
<% end %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%= version.serial %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%= version.product.os %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%= version.product.arch %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%= Calendar.strftime(
version.inserted_at,
"%B %d, %Y %H:%M:%S"
) %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
"""
end

def mount(_params, _session, socket) do
products =
Streams.list_products([:active, :with_latest_version])
|> Enum.group_by(fn p -> {p.os, p.release} end)
versions =
from(
v in Version,
where: v.current_state == ^"active",
join: p in assoc(v, :product),
preload: [{:product, p}],
order_by: [asc: [p.os, p.arch]],
order_by: [desc: :inserted_at]
)
|> Repo.all()

socket =
socket
|> assign(:grouped_products, products)
|> assign(:versions, versions)
|> assign(:page_title, gettext("OpsMaru Images"))
|> assign(:current_path, ~p"/")

Expand Down

0 comments on commit e9628b3

Please sign in to comment.