add more recents to profile page

This commit is contained in:
byte[] 2019-12-04 23:53:56 -05:00
parent 27e4fe5841
commit 3d94deb7e5
7 changed files with 97 additions and 10 deletions

View file

@ -3,7 +3,12 @@ defmodule PhilomenaWeb.ProfileController do
alias PhilomenaWeb.ImageLoader alias PhilomenaWeb.ImageLoader
alias Philomena.Users.User alias Philomena.Users.User
alias Philomena.Galleries.Gallery
alias Philomena.Posts.Post
alias Philomena.Comments.Comment
alias Philomena.Interactions alias Philomena.Interactions
alias Philomena.Repo
import Ecto.Query
plug :load_and_authorize_resource, model: User, only: :show, id_field: "slug", preload: [awards: :badge, public_links: :tag] plug :load_and_authorize_resource, model: User, only: :show, id_field: "slug", preload: [awards: :badge, public_links: :tag]
@ -25,6 +30,49 @@ defmodule PhilomenaWeb.ProfileController do
pagination: %{page_number: 1, page_size: 6} pagination: %{page_number: 1, page_size: 6}
) )
recent_comments =
Comment.search_records(
%{
query: %{
bool: %{
must: [
%{term: %{user_id: user.id}},
%{term: %{anonymous: false}},
%{term: %{hidden_from_users: false}}
]
}
}
},
%{page_size: 3},
Comment |> preload(user: [awards: :badge], image: :tags)
)
|> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image))
recent_posts =
Post.search_records(
%{
query: %{
bool: %{
must: [
%{term: %{user_id: user.id}},
%{term: %{anonymous: false}},
%{term: %{hidden_from_users: false}}
]
}
}
},
%{page_size: 6},
Post |> preload(user: [awards: :badge], topic: :forum)
)
|> Enum.filter(&Canada.Can.can?(current_user, :show, &1.topic))
recent_galleries =
Gallery
|> where(creator_id: ^user.id)
|> preload([:creator, thumbnail: :tags])
|> limit(5)
|> Repo.all()
interactions = interactions =
Interactions.user_interactions([recent_uploads, recent_faves], current_user) Interactions.user_interactions([recent_uploads, recent_faves], current_user)
@ -35,6 +83,9 @@ defmodule PhilomenaWeb.ProfileController do
interactions: interactions, interactions: interactions,
recent_uploads: recent_uploads, recent_uploads: recent_uploads,
recent_faves: recent_faves, recent_faves: recent_faves,
recent_comments: recent_comments,
recent_posts: recent_posts,
recent_galleries: recent_galleries,
layout_class: "layout--wide" layout_class: "layout--wide"
) )
end end

View file

@ -72,7 +72,7 @@ header.header
a.header__link href='/comments?cq=my:comments' a.header__link href='/comments?cq=my:comments'
i.fa.fa-fw.fa-comments> i.fa.fa-fw.fa-comments>
| Comments | Comments
a.header__link href="/posts/?pq=my:posts" a.header__link href="/posts?pq=my:posts"
i.fa.fa-fw.fa-pencil> i.fa.fa-fw.fa-pencil>
| Posts | Posts
a.header__link href='/user_links' a.header__link href='/user_links'

View file

@ -0,0 +1,9 @@
= if Enum.any?(@comments) do
.block
.block__header
span.block__header__title Recent Comments
= link "View all", to: Routes.comment_path(@conn, :index, cq: "user_id:#{@user.id}")
.block__content
= for comment <- @comments do
= render PhilomenaWeb.CommentView, "_comment_with_image.html", comment: comment, conn: @conn

View file

@ -0,0 +1,9 @@
= if Enum.any?(@galleries) do
.block
.block__header
span.block__header__title Recent Galleries
= link "View all", to: Routes.gallery_path(@conn, :index, gallery: [creator: @user.name])
.block__content.js-resizable-media-container
= for gallery <- @galleries do
= render PhilomenaWeb.GalleryView, "_gallery.html", gallery: gallery, conn: @conn

View file

@ -1,4 +1,5 @@
.block = if Enum.any?(@images) do
.block
.block__header .block__header
span.block__header__title = @title span.block__header__title = @title
= if assigns[:view_all_path] do = if assigns[:view_all_path] do

View file

@ -0,0 +1,14 @@
= if Enum.any?(@posts) do
.block
.block__header
span.block__header__title Recent Forum Posts
= link "View all", to: Routes.post_path(@conn, :index, pq: "user_id:#{@user.id}")
.block__content
.block
= for post <- @posts do
.block__content.alternating-color
| Post
=> link pretty_time(post.created_at), to: Routes.forum_topic_path(@conn, :show, post.topic.forum, post.topic, post_id: post) <> "#post_#{post.id}"
| in topic
=> link post.topic.title, to: Routes.forum_topic_path(@conn, :show, post.topic.forum, post.topic)

View file

@ -53,3 +53,6 @@
.column-layout__main .column-layout__main
= 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_comments.html", comments: @recent_comments, user: @user, conn: @conn
= render PhilomenaWeb.ProfileView, "_recent_posts.html", posts: @recent_posts, user: @user, conn: @conn