mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
tag detail page
This commit is contained in:
parent
e2496cd43b
commit
d8b425bdf6
6 changed files with 102 additions and 0 deletions
49
lib/philomena_web/controllers/tag/detail_controller.ex
Normal file
49
lib/philomena_web/controllers/tag/detail_controller.ex
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
defmodule PhilomenaWeb.Tag.DetailController do
|
||||||
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
|
alias Philomena.Tags.Tag
|
||||||
|
alias Philomena.Filters.Filter
|
||||||
|
alias Philomena.Users.User
|
||||||
|
alias Philomena.Repo
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
plug :verify_authorized
|
||||||
|
plug :load_resource, model: Tag, id_name: "tag_id", id_field: "slug", persisted: true
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
tag = conn.assigns.tag
|
||||||
|
|
||||||
|
filters_spoilering =
|
||||||
|
Filter
|
||||||
|
|> where([f], fragment("? @> ARRAY[?]::integer[]", f.spoilered_tag_ids, ^tag.id))
|
||||||
|
|> preload(:user)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
|
filters_hiding =
|
||||||
|
Filter
|
||||||
|
|> where([f], fragment("? @> ARRAY[?]::integer[]", f.hidden_tag_ids, ^tag.id))
|
||||||
|
|> preload(:user)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
|
users_watching =
|
||||||
|
User
|
||||||
|
|> where([u], fragment("? @> ARRAY[?]::integer[]", u.watched_tag_ids, ^tag.id))
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
|
render(
|
||||||
|
conn,
|
||||||
|
"index.html",
|
||||||
|
title: "Tag Usage for Tag `#{tag.name}'",
|
||||||
|
filters_spoilering: filters_spoilering,
|
||||||
|
filters_hiding: filters_hiding,
|
||||||
|
users_watching: users_watching
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp verify_authorized(conn, _opts) do
|
||||||
|
case Canada.Can.can?(conn.assigns.current_user, :edit, %Tag{}) do
|
||||||
|
true -> conn
|
||||||
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -174,6 +174,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
|
|
||||||
resources "/tags", TagController, only: [] do
|
resources "/tags", TagController, only: [] do
|
||||||
resources "/watch", Tag.WatchController, only: [:create, :delete], singleton: true
|
resources "/watch", Tag.WatchController, only: [:create, :delete], singleton: true
|
||||||
|
resources "/details", Tag.DetailController, only: [:index]
|
||||||
end
|
end
|
||||||
|
|
||||||
resources "/avatar", AvatarController, only: [:edit, :update, :delete], singleton: true
|
resources "/avatar", AvatarController, only: [:edit, :update, :delete], singleton: true
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
= link "Tag changes", to: Routes.tag_tag_change_path(@conn, :index, @tag), class: "detail-link"
|
= link "Tag changes", to: Routes.tag_tag_change_path(@conn, :index, @tag), class: "detail-link"
|
||||||
= if manages_tags?(@conn) do
|
= if manages_tags?(@conn) do
|
||||||
= link "Edit details", to: Routes.tag_path(@conn, :edit, @tag), class: "detail-link"
|
= link "Edit details", to: Routes.tag_path(@conn, :edit, @tag), class: "detail-link"
|
||||||
|
= link "Usage", to: Routes.tag_detail_path(@conn, :index, @tag), class: "detail-link"
|
||||||
|
|
||||||
br
|
br
|
||||||
|
|
||||||
|
|
31
lib/philomena_web/templates/tag/detail/_filters.html.slime
Normal file
31
lib/philomena_web/templates/tag/detail/_filters.html.slime
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
table.table
|
||||||
|
thead
|
||||||
|
tr
|
||||||
|
th Filter
|
||||||
|
th Type
|
||||||
|
th Owner
|
||||||
|
th Spoilers
|
||||||
|
th Hides
|
||||||
|
tbody
|
||||||
|
= for filter <- @filters do
|
||||||
|
tr
|
||||||
|
td = link filter.name, to: Routes.filter_path(@conn, :show, filter)
|
||||||
|
td
|
||||||
|
= cond do
|
||||||
|
- filter.system ->
|
||||||
|
' System
|
||||||
|
|
||||||
|
- filter.public ->
|
||||||
|
' Public
|
||||||
|
|
||||||
|
- true ->
|
||||||
|
' Private
|
||||||
|
|
||||||
|
td
|
||||||
|
= if filter.user do
|
||||||
|
= link filter.user.name, to: Routes.profile_path(@conn, :show, filter.user)
|
||||||
|
- else
|
||||||
|
' No user associated
|
||||||
|
|
||||||
|
td = length(filter.spoilered_tag_ids)
|
||||||
|
td = length(filter.hidden_tag_ids)
|
17
lib/philomena_web/templates/tag/detail/index.html.slime
Normal file
17
lib/philomena_web/templates/tag/detail/index.html.slime
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
h1
|
||||||
|
' Tag Usage for
|
||||||
|
= link @tag.name, to: Routes.tag_path(@conn, :show, @tag)
|
||||||
|
|
||||||
|
h3 Filters that spoiler this tag:
|
||||||
|
= render PhilomenaWeb.Tag.DetailView, "_filters.html", filters: @filters_spoilering, conn: @conn
|
||||||
|
|
||||||
|
h3 Filters that hide this tag:
|
||||||
|
= render PhilomenaWeb.Tag.DetailView, "_filters.html", filters: @filters_hiding, conn: @conn
|
||||||
|
|
||||||
|
h3
|
||||||
|
| Users that watch this tag (
|
||||||
|
= length(@users_watching)
|
||||||
|
| )
|
||||||
|
|
||||||
|
= for u <- @users_watching do
|
||||||
|
= link u.name, to: Routes.profile_path(@conn, :show, u), class: "interaction-user-list-item"
|
3
lib/philomena_web/views/tag/detail_view.ex
Normal file
3
lib/philomena_web/views/tag/detail_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule PhilomenaWeb.Tag.DetailView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
end
|
Loading…
Reference in a new issue