Implement added filters and image count to source changes pages

This commit is contained in:
mdashlw 2025-02-11 12:07:50 +00:00 committed by GitHub
parent 10616da04f
commit 9499931da9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 85 additions and 10 deletions

View file

@ -7,10 +7,11 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
plug :verify_authorized
def index(conn, %{"fingerprint_profile_id" => fingerprint}) do
def index(conn, %{"fingerprint_profile_id" => fingerprint} = params) do
source_changes =
SourceChange
|> where(fingerprint: ^fingerprint)
|> added_filter(params)
|> order_by(desc: :id)
|> preload([:user, image: [:user, :sources, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener)
@ -22,6 +23,15 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
)
end
defp added_filter(query, %{"added" => "1"}),
do: where(query, added: true)
defp added_filter(query, %{"added" => "0"}),
do: where(query, added: false)
defp added_filter(query, _params),
do: query
defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do
true -> conn

View file

@ -15,6 +15,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
source_changes =
SourceChange
|> where(fragment("? >>= ip", ^range))
|> added_filter(params)
|> order_by(desc: :id)
|> preload([:user, image: [:user, :sources, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener)
@ -26,6 +27,15 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
)
end
defp added_filter(query, %{"added" => "1"}),
do: where(query, added: true)
defp added_filter(query, %{"added" => "0"}),
do: where(query, added: false)
defp added_filter(query, _params),
do: query
defp verify_authorized(conn, _opts) do
case Canada.Can.can?(conn.assigns.current_user, :show, :ip_address) do
true -> conn

View file

@ -15,24 +15,43 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do
id_field: "slug",
persisted: true
def index(conn, _params) do
def index(conn, params) do
user = conn.assigns.user
source_changes =
common_query =
SourceChange
|> join(:inner, [sc], i in Image, on: sc.image_id == i.id)
|> where(
[sc, i],
sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
)
|> added_filter(params)
source_changes =
common_query
|> preload([: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()
render(conn, "index.html",
title: "Source Changes for User `#{user.name}'",
user: user,
source_changes: source_changes
source_changes: source_changes,
image_count: image_count
)
end
defp added_filter(query, %{"added" => "1"}),
do: where(query, added: true)
defp added_filter(query, %{"added" => "0"}),
do: where(query, added: false)
defp added_filter(query, _params),
do: query
end

View file

@ -3,6 +3,16 @@ h1
= @fingerprint
- route = fn p -> ~p"/fingerprint_profiles/#{@fingerprint}/source_changes?#{p}" end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn
- params = if @conn.params["added"], do: [added: @conn.params["added"]]
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn, params: params
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination
.block
.block__header
span.block__header__title
| Display only:
= link "Removed", to: ~p"/fingerprint_profiles/#{@fingerprint}/source_changes?#{[added: 0]}"
= link "Added", to: ~p"/fingerprint_profiles/#{@fingerprint}/source_changes?#{[added: 1]}"
= link "All", to: ~p"/fingerprint_profiles/#{@fingerprint}/source_changes"
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination

View file

@ -3,6 +3,16 @@ h1
= @ip
- route = fn p -> ~p"/ip_profiles/#{to_string(@ip)}/source_changes?#{p}" end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn
- params = if @conn.params["added"], do: [added: @conn.params["added"]]
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn, params: params
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination
.block
.block__header
span.block__header__title
| Display only:
= link "Removed", to: ~p"/ip_profiles/#{to_string(@ip)}/source_changes?#{[added: 0]}"
= link "Added", to: ~p"/ip_profiles/#{to_string(@ip)}/source_changes?#{[added: 1]}"
= link "All", to: ~p"/ip_profiles/#{to_string(@ip)}/source_changes"
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination

View file

@ -4,6 +4,22 @@ h1
= @user.name
- route = fn p -> ~p"/profiles/#{@user}/source_changes?#{p}" end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn
- params = if @conn.params["added"], do: [added: @conn.params["added"]]
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @source_changes, route: route, conn: @conn, params: params
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination
.block
.block__header
span.block__header__title
| Display only:
= link "Removed", to: ~p"/profiles/#{@user}/source_changes?#{[added: 0]}"
= link "Added", to: ~p"/profiles/#{@user}/source_changes?#{[added: 1]}"
= link "All", to: ~p"/profiles/#{@user}/source_changes"
.block__header.block__header--light
span.block__header__title.page__info
' Listing changes for
=> @image_count
= pluralize("image", "images", @image_count)
= render PhilomenaWeb.SourceChangeView, "index.html", conn: @conn, source_changes: @source_changes, pagination: pagination