diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 03511a98..c1fb1100 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -3,7 +3,12 @@ defmodule PhilomenaWeb.ProfileController do alias PhilomenaWeb.ImageLoader alias Philomena.Users.User + alias Philomena.Galleries.Gallery + alias Philomena.Posts.Post + alias Philomena.Comments.Comment 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] @@ -25,6 +30,49 @@ defmodule PhilomenaWeb.ProfileController do 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.user_interactions([recent_uploads, recent_faves], current_user) @@ -35,6 +83,9 @@ defmodule PhilomenaWeb.ProfileController do interactions: interactions, recent_uploads: recent_uploads, recent_faves: recent_faves, + recent_comments: recent_comments, + recent_posts: recent_posts, + recent_galleries: recent_galleries, layout_class: "layout--wide" ) end diff --git a/lib/philomena_web/templates/layout/_header.html.slime b/lib/philomena_web/templates/layout/_header.html.slime index b7082e19..6efa75f3 100644 --- a/lib/philomena_web/templates/layout/_header.html.slime +++ b/lib/philomena_web/templates/layout/_header.html.slime @@ -72,7 +72,7 @@ header.header a.header__link href='/comments?cq=my:comments' i.fa.fa-fw.fa-comments> | Comments - a.header__link href="/posts/?pq=my:posts" + a.header__link href="/posts?pq=my:posts" i.fa.fa-fw.fa-pencil> | Posts a.header__link href='/user_links' diff --git a/lib/philomena_web/templates/profile/_recent_comments.html.slime b/lib/philomena_web/templates/profile/_recent_comments.html.slime new file mode 100644 index 00000000..72b5de9d --- /dev/null +++ b/lib/philomena_web/templates/profile/_recent_comments.html.slime @@ -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 diff --git a/lib/philomena_web/templates/profile/_recent_galleries.html.slime b/lib/philomena_web/templates/profile/_recent_galleries.html.slime new file mode 100644 index 00000000..d67f1061 --- /dev/null +++ b/lib/philomena_web/templates/profile/_recent_galleries.html.slime @@ -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 \ No newline at end of file diff --git a/lib/philomena_web/templates/profile/_recent_images.html.slime b/lib/philomena_web/templates/profile/_recent_images.html.slime index 48df4437..d3db5ced 100644 --- a/lib/philomena_web/templates/profile/_recent_images.html.slime +++ b/lib/philomena_web/templates/profile/_recent_images.html.slime @@ -1,9 +1,10 @@ -.block - .block__header - span.block__header__title = @title - = if assigns[:view_all_path] do - = link("View all", to: assigns[:view_all_path]) += if Enum.any?(@images) do + .block + .block__header + span.block__header__title = @title + = if assigns[:view_all_path] do + = link("View all", to: assigns[:view_all_path]) - .block__content.js-resizable-media-container - = for image <- @images do - = render PhilomenaWeb.ImageView, "_image_box.html", image: image, size: :thumb, conn: @conn \ No newline at end of file + .block__content.js-resizable-media-container + = for image <- @images do + = render PhilomenaWeb.ImageView, "_image_box.html", image: image, size: :thumb, conn: @conn \ No newline at end of file diff --git a/lib/philomena_web/templates/profile/_recent_posts.html.slime b/lib/philomena_web/templates/profile/_recent_posts.html.slime new file mode 100644 index 00000000..83c90adb --- /dev/null +++ b/lib/philomena_web/templates/profile/_recent_posts.html.slime @@ -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) diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index 6b58e3e5..146b3eb6 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -52,4 +52,7 @@ .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 Favorites", images: @recent_faves, view_all_path: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}"), conn: @conn \ No newline at end of file + = 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 \ No newline at end of file