diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index c79dc04a..f722d75b 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -2,8 +2,14 @@ article.block.communication id="comment_#{@comment.id}" .block__content.flex.flex--no-wrap .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, awards: true, conn: @conn + br + + = render PhilomenaWeb.UserAttributionView, "_anon_user_title.html", object: @comment, conn: @conn + .communication__body__text = if @comment.hidden_from_users do strong.comment_deleted diff --git a/lib/philomena_web/templates/comment/_comment_with_image.html.slime b/lib/philomena_web/templates/comment/_comment_with_image.html.slime index 6f7b7508..61092f6a 100644 --- a/lib/philomena_web/templates/comment/_comment_with_image.html.slime +++ b/lib/philomena_web/templates/comment/_comment_with_image.html.slime @@ -3,8 +3,13 @@ article.block.communication id="comment_#{@comment.id}" .flex__fixed.spacing-right .post-image-container = render PhilomenaWeb.ImageView, "_image_container.html", image: @comment.image, size: :thumb_tiny, conn: @conn + .flex__grow.communication__body span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment, awards: true, conn: @conn + br + + = render PhilomenaWeb.UserAttributionView, "_anon_user_title.html", object: @comment, conn: @conn + .communication__body__text = if @comment.hidden_from_users do strong.comment_deleted diff --git a/lib/philomena_web/templates/message/_message.html.slime b/lib/philomena_web/templates/message/_message.html.slime index d8b0a484..6e3ed41a 100644 --- a/lib/philomena_web/templates/message/_message.html.slime +++ b/lib/philomena_web/templates/message/_message.html.slime @@ -2,9 +2,13 @@ article.block.communication .block__content.flex.flex--no-wrap .flex__fixed.spacing-right = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @message.from}, conn: @conn, class: "avatar--100px" + .flex__grow.communication__body - span.communication__body__sender-name - = render PhilomenaWeb.UserAttributionView, "_user.html", object: %{user: @message.from}, badges: true, conn: @conn + + span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_user.html", object: %{user: @message.from}, badges: true, conn: @conn + br + + = render PhilomenaWeb.UserAttributionView, "_user_title.html", object: %{user: @message.from}, conn: @conn br diff --git a/lib/philomena_web/templates/post/_post.html.slime b/lib/philomena_web/templates/post/_post.html.slime index 123c25ef..b213fb81 100644 --- a/lib/philomena_web/templates/post/_post.html.slime +++ b/lib/philomena_web/templates/post/_post.html.slime @@ -2,8 +2,13 @@ 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, awards: true, conn: @conn + .flex__grow.communication__body span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, conn: @conn + br + + = render PhilomenaWeb.UserAttributionView, "_anon_user_title.html", object: @post, conn: @conn + .communication__body__text = if !@post.hidden_from_users do ==<> @body diff --git a/lib/philomena_web/templates/user_attribution/_anon_user_title.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user_title.html.slime new file mode 100644 index 00000000..2d0a6d45 --- /dev/null +++ b/lib/philomena_web/templates/user_attribution/_anon_user_title.html.slime @@ -0,0 +1,6 @@ += if !!@object.user and !anonymous?(@object) do + = for {class, label} <- user_labels(@object) do + = if assigns[:large] do + .label.label--block class=class = label + - else + .label.label--block.label--small class=class = label \ No newline at end of file diff --git a/lib/philomena_web/templates/user_attribution/_user_title.html.slime b/lib/philomena_web/templates/user_attribution/_user_title.html.slime new file mode 100644 index 00000000..8695b48c --- /dev/null +++ b/lib/philomena_web/templates/user_attribution/_user_title.html.slime @@ -0,0 +1,5 @@ += for {class, label} <- user_labels(@object) do + = if assigns[:large] do + .label.label--block class=class = label + - else + .label.label--block.label--small class=class = label \ No newline at end of file diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 7c7912b1..8645df72 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -33,6 +33,32 @@ defmodule PhilomenaWeb.UserAttributionView do def user_avatar(%{user: %{avatar: avatar}}, class), do: img_tag(avatar_url_root() <> "/" <> avatar, class: class) + def user_labels(%{user: user}) do + [] + |> personal_title(user) + |> secondary_role(user) + |> staff_role(user) + end + + defp personal_title(labels, %{personal_title: t}) when t not in [nil, ""], + do: [{"label--primary", t} | labels] + defp personal_title(labels, _user), + do: labels + + defp secondary_role(labels, %{secondary_role: t}) when t not in [nil, ""], + do: [{"label--warning", t} | labels] + defp secondary_role(labels, _user), + do: labels + + defp staff_role(labels, %{hide_default_role: false, role: "admin"}), + do: [{"label--danger", "Site Administrator"} | labels] + defp staff_role(labels, %{hide_default_role: false, role: "moderator"}), + do: [{"label--success", "Site Moderator"} | labels] + defp staff_role(labels, %{hide_default_role: false, role: "assisant"}), + do: [{"label--purple", "Site Assistant"} | labels] + defp staff_role(labels, _user), + do: labels + defp avatar_url_root do Application.get_env(:philomena, :avatar_url_root) end