Added total downloaded count to source view (#134)

This commit is contained in:
Kieran
2024-03-27 18:27:48 -07:00
committed by GitHub
parent 320b25f5b6
commit 2006f33792
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}