mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
display tag/source change counters on image pages
This commit is contained in:
parent
306c954546
commit
c3f745ddee
6 changed files with 41 additions and 14 deletions
|
@ -1,9 +1,12 @@
|
|||
defmodule PhilomenaWeb.Image.SourceController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.SourceChanges.SourceChange
|
||||
alias Philomena.UserStatistics
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Images
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug PhilomenaWeb.FilterBannedUsersPlug
|
||||
plug PhilomenaWeb.CaptchaPlug
|
||||
|
@ -20,16 +23,21 @@ defmodule PhilomenaWeb.Image.SourceController do
|
|||
changeset =
|
||||
Images.change_image(image)
|
||||
|
||||
source_change_count =
|
||||
SourceChange
|
||||
|> where(image_id: ^image.id)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
|
||||
UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates)
|
||||
|
||||
conn
|
||||
|> put_view(PhilomenaWeb.ImageView)
|
||||
|> render("_source.html", layout: false, image: image, changeset: changeset)
|
||||
|> render("_source.html", layout: false, source_change_count: source_change_count, image: image, changeset: changeset)
|
||||
|
||||
{:error, :image, changeset, _} ->
|
||||
conn
|
||||
|> put_view(PhilomenaWeb.ImageView)
|
||||
|> render("_source.html", layout: false, image: image, changeset: changeset)
|
||||
|> render("_source.html", layout: false, source_change_count: 0, image: image, changeset: changeset)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,11 +1,13 @@
|
|||
defmodule PhilomenaWeb.Image.TagController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.UserStatistics
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Images
|
||||
alias Philomena.Tags
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug PhilomenaWeb.FilterBannedUsersPlug
|
||||
plug PhilomenaWeb.CaptchaPlug
|
||||
|
@ -23,6 +25,11 @@ defmodule PhilomenaWeb.Image.TagController do
|
|||
Tags.reindex_tags(added_tags ++ removed_tags)
|
||||
UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates)
|
||||
|
||||
tag_change_count =
|
||||
TagChange
|
||||
|> where(image_id: ^image.id)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
|
||||
image =
|
||||
image
|
||||
|> Repo.preload(:tags, force: true)
|
||||
|
@ -32,12 +39,12 @@ defmodule PhilomenaWeb.Image.TagController do
|
|||
|
||||
conn
|
||||
|> put_view(PhilomenaWeb.ImageView)
|
||||
|> render("_tags.html", layout: false, image: image, changeset: changeset)
|
||||
|> render("_tags.html", layout: false, tag_change_count: tag_change_count, image: image, changeset: changeset)
|
||||
|
||||
{:error, :image, changeset, _} ->
|
||||
conn
|
||||
|> put_view(PhilomenaWeb.ImageView)
|
||||
|> render("_tags.html", layout: false, image: image, changeset: changeset)
|
||||
|> render("_tags.html", layout: false, tag_change_count: 0, image: image, changeset: changeset)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -139,10 +139,13 @@ defmodule PhilomenaWeb.ImageController do
|
|||
defp load_image(conn, _opts) do
|
||||
id = conn.params["id"]
|
||||
|
||||
image =
|
||||
{image, tag_changes, source_changes} =
|
||||
Image
|
||||
|> where(id: ^id)
|
||||
|> join(:inner_lateral, [i], _ in fragment("SELECT COUNT(*) FROM tag_changes t WHERE t.image_id = ?", i.id))
|
||||
|> join(:inner_lateral, [i, _], _ in fragment("SELECT COUNT(*) FROM source_changes s WHERE s.image_id = ?", i.id))
|
||||
|> preload([:tags, :deleter, user: [awards: :badge]])
|
||||
|> select([i, t, s], {i, t.count, s.count})
|
||||
|> Repo.one()
|
||||
|
||||
cond do
|
||||
|
@ -158,7 +161,10 @@ defmodule PhilomenaWeb.ImageController do
|
|||
render(conn, "deleted.html", image: image)
|
||||
|
||||
true ->
|
||||
assign(conn, :image, image)
|
||||
conn
|
||||
|> assign(:image, image)
|
||||
|> assign(:tag_change_count, tag_changes)
|
||||
|> assign(:source_change_count, source_changes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
- else
|
||||
em> not provided yet
|
||||
|
||||
= if @source_change_count > 0 do
|
||||
a.button.button--link.button--separate-left href=Routes.image_source_change_path(@conn, :index, @image) title="Source history"
|
||||
i.fa.fa-history>
|
||||
' History
|
||||
| History (
|
||||
= @source_change_count
|
||||
| )
|
||||
|
|
|
@ -55,8 +55,11 @@
|
|||
i.fas.fa-edit>
|
||||
' Tags:
|
||||
|
||||
= if @tag_change_count > 0 do
|
||||
a.button.button--link.button--separate-left href=Routes.image_tag_change_path(@conn, :index, @image) title="Tag history"
|
||||
i.fa.fa-history>
|
||||
' History
|
||||
| History (
|
||||
= @tag_change_count
|
||||
| )
|
||||
|
||||
= render PhilomenaWeb.TagView, "_tag_list.html", tags: display_order(@image.tags), conn: @conn
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
= render PhilomenaWeb.ImageView, "_description.html", image: @image, body: @description, conn: @conn
|
||||
= render PhilomenaWeb.Image.DescriptionView, "_form.html", image: @image, changeset: @image_changeset, conn: @conn
|
||||
|
||||
= render PhilomenaWeb.ImageView, "_tags.html", image: @image, changeset: @image_changeset, conn: @conn
|
||||
= render PhilomenaWeb.ImageView, "_source.html", image: @image, changeset: @image_changeset, conn: @conn
|
||||
= render PhilomenaWeb.ImageView, "_tags.html", image: @image, tag_change_count: @tag_change_count, changeset: @image_changeset, conn: @conn
|
||||
= render PhilomenaWeb.ImageView, "_source.html", image: @image, source_change_count: @source_change_count, changeset: @image_changeset, conn: @conn
|
||||
= render PhilomenaWeb.ImageView, "_options.html", image: @image, conn: @conn
|
||||
|
||||
h4 Comments
|
||||
|
|
Loading…
Reference in a new issue