mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-21 12:53:11 +01:00
Merge pull request #414 from mdashlw/source-changes-info
Implement added filters and image count to source changes pages
This commit is contained in:
commit
7673183d6f
6 changed files with 85 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue