[WIP] reverted MP index table; added source count to MP index

This commit is contained in:
Kieran Eglin 2024-11-20 12:36:13 -08:00
parent e893b71e20
commit 6316d4e832
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 33 additions and 64 deletions

View file

@ -1,20 +1,31 @@
defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
use PinchflatWeb, :controller
use Pinchflat.Sources.SourcesQuery
use Pinchflat.Profiles.ProfilesQuery
alias Pinchflat.Repo
alias Pinchflat.Profiles
alias Pinchflat.Sources.Source
alias Pinchflat.Profiles.MediaProfile
alias Pinchflat.Profiles.MediaProfileDeletionWorker
def index(conn, _params) do
media_profiles =
MediaProfile
|> where([mp], is_nil(mp.marked_for_deletion_at))
|> order_by(asc: :name)
|> Repo.all()
media_profiles_query =
from mp in MediaProfile,
as: :media_profile,
where: is_nil(mp.marked_for_deletion_at),
order_by: [asc: mp.name],
select: map(mp, ^MediaProfile.__schema__(:fields)),
select_merge: %{
source_count:
subquery(
from s in Source,
where: s.media_profile_id == parent_as(:media_profile).id,
select: count(s.id)
)
}
render(conn, :index, media_profiles: media_profiles)
render(conn, :index, media_profiles: Repo.all(media_profiles_query))
end
def new(conn, _params) do

View file

@ -14,7 +14,22 @@
<div class="rounded-sm border border-stroke bg-white shadow-default dark:border-strokedark dark:bg-boxdark">
<div class="max-w-full overflow-x-auto">
<div class="flex flex-col gap-10 min-w-max">
<%= live_render(@conn, PinchflatWeb.MediaProfiles.IndexTableLive) %>
<.table rows={@media_profiles} table_class="text-black dark:text-white">
<:col :let={media_profile} label="Name">
<.subtle_link href={~p"/media_profiles/#{media_profile.id}"}>
<%= media_profile.name %>
</.subtle_link>
</:col>
<:col :let={media_profile} label="Preferred Resolution">
<%= media_profile.preferred_resolution %>
</:col>
<:col :let={media_profile} label="Sources">
<.localized_number number={media_profile.source_count} />
</:col>
<:col :let={media_profile} label="" class="flex justify-end">
<.icon_link href={~p"/media_profiles/#{media_profile.id}/edit"} icon="hero-pencil-square" class="mr-4" />
</:col>
</.table>
</div>
</div>
</div>

View file

@ -1,57 +0,0 @@
defmodule PinchflatWeb.MediaProfiles.IndexTableLive do
use PinchflatWeb, :live_view
use Pinchflat.Profiles.ProfilesQuery
alias Pinchflat.Repo
def render(assigns) do
~H"""
<.table rows={@media_profiles} table_class="text-black dark:text-white">
<:col :let={media_profile} label="Name">
<.subtle_link href={~p"/media_profiles/#{media_profile.id}"}>
<%= media_profile.name %>
</.subtle_link>
</:col>
<:col :let={media_profile} label="Preferred Resolution">
<%= media_profile.preferred_resolution %>
</:col>
<:col :let={media_profile} label="Enabled?">
<.input
name={"media_profile[#{media_profile.id}][enabled]"}
id={"media_profile_#{media_profile.id}_enabled"}
phx-hook="formless-input"
data-subscribe="change"
data-event-name="toggle_enabled"
data-identifier={media_profile.id}
type="toggle"
/>
</:col>
<:col :let={media_profile} label="" class="flex justify-end">
<.icon_link href={~p"/media_profiles/#{media_profile.id}/edit"} icon="hero-pencil-square" class="mr-4" />
</:col>
</.table>
"""
end
def mount(_params, _session, socket) do
new_assigns = %{
media_profiles: get_media_profiles()
}
{:ok, assign(socket, new_assigns)}
end
def handle_event("formless-input", %{"event" => "toggle_enabled"} = params, socket) do
# should_enable = params["value"] == "true"
IO.inspect(params)
{:noreply, socket}
end
defp get_media_profiles do
ProfilesQuery.new()
|> where([mp], is_nil(mp.marked_for_deletion_at))
|> order_by(asc: :name)
|> Repo.all()
end
end