[Enhancement] Added "other" tab to see media that's not set for download (#258)

* Added tab for other (non-downloaded and non-pending) media

* Added column for tracking if media was manually ignored
This commit is contained in:
Kieran 2024-05-23 10:24:52 -07:00 committed by GitHub
parent 776b84c585
commit d2f91a8253
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 9 deletions

View file

@ -30,6 +30,9 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
<%= StringUtils.truncate(media_item.title, 50) %>
</.subtle_link>
</:col>
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?">
<.icon name={if media_item.prevent_download, do: "hero-check", else: "hero-x-mark"} />
</:col>
<:col :let={media_item} label="" class="flex justify-end">
<.icon_link href={~p"/sources/#{@source.id}/media/#{media_item.id}/edit"} icon="hero-pencil-square" class="mr-4" />
</:col>
@ -42,13 +45,25 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
end
def mount(_params, session, socket) do
PinchflatWeb.Endpoint.subscribe("media_table")
page = 1
media_state = session["media_state"]
source = Sources.get_source!(session["source_id"])
base_query = generate_base_query(source, media_state)
pagination_attrs = fetch_pagination_attributes(base_query, page)
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query, source: source}))}
new_assigns =
Map.merge(
pagination_attrs,
%{
base_query: base_query,
source: source,
media_state: media_state
}
)
{:ok, assign(socket, new_assigns)}
end
def handle_event("page_change", %{"direction" => direction}, %{assigns: assigns} = socket) do
@ -59,7 +74,13 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
{:noreply, assign(socket, new_assigns)}
end
def handle_event("reload_page", _params, %{assigns: assigns} = socket) do
def handle_event("reload_page", _params, socket) do
PinchflatWeb.Endpoint.broadcast("media_table", "reload", nil)
{:noreply, socket}
end
def handle_info(%{topic: "media_table", event: "reload"}, %{assigns: assigns} = socket) do
new_assigns = fetch_pagination_attributes(assigns.base_query, assigns.page)
{:noreply, assign(socket, new_assigns)}
@ -95,4 +116,16 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
|> where(^dynamic(^MediaQuery.for_source(source) and ^MediaQuery.downloaded()))
|> order_by(desc: :id)
end
defp generate_base_query(source, "other") do
MediaQuery.new()
|> MediaQuery.require_assoc(:media_profile)
|> where(
^dynamic(
^MediaQuery.for_source(source) and
(not (^MediaQuery.downloaded()) and not (^MediaQuery.pending()))
)
)
|> order_by(desc: :id)
end
end

View file

@ -36,21 +36,28 @@
<.list_items_from_map map={Map.from_struct(@source)} />
</div>
</:tab>
<:tab title="Pending Media" id="pending">
<:tab title="Pending" id="pending">
<%= live_render(
@conn,
Pinchflat.Sources.MediaItemTableLive,
session: %{"source_id" => @source.id, "media_state" => "pending"}
) %>
</:tab>
<:tab title="Downloaded Media" id="downloaded">
<:tab title="Downloaded" id="downloaded">
<%= live_render(
@conn,
Pinchflat.Sources.MediaItemTableLive,
session: %{"source_id" => @source.id, "media_state" => "downloaded"}
) %>
</:tab>
<:tab title="Pending Tasks" id="tasks">
<:tab title="Other" id="other">
<%= live_render(
@conn,
Pinchflat.Sources.MediaItemTableLive,
session: %{"source_id" => @source.id, "media_state" => "other"}
) %>
</:tab>
<:tab title="Tasks" id="tasks">
<%= if match?([_|_], @pending_tasks) do %>
<.table rows={@pending_tasks} table_class="text-black dark:text-white">
<:col :let={task} label="Worker">

View file

@ -4,6 +4,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLiveTest do
import Phoenix.LiveViewTest
import Pinchflat.MediaFixtures
import Pinchflat.SourcesFixtures
import Pinchflat.ProfilesFixtures
alias Pinchflat.Sources.MediaItemTableLive
@ -34,10 +35,8 @@ defmodule PinchflatWeb.Sources.MediaItemTableLiveTest do
describe "media_state" do
test "shows pending media when pending", %{conn: conn, source: source} do
downloaded_media_item = media_item_fixture(source_id: source.id, title: "DL-#{Enum.random(0..9999)}")
pending_media_item =
media_item_fixture(source_id: source.id, media_filepath: nil, title: "P-#{Enum.random(0..9999)}")
downloaded_media_item = media_item_fixture(source_id: source.id)
pending_media_item = media_item_fixture(source_id: source.id, media_filepath: nil)
{:ok, _view, html} = live_isolated(conn, MediaItemTableLive, session: create_session(source, "pending"))
@ -54,6 +53,29 @@ defmodule PinchflatWeb.Sources.MediaItemTableLiveTest do
assert html =~ downloaded_media_item.title
refute html =~ pending_media_item.title
end
test "shows records that aren't pending or downloaded when other", %{conn: conn} do
media_profile = media_profile_fixture(shorts_behaviour: :exclude)
source = source_fixture(media_profile_id: media_profile.id)
downloaded_media_item = media_item_fixture(source_id: source.id)
pending_media_item = media_item_fixture(source_id: source.id, media_filepath: nil)
other_media_item = media_item_fixture(source_id: source.id, media_filepath: nil, short_form_content: true)
{:ok, _view, html} = live_isolated(conn, MediaItemTableLive, session: create_session(source, "other"))
assert html =~ other_media_item.title
refute html =~ downloaded_media_item.title
refute html =~ pending_media_item.title
end
test "shows 'Manually Ignored' column when other", %{conn: conn, source: source} do
_media_item = media_item_fixture(source_id: source.id, prevent_download: true, media_filepath: nil)
{:ok, _view, html} = live_isolated(conn, MediaItemTableLive, session: create_session(source, "other"))
assert html =~ "Manually Ignored?"
end
end
defp create_session(source, media_state \\ "pending") do