mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
Tag change search (#234)
* profile/tag_change: add search box to show only a single tag * Minor fixup --------- Co-authored-by: prg <prg@lacunae.de>
This commit is contained in:
parent
f1a75e87f2
commit
eb79ee45d2
2 changed files with 29 additions and 8 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,19 +17,27 @@ 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)
|
||||||
|
|
||||||
|
# params.permit(:added, :only_tag) ...
|
||||||
|
pagination_params =
|
||||||
|
[added: conn.params["added"], only_tag: conn.params["only_tag"]]
|
||||||
|
|> Keyword.filter(fn {k, _v} -> Map.has_key?(conn.params, "#{k}") end)
|
||||||
|
|
||||||
render(conn, "index.html",
|
render(conn, "index.html",
|
||||||
title: "Tag Changes for User `#{user.name}'",
|
title: "Tag Changes for User `#{user.name}'",
|
||||||
user: user,
|
user: user,
|
||||||
tag_changes: tag_changes
|
tag_changes: tag_changes,
|
||||||
|
pagination_params: pagination_params
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,4 +49,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,16 @@ 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"]]
|
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @tag_changes, route: route, conn: @conn, params: @pagination_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:
|
= text_input f, :only_tag, class: "input", placeholder: "Tag", title: "Only show this tag", autocapitalize: "none"
|
||||||
|
= submit "Search", class: "button", title: "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, Keyword.merge(@pagination_params, added: 0))
|
||||||
= link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 1)
|
= link "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, Keyword.merge(@pagination_params, added: 1))
|
||||||
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user)
|
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user, Keyword.delete(@pagination_params, :added))
|
||||||
|
|
||||||
= 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…
Reference in a new issue