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
|
def table(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<table class={["w-full table-auto", @table_class]}>
|
<table class={["w-full table-auto bg-boxdark", @table_class]}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-gray-2 text-left dark:bg-meta-4">
|
<tr class="text-left bg-meta-4">
|
||||||
<th :for={col <- @col} class="px-4 py-4 font-medium text-black dark:text-white xl:pl-11">
|
<th :for={col <- @col} class="px-4 py-4 font-medium text-white xl:pl-11">
|
||||||
<%= col[:label] %>
|
<%= col[:label] %>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr :for={{row, i} <- Enum.with_index(@rows)}>
|
<tr :for={row <- @rows} class="border-b border-boxdark hover:border-strokedark">
|
||||||
<td
|
<td
|
||||||
:for={col <- @col}
|
:for={col <- @col}
|
||||||
class={[
|
class={[
|
||||||
"px-4 py-5 pl-9 dark:border-strokedark xl:pl-11",
|
"px-4 py-5 pl-9 xl:pl-11",
|
||||||
i + 1 > length(@rows) && "border-b border-[#eee] dark:border-π",
|
|
||||||
col[:class]
|
col[:class]
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
|> redirect(to: ~p"/sources")
|
|> redirect(to: ~p"/sources")
|
||||||
end
|
end
|
||||||
|
|
||||||
def force_download(conn, %{"source_id" => id}) do
|
def force_download_pending(conn, %{"source_id" => id}) do
|
||||||
wrap_forced_action(
|
wrap_forced_action(
|
||||||
conn,
|
conn,
|
||||||
id,
|
id,
|
||||||
|
|
@ -113,6 +113,15 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
)
|
)
|
||||||
end
|
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
|
def force_index(conn, %{"source_id" => id}) do
|
||||||
wrap_forced_action(
|
wrap_forced_action(
|
||||||
conn,
|
conn,
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,20 @@
|
||||||
</:option>
|
</:option>
|
||||||
<:option :if={@source.download_media}>
|
<:option :if={@source.download_media}>
|
||||||
<.link
|
<.link
|
||||||
href={~p"/sources/#{@source}/force_download"}
|
href={~p"/sources/#{@source}/force_download_pending"}
|
||||||
method="post"
|
method="post"
|
||||||
data-confirm="Are you sure you want to force a download of all *pending* media items? This isn't normally needed."
|
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>
|
</.link>
|
||||||
</:option>
|
</:option>
|
||||||
<:option>
|
<:option>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ defmodule PinchflatWeb.Router do
|
||||||
resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true
|
resources "/settings", Settings.SettingController, only: [:show, :update], singleton: true
|
||||||
|
|
||||||
resources "/sources", Sources.SourceController do
|
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_index", Sources.SourceController, :force_index
|
||||||
post "/force_metadata_refresh", Sources.SourceController, :force_metadata_refresh
|
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
|
describe "kickoff_redownload_for_existing_media/1" do
|
||||||
test "enqueues a download job for each downloaded media item" do
|
test "enqueues a download job for each downloaded media item" do
|
||||||
source = source_fixture()
|
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)
|
assert [{:ok, _}] = DownloadingHelpers.kickoff_redownload_for_existing_media(source)
|
||||||
|
|
||||||
|
|
@ -125,13 +125,13 @@ defmodule Pinchflat.Downloading.DownloadingHelpersTest do
|
||||||
source = source_fixture()
|
source = source_fixture()
|
||||||
other_source = source_fixture()
|
other_source = source_fixture()
|
||||||
_not_downloaded = media_item_fixture(source_id: source.id, media_downloaded_at: nil)
|
_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 =
|
_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 =
|
_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)
|
assert [] = DownloadingHelpers.kickoff_redownload_for_existing_media(source)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,20 +166,38 @@ defmodule PinchflatWeb.SourceControllerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "force_download" do
|
describe "force_download_pending" do
|
||||||
test "enqueues pending download tasks", %{conn: conn} do
|
test "enqueues pending download tasks", %{conn: conn} do
|
||||||
source = source_fixture()
|
source = source_fixture()
|
||||||
_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil})
|
||||||
|
|
||||||
assert [] = all_enqueued(worker: MediaDownloadWorker)
|
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)
|
assert [_] = all_enqueued(worker: MediaDownloadWorker)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "redirects to the source page", %{conn: conn} do
|
test "redirects to the source page", %{conn: conn} do
|
||||||
source = source_fixture()
|
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}"
|
assert redirected_to(conn) == ~p"/sources/#{source.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue