From 5b35b75b1da4e311fdf9c5d594a8c4410c46f830 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 11 Nov 2019 21:53:19 -0500 Subject: [PATCH] load awards --- lib/philomena_web/controllers/image/comment_controller.ex | 4 ++-- lib/philomena_web/controllers/image_controller.ex | 4 ++-- lib/philomena_web/controllers/topic_controller.ex | 2 +- lib/philomena_web/templates/comment/_comment.html.slime | 2 +- lib/philomena_web/templates/image/_image_meta.html.slime | 2 +- lib/philomena_web/templates/post/_post.html.slime | 2 +- lib/philomena_web/templates/profile/_awards.html.slime | 5 +++++ .../templates/user_attribution/_anon_user.html.slime | 2 ++ .../templates/user_attribution/_user.html.slime | 4 +++- 9 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 lib/philomena_web/templates/profile/_awards.html.slime diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index 1ce3df02..942b8f13 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -6,14 +6,14 @@ defmodule PhilomenaWeb.Image.CommentController do import Ecto.Query plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true - plug :load_and_authorize_resource, model: Comment, only: [:show], preload: [:image, :user] + plug :load_and_authorize_resource, model: Comment, only: [:show], preload: [:image, user: [awards: :badge]] def index(conn, _params) do comments = Comment |> where(image_id: ^conn.assigns.image.id) |> order_by(desc: :created_at) - |> preload([:image, :user]) + |> preload([:image, user: [awards: :badge]]) |> Repo.paginate(conn.assigns.scrivener) rendered = diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index e85a91d6..86f95a01 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.ImageController do alias Philomena.Repo import Ecto.Query - plug :load_and_authorize_resource, model: Image, only: :show, preload: [:user, :tags] + plug :load_and_authorize_resource, model: Image, only: :show, preload: [:tags, user: [awards: :badge]] def index(conn, _params) do query = conn.assigns.compiled_filter @@ -27,7 +27,7 @@ defmodule PhilomenaWeb.ImageController do comments = Comment |> where(image_id: ^conn.assigns.image.id) - |> preload([:user, :image]) + |> preload([:image, user: [awards: :badge]]) |> order_by(desc: :created_at) |> limit(25) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index 3a23fef4..16d9d7a7 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -33,7 +33,7 @@ defmodule PhilomenaWeb.TopicController do |> where(topic_id: ^conn.assigns.topic.id) |> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page)) |> order_by(asc: :created_at) - |> preload([:user, topic: :forum]) + |> preload([topic: :forum, user: [awards: :badge]]) |> Repo.all() rendered = diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index 75ac176a..eba40fd0 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -3,7 +3,7 @@ article.block.communication id="comment_#{@comment.id}" .flex__fixed.spacing-right = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn .flex__grow.communication__body - span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment, conn: @conn + span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment, awards: true, conn: @conn .communication__body__text /- if comment.hidden_from_users / strong.comment_deleted diff --git a/lib/philomena_web/templates/image/_image_meta.html.slime b/lib/philomena_web/templates/image/_image_meta.html.slime index e68230ff..b8a717a3 100644 --- a/lib/philomena_web/templates/image/_image_meta.html.slime +++ b/lib/philomena_web/templates/image/_image_meta.html.slime @@ -51,7 +51,7 @@ ' Uploaded => pretty_time(@image.created_at) ' by - => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @image, conn: @conn + => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @image, awards: true, conn: @conn span.image-size |   = @image.image_width diff --git a/lib/philomena_web/templates/post/_post.html.slime b/lib/philomena_web/templates/post/_post.html.slime index 5f91b27e..123c25ef 100644 --- a/lib/philomena_web/templates/post/_post.html.slime +++ b/lib/philomena_web/templates/post/_post.html.slime @@ -1,7 +1,7 @@ article.block.communication id="post_#{@post.id}" .block__content.flex.flex--no-wrap .flex__fixed.spacing-right - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, awards: true, conn: @conn .flex__grow.communication__body span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, conn: @conn .communication__body__text diff --git a/lib/philomena_web/templates/profile/_awards.html.slime b/lib/philomena_web/templates/profile/_awards.html.slime new file mode 100644 index 00000000..269a7659 --- /dev/null +++ b/lib/philomena_web/templates/profile/_awards.html.slime @@ -0,0 +1,5 @@ +.badges + = for award <- award_order(@awards) do + - title = [award_title(award), award.label] |> Enum.join(" - ") + .badge + = badge_image(award.badge, alt: title, title: title, width: "18", height: "18") \ No newline at end of file diff --git a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime index 69b0e6da..f5747320 100644 --- a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime +++ b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime @@ -1,6 +1,8 @@ = if !!@object.user and !@object.anonymous do strong<> = link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user)) + = if assigns[:awards] do + = render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards - else strong<> | Background Pony # diff --git a/lib/philomena_web/templates/user_attribution/_user.html.slime b/lib/philomena_web/templates/user_attribution/_user.html.slime index 7ae0802e..e58b85a4 100644 --- a/lib/philomena_web/templates/user_attribution/_user.html.slime +++ b/lib/philomena_web/templates/user_attribution/_user.html.slime @@ -1,3 +1,5 @@ = if !!@object.user do strong<> - = link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user)) \ No newline at end of file + = link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user)) + = if assigns[:awards] do + = render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards \ No newline at end of file