mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
load awards
This commit is contained in:
parent
95ace30af5
commit
5b35b75b1d
9 changed files with 18 additions and 9 deletions
|
@ -6,14 +6,14 @@ defmodule PhilomenaWeb.Image.CommentController do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
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
|
def index(conn, _params) do
|
||||||
comments =
|
comments =
|
||||||
Comment
|
Comment
|
||||||
|> where(image_id: ^conn.assigns.image.id)
|
|> where(image_id: ^conn.assigns.image.id)
|
||||||
|> order_by(desc: :created_at)
|
|> order_by(desc: :created_at)
|
||||||
|> preload([:image, :user])
|
|> preload([:image, user: [awards: :badge]])
|
||||||
|> Repo.paginate(conn.assigns.scrivener)
|
|> Repo.paginate(conn.assigns.scrivener)
|
||||||
|
|
||||||
rendered =
|
rendered =
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
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
|
def index(conn, _params) do
|
||||||
query = conn.assigns.compiled_filter
|
query = conn.assigns.compiled_filter
|
||||||
|
@ -27,7 +27,7 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
comments =
|
comments =
|
||||||
Comment
|
Comment
|
||||||
|> where(image_id: ^conn.assigns.image.id)
|
|> where(image_id: ^conn.assigns.image.id)
|
||||||
|> preload([:user, :image])
|
|> preload([:image, user: [awards: :badge]])
|
||||||
|> order_by(desc: :created_at)
|
|> order_by(desc: :created_at)
|
||||||
|> limit(25)
|
|> limit(25)
|
||||||
|> Repo.paginate(conn.assigns.scrivener)
|
|> Repo.paginate(conn.assigns.scrivener)
|
||||||
|
|
|
@ -33,7 +33,7 @@ defmodule PhilomenaWeb.TopicController do
|
||||||
|> where(topic_id: ^conn.assigns.topic.id)
|
|> where(topic_id: ^conn.assigns.topic.id)
|
||||||
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|
||||||
|> order_by(asc: :created_at)
|
|> order_by(asc: :created_at)
|
||||||
|> preload([:user, topic: :forum])
|
|> preload([topic: :forum, user: [awards: :badge]])
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
rendered =
|
rendered =
|
||||||
|
|
|
@ -3,7 +3,7 @@ article.block.communication id="comment_#{@comment.id}"
|
||||||
.flex__fixed.spacing-right
|
.flex__fixed.spacing-right
|
||||||
= render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn
|
= render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn
|
||||||
.flex__grow.communication__body
|
.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
|
.communication__body__text
|
||||||
/- if comment.hidden_from_users
|
/- if comment.hidden_from_users
|
||||||
/ strong.comment_deleted
|
/ strong.comment_deleted
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
' Uploaded
|
' Uploaded
|
||||||
=> pretty_time(@image.created_at)
|
=> pretty_time(@image.created_at)
|
||||||
' by
|
' 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
|
span.image-size
|
||||||
|
|
|
|
||||||
= @image.image_width
|
= @image.image_width
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
article.block.communication id="post_#{@post.id}"
|
article.block.communication id="post_#{@post.id}"
|
||||||
.block__content.flex.flex--no-wrap
|
.block__content.flex.flex--no-wrap
|
||||||
.flex__fixed.spacing-right
|
.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
|
.flex__grow.communication__body
|
||||||
span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, conn: @conn
|
span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, conn: @conn
|
||||||
.communication__body__text
|
.communication__body__text
|
||||||
|
|
5
lib/philomena_web/templates/profile/_awards.html.slime
Normal file
5
lib/philomena_web/templates/profile/_awards.html.slime
Normal file
|
@ -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")
|
|
@ -1,6 +1,8 @@
|
||||||
= if !!@object.user and !@object.anonymous do
|
= if !!@object.user and !@object.anonymous do
|
||||||
strong<>
|
strong<>
|
||||||
= link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user))
|
= 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
|
- else
|
||||||
strong<>
|
strong<>
|
||||||
| Background Pony #
|
| Background Pony #
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
= if !!@object.user do
|
= if !!@object.user do
|
||||||
strong<>
|
strong<>
|
||||||
= link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user))
|
= 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
|
Loading…
Reference in a new issue