mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
add recent artwork to profile page
This commit is contained in:
parent
a4197ee8c3
commit
823e44495d
3 changed files with 25 additions and 0 deletions
|
@ -34,6 +34,9 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
pagination: %{page_number: 1, page_size: 6}
|
pagination: %{page_number: 1, page_size: 6}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tags = tags(conn.assigns.user.public_links)
|
||||||
|
recent_artwork = recent_artwork(conn, tags)
|
||||||
|
|
||||||
recent_comments =
|
recent_comments =
|
||||||
Comment.search_records(
|
Comment.search_records(
|
||||||
%{
|
%{
|
||||||
|
@ -102,6 +105,7 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
user: user,
|
user: user,
|
||||||
interactions: interactions,
|
interactions: interactions,
|
||||||
commission_information: commission_information,
|
commission_information: commission_information,
|
||||||
|
recent_artwork: recent_artwork,
|
||||||
recent_uploads: recent_uploads,
|
recent_uploads: recent_uploads,
|
||||||
recent_faves: recent_faves,
|
recent_faves: recent_faves,
|
||||||
recent_comments: recent_comments,
|
recent_comments: recent_comments,
|
||||||
|
@ -109,6 +113,7 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
recent_galleries: recent_galleries,
|
recent_galleries: recent_galleries,
|
||||||
statistics: statistics,
|
statistics: statistics,
|
||||||
about_me: about_me,
|
about_me: about_me,
|
||||||
|
tags: tags,
|
||||||
layout_class: "layout--medium"
|
layout_class: "layout--medium"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -146,4 +151,19 @@ defmodule PhilomenaWeb.ProfileController do
|
||||||
defp commission_info(%{information: info}, conn) when info not in [nil, ""],
|
defp commission_info(%{information: info}, conn) when info not in [nil, ""],
|
||||||
do: Renderer.render_one(%{body: info}, conn)
|
do: Renderer.render_one(%{body: info}, conn)
|
||||||
defp commission_info(_commission, _conn), do: ""
|
defp commission_info(_commission, _conn), do: ""
|
||||||
|
|
||||||
|
defp tags([]), do: []
|
||||||
|
defp tags(links), do: Enum.map(& &1.tag) |> Enum.reject(&is_nil/1)
|
||||||
|
|
||||||
|
defp recent_artwork(_conn, []), do: []
|
||||||
|
defp recent_artwork(conn, tags) do
|
||||||
|
{images, _tags} =
|
||||||
|
ImageLoader.query(
|
||||||
|
conn,
|
||||||
|
%{terms: %{tag_ids: Enum.map(tags, & &1.id)}},
|
||||||
|
pagination: %{page_number: 1, page_size: 6}
|
||||||
|
)
|
||||||
|
|
||||||
|
images
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
|
|
||||||
.column-layout__main
|
.column-layout__main
|
||||||
= render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn
|
= render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn
|
||||||
|
= render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Artwork", images: @recent_artwork, view_all_path: Routes.search_path(@conn, :index, q: tag_disjunction(@tags)), conn: @conn
|
||||||
= render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Uploads", images: @recent_uploads, view_all_path: Routes.search_path(@conn, :index, q: "uploader_id:#{@user.id}"), conn: @conn
|
= render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Uploads", images: @recent_uploads, view_all_path: Routes.search_path(@conn, :index, q: "uploader_id:#{@user.id}"), conn: @conn
|
||||||
= render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Favorites", images: @recent_faves, view_all_path: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}"), conn: @conn
|
= render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Favorites", images: @recent_faves, view_all_path: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}"), conn: @conn
|
||||||
= render PhilomenaWeb.ProfileView, "_recent_galleries.html", galleries: @recent_galleries, user: @user, conn: @conn
|
= render PhilomenaWeb.ProfileView, "_recent_galleries.html", galleries: @recent_galleries, user: @user, conn: @conn
|
||||||
|
|
|
@ -46,6 +46,10 @@ defmodule PhilomenaWeb.ProfileView do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_disjunction(tags) do
|
||||||
|
Enum.map_join(tags, " || ", & &1.name)
|
||||||
|
end
|
||||||
|
|
||||||
defp zero_div(_num, 0), do: 0
|
defp zero_div(_num, 0), do: 0
|
||||||
defp zero_div(num, den), do: div(num, den)
|
defp zero_div(num, den), do: div(num, den)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue