-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from it3s/talk
Talk
- Loading branch information
Showing
29 changed files
with
301 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
App.components.comments = -> | ||
attributes: -> | ||
list: @container.find('#comments-list') | ||
identifier: 'remoteForm:comment-form' | ||
|
||
initialize: -> | ||
App.mediator.subscribe 'remoteForm:success', @onSuccess.bind(this) | ||
|
||
onSuccess: (evt, data) -> | ||
if data.identifier is @attr.identifier | ||
@cleanEditor() | ||
@addToList data.response.comment_html | ||
App.utils.flashMessage data.response.flash | ||
|
||
addToList: (comment_html) -> | ||
@attr.list.prepend $(comment_html) | ||
|
||
cleanEditor: -> | ||
App.mediator.publish 'editor:clean', {identifier: 'editor:comment_comment'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,4 @@ | |
@import "notifications"; | ||
@import "pictures"; | ||
@import "import"; | ||
@import "comments"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.comments { | ||
#comment-form { | ||
position: relative; | ||
|
||
input[type=submit] { | ||
margin-top: 10px; | ||
position: absolute; | ||
right: 0; | ||
} | ||
} | ||
|
||
.comments-list { | ||
margin-top: 60px; | ||
|
||
.comment { | ||
border-top: solid 1px $soft-grey; | ||
padding: 10px; | ||
color: $dark-grey; | ||
|
||
.comment-headline { | ||
a { | ||
color: $link-color; | ||
text-decoration: none; | ||
} | ||
.avatar { | ||
width: 30px; | ||
height: 30px; | ||
border-radius: 15px; | ||
top: 10px; | ||
position: relative; | ||
margin-right: 5px; | ||
} | ||
.comment-time { | ||
color: $grey; | ||
font-size: 0.9em; | ||
margin-left: 10px; | ||
} | ||
} | ||
.comment-text { | ||
margin: 20px 15px; | ||
border-left: solid 3px $ultra-soft-grey; | ||
padding-left: 15px; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class CommentsController < ApplicationController | ||
|
||
before_action :require_login | ||
before_action :find_commentable | ||
after_action :publish_commented_event | ||
|
||
def create | ||
@comment = Comment.new comment_params | ||
if @comment.save | ||
render json: {flash: flash_xhr(t 'comments.saved'), comment_html: comment_html} | ||
else | ||
render json: {errors: @comment.errors.messages}, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_commentable | ||
@commentable ||= find_polymorphic_object | ||
end | ||
|
||
def comment_params | ||
{user: current_user, content: @commentable, comment: params[:comment][:comment]} | ||
end | ||
|
||
def comment_html | ||
render_to_string(partial: 'comments/comment', locals: {comment: @comment}) | ||
end | ||
|
||
def publish_commented_event | ||
if response.ok? | ||
EventBus.publish "commented", object: @commentable, current_user: current_user, changes: {'comment' => @comment.comment} | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :content, polymorphic: true | ||
|
||
validates :user, :content, :comment, presence: true | ||
|
||
default_scope { includes(:user).order('created_at desc') } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Commentable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_many :comments, as: :content, dependent: :destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="comment"> | ||
<div class="comment-headline"> | ||
<%= image_tag comment.user.avatar.thumb , class: "avatar", title: comment.user.name %> | ||
<a href="<%= user_path(comment.user) %>"> | ||
<span><%= comment.user.name %></span> | ||
</a> | ||
<time class="comment-time" datetime="<%= comment.created_at.to_datetime.rfc3339 %>"> | ||
<%= t 'time_ago', time: time_ago_in_words(comment.created_at) %> | ||
</time> | ||
</div> | ||
<div class="comment-text"> | ||
<%= raw comment.comment %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div id="comments" class="comments" data-components='comments'> | ||
|
||
<% if logged_in? && !edit_mode? %> | ||
<%= form_tag url_for([object, :comments]), method: :post, id: "comment-form", | ||
remote: true, "data-components" => "remoteForm" do %> | ||
<div class="field"> | ||
<textarea id="comment_comment" class="comment_input tinymce" name="comment[comment]" | ||
data-components="editor" data-editor-options='{"height":70}' > | ||
</textarea> | ||
</div> | ||
<%= submit_tag 'Add comment' %> | ||
<% end %> | ||
|
||
<ul id="comments-list" class="comments-list"> | ||
<%= render comments %> | ||
</ul> | ||
|
||
<% else %> | ||
<% if comments.empty? %> | ||
<p class="empty"><%= t 'comments.empty', {name: object.name} %></p> | ||
<% else %> | ||
<ul id="comments-list" class="comments-list"> | ||
<%= render comments %> | ||
</ul> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
comments: | ||
empty: '%{name} has no comments yet.' | ||
submit: 'Add comment' | ||
saved: 'Comment added' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pt-BR: | ||
comments: | ||
empty: '%{name} não possui comentários ainda.' | ||
submit: 'Adicionar comentário' | ||
saved: 'Comentário adicionado' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def change | ||
create_table :comments do |t| | ||
t.references :user, null: false, index: true | ||
t.references :content, null: false, index: true, polymorphic: true | ||
t.text :comment, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.