mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
better tag info row
This commit is contained in:
parent
a3187ae150
commit
8b6fef83e2
14 changed files with 90 additions and 26 deletions
|
@ -10,14 +10,14 @@ defmodule PhilomenaWeb.ActivityController do
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
user = conn.assigns.current_user
|
user = conn.assigns.current_user
|
||||||
|
|
||||||
{:ok, images} =
|
{:ok, {images, _tags}} =
|
||||||
ImageLoader.search_string(
|
ImageLoader.search_string(
|
||||||
conn,
|
conn,
|
||||||
"created_at.lte:3 minutes ago",
|
"created_at.lte:3 minutes ago",
|
||||||
pagination: %{conn.assigns.image_pagination | page_number: 1}
|
pagination: %{conn.assigns.image_pagination | page_number: 1}
|
||||||
)
|
)
|
||||||
|
|
||||||
top_scoring =
|
{top_scoring, _tags} =
|
||||||
ImageLoader.query(
|
ImageLoader.query(
|
||||||
conn,
|
conn,
|
||||||
%{range: %{first_seen_at: %{gt: "now-3d"}}},
|
%{range: %{first_seen_at: %{gt: "now-3d"}}},
|
||||||
|
@ -46,7 +46,7 @@ defmodule PhilomenaWeb.ActivityController do
|
||||||
)
|
)
|
||||||
|
|
||||||
watched = if !!user do
|
watched = if !!user do
|
||||||
{:ok, watched_images} =
|
{:ok, {watched_images, _tags}} =
|
||||||
ImageLoader.search_string(
|
ImageLoader.search_string(
|
||||||
conn,
|
conn,
|
||||||
"my:watched",
|
"my:watched",
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Api.Json.SearchController do
|
||||||
sort = ImageSorter.parse_sort(params)
|
sort = ImageSorter.parse_sort(params)
|
||||||
|
|
||||||
case ImageLoader.search_string(conn, params["q"], sorts: sort.sorts, queries: sort.queries, queryable: queryable) do
|
case ImageLoader.search_string(conn, params["q"], sorts: sort.sorts, queries: sort.queries, queryable: queryable) do
|
||||||
{:ok, images} ->
|
{:ok, {images, _tags}} ->
|
||||||
interactions =
|
interactions =
|
||||||
Interactions.user_interactions(images, user)
|
Interactions.user_interactions(images, user)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ defmodule PhilomenaWeb.GalleryController do
|
||||||
params = Map.put(conn.params, "q", query)
|
params = Map.put(conn.params, "q", query)
|
||||||
sort = ImageSorter.parse_sort(%{"sf" => "gallery_id:#{gallery.id}", "sd" => position_order(gallery)})
|
sort = ImageSorter.parse_sort(%{"sf" => "gallery_id:#{gallery.id}", "sd" => position_order(gallery)})
|
||||||
|
|
||||||
{:ok, images} = ImageLoader.search_string(conn, query, queries: sort.queries, sorts: sort.sorts)
|
{:ok, {images, _tags}} = ImageLoader.search_string(conn, query, queries: sort.queries, sorts: sort.sorts)
|
||||||
interactions = Interactions.user_interactions(images, user)
|
interactions = Interactions.user_interactions(images, user)
|
||||||
|
|
||||||
watching = Galleries.subscribed?(gallery, user)
|
watching = Galleries.subscribed?(gallery, user)
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
plug PhilomenaWeb.AdvertPlug when action in [:show]
|
plug PhilomenaWeb.AdvertPlug when action in [:show]
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
images = ImageLoader.query(conn, %{match_all: %{}})
|
{images, _tags} = ImageLoader.query(conn, %{match_all: %{}})
|
||||||
|
|
||||||
interactions =
|
interactions =
|
||||||
Interactions.user_interactions(images, conn.assigns.current_user)
|
Interactions.user_interactions(images, conn.assigns.current_user)
|
||||||
|
|
|
@ -18,14 +18,14 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
current_user = conn.assigns.current_user
|
current_user = conn.assigns.current_user
|
||||||
user = conn.assigns.user
|
user = conn.assigns.user
|
||||||
|
|
||||||
{:ok, recent_uploads} =
|
{:ok, {recent_uploads, _tags}} =
|
||||||
ImageLoader.search_string(
|
ImageLoader.search_string(
|
||||||
conn,
|
conn,
|
||||||
"uploader_id:#{user.id}",
|
"uploader_id:#{user.id}",
|
||||||
pagination: %{page_number: 1, page_size: 6}
|
pagination: %{page_number: 1, page_size: 6}
|
||||||
)
|
)
|
||||||
|
|
||||||
{:ok, recent_faves} =
|
{:ok, {recent_faves, _tags}} =
|
||||||
ImageLoader.search_string(
|
ImageLoader.search_string(
|
||||||
conn,
|
conn,
|
||||||
"faved_by_id:#{user.id}",
|
"faved_by_id:#{user.id}",
|
||||||
|
|
|
@ -10,12 +10,12 @@ defmodule PhilomenaWeb.SearchController do
|
||||||
sort = ImageSorter.parse_sort(params)
|
sort = ImageSorter.parse_sort(params)
|
||||||
|
|
||||||
case ImageLoader.search_string(conn, params["q"], sorts: sort.sorts, queries: sort.queries) do
|
case ImageLoader.search_string(conn, params["q"], sorts: sort.sorts, queries: sort.queries) do
|
||||||
{:ok, images} ->
|
{:ok, {images, tags}} ->
|
||||||
interactions =
|
interactions =
|
||||||
Interactions.user_interactions(images, user)
|
Interactions.user_interactions(images, user)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> render("index.html", images: images, search_query: params["q"], interactions: interactions, layout_class: "layout--wide")
|
|> render("index.html", images: images, tags: tags, search_query: params["q"], interactions: interactions, layout_class: "layout--wide")
|
||||||
|
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
render(conn, "index.html", images: [], error: msg, search_query: params["q"])
|
render(conn, "index.html", images: [], error: msg, search_query: params["q"])
|
||||||
|
|
|
@ -39,7 +39,7 @@ defmodule PhilomenaWeb.TagController do
|
||||||
|> preload([:aliases, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user])
|
|> preload([:aliases, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user])
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|
|
||||||
images =
|
{images, _tags} =
|
||||||
ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}})
|
ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}})
|
||||||
|
|
||||||
interactions =
|
interactions =
|
||||||
|
@ -55,6 +55,8 @@ defmodule PhilomenaWeb.TagController do
|
||||||
Enum.zip(dnp_bodies, tag.dnp_entries)
|
Enum.zip(dnp_bodies, tag.dnp_entries)
|
||||||
|
|
||||||
search_query = escape_name(tag)
|
search_query = escape_name(tag)
|
||||||
|
params = Map.put(conn.params, "q", search_query)
|
||||||
|
conn = Map.put(conn, :params, params)
|
||||||
|
|
||||||
render(
|
render(
|
||||||
conn,
|
conn,
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
defmodule PhilomenaWeb.ImageLoader do
|
defmodule PhilomenaWeb.ImageLoader do
|
||||||
alias Philomena.Images.{Image, Query}
|
alias Philomena.Images.{Image, Query}
|
||||||
|
alias Philomena.Textile.Renderer
|
||||||
|
alias Philomena.Tags.Tag
|
||||||
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def search_string(conn, search_string, options \\ []) do
|
def search_string(conn, search_string, options \\ []) do
|
||||||
|
@ -23,19 +26,28 @@ defmodule PhilomenaWeb.ImageLoader do
|
||||||
filter = conn.assigns.compiled_filter
|
filter = conn.assigns.compiled_filter
|
||||||
filters = create_filters(user, filter)
|
filters = create_filters(user, filter)
|
||||||
|
|
||||||
Image.search_records(
|
records =
|
||||||
%{
|
Image.search_records(
|
||||||
query: %{
|
%{
|
||||||
bool: %{
|
query: %{
|
||||||
must: List.flatten([body, sort_queries]),
|
bool: %{
|
||||||
must_not: filters
|
must: List.flatten([body, sort_queries]),
|
||||||
}
|
must_not: filters
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sort: sort_sorts
|
||||||
},
|
},
|
||||||
sort: sort_sorts
|
pagination,
|
||||||
},
|
queryable
|
||||||
pagination,
|
)
|
||||||
queryable
|
|
||||||
)
|
tags =
|
||||||
|
body
|
||||||
|
|> search_tag_names()
|
||||||
|
|> load_tags()
|
||||||
|
|> render_dnp_entries(conn)
|
||||||
|
|
||||||
|
{records, tags}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp create_filters(user, filter) do
|
defp create_filters(user, filter) do
|
||||||
|
@ -51,4 +63,34 @@ defmodule PhilomenaWeb.ImageLoader do
|
||||||
|
|
||||||
defp maybe_custom_hide(filters, _user),
|
defp maybe_custom_hide(filters, _user),
|
||||||
do: filters
|
do: filters
|
||||||
|
|
||||||
|
# TODO: the search parser should try to optimize queries
|
||||||
|
defp search_tag_name(%{term: %{"namespaced_tags.name" => tag_name}}), do: [tag_name]
|
||||||
|
defp search_tag_name(_other_query), do: []
|
||||||
|
|
||||||
|
defp search_tag_names(%{bool: %{must: musts}}), do: Enum.flat_map(musts, &search_tag_name(&1))
|
||||||
|
defp search_tag_names(%{bool: %{should: shoulds}}), do: Enum.flat_map(shoulds, &search_tag_name(&1))
|
||||||
|
defp search_tag_names(%{term: %{"namespaced_tags.name" => tag_name}}), do: [tag_name]
|
||||||
|
defp search_tag_names(_other_query), do: []
|
||||||
|
|
||||||
|
defp load_tags([]), do: []
|
||||||
|
defp load_tags(tags) do
|
||||||
|
Tag
|
||||||
|
|> join(:left, [t], at in Tag, on: t.id == at.aliased_tag_id)
|
||||||
|
|> where([t, at], t.name in ^tags or at.name in ^tags)
|
||||||
|
|> preload([:aliases, :implied_tags, :implied_by_tags, :dnp_entries, public_links: :user])
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp render_dnp_entries([], _conn), do: []
|
||||||
|
defp render_dnp_entries([tag], conn) do
|
||||||
|
dnp_bodies =
|
||||||
|
Renderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), conn)
|
||||||
|
|
||||||
|
dnp_entries =
|
||||||
|
Enum.zip(dnp_bodies, tag.dnp_entries)
|
||||||
|
|
||||||
|
[{tag, dnp_entries}]
|
||||||
|
end
|
||||||
|
defp render_dnp_entries(tags, _conn), do: tags
|
||||||
end
|
end
|
|
@ -2,6 +2,7 @@ elixir:
|
||||||
header = assigns[:header] || ""
|
header = assigns[:header] || ""
|
||||||
params = assigns[:params] || assigns[:scope] || []
|
params = assigns[:params] || assigns[:scope] || []
|
||||||
scope = assigns[:scope] || []
|
scope = assigns[:scope] || []
|
||||||
|
tags = assigns[:tags] || []
|
||||||
route = assigns[:route] || fn p -> Routes.image_path(@conn, :index, p) end
|
route = assigns[:route] || fn p -> Routes.image_path(@conn, :index, p) end
|
||||||
image_url = fn image -> Routes.image_path(@conn, :show, image, scope) end
|
image_url = fn image -> Routes.image_path(@conn, :show, image, scope) end
|
||||||
pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @images, route: route, params: params
|
pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @images, route: route, params: params
|
||||||
|
@ -13,6 +14,8 @@ elixir:
|
||||||
=> header
|
=> header
|
||||||
= pagination
|
= pagination
|
||||||
|
|
||||||
|
= info_row @conn, tags
|
||||||
|
|
||||||
.block__content.js-resizable-media-container
|
.block__content.js-resizable-media-container
|
||||||
= for image <- @images do
|
= for image <- @images do
|
||||||
= render PhilomenaWeb.ImageView, "_image_box.html", image: image, link: image_url.(image), size: assigns[:size] || :thumb, conn: @conn
|
= render PhilomenaWeb.ImageView, "_image_box.html", image: image, link: image_url.(image), size: assigns[:size] || :thumb, conn: @conn
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
= cond do
|
= cond do
|
||||||
- Enum.any?(@images) ->
|
- Enum.any?(@images) ->
|
||||||
= render PhilomenaWeb.ImageView, "index.html", conn: @conn, images: @images, route: fn p -> Routes.search_path(@conn, :index, p) end, scope: scope(@conn)
|
= render PhilomenaWeb.ImageView, "index.html", conn: @conn, tags: @tags, images: @images, route: fn p -> Routes.search_path(@conn, :index, p) end, scope: scope(@conn)
|
||||||
- assigns[:error] ->
|
- assigns[:error] ->
|
||||||
p
|
p
|
||||||
' Oops, there was an error evaluating your query:
|
' Oops, there was an error evaluating your query:
|
||||||
|
|
3
lib/philomena_web/templates/tag/_tags_row.html.slime
Normal file
3
lib/philomena_web/templates/tag/_tags_row.html.slime
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.block__content.js-imagelist-info.flex class=tags_row_class(@conn)
|
||||||
|
.flex__grow
|
||||||
|
= render PhilomenaWeb.TagView, "_tag_list.html", tags: @tags, conn: @conn
|
|
@ -1,2 +1,3 @@
|
||||||
= render PhilomenaWeb.TagView, "_tag_info_row.html", tag: @tag, body: @body, dnp_entries: @dnp_entries, conn: @conn
|
= render PhilomenaWeb.ImageView, "index.html", conn: @conn, tags: [{@tag, @dnp_entries}], images: @images, scope: [q: @search_query]
|
||||||
= render PhilomenaWeb.ImageView, "index.html", conn: @conn, images: @images, scope: [q: @search_query]
|
|
||||||
|
= render PhilomenaWeb.SearchView, "_form.html", conn: @conn
|
|
@ -136,6 +136,14 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
conn.assigns.current_user.anonymous_by_default
|
conn.assigns.current_user.anonymous_by_default
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def info_row(_conn, []), do: []
|
||||||
|
def info_row(conn, [{tag, dnp_entries}]) do
|
||||||
|
render PhilomenaWeb.TagView, "_tag_info_row.html", conn: conn, tag: tag, dnp_entries: dnp_entries
|
||||||
|
end
|
||||||
|
def info_row(conn, tags) do
|
||||||
|
render PhilomenaWeb.TagView, "_tags_row.html", conn: conn, tags: tags
|
||||||
|
end
|
||||||
|
|
||||||
defp thumb_format("svg", _name), do: "png"
|
defp thumb_format("svg", _name), do: "png"
|
||||||
defp thumb_format(_, :rendered), do: "png"
|
defp thumb_format(_, :rendered), do: "png"
|
||||||
defp thumb_format(format, _name), do: format
|
defp thumb_format(format, _name), do: format
|
||||||
|
|
|
@ -41,6 +41,11 @@ defmodule PhilomenaWeb.TagView do
|
||||||
link tag_name, to: "#", title: title, data: [tag_name: tag_name, click_addtag: tag_name]
|
link tag_name, to: "#", title: title, data: [tag_name: tag_name, click_addtag: tag_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tags_row_class(%{params: %{"page" => "0"}}), do: nil
|
||||||
|
def tags_row_class(%{params: %{"page" => "1"}}), do: nil
|
||||||
|
def tags_row_class(%{params: %{"page" => _page}}), do: "hidden"
|
||||||
|
def tags_row_class(_conn), do: nil
|
||||||
|
|
||||||
defp implications(%{implied_tags: []}), do: []
|
defp implications(%{implied_tags: []}), do: []
|
||||||
defp implications(%{implied_tags: it}) do
|
defp implications(%{implied_tags: it}) do
|
||||||
names =
|
names =
|
||||||
|
|
Loading…
Reference in a new issue