Added new redownload option to source actions dropdown
This commit is contained in:
parent
1f453fd66b
commit
557be0887e
6 changed files with 53 additions and 17 deletions
|
|
@ -27,21 +27,20 @@ defmodule PinchflatWeb.CustomComponents.TableComponents do
|
|||
|
||||
def table(assigns) do
|
||||
~H"""
|
||||
<table class={["w-full table-auto", @table_class]}>
|
||||
<table class={["w-full table-auto bg-boxdark", @table_class]}>
|
||||
<thead>
|
||||
<tr class="bg-gray-2 text-left dark:bg-meta-4">
|
||||
<th :for={col <- @col} class="px-4 py-4 font-medium text-black dark:text-white xl:pl-11">
|
||||
<tr class="text-left bg-meta-4">
|
||||
<th :for={col <- @col} class="px-4 py-4 font-medium text-white xl:pl-11">
|
||||
<%= col[:label] %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr :for={{row, i} <- Enum.with_index(@rows)}>
|
||||
<tr :for={row <- @rows} class="border-b border-boxdark hover:border-strokedark">
|
||||
<td
|
||||
:for={col <- @col}
|
||||
class={[
|
||||
"px-4 py-5 pl-9 dark:border-strokedark xl:pl-11",
|
||||
i + 1 > length(@rows) && "border-b border-[#eee] dark:border-π",
|
||||
"px-4 py-5 pl-9 xl:pl-11",
|
||||
col[:class]
|
||||
]}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
|> redirect(to: ~p"/sources")
|
||||
end
|
||||
|
||||
def force_download(conn, %{"source_id" => id}) do
|
||||
def force_download_pending(conn, %{"source_id" => id}) do
|
||||
wrap_forced_action(
|
||||
conn,
|
||||
id,
|
||||
|
|
@ -113,6 +113,15 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
)
|
||||
end
|
||||
|
||||
def force_redownload(conn, %{"source_id" => id}) do
|
||||
wrap_forced_action(
|
||||
conn,
|
||||
id,
|
||||
"Forcing re-download of downloaded media items.",
|
||||
&DownloadingHelpers.kickoff_redownload_for_existing_media/1
|
||||
)
|
||||
end
|
||||
|
||||
def force_index(conn, %{"source_id" => id}) do
|
||||
wrap_forced_action(
|
||||
conn,
|
||||
|
|
|
|||
|
|
@ -31,11 +31,20 @@
|
|||
</:option>
|
||||
<:option :if={@source.download_media}>
|
||||
<.link
|
||||
href={~p"/sources/#{@source}/force_download"}
|
||||
href={~p"/sources/#{@source}/force_download_pending"}
|
||||
method="post"
|
||||
data-confirm="Are you sure you want to force a download of all *pending* media items? This isn't normally needed."
|
||||
>
|
||||
Force Download
|
||||
Download Pending
|
||||
</.link>
|
||||
</:option>
|
||||
<:option :if={@source.download_media}>
|
||||
<.link
|
||||
href={~p"/sources/#{@source}/force_redownload"}
|
||||
method="post"
|
||||
data-confirm="Are you sure you want to re-download all currently downloaded media items? This isn't normally needed and won't change anything if the files already exist."
|
||||
>
|
||||
Redownload Existing
|
||||
</.link>
|
||||
</:option>
|
||||
<:option>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ defmodule PinchflatWeb.Router do
|
|||
resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true
|
||||
|
||||
resources "/sources", Sources.SourceController do
|
||||
post "/force_download", Sources.SourceController, :force_download
|
||||
post "/force_download_pending", Sources.SourceController, :force_download_pending
|
||||
post "/force_redownload", Sources.SourceController, :force_redownload
|
||||
post "/force_index", Sources.SourceController, :force_index
|
||||
post "/force_metadata_refresh", Sources.SourceController, :force_metadata_refresh
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ defmodule Pinchflat.Downloading.DownloadingHelpersTest do
|
|||
describe "kickoff_redownload_for_existing_media/1" do
|
||||
test "enqueues a download job for each downloaded media item" do
|
||||
source = source_fixture()
|
||||
media_item = media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now())
|
||||
media_item = media_item_fixture(source_id: source.id, media_downloaded_at: now())
|
||||
|
||||
assert [{:ok, _}] = DownloadingHelpers.kickoff_redownload_for_existing_media(source)
|
||||
|
||||
|
|
@ -125,13 +125,13 @@ defmodule Pinchflat.Downloading.DownloadingHelpersTest do
|
|||
source = source_fixture()
|
||||
other_source = source_fixture()
|
||||
_not_downloaded = media_item_fixture(source_id: source.id, media_downloaded_at: nil)
|
||||
_other_source = media_item_fixture(source_id: other_source.id, media_downloaded_at: DateTime.utc_now())
|
||||
_other_source = media_item_fixture(source_id: other_source.id, media_downloaded_at: now())
|
||||
|
||||
_download_prevented =
|
||||
media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now(), prevent_download: true)
|
||||
media_item_fixture(source_id: source.id, media_downloaded_at: now(), prevent_download: true)
|
||||
|
||||
_culled =
|
||||
media_item_fixture(source_id: source.id, media_downloaded_at: DateTime.utc_now(), culled_at: DateTime.utc_now())
|
||||
media_item_fixture(source_id: source.id, media_downloaded_at: now(), culled_at: now())
|
||||
|
||||
assert [] = DownloadingHelpers.kickoff_redownload_for_existing_media(source)
|
||||
|
||||
|
|
|
|||
|
|
@ -166,20 +166,38 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "force_download" do
|
||||
describe "force_download_pending" do
|
||||
test "enqueues pending download tasks", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||
|
||||
assert [] = all_enqueued(worker: MediaDownloadWorker)
|
||||
post(conn, ~p"/sources/#{source.id}/force_download")
|
||||
post(conn, ~p"/sources/#{source.id}/force_download_pending")
|
||||
assert [_] = all_enqueued(worker: MediaDownloadWorker)
|
||||
end
|
||||
|
||||
test "redirects to the source page", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
|
||||
conn = post(conn, ~p"/sources/#{source.id}/force_download")
|
||||
conn = post(conn, ~p"/sources/#{source.id}/force_download_pending")
|
||||
assert redirected_to(conn) == ~p"/sources/#{source.id}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "force_redownload" do
|
||||
test "enqueues re-download tasks", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
_media_item = media_item_fixture(source_id: source.id, media_downloaded_at: now())
|
||||
|
||||
assert [] = all_enqueued(worker: MediaDownloadWorker)
|
||||
post(conn, ~p"/sources/#{source.id}/force_redownload")
|
||||
assert [_] = all_enqueued(worker: MediaDownloadWorker)
|
||||
end
|
||||
|
||||
test "redirects to the source page", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
|
||||
conn = post(conn, ~p"/sources/#{source.id}/force_redownload")
|
||||
assert redirected_to(conn) == ~p"/sources/#{source.id}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue