comment destroying (css wip)

This commit is contained in:
Luna D 2019-12-11 17:21:14 -05:00
parent 3fe828ae9a
commit 5101bd31f2
No known key found for this signature in database
GPG key ID: D0F46C94720BAA4B
9 changed files with 60 additions and 8 deletions

View file

@ -30,6 +30,8 @@ $vote_up_color: #67af2b !default;
$vote_down_color: #cf0001 !default;
$hide_color: #cf0001 !default;
$destroyed_comment_color: #f3baba !default;
$assistant_color: #eeceed !default;
$tag_normal_color: #6f8f0e !default;

View file

@ -17,6 +17,8 @@ $success_light_color: #144714 !default;
$danger_light_color: #66211f !default;
$warning_light_color: #7d4825 !default;
$destroyed_comment_color: #382c2f !default;
$meta_color: #191f2a !default;
$header_color: #284371 !default;

View file

@ -7,6 +7,10 @@
color: $vote_down_color;
}
.comment--destroyed {
background-color: $destroyed_comment_color;
}
.comment_under_review {
color: blue;
}

View file

@ -146,6 +146,12 @@ defmodule Philomena.Comments do
|> Repo.update()
end
def destroy_comment(%Comment{} = comment) do
comment
|> Comment.destroy_changeset()
|> Repo.update()
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking comment changes.

View file

@ -64,6 +64,12 @@ defmodule Philomena.Comments.Comment do
|> put_change(:deletion_reason, "")
end
def destroy_changeset(comment) do
change(comment)
|> put_change(:destroyed_content, true)
|> put_change(:body, "")
end
defp put_name_at_post_time(changeset, nil), do: changeset
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
end

View file

@ -8,5 +8,19 @@ defmodule PhilomenaWeb.Image.Comment.DeleteController do
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true
def delete(conn, _params) do
comment = conn.assigns.comment
case Comments.destroy_comment(comment) do
{:ok, comment} ->
Comments.reindex_comment(comment)
conn
|> put_flash(:info, "Comment successfully destroyed!")
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
{:error, _changeset} ->
conn
|> put_flash(:error, "Unable to destroy comment!")
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
end
end
end

View file

@ -1,5 +1,5 @@
article.block.communication id="comment_#{@comment.id}"
.block__content.flex.flex--no-wrap
.block__content.flex.flex--no-wrap class=comment_body_class(@comment)
.flex__fixed.spacing-right
= render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn
.flex__grow.communication__body
@ -16,6 +16,11 @@ article.block.communication id="comment_#{@comment.id}"
= @comment.deleted_by.name
| )
= if can?(@conn, :delete, @comment) do
= if @comment.destroyed_content do
br
strong.comment_deleted>
| This comment's contents have been destroyed.
- else
br
==<> @body
- else

View file

@ -1,5 +1,5 @@
article.block.communication id="comment_#{@comment.id}"
.block__content.flex.flex--no-wrap
.block__content.flex.flex--no-wrap class=comment_body_class(@comment)
.flex__fixed.spacing-right
.post-image-container
= render PhilomenaWeb.ImageView, "_image_container.html", image: @comment.image, size: :thumb_tiny, conn: @conn
@ -14,8 +14,18 @@ article.block.communication id="comment_#{@comment.id}"
= if @comment.hidden_from_users do
strong.comment_deleted
' Deletion reason:
=> @comment.deletion_reason
=<> @comment.deletion_reason
= if can?(@conn, :delete, @comment) do
| (
= @comment.deleted_by.name
| )
= if can?(@conn, :delete, @comment) do
= if @comment.destroyed_content do
br
strong.comment_deleted>
| This comment's contents have been destroyed.
- else
br
==<> @body
.block__content.communication__options

View file

@ -1,3 +1,6 @@
defmodule PhilomenaWeb.CommentView do
use PhilomenaWeb, :view
defp comment_body_class(%{destroyed_content: true}), do: "comment--destroyed"
defp comment_body_class(_comment), do: nil
end