Merged parent
This commit is contained in:
commit
e43fbd2888
6 changed files with 140 additions and 17 deletions
|
|
@ -28,9 +28,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
</span>
|
</span>
|
||||||
<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">
|
<:col :let={media_item} label="Title" class="truncate max-w-xs">
|
||||||
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}>
|
<.subtle_link href={~p"/sources/#{media_item.source_id}/media/#{media_item}"}>
|
||||||
{StringUtils.truncate(media_item.title, 35)}
|
{media_item.title}
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={media_item} label="Upload Date">
|
<:col :let={media_item} label="Upload Date">
|
||||||
|
|
@ -42,9 +42,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
<:col :let={media_item} label="Downloaded At">
|
<:col :let={media_item} label="Downloaded At">
|
||||||
{format_datetime(media_item.media_downloaded_at)}
|
{format_datetime(media_item.media_downloaded_at)}
|
||||||
</:col>
|
</:col>
|
||||||
<: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}"}>
|
<.subtle_link href={~p"/sources/#{media_item.source_id}"}>
|
||||||
{StringUtils.truncate(media_item.source.custom_name, 35)}
|
{media_item.source.custom_name}
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
</.table>
|
</.table>
|
||||||
|
|
@ -56,9 +56,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, session, socket) do
|
||||||
page = 1
|
page = 1
|
||||||
base_query = generate_base_query()
|
base_query = generate_base_query(session["media_state"])
|
||||||
pagination_attrs = fetch_pagination_attributes(base_query, page)
|
pagination_attrs = fetch_pagination_attributes(base_query, page)
|
||||||
|
|
||||||
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))}
|
{:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))}
|
||||||
|
|
@ -97,10 +97,17 @@ defmodule Pinchflat.Pages.HistoryTableLive do
|
||||||
|> Repo.preload(:source)
|
|> Repo.preload(:source)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp generate_base_query do
|
defp generate_base_query("pending") do
|
||||||
MediaQuery.new()
|
MediaQuery.new()
|
||||||
|> MediaQuery.require_assoc(:media_profile)
|
|> 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)
|
|> order_by(desc: :id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,22 @@
|
||||||
|
|
||||||
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
||||||
<span class="text-2xl font-medium mb-4">Media History</span>
|
<span class="text-2xl font-medium mb-4">Media History</span>
|
||||||
<section class="mt-6">
|
<.tabbed_layout>
|
||||||
{live_render(@conn, Pinchflat.Pages.HistoryTableLive)}
|
<:tab title="Downloaded" id="downloaded">
|
||||||
</section>
|
{live_render(
|
||||||
|
@conn,
|
||||||
|
Pinchflat.Pages.HistoryTableLive,
|
||||||
|
session: %{"media_state" => "downloaded"}
|
||||||
|
)}
|
||||||
|
</:tab>
|
||||||
|
<:tab title="Pending" id="pending">
|
||||||
|
{live_render(
|
||||||
|
@conn,
|
||||||
|
Pinchflat.Pages.HistoryTableLive,
|
||||||
|
session: %{"media_state" => "pending"}
|
||||||
|
)}
|
||||||
|
</:tab>
|
||||||
|
</.tabbed_layout>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
<div class="rounded-sm border shadow-default border-strokedark bg-boxdark mt-4 p-5">
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ defmodule Pinchflat.Pages.JobTableLive do
|
||||||
<:col :let={task} label="Task">
|
<:col :let={task} label="Task">
|
||||||
{worker_to_task_name(task.job.worker)}
|
{worker_to_task_name(task.job.worker)}
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={task} label="Subject">
|
<:col :let={task} label="Subject" class="truncate max-w-xs">
|
||||||
<.subtle_link href={task_to_link(task)}>
|
<.subtle_link href={task_to_link(task)}>
|
||||||
{StringUtils.truncate(task_to_record_name(task), 35)}
|
{task_to_record_name(task)}
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={task} label="Attempt No.">
|
<:col :let={task} label="Attempt No.">
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@
|
||||||
<div class="flex flex-col gap-10 dark:text-white">
|
<div class="flex flex-col gap-10 dark:text-white">
|
||||||
<%= if match?([_|_], @search_results) do %>
|
<%= if match?([_|_], @search_results) do %>
|
||||||
<.table rows={@search_results} table_class="text-black dark:text-white">
|
<.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}"}>
|
<.subtle_link href={~p"/sources/#{result.source_id}/media/#{result.id}"}>
|
||||||
{StringUtils.truncate(result.title, 35)}
|
{result.title}
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={result} label="Excerpt">
|
<:col :let={result} label="Excerpt">
|
||||||
|
|
|
||||||
|
|
@ -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}
|
||||||
|
</.subtle_link>
|
||||||
|
</:col>
|
||||||
|
<:col :let={source} label="Pending">
|
||||||
|
<.subtle_link href={~p"/sources/#{source.id}/#tab-pending"}>
|
||||||
|
<.localized_number number={source.pending_count} />
|
||||||
|
</.subtle_link>
|
||||||
|
</:col>
|
||||||
|
<:col :let={source} label="Downloaded">
|
||||||
|
<.subtle_link href={~p"/sources/#{source.id}/#tab-downloaded"}>
|
||||||
|
<.localized_number number={source.downloaded_count} />
|
||||||
|
</.subtle_link>
|
||||||
|
</:col>
|
||||||
|
<: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 %>
|
||||||
|
<span class="text-lg">∞</span>
|
||||||
|
<% end %>
|
||||||
|
</:col>
|
||||||
|
<:col :let={source} label="Media Profile">
|
||||||
|
<.subtle_link href={~p"/media_profiles/#{source.media_profile_id}"}>
|
||||||
|
{source.media_profile.name}
|
||||||
|
</.subtle_link>
|
||||||
|
</:col>
|
||||||
|
<: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>
|
||||||
|
<:col :let={source} label="" class="flex place-content-evenly">
|
||||||
|
<.icon_link href={~p"/sources/#{source.id}/edit"} icon="hero-pencil-square" class="mx-1" />
|
||||||
|
</:col>
|
||||||
|
</.table>
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
|
@ -46,9 +46,9 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<.table rows={@records} table_class="text-white">
|
<.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}"}>
|
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
|
||||||
{StringUtils.truncate(media_item.title, 50)}
|
{media_item.title}
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?">
|
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue