Added total downloaded count to source view (#134)
This commit is contained in:
parent
854502634c
commit
8ef5e0f41f
2 changed files with 17 additions and 2 deletions
|
|
@ -1,12 +1,15 @@
|
|||
defmodule PinchflatWeb.Sources.SourceController do
|
||||
use PinchflatWeb, :controller
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Media
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Sources.Source
|
||||
alias Pinchflat.Media.MediaItem
|
||||
|
||||
def index(conn, _params) do
|
||||
sources = Repo.preload(Sources.list_sources(), :media_profile)
|
||||
|
|
@ -54,7 +57,8 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
source: source,
|
||||
pending_tasks: pending_tasks,
|
||||
pending_media: pending_media,
|
||||
downloaded_media: downloaded_media
|
||||
downloaded_media: downloaded_media,
|
||||
total_downloaded: total_downloaded_for(source)
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -104,6 +108,17 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
Profiles.list_media_profiles()
|
||||
end
|
||||
|
||||
# NOTE: should move this out of the controller
|
||||
# once I finally add some query fragment layer
|
||||
defp total_downloaded_for(source) do
|
||||
from(
|
||||
m in MediaItem,
|
||||
where: m.source_id == ^source.id,
|
||||
where: not is_nil(m.media_filepath)
|
||||
)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
defp get_onboarding_layout do
|
||||
if Settings.get!(:onboarding) do
|
||||
{Layouts, :onboarding}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@
|
|||
</:tab>
|
||||
<:tab title="Downloaded Media">
|
||||
<%= if match?([_|_], @downloaded_media) do %>
|
||||
<h4 class="text-white text-lg mb-6">Shows a maximum of 100 media items</h4>
|
||||
<h4 class="text-white text-lg mb-6">Shows a maximum of 100 media items (<%= @total_downloaded %> total)</h4>
|
||||
<.table rows={@downloaded_media} table_class="text-black dark:text-white">
|
||||
<:col :let={media_item} label="Title">
|
||||
<%= StringUtils.truncate(media_item.title, 50) %>
|
||||
|
|
|
|||
Loading…
Reference in a new issue