From 0c3da6f3f2c621f93e28b6ff758ba6302300d78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Tue, 13 May 2025 12:10:17 +0300 Subject: [PATCH 1/5] add quick download button #720 --- .../sources/source_html/media_item_table_live.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index 604ee49..95dc9b0 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -56,6 +56,17 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do > <.icon name="hero-exclamation-circle-solid" class="text-red-500" /> + + <.link + href={~p"/sources/#{@source.id}/media/#{media_item.id}/force_download"} + :if={!media_item.prevent_download} + method="post" + target="_blank" + data-confirm="Are you sure you force a download of this media?" + > + <.icon name="hero-arrow-down-tray" /> + + <.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}> {media_item.title} From a8c080ffd54edb0bc292187b252fe46704c1f185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Sat, 7 Jun 2025 11:12:03 +0300 Subject: [PATCH 2/5] don't show download button on already downloaded items. --- .../controllers/sources/source_html/media_item_table_live.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index 95dc9b0..3a97870 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -59,7 +59,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do <.link href={~p"/sources/#{@source.id}/media/#{media_item.id}/force_download"} - :if={!media_item.prevent_download} + :if={@media_state !== "downloaded"} method="post" target="_blank" data-confirm="Are you sure you force a download of this media?" From 37ef79e6ef11e435c98787b1b3841a8a457c8af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Sat, 7 Jun 2025 14:38:12 +0300 Subject: [PATCH 3/5] Add download in-page without page refresh --- .../pages/page_html/history_table_live.ex | 25 +++++++++++++++- .../source_html/media_item_table_live.ex | 30 +++++++++++++------ 2 files changed, 45 insertions(+), 10 deletions(-) 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 6c104aa..2e5ee59 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 @@ -6,6 +6,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do alias Pinchflat.Utils.NumberUtils alias PinchflatWeb.CustomComponents.TextComponents + alias Pinchflat.Media + alias Pinchflat.Downloading.MediaDownloadWorker + @limit 5 def render(%{records: []} = assigns) do @@ -29,7 +32,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
<.table rows={@records} table_class="text-white"> <:col :let={media_item} label="Title" class="max-w-xs"> -
+
<.tooltip :if={media_item.last_error} tooltip={media_item.last_error} @@ -38,6 +41,17 @@ defmodule Pinchflat.Pages.HistoryTableLive do > <.icon name="hero-exclamation-circle-solid" class="text-red-500" /> + + <.icon_button + icon_name="hero-arrow-down-tray" + class="h-10 w-10" + phx-click="force_download" + phx-value-source-id={media_item.source_id} + phx-value-media-id={media_item.id} + data-confirm="Are you sure you force a download of this media?" + :if={media_item.media_downloaded_at === nil} + /> + <.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item.id}"}> {media_item.title} @@ -90,6 +104,15 @@ defmodule Pinchflat.Pages.HistoryTableLive do {:noreply, assign(socket, new_assigns)} end + def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do + IO.puts("source_id: #{source_id}, media_id: #{media_id}") + + media_item = Media.get_media_item!(media_id) + MediaDownloadWorker.kickoff_with_task(media_item, %{force: true}) + + {:noreply, socket} + end + defp fetch_pagination_attributes(base_query, page) do total_record_count = Repo.aggregate(base_query, :count, :id) total_pages = max(ceil(total_record_count / @limit), 1) diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index 3a97870..203a35f 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -6,6 +6,9 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do alias Pinchflat.Sources alias Pinchflat.Utils.NumberUtils + alias Pinchflat.Media + alias Pinchflat.Downloading.MediaDownloadWorker + @limit 10 def render(%{total_record_count: 0} = assigns) do @@ -47,7 +50,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do <.table rows={@records} table_class="text-white"> <:col :let={media_item} label="Title" class="max-w-xs"> -
+
<.tooltip :if={media_item.last_error} tooltip={media_item.last_error} @@ -57,15 +60,15 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do <.icon name="hero-exclamation-circle-solid" class="text-red-500" /> - <.link - href={~p"/sources/#{@source.id}/media/#{media_item.id}/force_download"} - :if={@media_state !== "downloaded"} - method="post" - target="_blank" + <.icon_button + icon_name="hero-arrow-down-tray" + class="h-10 w-10" + phx-click="force_download" + phx-value-source-id={@source.id} + phx-value-media-id={media_item.id} data-confirm="Are you sure you force a download of this media?" - > - <.icon name="hero-arrow-down-tray" /> - + :if={@media_state !== "downloaded"} + /> <.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}> @@ -128,6 +131,15 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do {:noreply, assign(socket, new_assigns)} end + def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do + IO.puts("source_id: #{source_id}, media_id: #{media_id}") + + media_item = Media.get_media_item!(media_id) + MediaDownloadWorker.kickoff_with_task(media_item, %{force: true}) + + {:noreply, socket} + end + # This, along with the handle_info below, is a pattern to reload _all_ # tables on page rather than just the one that triggered the reload. def handle_event("reload_page", _params, socket) do From 0779e0b63461736f059cb8a98bd0a668f0a2326e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Sat, 7 Jun 2025 14:39:45 +0300 Subject: [PATCH 4/5] cleanup logs --- .../controllers/pages/page_html/history_table_live.ex | 2 -- .../controllers/sources/source_html/media_item_table_live.ex | 2 -- 2 files changed, 4 deletions(-) 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 2e5ee59..29d7ece 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 @@ -105,8 +105,6 @@ defmodule Pinchflat.Pages.HistoryTableLive do end def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do - IO.puts("source_id: #{source_id}, media_id: #{media_id}") - media_item = Media.get_media_item!(media_id) MediaDownloadWorker.kickoff_with_task(media_item, %{force: true}) diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index 203a35f..b627a4b 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -132,8 +132,6 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do end def handle_event("force_download", %{ "source-id" => source_id, "media-id" => media_id }, socket) do - IO.puts("source_id: #{source_id}, media_id: #{media_id}") - media_item = Media.get_media_item!(media_id) MediaDownloadWorker.kickoff_with_task(media_item, %{force: true}) From 42acbc38348feeb4342d50889136accb78bf216b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Sat, 7 Jun 2025 14:52:33 +0300 Subject: [PATCH 5/5] button size tweaks --- .../controllers/pages/page_html/history_table_live.ex | 2 +- .../controllers/sources/source_html/media_item_table_live.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 29d7ece..cdc7433 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 @@ -44,7 +44,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do <.icon_button icon_name="hero-arrow-down-tray" - class="h-10 w-10" + class="p-1" phx-click="force_download" phx-value-source-id={media_item.source_id} phx-value-media-id={media_item.id} diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index b627a4b..c89dd1b 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -62,7 +62,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do <.icon_button icon_name="hero-arrow-down-tray" - class="h-10 w-10" + class="p-1" phx-click="force_download" phx-value-source-id={@source.id} phx-value-media-id={media_item.id}