mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
add tag changes to tag, profile
This commit is contained in:
parent
ad17b48011
commit
015abf068b
10 changed files with 116 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
32
lib/philomena_web/controllers/tag/tag_change_controller.ex
Normal file
32
lib/philomena_web/controllers/tag/tag_change_controller.ex
Normal 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
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
@ -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
|
||||||
|
|
18
lib/philomena_web/templates/tag/tag_change/index.html.slime
Normal file
18
lib/philomena_web/templates/tag/tag_change/index.html.slime
Normal 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
|
3
lib/philomena_web/views/profile/tag_change_view.ex
Normal file
3
lib/philomena_web/views/profile/tag_change_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule PhilomenaWeb.Profile.TagChangeView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
end
|
3
lib/philomena_web/views/tag/tag_change_view.ex
Normal file
3
lib/philomena_web/views/tag/tag_change_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule PhilomenaWeb.Tag.TagChangeView do
|
||||||
|
use PhilomenaWeb, :view
|
||||||
|
end
|
Loading…
Reference in a new issue