add tag changes to tag, profile

This commit is contained in:
byte[] 2019-12-04 17:10:35 -05:00
parent ad17b48011
commit 015abf068b
10 changed files with 116 additions and 2 deletions

View file

@ -45,6 +45,8 @@ defmodule Philomena.Tags.Tag do
"video" => "content-fanmade" "video" => "content-fanmade"
} }
@derive {Phoenix.Param, key: :slug}
schema "tags" do schema "tags" do
belongs_to :aliased_tag, Tag, source: :aliased_tag_id belongs_to :aliased_tag, Tag, source: :aliased_tag_id
has_many :aliases, Tag, foreign_key: :aliased_tag_id has_many :aliases, Tag, foreign_key: :aliased_tag_id

View file

@ -0,0 +1,34 @@
defmodule PhilomenaWeb.Profile.TagChangeController do
use PhilomenaWeb, :controller
alias Philomena.Users.User
alias Philomena.Images.Image
alias Philomena.TagChanges.TagChange
alias Philomena.Repo
import Ecto.Query
plug PhilomenaWeb.CanaryMapPlug, index: :show
plug :load_resource, model: User, id_name: "profile_id", id_field: "slug", persisted: true
def index(conn, params) do
user = conn.assigns.user
tag_changes =
TagChange
|> join(:inner, [tc], i in Image, on: tc.image_id == i.id)
|> where([tc, i], tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true))
|> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]])
|> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", user: user, tag_changes: tag_changes)
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

@ -0,0 +1,32 @@
defmodule PhilomenaWeb.Tag.TagChangeController do
use PhilomenaWeb, :controller
alias Philomena.Tags.Tag
alias Philomena.TagChanges.TagChange
alias Philomena.Repo
import Ecto.Query
plug PhilomenaWeb.CanaryMapPlug, index: :show
plug :load_resource, model: Tag, id_name: "tag_id", id_field: "slug", persisted: true
def index(conn, params) do
tag = conn.assigns.tag
tag_changes =
TagChange
|> where(tag_id: ^tag.id)
|> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]])
|> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", tag: tag, tag_changes: tag_changes)
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

@ -155,7 +155,9 @@ defmodule PhilomenaWeb.Router do
resources "/autocomplete", AutocompleteController, only: [:show], singleton: true resources "/autocomplete", AutocompleteController, only: [:show], singleton: true
resources "/fetch", FetchController, only: [:index] resources "/fetch", FetchController, only: [:index]
end end
resources "/tags", TagController, only: [:index, :show] resources "/tags", TagController, only: [:index, :show] do
resources "/tag_changes", Tag.TagChangeController, only: [:index]
end
scope "/search", Search, as: :search do scope "/search", Search, as: :search do
resources "/reverse", ReverseController, only: [:index, :create] resources "/reverse", ReverseController, only: [:index, :create]
end end
@ -176,6 +178,7 @@ defmodule PhilomenaWeb.Router do
resources "/profiles", ProfileController, only: [:show] do resources "/profiles", ProfileController, only: [:show] do
resources "/reports", Profile.ReportController, only: [:new, :create] resources "/reports", Profile.ReportController, only: [:new, :create]
resources "/commission", Profile.CommissionController, only: [:show], singleton: true resources "/commission", Profile.CommissionController, only: [:show], singleton: true
resources "/tag_changes", Profile.TagChangeController, only: [:index]
end end
resources "/captchas", CaptchaController, only: [:create] resources "/captchas", CaptchaController, only: [:create]
scope "/posts", Post, as: :post do scope "/posts", Post, as: :post do

View file

@ -23,7 +23,7 @@
ul.profile-top__options__column ul.profile-top__options__column
li = link("Favorites", to: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}")) li = link("Favorites", to: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}"))
li = link("Tag changes", to: "#") li = link("Tag changes", to: Routes.profile_tag_change_path(@conn, :index, @user))
li = link("Source changes", to: "#") li = link("Source changes", to: "#")
.column-layout .column-layout

View file

@ -0,0 +1,18 @@
h1
' Tag changes by
a href=Routes.profile_path(@conn, :show, @user)
= @user.name
- route = fn p -> Routes.profile_tag_change_path(@conn, :index, @user, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn
.block
.block__header
span.block__header_title
| Display only:
= link "Removed", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 0)
= link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 1)
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user)
= render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination

View file

@ -7,6 +7,7 @@
.flex__grow .flex__grow
= render PhilomenaWeb.TagView, "_tag.html", tag: @tag = render PhilomenaWeb.TagView, "_tag.html", tag: @tag
= link "Tag changes", to: Routes.tag_tag_change_path(@conn, :index, @tag), class: "detail-link"
br br
= if @tag.short_description not in [nil, ""] do = if @tag.short_description not in [nil, ""] do

View file

@ -0,0 +1,18 @@
h1
' Tag changes on tag
a href=Routes.tag_path(@conn, :show, @tag)
= @tag.name
- route = fn p -> Routes.tag_tag_change_path(@conn, :index, @tag, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn
.block
.block__header
span.block__header_title
| Display only:
= link "Removed", to: Routes.tag_tag_change_path(@conn, :index, @tag, added: 0)
= link "Added", to: Routes.tag_tag_change_path(@conn, :index, @tag, added: 1)
= link "All", to: Routes.tag_tag_change_path(@conn, :index, @tag)
= render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.Profile.TagChangeView do
use PhilomenaWeb, :view
end

View file

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