mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-31 00:37:45 +02:00
profile/tag_change: add search box to show only a single tag
This commit is contained in:
parent
7ba9579078
commit
9782c943c2
2 changed files with 25 additions and 6 deletions
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
||||||
|
|
||||||
alias Philomena.Users.User
|
alias Philomena.Users.User
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
|
alias Philomena.Tags.Tag
|
||||||
alias Philomena.TagChanges.TagChange
|
alias Philomena.TagChanges.TagChange
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
@ -16,11 +17,13 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
||||||
tag_changes =
|
tag_changes =
|
||||||
TagChange
|
TagChange
|
||||||
|> join(:inner, [tc], i in Image, on: tc.image_id == i.id)
|
|> join(:inner, [tc], i in Image, on: tc.image_id == i.id)
|
||||||
|
|> only_tag_join(params)
|
||||||
|> where(
|
|> where(
|
||||||
[tc, i],
|
[tc, i],
|
||||||
tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
|
tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
|
||||||
)
|
)
|
||||||
|> added_filter(params)
|
|> added_filter(params)
|
||||||
|
|> only_tag_filter(params)
|
||||||
|> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|
|> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|
||||||
|> order_by(desc: :id)
|
|> order_by(desc: :id)
|
||||||
|> Repo.paginate(conn.assigns.scrivener)
|
|> Repo.paginate(conn.assigns.scrivener)
|
||||||
|
@ -40,4 +43,16 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
||||||
|
|
||||||
defp added_filter(query, _params),
|
defp added_filter(query, _params),
|
||||||
do: query
|
do: query
|
||||||
|
|
||||||
|
defp only_tag_join(query, %{"only_tag" => only_tag}) when only_tag != "",
|
||||||
|
do: join(query, :inner, [tc], t in Tag, on: tc.tag_id == t.id)
|
||||||
|
|
||||||
|
defp only_tag_join(query, _params),
|
||||||
|
do: query
|
||||||
|
|
||||||
|
defp only_tag_filter(query, %{"only_tag" => only_tag}) when only_tag != "",
|
||||||
|
do: where(query, [_, _, t], t.name == ^only_tag)
|
||||||
|
|
||||||
|
defp only_tag_filter(query, _params),
|
||||||
|
do: query
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,16 +4,20 @@ h1
|
||||||
= @user.name
|
= @user.name
|
||||||
|
|
||||||
- route = fn p -> Routes.profile_tag_change_path(@conn, :index, @user, p) end
|
- route = fn p -> Routes.profile_tag_change_path(@conn, :index, @user, p) end
|
||||||
- params = if @conn.params["added"], do: [added: @conn.params["added"]]
|
- only_tag = if is_binary(@conn.params["only_tag"]) && @conn.params["only_tag"] != "", do: @conn.params["only_tag"]
|
||||||
|
- only_tag_param = (if only_tag, do: [only_tag: only_tag], else: [])
|
||||||
|
- params = (if @conn.params["added"], do: [added: @conn.params["added"]], else: []) ++ only_tag_param
|
||||||
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn, params: params
|
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn, params: params
|
||||||
|
|
||||||
.block
|
.block
|
||||||
.block__header
|
.block__header
|
||||||
span.block__header__title
|
= form_for @conn, Routes.profile_tag_change_path(@conn, :index, @user), [method: "get", enforce_utf8: false], fn f ->
|
||||||
| Display only:
|
input.input name="only_tag" title="Only show this tag." value=only_tag placeholder="Tag" autocapitalize="none"
|
||||||
|
button.button type="submit" title="Search"
|
||||||
|
i.fa.fa-search
|
||||||
|
|
||||||
= link "Removed", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 0)
|
= link "Removed", to: Routes.profile_tag_change_path(@conn, :index, @user, [added: 0] ++ only_tag_param)
|
||||||
= link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 1)
|
= link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, [added: 1] ++ only_tag_param)
|
||||||
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user)
|
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user, only_tag_param)
|
||||||
|
|
||||||
= render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination
|
= render PhilomenaWeb.TagChangeView, "index.html", conn: @conn, tag_changes: @tag_changes, pagination: pagination
|
||||||
|
|
Loading…
Add table
Reference in a new issue