Move comments under cards
This commit is contained in:
+3
-3
@@ -1,4 +1,4 @@
|
||||
class Comments::ReactionsController < ApplicationController
|
||||
class Cards::Comments::ReactionsController < ApplicationController
|
||||
before_action :set_comment
|
||||
|
||||
def index
|
||||
@@ -12,7 +12,7 @@ class Comments::ReactionsController < ApplicationController
|
||||
@reaction = @comment.reactions.create!(reaction_params)
|
||||
|
||||
broadcast_create
|
||||
redirect_to collection_card_comment_reactions_url(@comment.card.collection, @comment.card, @comment)
|
||||
redirect_to card_comment_reactions_url(@comment.card, @comment)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -33,7 +33,7 @@ class Comments::ReactionsController < ApplicationController
|
||||
|
||||
def broadcast_create
|
||||
@reaction.broadcast_append_to @reaction.comment, :comments,
|
||||
target: "reactions_comment_#{@comment.id}", partial: "comments/reactions/reaction", locals: { comment: @comment }
|
||||
target: "reactions_comment_#{@comment.id}", partial: "cards/comments/reactions/reaction", locals: { comment: @comment }
|
||||
end
|
||||
|
||||
def broadcast_remove
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class CommentsController < ApplicationController
|
||||
class Cards::CommentsController < ApplicationController
|
||||
include CardScoped
|
||||
before_action :set_comment, only: [ :show, :edit, :update, :destroy ]
|
||||
before_action :require_own_comment, only: [ :edit, :update, :destroy ]
|
||||
@@ -18,6 +18,10 @@ class Comment < ApplicationRecord
|
||||
card_comments.many? && card_comments_prior.last&.creator != creator
|
||||
end
|
||||
|
||||
def to_partial_path
|
||||
"cards/#{super}"
|
||||
end
|
||||
|
||||
private
|
||||
def cleanup_events
|
||||
# Delete events that reference through event_summary
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%= messages_tag(card) do %>
|
||||
<%= render partial: "messages/message", collection: card.messages, cached: true %>
|
||||
<%= render "comments/new", card: card, cached: true %>
|
||||
<%= render "cards/comments/new", card: card, cached: true %>
|
||||
|
||||
<div class="comments__subscribers flex flex-column margin-block txt-align-start full-width">
|
||||
<strong class="txt-uppercase">Subscribers</strong>
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<%= link_to comment.creator.name, user_path(comment.creator), class: "txt-ink btn btn--plain fill-transparent", data: { turbo_frame: "_top" } %>
|
||||
</strong>
|
||||
|
||||
<%= link_to collection_card_path(comment.card.collection, comment.card, anchor: "comment_#{comment.id}"), class: "txt-undecorated txt-uppercase" do %>
|
||||
<%= link_to card_path(comment.card, anchor: "comment_#{comment.id}"), class: "txt-undecorated txt-uppercase" do %>
|
||||
<%= local_datetime_tag comment.created_at, style: :shortdate, class: "txt-ink translucent" %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to edit_collection_card_comment_path(comment.card.collection, comment.card, comment),
|
||||
<%= link_to edit_card_comment_path(comment.card, comment),
|
||||
class: "comment__edit btn btn--plain txt-xx-small fill-transparent translucent flex-item-justify-end" do %>
|
||||
<%= icon_tag "menu-dots-horizontal" %>
|
||||
<span class="for-screen-reader">Edit this comment</span>
|
||||
@@ -20,7 +20,7 @@
|
||||
<%= sanitize comment.body_html %>
|
||||
</div>
|
||||
|
||||
<%= render "comments/reactions/reactions", comment: comment %>
|
||||
<%= render "cards/comments/reactions/reactions", comment: comment %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -3,5 +3,5 @@
|
||||
<%= avatar_tag comment.creator, hidden_for_screen_reader: true %>
|
||||
</figure>
|
||||
|
||||
<%= render "comments/body", comment: comment %>
|
||||
<%= render "cards/comments/body", comment: comment %>
|
||||
<% end %>
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<div class="comment__content flex-inline flex-column full-width">
|
||||
<div class="comment__body txt-align-start">
|
||||
<%= form_with model: Comment.new, url: collection_card_comments_path(card.collection, card), class: "flex flex-column gap full-width",
|
||||
<%= form_with model: Comment.new, url: card_comments_path(card), class: "flex flex-column gap full-width",
|
||||
data: { controller: "form paste local-save",
|
||||
local_save_key_value: "comment-#{card.id}",
|
||||
action: "turbo:submit-end->local-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop paste->paste#pasteFiles" } do |form| %>
|
||||
@@ -1,14 +1,14 @@
|
||||
<%= turbo_frame_tag dom_id(@comment) do %>
|
||||
<div class="comment__content comment--edit flex-inline flex-column full-width">
|
||||
<div class="comment__body txt-align-start">
|
||||
<%= form_with model: [@card.collection, @card, @comment], class: "flex flex-column gap full-width",
|
||||
<%= form_with model: [ @card, @comment ], class: "flex flex-column gap full-width",
|
||||
data: { controller: "form paste", action: "keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop paste->paste#pasteFiles" } do |form| %>
|
||||
<%= form.markdown_area :body, class: "input comment__input", required: true, autofocus: true, placeholder: new_comment_placeholder(@card) %>
|
||||
<div class="flex gap-half justify-start">
|
||||
<%= form.button class: "btn btn--reversed", type: :submit do %>
|
||||
<span>Save changes</span>
|
||||
<% end %>
|
||||
<%= link_to collection_card_comment_path(@card.collection, @card, @comment), class: "btn", data: { form_target: "cancel" } do %>
|
||||
<%= link_to card_comment_path(@card, @comment), class: "btn", data: { form_target: "cancel" } do %>
|
||||
<span">Cancel</span>
|
||||
<% end %>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_with url: collection_card_comment_path(@card.collection, @card, @comment), method: :delete, id: dom_id(@comment, :delete_form), data: { turbo_frame: "_top" } %>
|
||||
<%= form_with url: card_comment_path(@card, @comment), method: :delete, id: dom_id(@comment, :delete_form), data: { turbo_frame: "_top" } %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
class: [ "txt-small", { "txt-medium": reaction.all_emoji? } ],
|
||||
data: { action: "click->reaction-delete#reveal keydown.enter->reaction-delete#reveal:prevent", reaction_delete_target: "content" } %>
|
||||
|
||||
<%= button_to collection_card_comment_reaction_path(comment.card.collection, comment.card, comment, reaction),
|
||||
<%= button_to card_comment_reaction_path(comment.card, comment, reaction),
|
||||
method: :delete,
|
||||
class: "btn btn--negative flex-item-justify-end reaction__delete",
|
||||
data: { action: "reaction-delete#perform", reaction_delete_target: "button" } do %>
|
||||
+2
-2
@@ -2,12 +2,12 @@
|
||||
<%= turbo_stream_from comment, :comments %>
|
||||
<div class="reactions flex flex-wrap align-center gap full-width">
|
||||
<div class="flex-inline flex-wrap gap" id="<%= dom_id(comment, :reactions) %>" data-turbo-streaming-target="container">
|
||||
<%= render partial: "comments/reactions/reaction", collection: comment.reactions.ordered, locals: { comment: comment }, cached: true %>
|
||||
<%= render partial: "cards/comments/reactions/reaction", collection: comment.reactions.ordered, locals: { comment: comment }, cached: true %>
|
||||
</div>
|
||||
|
||||
<%= turbo_frame_tag comment, :new_reaction do %>
|
||||
<div class="flex-inline" data-controller="soft-keyboard">
|
||||
<%= link_to new_collection_card_comment_reaction_path(comment.card.collection, comment.card, comment), role: "button",
|
||||
<%= link_to new_card_comment_reaction_path(comment.card, comment), role: "button",
|
||||
class: "btn reaction__action", action: "soft-keyboard#open" do %>
|
||||
<%= icon_tag "reaction" %>
|
||||
<span class="for-screen-reader">Add a reaction</span>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render "cards/comments/reactions/reactions", comment: @comment %>
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<%= turbo_frame_tag dom_id(@comment, :new_reaction) do %>
|
||||
<%= form_with url: collection_card_comment_reactions_path(@comment.card.collection, @comment.card, @comment),
|
||||
<%= form_with url: card_comment_reactions_path(@comment.card, @comment),
|
||||
class: "reaction reaction__form flex-inline postion--relative max-width align-center fill-white gap expanded",
|
||||
html: { aria: { label: "New reaction" } },
|
||||
data: { controller: "form", turbo_frame: dom_id(@comment, :reacting), action: "keydown.esc->form#cancel" } do |form| %>
|
||||
@@ -17,7 +17,7 @@
|
||||
<span class="for-screen-reader">Submit</span>
|
||||
<% end %>
|
||||
|
||||
<%= link_to collection_card_comment_reactions_path(@comment.card.collection, @comment.card, @comment), role: "button",
|
||||
<%= link_to card_comment_reactions_path(@comment.card, @comment), role: "button",
|
||||
data: { turbo_frame: dom_id(@comment, :reactions), form_target: "cancel" }, class: "btn btn--negative" do %>
|
||||
<%= icon_tag "minus" %>
|
||||
<span class="for-screen-reader">Cancel</span>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render "cards/comments/body", comment: @comment %>
|
||||
@@ -0,0 +1 @@
|
||||
<%= render "cards/comments/body", comment: @comment %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render "comments/reactions/reactions", comment: @comment %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render "comments/body", comment: @comment %>
|
||||
@@ -1 +0,0 @@
|
||||
<%= render "comments/body", comment: @comment %>
|
||||
@@ -1,5 +1,5 @@
|
||||
<% cache message do %>
|
||||
<%# Template Dependency: comments/comment %>
|
||||
<%# Template Dependency: cards/comments/comment %>
|
||||
<%# Template Dependency: event_summaries/event_summary %>
|
||||
<%= render partial: message.messageable.to_partial_path, object: message.messageable %>
|
||||
<% end %>
|
||||
|
||||
+5
-5
@@ -28,6 +28,10 @@ Rails.application.routes.draw do
|
||||
resources :boosts
|
||||
resources :stagings
|
||||
resources :taggings
|
||||
|
||||
resources :comments do
|
||||
resources :reactions, module: :comments
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,11 +56,7 @@ Rails.application.routes.draw do
|
||||
resource :involvement
|
||||
end
|
||||
|
||||
resources :cards do
|
||||
resources :comments do
|
||||
resources :reactions, module: :comments
|
||||
end
|
||||
end
|
||||
resources :cards
|
||||
end
|
||||
|
||||
resources :events, only: :index
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
require "test_helper"
|
||||
|
||||
class Cards::Comments::ReactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :jz
|
||||
@comment = comments(:logo_agreement_jz)
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_turbo_stream_broadcasts [ @comment, :comments ], count: 1 do
|
||||
assert_difference -> { @comment.reactions.count }, 1 do
|
||||
post card_comment_reactions_url(@comment.card, @comment, format: :turbo_stream), params: { reaction: { content: "Great work!" } }
|
||||
assert_redirected_to card_comment_reactions_url(@comment.card, @comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "destroy" do
|
||||
assert_turbo_stream_broadcasts [ @comment, :comments ], count: 1 do
|
||||
assert_difference -> { @comment.reactions.count }, -1 do
|
||||
delete card_comment_reaction_url(@comment.card, @comment, reactions(:kevin), format: :turbo_stream)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
require "test_helper"
|
||||
|
||||
class Cards::CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_difference "cards(:logo).messages.comments.count", +1 do
|
||||
post card_comments_url(cards(:logo), params: { comment: { body: "Agreed." } })
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "update" do
|
||||
put card_comment_url(cards(:logo), comments(:logo_agreement_kevin)), params: { comment: { body: "I've changed my mind" } }
|
||||
|
||||
assert_response :success
|
||||
assert_equal "I've changed my mind", comments(:logo_agreement_kevin).reload.body.content
|
||||
end
|
||||
|
||||
test "update another user's comment" do
|
||||
assert_no_changes "comments(:logo_agreement_jz).body.content" do
|
||||
put card_comment_url(cards(:logo), comments(:logo_agreement_jz)), params: { comment: { body: "I've changed my mind" } }
|
||||
end
|
||||
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_difference "cards(:logo).messages.comments.count", +1 do
|
||||
post collection_card_comments_url(collections(:writebook), cards(:logo), params: { comment: { body: "Agreed." } })
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "update" do
|
||||
put collection_card_comment_url(collections(:writebook), cards(:logo), comments(:logo_agreement_kevin)), params: { comment: { body: "I've changed my mind" } }
|
||||
|
||||
assert_response :success
|
||||
assert_equal "I've changed my mind", comments(:logo_agreement_kevin).reload.body.content
|
||||
end
|
||||
|
||||
test "update another user's comment" do
|
||||
assert_no_changes "comments(:logo_agreement_jz).body.content" do
|
||||
put collection_card_comment_url(collections(:writebook), cards(:logo), comments(:logo_agreement_jz)), params: { comment: { body: "I've changed my mind" } }
|
||||
end
|
||||
|
||||
assert_response :forbidden
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Comments::ReactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :jz
|
||||
@comment = comments(:logo_agreement_jz)
|
||||
end
|
||||
|
||||
test "create" do
|
||||
assert_turbo_stream_broadcasts [ @comment, :comments ], count: 1 do
|
||||
assert_difference -> { @comment.reactions.count }, 1 do
|
||||
post collection_card_comment_reactions_url(@comment.card.collection, @comment.card, @comment, format: :turbo_stream), params: { reaction: { content: "Great work!" } }
|
||||
assert_redirected_to collection_card_comment_reactions_url(@comment.card.collection, @comment.card, @comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "destroy" do
|
||||
assert_turbo_stream_broadcasts [ @comment, :comments ], count: 1 do
|
||||
assert_difference -> { @comment.reactions.count }, -1 do
|
||||
delete collection_card_comment_reaction_url(@comment.card.collection, @comment.card, @comment, reactions(:kevin), format: :turbo_stream)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user