Added size to sources table
This commit is contained in:
parent
da2eec0c39
commit
82729085d2
5 changed files with 33 additions and 35 deletions
|
|
@ -2,6 +2,7 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
|
|
||||||
|
alias Pinchflat.Utils.NumberUtils
|
||||||
alias PinchflatWeb.CoreComponents
|
alias PinchflatWeb.CoreComponents
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -125,4 +126,24 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do
|
||||||
{@word}{if @count == 1, do: "", else: @suffix}
|
{@word}{if @count == 1, do: "", else: @suffix}
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Renders a human-readable byte size
|
||||||
|
"""
|
||||||
|
|
||||||
|
attr :byte_size, :integer, required: true
|
||||||
|
|
||||||
|
def readable_filesize(assigns) do
|
||||||
|
{num, suffix} = NumberUtils.human_byte_size(assigns.byte_size, precision: 2)
|
||||||
|
|
||||||
|
assigns =
|
||||||
|
Map.merge(assigns, %{
|
||||||
|
num: num,
|
||||||
|
suffix: suffix
|
||||||
|
})
|
||||||
|
|
||||||
|
~H"""
|
||||||
|
<.localized_number number={@num} /> {@suffix}
|
||||||
|
"""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,5 @@
|
||||||
defmodule PinchflatWeb.Pages.PageHTML do
|
defmodule PinchflatWeb.Pages.PageHTML do
|
||||||
use PinchflatWeb, :html
|
use PinchflatWeb, :html
|
||||||
|
|
||||||
alias Pinchflat.Utils.NumberUtils
|
|
||||||
|
|
||||||
embed_templates "page_html/*"
|
embed_templates "page_html/*"
|
||||||
|
|
||||||
attr :media_filesize, :integer, required: true
|
|
||||||
|
|
||||||
def readable_media_filesize(assigns) do
|
|
||||||
{num, suffix} = NumberUtils.human_byte_size(assigns.media_filesize, precision: 2)
|
|
||||||
|
|
||||||
assigns =
|
|
||||||
Map.merge(assigns, %{
|
|
||||||
num: num,
|
|
||||||
suffix: suffix
|
|
||||||
})
|
|
||||||
|
|
||||||
~H"""
|
|
||||||
<.localized_number number={@num} /> {@suffix}
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
<span class="flex flex-col items-center py-2">
|
<span class="flex flex-col items-center py-2">
|
||||||
<span class="text-md font-medium">Library Size</span>
|
<span class="text-md font-medium">Library Size</span>
|
||||||
<h4 class="text-title-md font-bold text-white">
|
<h4 class="text-title-md font-bold text-white">
|
||||||
<.readable_media_filesize media_filesize={@media_item_size} />
|
<.readable_filesize byte_size={@media_item_size} />
|
||||||
</h4>
|
</h4>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,12 @@ defmodule PinchflatWeb.Sources.SourceLive.IndexTableLive do
|
||||||
|> then(&{:noreply, &1})
|
|> then(&{:noreply, &1})
|
||||||
end
|
end
|
||||||
|
|
||||||
defp sort_attr(:pending_count), do: dynamic([s, mp, dl, pe], field(pe, :pending_count))
|
defp sort_attr(:pending_count), do: dynamic([s, mp, dl, pe], pe.pending_count)
|
||||||
defp sort_attr(:downloaded_count), do: dynamic([s, mp, dl], field(dl, :downloaded_count))
|
defp sort_attr(:downloaded_count), do: dynamic([s, mp, dl], dl.downloaded_count)
|
||||||
defp sort_attr(:media_profile_name), do: dynamic([s, mp], field(mp, :name))
|
defp sort_attr(:media_size_bytes), do: dynamic([s, mp, dl], dl.media_size_bytes)
|
||||||
defp sort_attr(:custom_name), do: dynamic([s], field(s, :custom_name))
|
defp sort_attr(:media_profile_name), do: dynamic([s, mp], mp.name)
|
||||||
defp sort_attr(:enabled), do: dynamic([s], field(s, :enabled))
|
defp sort_attr(:custom_name), do: dynamic([s], s.custom_name)
|
||||||
defp sort_attr(:retention_period_days), do: dynamic([s], field(s, :retention_period_days))
|
defp sort_attr(:enabled), do: dynamic([s], s.enabled)
|
||||||
defp sort_attr(_), do: sort_attr(:custom_name)
|
|
||||||
|
|
||||||
defp set_sources(%{assigns: assigns} = socket) do
|
defp set_sources(%{assigns: assigns} = socket) do
|
||||||
sources =
|
sources =
|
||||||
|
|
@ -74,7 +73,7 @@ defmodule PinchflatWeb.Sources.SourceLive.IndexTableLive do
|
||||||
downloaded_subquery =
|
downloaded_subquery =
|
||||||
from(
|
from(
|
||||||
m in MediaItem,
|
m in MediaItem,
|
||||||
select: %{downloaded_count: count(m.id), source_id: m.source_id},
|
select: %{downloaded_count: count(m.id), source_id: m.source_id, media_size_bytes: sum(m.media_size_bytes)},
|
||||||
where: ^MediaQuery.downloaded(),
|
where: ^MediaQuery.downloaded(),
|
||||||
group_by: m.source_id
|
group_by: m.source_id
|
||||||
)
|
)
|
||||||
|
|
@ -102,7 +101,8 @@ defmodule PinchflatWeb.Sources.SourceLive.IndexTableLive do
|
||||||
select: map(s, ^Source.__schema__(:fields)),
|
select: map(s, ^Source.__schema__(:fields)),
|
||||||
select_merge: %{
|
select_merge: %{
|
||||||
downloaded_count: coalesce(d.downloaded_count, 0),
|
downloaded_count: coalesce(d.downloaded_count, 0),
|
||||||
pending_count: coalesce(p.pending_count, 0)
|
pending_count: coalesce(p.pending_count, 0),
|
||||||
|
media_size_bytes: coalesce(d.media_size_bytes, 0)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,8 @@
|
||||||
<.localized_number number={source.downloaded_count} />
|
<.localized_number number={source.downloaded_count} />
|
||||||
</.subtle_link>
|
</.subtle_link>
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={source} label="Retention" sort_key="retention_period_days">
|
<:col :let={source} label="Size" sort_key="media_size_bytes">
|
||||||
<%= if source.retention_period_days && source.retention_period_days > 0 do %>
|
<.readable_filesize byte_size={source.media_size_bytes} />
|
||||||
<.localized_number number={source.retention_period_days} />
|
|
||||||
<.pluralize count={source.retention_period_days} word="day" />
|
|
||||||
<% else %>
|
|
||||||
<span class="text-lg">∞</span>
|
|
||||||
<% end %>
|
|
||||||
</:col>
|
</:col>
|
||||||
<:col :let={source} label="Media Profile" sort_key="media_profile_name">
|
<:col :let={source} label="Media Profile" sort_key="media_profile_name">
|
||||||
<.subtle_link href={~p"/media_profiles/#{source.media_profile_id}"}>
|
<.subtle_link href={~p"/media_profiles/#{source.media_profile_id}"}>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue