From d5e710e4ac03389e53cade91132d47718a2e3ec3 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 7 May 2024 11:25:57 -0700 Subject: [PATCH] Improved homepage history query --- lib/pinchflat/media/media_query.ex | 6 +++ .../controllers/pages/page_controller.ex | 8 ++-- .../pages/page_html/history_table_live.ex | 45 ++++++++++--------- .../pages/page_html/home.html.heex | 24 +++------- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/lib/pinchflat/media/media_query.ex b/lib/pinchflat/media/media_query.ex index 53e2c35..349e875 100644 --- a/lib/pinchflat/media/media_query.ex +++ b/lib/pinchflat/media/media_query.ex @@ -172,6 +172,12 @@ defmodule Pinchflat.Media.MediaQuery do |> matching_source_title_regex() 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 if has_named_binding?(query, identifier) do query diff --git a/lib/pinchflat_web/controllers/pages/page_controller.ex b/lib/pinchflat_web/controllers/pages/page_controller.ex index ef1b154..b66a96b 100644 --- a/lib/pinchflat_web/controllers/pages/page_controller.ex +++ b/lib/pinchflat_web/controllers/pages/page_controller.ex @@ -1,10 +1,9 @@ defmodule PinchflatWeb.Pages.PageController do - alias Pinchflat.Media.MediaItem use PinchflatWeb, :controller alias Pinchflat.Repo alias Pinchflat.Sources.Source - alias Pinchflat.Media.MediaItem + alias Pinchflat.Media.MediaQuery alias Pinchflat.Profiles.MediaProfile def home(conn, params) do @@ -25,7 +24,10 @@ defmodule PinchflatWeb.Pages.PageController do |> render(:home, media_profile_count: Repo.aggregate(MediaProfile, :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 diff --git a/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex b/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex index bd5c2a7..4d221a2 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex +++ b/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex @@ -24,27 +24,29 @@ defmodule Pinchflat.Pages.HistoryTableLive do <.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" /> Showing <%= length(@records) %> of <%= @total_record_count %> - <.table rows={@records} table_class="text-white"> - <:col :let={media_item} label="Title"> - <.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}> - <%= StringUtils.truncate(media_item.title, 35) %> - - - <:col :let={media_item} label="Upload Date"> - <%= media_item.upload_date %> - - <:col :let={media_item} label="Indexed At (UTC)"> - <%= format_datetime(media_item.inserted_at) %> - - <:col :let={media_item} label="Downloaded At (UTC)"> - <%= format_datetime(media_item.media_downloaded_at) %> - - <:col :let={media_item} label="Source"> - <.subtle_link href={~p"/sources/#{media_item.source_id}"}> - <%= StringUtils.truncate(media_item.source.custom_name, 35) %> - - - +
+ <.table rows={@records} table_class="text-white"> + <:col :let={media_item} label="Title"> + <.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}> + <%= StringUtils.truncate(media_item.title, 35) %> + + + <:col :let={media_item} label="Upload Date"> + <%= media_item.upload_date %> + + <:col :let={media_item} label="Indexed At"> + <%= format_datetime(media_item.inserted_at) %> + + <:col :let={media_item} label="Downloaded At"> + <%= format_datetime(media_item.media_downloaded_at) %> + + <:col :let={media_item} label="Source"> + <.subtle_link href={~p"/sources/#{media_item.source_id}"}> + <%= StringUtils.truncate(media_item.source.custom_name, 35) %> + + + +
<.live_pagination_controls page_number={@page} total_pages={@total_pages} />
@@ -95,6 +97,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do defp generate_base_query do MediaQuery.new() + |> MediaQuery.where_pending_or_downloaded() |> order_by(desc: :id) end diff --git a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex index c417681..d018bcb 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex +++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex @@ -17,7 +17,7 @@
- Media Item(s) + Downloaded Media

<%= @media_item_count %>

@@ -26,22 +26,8 @@
-
- Download History -
- <%= live_render(@conn, Pinchflat.Pages.HistoryTableLive) %> -
-
+ History +
+ <%= live_render(@conn, Pinchflat.Pages.HistoryTableLive) %> +
- -<%!--
-
-
- <.table rows={[]} table_class="text-black dark:text-white"> - <:col :let={_source} label="Name">Test - -
-
-
--%> - -I know this page isn't super useful yet, but give it time :)