Improved homepage history query
This commit is contained in:
parent
e3c9326003
commit
d5e710e4ac
4 changed files with 40 additions and 43 deletions
|
|
@ -172,6 +172,12 @@ defmodule Pinchflat.Media.MediaQuery do
|
||||||
|> matching_source_title_regex()
|
|> matching_source_title_regex()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def where_pending_or_downloaded(query) do
|
||||||
|
query
|
||||||
|
|> where_pending_download()
|
||||||
|
|> or_where([mi], not is_nil(mi.media_downloaded_at))
|
||||||
|
end
|
||||||
|
|
||||||
defp require_assoc(query, identifier) do
|
defp require_assoc(query, identifier) do
|
||||||
if has_named_binding?(query, identifier) do
|
if has_named_binding?(query, identifier) do
|
||||||
query
|
query
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
defmodule PinchflatWeb.Pages.PageController do
|
defmodule PinchflatWeb.Pages.PageController do
|
||||||
alias Pinchflat.Media.MediaItem
|
|
||||||
use PinchflatWeb, :controller
|
use PinchflatWeb, :controller
|
||||||
|
|
||||||
alias Pinchflat.Repo
|
alias Pinchflat.Repo
|
||||||
alias Pinchflat.Sources.Source
|
alias Pinchflat.Sources.Source
|
||||||
alias Pinchflat.Media.MediaItem
|
alias Pinchflat.Media.MediaQuery
|
||||||
alias Pinchflat.Profiles.MediaProfile
|
alias Pinchflat.Profiles.MediaProfile
|
||||||
|
|
||||||
def home(conn, params) do
|
def home(conn, params) do
|
||||||
|
|
@ -25,7 +24,10 @@ defmodule PinchflatWeb.Pages.PageController do
|
||||||
|> render(:home,
|
|> render(:home,
|
||||||
media_profile_count: Repo.aggregate(MediaProfile, :count, :id),
|
media_profile_count: Repo.aggregate(MediaProfile, :count, :id),
|
||||||
source_count: Repo.aggregate(Source, :count, :id),
|
source_count: Repo.aggregate(Source, :count, :id),
|
||||||
media_item_count: Repo.aggregate(MediaItem, :count, :id)
|
media_item_count:
|
||||||
|
MediaQuery.new()
|
||||||
|
|> MediaQuery.with_media_downloaded_at()
|
||||||
|
|> Repo.aggregate(:count, :id)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
<.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" />
|
<.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" />
|
||||||
<span class="ml-2">Showing <%= length(@records) %> of <%= @total_record_count %></span>
|
<span class="ml-2">Showing <%= length(@records) %> of <%= @total_record_count %></span>
|
||||||
</span>
|
</span>
|
||||||
|
<div class="max-w-full overflow-x-auto">
|
||||||
<.table rows={@records} table_class="text-white">
|
<.table rows={@records} table_class="text-white">
|
||||||
<:col :let={media_item} label="Title">
|
<:col :let={media_item} label="Title">
|
||||||
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}>
|
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}>
|
||||||
|
|
@ -33,10 +34,10 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
<:col :let={media_item} label="Upload Date">
|
<:col :let={media_item} label="Upload Date">
|
||||||
<%= media_item.upload_date %>
|
<%= media_item.upload_date %>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={media_item} label="Indexed At (UTC)">
|
<:col :let={media_item} label="Indexed At">
|
||||||
<%= format_datetime(media_item.inserted_at) %>
|
<%= format_datetime(media_item.inserted_at) %>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={media_item} label="Downloaded At (UTC)">
|
<:col :let={media_item} label="Downloaded At">
|
||||||
<%= format_datetime(media_item.media_downloaded_at) %>
|
<%= format_datetime(media_item.media_downloaded_at) %>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={media_item} label="Source">
|
<:col :let={media_item} label="Source">
|
||||||
|
|
@ -45,6 +46,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
</.table>
|
</.table>
|
||||||
|
</div>
|
||||||
<section class="flex justify-center mt-5">
|
<section class="flex justify-center mt-5">
|
||||||
<.live_pagination_controls page_number={@page} total_pages={@total_pages} />
|
<.live_pagination_controls page_number={@page} total_pages={@total_pages} />
|
||||||
</section>
|
</section>
|
||||||
|
|
@ -95,6 +97,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
|
|
||||||
defp generate_base_query do
|
defp generate_base_query do
|
||||||
MediaQuery.new()
|
MediaQuery.new()
|
||||||
|
|> MediaQuery.where_pending_or_downloaded()
|
||||||
|> order_by(desc: :id)
|
|> order_by(desc: :id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="rounded-sm border px-7.5 py-6 shadow-default border-strokedark bg-boxdark">
|
<div class="rounded-sm border px-7.5 py-6 shadow-default border-strokedark bg-boxdark">
|
||||||
<span class="mt-4 flex flex-col items-center justify-center">
|
<span class="mt-4 flex flex-col items-center justify-center">
|
||||||
<span class="text-md font-medium">Media Item(s)</span>
|
<span class="text-md font-medium">Downloaded Media</span>
|
||||||
<h4 class="text-title-md font-bold text-white">
|
<h4 class="text-title-md font-bold text-white">
|
||||||
<%= @media_item_count %>
|
<%= @media_item_count %>
|
||||||
</h4>
|
</h4>
|
||||||
|
|
@ -26,22 +26,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
||||||
<div class="max-w-full overflow-x-auto">
|
<span class="text-2xl font-medium mb-4">History</span>
|
||||||
<span class="text-2xl font-medium mb-4">Download History</span>
|
|
||||||
<section class="mt-6">
|
<section class="mt-6">
|
||||||
<%= live_render(@conn, Pinchflat.Pages.HistoryTableLive) %>
|
<%= live_render(@conn, Pinchflat.Pages.HistoryTableLive) %>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<%!-- <div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4">
|
|
||||||
<div class="max-w-full overflow-x-auto">
|
|
||||||
<div class="flex flex-col gap-10 min-w-max">
|
|
||||||
<.table rows={[]} table_class="text-black dark:text-white">
|
|
||||||
<:col :let={_source} label="Name">Test</:col>
|
|
||||||
</.table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> --%>
|
|
||||||
|
|
||||||
<span class="text-strokedark">I know this page isn't super useful yet, but give it time :)</span>
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue