Add download in-page without page refresh
This commit is contained in:
parent
a8c080ffd5
commit
37ef79e6ef
2 changed files with 45 additions and 10 deletions
|
|
@ -6,6 +6,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
alias Pinchflat.Utils.NumberUtils
|
alias Pinchflat.Utils.NumberUtils
|
||||||
alias PinchflatWeb.CustomComponents.TextComponents
|
alias PinchflatWeb.CustomComponents.TextComponents
|
||||||
|
|
||||||
|
alias Pinchflat.Media
|
||||||
|
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||||
|
|
||||||
@limit 5
|
@limit 5
|
||||||
|
|
||||||
def render(%{records: []} = assigns) do
|
def render(%{records: []} = assigns) do
|
||||||
|
|
@ -29,7 +32,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
<div class="max-w-full overflow-x-auto">
|
<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" class="max-w-xs">
|
<:col :let={media_item} label="Title" class="max-w-xs">
|
||||||
<section class="flex items-center space-x-1">
|
<section class="flex items-center space-x-1 gap-2">
|
||||||
<.tooltip
|
<.tooltip
|
||||||
:if={media_item.last_error}
|
:if={media_item.last_error}
|
||||||
tooltip={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 name="hero-exclamation-circle-solid" class="text-red-500" />
|
||||||
</.tooltip>
|
</.tooltip>
|
||||||
|
|
||||||
|
<.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}
|
||||||
|
/>
|
||||||
|
|
||||||
<span class="truncate">
|
<span class="truncate">
|
||||||
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item.id}"}>
|
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item.id}"}>
|
||||||
{media_item.title}
|
{media_item.title}
|
||||||
|
|
@ -90,6 +104,15 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
{:noreply, assign(socket, new_assigns)}
|
{:noreply, assign(socket, new_assigns)}
|
||||||
end
|
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
|
defp fetch_pagination_attributes(base_query, page) do
|
||||||
total_record_count = Repo.aggregate(base_query, :count, :id)
|
total_record_count = Repo.aggregate(base_query, :count, :id)
|
||||||
total_pages = max(ceil(total_record_count / @limit), 1)
|
total_pages = max(ceil(total_record_count / @limit), 1)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
||||||
alias Pinchflat.Sources
|
alias Pinchflat.Sources
|
||||||
alias Pinchflat.Utils.NumberUtils
|
alias Pinchflat.Utils.NumberUtils
|
||||||
|
|
||||||
|
alias Pinchflat.Media
|
||||||
|
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||||
|
|
||||||
@limit 10
|
@limit 10
|
||||||
|
|
||||||
def render(%{total_record_count: 0} = assigns) do
|
def render(%{total_record_count: 0} = assigns) do
|
||||||
|
|
@ -47,7 +50,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
||||||
</header>
|
</header>
|
||||||
<.table rows={@records} table_class="text-white">
|
<.table rows={@records} table_class="text-white">
|
||||||
<:col :let={media_item} label="Title" class="max-w-xs">
|
<:col :let={media_item} label="Title" class="max-w-xs">
|
||||||
<section class="flex items-center space-x-1">
|
<section class="flex items-center space-x-1 gap-2">
|
||||||
<.tooltip
|
<.tooltip
|
||||||
:if={media_item.last_error}
|
:if={media_item.last_error}
|
||||||
tooltip={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" />
|
<.icon name="hero-exclamation-circle-solid" class="text-red-500" />
|
||||||
</.tooltip>
|
</.tooltip>
|
||||||
|
|
||||||
<.link
|
<.icon_button
|
||||||
href={~p"/sources/#{@source.id}/media/#{media_item.id}/force_download"}
|
icon_name="hero-arrow-down-tray"
|
||||||
:if={@media_state !== "downloaded"}
|
class="h-10 w-10"
|
||||||
method="post"
|
phx-click="force_download"
|
||||||
target="_blank"
|
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?"
|
data-confirm="Are you sure you force a download of this media?"
|
||||||
>
|
:if={@media_state !== "downloaded"}
|
||||||
<.icon name="hero-arrow-down-tray" />
|
/>
|
||||||
</.link>
|
|
||||||
|
|
||||||
<span class="truncate">
|
<span class="truncate">
|
||||||
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
|
<.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)}
|
{:noreply, assign(socket, new_assigns)}
|
||||||
end
|
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_
|
# 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.
|
# tables on page rather than just the one that triggered the reload.
|
||||||
def handle_event("reload_page", _params, socket) do
|
def handle_event("reload_page", _params, socket) do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue