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 ae4748b..d2cab17 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
@@ -28,9 +28,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
<.table rows={@records} table_class="text-white">
- <:col :let={media_item} label="Title">
+ <:col :let={media_item} label="Title" class="truncate max-w-xs">
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}>
- {StringUtils.truncate(media_item.title, 35)}
+ {media_item.title}
<:col :let={media_item} label="Upload Date">
@@ -42,9 +42,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
<:col :let={media_item} label="Downloaded At">
{format_datetime(media_item.media_downloaded_at)}
- <:col :let={media_item} label="Source">
+ <:col :let={media_item} label="Source" class="truncate max-w-xs">
<.subtle_link href={~p"/sources/#{media_item.source_id}"}>
- {StringUtils.truncate(media_item.source.custom_name, 35)}
+ {media_item.source.custom_name}
@@ -56,9 +56,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
"""
end
- def mount(_params, _session, socket) do
+ def mount(_params, session, socket) do
page = 1
- base_query = generate_base_query()
+ base_query = generate_base_query(session["media_state"])
pagination_attrs = fetch_pagination_attributes(base_query, page)
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))}
@@ -97,10 +97,17 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|> Repo.preload(:source)
end
- defp generate_base_query do
+ defp generate_base_query("pending") do
MediaQuery.new()
|> MediaQuery.require_assoc(:media_profile)
- |> where(^dynamic(^MediaQuery.downloaded() or ^MediaQuery.pending()))
+ |> where(^dynamic(^MediaQuery.pending()))
+ |> order_by(desc: :id)
+ end
+
+ defp generate_base_query("downloaded") do
+ MediaQuery.new()
+ |> MediaQuery.require_assoc(:media_profile)
+ |> where(^dynamic(^MediaQuery.downloaded()))
|> order_by(desc: :id)
end
diff --git a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex
index 1d7b50c..1579c31 100644
--- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex
+++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex
@@ -41,9 +41,22 @@
Media History
-
- {live_render(@conn, Pinchflat.Pages.HistoryTableLive)}
-
+ <.tabbed_layout>
+ <:tab title="Downloaded" id="downloaded">
+ {live_render(
+ @conn,
+ Pinchflat.Pages.HistoryTableLive,
+ session: %{"media_state" => "downloaded"}
+ )}
+
+ <:tab title="Pending" id="pending">
+ {live_render(
+ @conn,
+ Pinchflat.Pages.HistoryTableLive,
+ session: %{"media_state" => "pending"}
+ )}
+
+
diff --git a/lib/pinchflat_web/controllers/pages/page_html/job_table_live.ex b/lib/pinchflat_web/controllers/pages/page_html/job_table_live.ex
index 4c3c4d4..7e6bdc0 100644
--- a/lib/pinchflat_web/controllers/pages/page_html/job_table_live.ex
+++ b/lib/pinchflat_web/controllers/pages/page_html/job_table_live.ex
@@ -21,9 +21,9 @@ defmodule Pinchflat.Pages.JobTableLive do
<:col :let={task} label="Task">
{worker_to_task_name(task.job.worker)}
- <:col :let={task} label="Subject">
+ <:col :let={task} label="Subject" class="truncate max-w-xs">
<.subtle_link href={task_to_link(task)}>
- {StringUtils.truncate(task_to_record_name(task), 35)}
+ {task_to_record_name(task)}
<:col :let={task} label="Attempt No.">
diff --git a/lib/pinchflat_web/controllers/searches/search_html/show.html.heex b/lib/pinchflat_web/controllers/searches/search_html/show.html.heex
index 310cc5c..6307eee 100644
--- a/lib/pinchflat_web/controllers/searches/search_html/show.html.heex
+++ b/lib/pinchflat_web/controllers/searches/search_html/show.html.heex
@@ -9,9 +9,9 @@
<%= if match?([_|_], @search_results) do %>
<.table rows={@search_results} table_class="text-black dark:text-white">
- <:col :let={result} label="Title">
+ <:col :let={result} label="Title" class="truncate max-w-xs">
<.subtle_link href={~p"/sources/#{result.source_id}/media/#{result.id}"}>
- {StringUtils.truncate(result.title, 35)}
+ {result.title}
<:col :let={result} label="Excerpt">
diff --git a/lib/pinchflat_web/controllers/sources/source_html/index_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/index_table_live.ex
new file mode 100644
index 0000000..453073c
--- /dev/null
+++ b/lib/pinchflat_web/controllers/sources/source_html/index_table_live.ex
@@ -0,0 +1,103 @@
+defmodule PinchflatWeb.Sources.IndexTableLive do
+ use PinchflatWeb, :live_view
+ use Pinchflat.Media.MediaQuery
+ use Pinchflat.Sources.SourcesQuery
+
+ alias Pinchflat.Repo
+ alias Pinchflat.Sources
+ alias Pinchflat.Sources.Source
+ alias Pinchflat.Media.MediaItem
+
+ def render(assigns) do
+ ~H"""
+ <.table rows={@sources} table_class="text-white">
+ <:col :let={source} label="Name" class="truncate max-w-xs">
+ <.subtle_link href={~p"/sources/#{source.id}"}>
+ {source.custom_name || source.collection_name}
+
+
+ <:col :let={source} label="Pending">
+ <.subtle_link href={~p"/sources/#{source.id}/#tab-pending"}>
+ <.localized_number number={source.pending_count} />
+
+
+ <:col :let={source} label="Downloaded">
+ <.subtle_link href={~p"/sources/#{source.id}/#tab-downloaded"}>
+ <.localized_number number={source.downloaded_count} />
+
+
+ <:col :let={source} label="Retention">
+ <%= if source.retention_period_days && source.retention_period_days > 0 do %>
+ <.localized_number number={source.retention_period_days} />
+ <.pluralize count={source.retention_period_days} word="day" />
+ <% else %>
+ ∞
+ <% end %>
+
+ <:col :let={source} label="Media Profile">
+ <.subtle_link href={~p"/media_profiles/#{source.media_profile_id}"}>
+ {source.media_profile.name}
+
+
+ <:col :let={source} label="Enabled?">
+ <.input
+ name={"source[#{source.id}][enabled]"}
+ value={source.enabled}
+ id={"source_#{source.id}_enabled"}
+ phx-hook="formless-input"
+ data-subscribe="change"
+ data-event-name="toggle_enabled"
+ data-identifier={source.id}
+ type="toggle"
+ />
+
+ <:col :let={source} label="" class="flex place-content-evenly">
+ <.icon_link href={~p"/sources/#{source.id}/edit"} icon="hero-pencil-square" class="mx-1" />
+
+
+ """
+ end
+
+ def mount(_params, _session, socket) do
+ {:ok, assign(socket, %{sources: get_sources()})}
+ end
+
+ def handle_event("formless-input", %{"event" => "toggle_enabled"} = params, socket) do
+ source = Sources.get_source!(params["id"])
+ should_enable = params["value"] == "true"
+
+ {:ok, _} = Sources.update_source(source, %{enabled: should_enable})
+
+ {:noreply, assign(socket, %{sources: get_sources()})}
+ end
+
+ defp get_sources do
+ query =
+ from s in Source,
+ as: :source,
+ inner_join: mp in assoc(s, :media_profile),
+ where: is_nil(s.marked_for_deletion_at) and is_nil(mp.marked_for_deletion_at),
+ preload: [media_profile: mp],
+ order_by: [asc: s.custom_name],
+ select: map(s, ^Source.__schema__(:fields)),
+ select_merge: %{
+ downloaded_count:
+ subquery(
+ from m in MediaItem,
+ where: m.source_id == parent_as(:source).id,
+ where: ^MediaQuery.downloaded(),
+ select: count(m.id)
+ ),
+ pending_count:
+ subquery(
+ from m in MediaItem,
+ join: s in assoc(m, :source),
+ where: m.source_id == parent_as(:source).id,
+ where: ^MediaQuery.pending(),
+ select: count(m.id)
+ )
+ }
+
+ Repo.all(query)
+ end
+end
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 2f0fda5..bbcf681 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
@@ -46,9 +46,9 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
<.table rows={@records} table_class="text-white">
- <:col :let={media_item} label="Title">
+ <:col :let={media_item} label="Title" class="truncate max-w-xs">
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
- {StringUtils.truncate(media_item.title, 50)}
+ {media_item.title}
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?">