Improve relationship UI handling (#42)
* Added tabbed view; improved relationships for media profile * Adds new maybe_limit method for queries * Improves UI for media items, associated tasks
This commit is contained in:
@@ -41,12 +41,14 @@ defmodule Pinchflat.Media do
|
||||
|
||||
Returns [%MediaItem{}, ...].
|
||||
"""
|
||||
def list_pending_media_items_for(%Source{} = source) do
|
||||
def list_pending_media_items_for(%Source{} = source, opts \\ []) do
|
||||
limit = Keyword.get(opts, :limit, nil)
|
||||
media_profile = Repo.preload(source, :media_profile).media_profile
|
||||
|
||||
MediaItem
|
||||
|> where([mi], mi.source_id == ^source.id and is_nil(mi.media_filepath))
|
||||
|> where(^build_format_clauses(media_profile))
|
||||
|> Repo.maybe_limit(limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@@ -55,9 +57,12 @@ defmodule Pinchflat.Media do
|
||||
|
||||
Returns [%MediaItem{}, ...].
|
||||
"""
|
||||
def list_downloaded_media_items_for(%Source{} = source) do
|
||||
def list_downloaded_media_items_for(%Source{} = source, opts \\ []) do
|
||||
limit = Keyword.get(opts, :limit, nil)
|
||||
|
||||
MediaItem
|
||||
|> where([mi], mi.source_id == ^source.id and not is_nil(mi.media_filepath))
|
||||
|> Repo.maybe_limit(limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Pinchflat.Sources.Source do
|
||||
import Ecto.Changeset
|
||||
import Pinchflat.Utils.ChangesetUtils
|
||||
|
||||
alias Pinchflat.Tasks.Task
|
||||
alias Pinchflat.Media.MediaItem
|
||||
alias Pinchflat.Profiles.MediaProfile
|
||||
|
||||
@@ -47,6 +48,7 @@ defmodule Pinchflat.Sources.Source do
|
||||
|
||||
belongs_to :media_profile, MediaProfile
|
||||
|
||||
has_many :tasks, Task
|
||||
has_many :media_items, MediaItem, foreign_key: :source_id
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
|
||||
@@ -3,6 +3,8 @@ defmodule Pinchflat.Repo do
|
||||
otp_app: :pinchflat,
|
||||
adapter: Ecto.Adapters.SQLite3
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
|
||||
@doc """
|
||||
It's not immediately obvious if an Oban job qualifies as unique, so this method
|
||||
attempts creating a job and checks for the `conflict?` field in the returned job.
|
||||
@@ -16,4 +18,13 @@ defmodule Pinchflat.Repo do
|
||||
err -> err
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Applies a limit to a query if provided, otherwise returns the query as-is.
|
||||
|
||||
Returns %Ecto.Query{}.
|
||||
"""
|
||||
def maybe_limit(query, limit) do
|
||||
if limit, do: limit(query, ^limit), else: query
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user