diff --git a/lib/pinchflat/tasks/tasks_query.ex b/lib/pinchflat/tasks/tasks_query.ex new file mode 100644 index 0000000..cb2da78 --- /dev/null +++ b/lib/pinchflat/tasks/tasks_query.ex @@ -0,0 +1,43 @@ +defmodule Pinchflat.Tasks.TasksQuery do + @moduledoc """ + Query helpers for the Tasks context. + + These methods are made to be one-ish liners used + to compose queries. Each method should strive to do + _one_ thing. These don't need to be tested as + they are just building blocks for other functionality + which, itself, will be tested. + """ + import Ecto.Query, warn: false + + alias Pinchflat.Tasks.Task + + # This allows the module to be aliased and query methods to be used + # all in one go + # usage: use Pinchflat.Tasks.TasksQuery + defmacro __using__(_opts) do + quote do + import Ecto.Query, warn: false + + alias unquote(__MODULE__) + end + end + + def new do + Task + end + + def join_job(query) do + join(query, :inner, [t], j in assoc(t, :job)) + end + + def in_state(states) when is_list(states) do + dynamic([t, j], j.state in ^states) + end + + def in_state(state), do: in_state([state]) + + def has_worker(worker_name) do + dynamic([t, j], fragment("? LIKE ?", j.worker, ^"%.#{worker_name}")) + end +end diff --git a/lib/pinchflat_web/controllers/pages/page_controller.ex b/lib/pinchflat_web/controllers/pages/page_controller.ex index a6e36da..bc990b4 100644 --- a/lib/pinchflat_web/controllers/pages/page_controller.ex +++ b/lib/pinchflat_web/controllers/pages/page_controller.ex @@ -20,14 +20,16 @@ defmodule PinchflatWeb.Pages.PageController do end defp render_home_page(conn) do + # TODO: revert conn |> render(:home, - media_profile_count: Repo.aggregate(MediaProfile, :count, :id), - source_count: Repo.aggregate(Source, :count, :id), + media_profile_count: 1 || Repo.aggregate(MediaProfile, :count, :id), + source_count: 1 || Repo.aggregate(Source, :count, :id), media_item_count: - MediaQuery.new() - |> MediaQuery.with_media_downloaded_at() - |> Repo.aggregate(:count, :id) + 1 || + MediaQuery.new() + |> MediaQuery.with_media_downloaded_at() + |> Repo.aggregate(:count, :id) ) end diff --git a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex index d018bcb..bec4635 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex +++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex @@ -26,8 +26,16 @@
Nothing Here!
+