mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-28 06:17:46 +01: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.Images.Image
|
||||
alias Philomena.Tags.Tag
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
@ -16,11 +17,13 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
|||
tag_changes =
|
||||
TagChange
|
||||
|> join(:inner, [tc], i in Image, on: tc.image_id == i.id)
|
||||
|> only_tag_join(params)
|
||||
|> where(
|
||||
[tc, i],
|
||||
tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
|
||||
)
|
||||
|> added_filter(params)
|
||||
|> only_tag_filter(params)
|
||||
|> preload([:tag, :user, image: [:user, :sources, tags: :aliases]])
|
||||
|> order_by(desc: :id)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
@ -40,4 +43,16 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
|||
|
||||
defp added_filter(query, _params),
|
||||
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
|
||||
|
|
|
@ -4,16 +4,20 @@ h1
|
|||
= @user.name
|
||||
|
||||
- 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
|
||||
|
||||
.block
|
||||
.block__header
|
||||
span.block__header__title
|
||||
| Display only:
|
||||
= form_for @conn, Routes.profile_tag_change_path(@conn, :index, @user), [method: "get", enforce_utf8: false], fn f ->
|
||||
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 "Added", to: Routes.profile_tag_change_path(@conn, :index, @user, added: 1)
|
||||
= link "All", to: Routes.profile_tag_change_path(@conn, :index, @user)
|
||||
= 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] ++ only_tag_param)
|
||||
= 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
|
||||
|
|
Loading…
Add table
Reference in a new issue