From 5b836580e1244ec3cadc77e5d046d78a584fefc5 Mon Sep 17 00:00:00 2001 From: liamwhite Date: Sun, 5 May 2024 10:12:17 -0400 Subject: [PATCH] profile/tag_change: show total affected image count (#248) * profile/tag_change: show total affected image count * Incorporate count into block header --------- Co-authored-by: prg --- .../controllers/profile/tag_change_controller.ex | 13 +++++++++++-- .../templates/profile/tag_change/index.html.slime | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/philomena_web/controllers/profile/tag_change_controller.ex b/lib/philomena_web/controllers/profile/tag_change_controller.ex index 6aaa4c3a..3fb67e28 100644 --- a/lib/philomena_web/controllers/profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/profile/tag_change_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do def index(conn, params) do user = conn.assigns.user - tag_changes = + common_query = TagChange |> join(:inner, [tc], i in Image, on: tc.image_id == i.id) |> only_tag_join(params) @@ -24,10 +24,18 @@ defmodule PhilomenaWeb.Profile.TagChangeController do ) |> added_filter(params) |> only_tag_filter(params) + + tag_changes = + common_query |> preload([:tag, :user, image: [:user, :sources, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) + image_count = + common_query + |> select([_, i], count(i.id, :distinct)) + |> Repo.one() + # params.permit(:added, :only_tag) ... pagination_params = [added: conn.params["added"], only_tag: conn.params["only_tag"]] @@ -37,7 +45,8 @@ defmodule PhilomenaWeb.Profile.TagChangeController do title: "Tag Changes for User `#{user.name}'", user: user, tag_changes: tag_changes, - pagination_params: pagination_params + pagination_params: pagination_params, + image_count: image_count ) end diff --git a/lib/philomena_web/templates/profile/tag_change/index.html.slime b/lib/philomena_web/templates/profile/tag_change/index.html.slime index 563a7fc3..806d843a 100644 --- a/lib/philomena_web/templates/profile/tag_change/index.html.slime +++ b/lib/philomena_web/templates/profile/tag_change/index.html.slime @@ -16,4 +16,10 @@ h1 = link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, Keyword.merge(@pagination_params, added: 1)) = link "All", to: Routes.profile_tag_change_path(@conn, :index, @user, Keyword.delete(@pagination_params, :added)) + .block__header.block__header--light + span.block__header__title.page__info + ' Listing changes for + => @image_count + = pluralize("image", "images", @image_count) + = render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination