diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 43143d4c..f27a06e2 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -1,7 +1,8 @@ defmodule PhilomenaWeb.ImageController do use PhilomenaWeb, :controller - alias Philomena.{Images.Image} + alias Philomena.{Images.Image, Comments.Comment} + alias Philomena.Repo import Ecto.Query plug ImageFilter @@ -23,6 +24,14 @@ defmodule PhilomenaWeb.ImageController do end def show(conn, %{"id" => _id}) do - render(conn, "show.html", image: conn.assigns.image) + comments = + Comment + |> where(image_id: ^conn.assigns.image.id) + |> preload([:user, :image]) + |> order_by(desc: :created_at) + |> limit(25) + |> Repo.all() + + render(conn, "show.html", image: conn.assigns.image, comments: comments) end end diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime new file mode 100644 index 00000000..3ab9c168 --- /dev/null +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -0,0 +1,48 @@ +article.block.communication id="comment_#{@comment.id}" + .block__content.flex.flex--no-wrap + .flex__fixed.spacing-right + /=<> user_avatar((comment.user if comment.user_visible?), 'avatar--100px', comment.author) + .flex__grow.communication__body + span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment + .communication__body__text + /- if comment.hidden_from_users + / strong.comment_deleted + / | Deletion reason: + / =<> comment.deletion_reason + / - if can?(:read, comment) + / | ( + / = comment.deleted_by.try(:name) || 'Orbital Friendship Cannon' + / | ) + / br + / - if comment.destroyed_content + / | This comment's contents have been destroyed. + / br + /= if can?(:read, @comment) + = if !@comment.hidden_from_users do + =<> @comment.body + + .block__content.communication__options + .flex.flex--wrap.flex--spaced-out + = render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment + /- if can?(:hide, Comment) + / .js-staff-action + / - if !comment.hidden_from_users && !comment.destroyed_content + / =<> link_to '#', class: 'communication__interaction togglable-delete-form-link', 'data-click-toggle': "#inline-del-form-comment-#{comment.id}" do + / i.fa.fa-times + / =<> 'Delete' + / - elsif comment.hidden_from_users && !comment.destroyed_content + / =<> link_to image_comment_hide_path(comment.image, comment), data: { confirm: t('are_you_sure') }, method: :delete, class: 'communication__interaction' do + / i.fa.fa-check + / =<> 'Restore' + / - if can?(:manage, Comment) + / =<> link_to image_comment_path(comment.image, comment), method: :delete, data: { confirm: t('are_you_sure') }, class: 'communication__interaction' do + / i.fa.fa-times + / =<> 'Delete Contents' + / - if can?(:manage, Comment) + / .communication__info + / =<> link_to_ip(comment.ip) + / .communication__info + / =<> link_to_fingerprint(comment.fingerprint, comment.user_agent) + / = form_tag image_comment_hide_path(comment.image, comment), class: 'togglable-delete-form hidden flex', id: "inline-del-form-comment-#{comment.id}" + / = text_field_tag :deletion_reason, nil, class: 'input input--wide', placeholder: 'Deletion Reason', id: "inline-del-reason-comment-#{comment.id}", required: true + / = submit_tag 'Delete', class: 'button' diff --git a/lib/philomena_web/templates/comment/_comment_options.html.slime b/lib/philomena_web/templates/comment/_comment_options.html.slime new file mode 100644 index 00000000..f9ae7fa1 --- /dev/null +++ b/lib/philomena_web/templates/comment/_comment_options.html.slime @@ -0,0 +1,31 @@ +div + ' Posted + => pretty_time(@comment.created_at) + /=<> link_to new_report_path(reportable_class: 'Comment', reportable_id: comment.id), class: 'communication__interaction' do + / i.fa.fa-flag + / =<> 'Report' + /- if comment.edited_at && can?(:read, comment) + / br + / a href=image_comment_history_path(comment.image, comment) + / | Edited + / =<> friendly_time(comment.edited_at) + / - if comment.edit_reason.present? + / | because: + / =<> comment.edit_reason +div + - link_path = "/images/#{@comment.image.id}#comment_#{@comment.id}" + a.communication__interaction title="Link to comment" href=link_path + i.fa.fa-link> + ' Link + /=<> link_to link_path, 'data-author': safe_author(comment), 'data-reply-url': link_path, 'data-post': (comment.hidden_from_users ? '' : comment.body), class: 'communication__interaction post-reply post-reply-quote' do + a.communication__interaction.post-reply.post-reply-quote href=link_path data-reply-url=link_path data-author="" data-post="" + i.fa.fa-quote-right> + ' Quote + /=<> link_to link_path, 'data-author': safe_author(comment), 'data-reply-url': link_path, class: 'communication__interaction post-reply' do + a.communication__interaction.post-reply href=link_path data-reply-url=link_path data-author="" + i.fa.fa-reply + ' Reply + /span.owner-options.hidden + / strong =<> link_to edit_image_comment_path(comment.image, comment), class: 'communication__interaction' do + / i.fas.fa-edit + / ' Edit diff --git a/lib/philomena_web/templates/image/show.html.slime b/lib/philomena_web/templates/image/show.html.slime index 9d9febe0..4a1a6e27 100644 --- a/lib/philomena_web/templates/image/show.html.slime +++ b/lib/philomena_web/templates/image/show.html.slime @@ -19,4 +19,9 @@ = if !!@image.source_url and @image.source_url != "" do a href=@image.source_url = @image.source_url - else - em> not provided yet \ No newline at end of file + em> not provided yet + + h4 Comments + #comments data-current-url="" data-loaded="true" + = for comment <- @comments do + = render PhilomenaWeb.CommentView, "_comment.html", comment: comment diff --git a/lib/philomena_web/views/comment_view.ex b/lib/philomena_web/views/comment_view.ex new file mode 100644 index 00000000..fbe88c11 --- /dev/null +++ b/lib/philomena_web/views/comment_view.ex @@ -0,0 +1,3 @@ +defmodule PhilomenaWeb.CommentView do + use PhilomenaWeb, :view +end