tag detail page

This commit is contained in:
byte[] 2019-12-17 13:12:58 -05:00
parent e2496cd43b
commit d8b425bdf6
6 changed files with 102 additions and 0 deletions

View 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

View file

@ -174,6 +174,7 @@ defmodule PhilomenaWeb.Router do
resources "/tags", TagController, only: [] do
resources "/watch", Tag.WatchController, only: [:create, :delete], singleton: true
resources "/details", Tag.DetailController, only: [:index]
end
resources "/avatar", AvatarController, only: [:edit, :update, :delete], singleton: true

View file

@ -10,6 +10,7 @@
= link "Tag changes", to: Routes.tag_tag_change_path(@conn, :index, @tag), class: "detail-link"
= if manages_tags?(@conn) do
= 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

View 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)

View 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"

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.Tag.DetailView do
use PhilomenaWeb, :view
end