diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index 0a95f7b1ae..6f612790e0 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -181,15 +181,17 @@ def make_answer def like_comment @comment_id = params["comment_id"].to_i @user_id = params["user_id"].to_i + @emoji_type = params["emoji_type"] comment = Comment.where(cid: @comment_id).first - like = comment.likes.where(user_id: @user_id) + like = comment.likes.where(user_id: @user_id, emoji_type: @emoji_type) @is_liked = like.count.positive? if like.count.positive? like.first.destroy else - comment.likes.create(user_id: @user_id) + comment.likes.create(user_id: @user_id, emoji_type: @emoji_type) end + @likes = comment.likes.group(:emoji_type).count respond_with do |format| format.js { render template: 'comment/like_comment' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3cbab154b5..8d0a6d816f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -39,6 +39,20 @@ def emoji_names_list { emojis: emojis, image_map: image_map } end + def emoji_info + emoji_names = ["thumbs-up", "thumbs-down", "laugh", + "hooray", "confused", "heart"] + emoji_image_map = { + "thumbs-up" => "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png", + "thumbs-down" => "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44e.png", + "laugh" => "https://assets-cdn.github.com/images/icons/emoji/unicode/1f604.png", + "hooray" => "https://assets-cdn.github.com/images/icons/emoji/unicode/1f389.png", + "confused" => "https://assets-cdn.github.com/images/icons/emoji/unicode/1f615.png", + "heart" => "https://assets-cdn.github.com/images/icons/emoji/unicode/2764.png" + } + [emoji_names, emoji_image_map] + end + def feature(title) features = Node.where(type: 'feature', title: title) if !features.empty? diff --git a/app/models/comment.rb b/app/models/comment.rb index 5a369b0e1d..167c7b6b7e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -200,6 +200,10 @@ def likers User.where(id: likes.pluck(:user_id)) end + def emoji_likes + likes.group(:emoji_type).count + end + def self.receive_mail(message) node_id = message.subject[/#([\d]+)/, 1] #This took out the node ID from the subject line unless node_id.nil? diff --git a/app/views/comment/like_comment.js.erb b/app/views/comment/like_comment.js.erb index d6c61e99eb..0ec5c77aff 100644 --- a/app/views/comment/like_comment.js.erb +++ b/app/views/comment/like_comment.js.erb @@ -1,14 +1,12 @@ -<% comment_star = "#comment-like-star-#{@comment_id}-#{@user_id}" %> -<% comment_count = "#comment-like-count-#{@comment_id}-#{@user_id}" %> - -<% if @is_liked %> - $("<%= comment_star %>").removeClass("fa fa-star").addClass("fa fa-star-o"); - oldValue = parseInt($("<%= comment_count %>").html()); - newValue = oldValue-1; - $("<%= comment_count %>").html(newValue); -<% else %> - $("<%= comment_star %>").removeClass("fa fa-star-o").addClass("fa fa-star"); - oldValue = parseInt($("<%= comment_count %>").html()); - newValue = oldValue+1; - $("<%= comment_count %>").html(newValue); -<% end %> \ No newline at end of file +<% str="##{@comment_id}-like-emojis button" %> +<% emoji_names = ["thumbs-up", "thumbs-down", "laugh", + "hooray", "confused", "heart"] %> +$("<%= str %>").css("display","none"); +<% emoji_names.each do |e| %> + <% str="##{@comment_id}-emoji-button-#{e}" %> + <% capitalized_emoji_name = e.split("-").map(&:capitalize).join %> + <% if @likes.has_key? capitalized_emoji_name %> + $("<%= str %>").css("display","flex"); + $("<%= str %> div").first().html("<%= @likes[capitalized_emoji_name] %>"); + <% end %> +<% end %> diff --git a/app/views/notes/_comment.html.erb b/app/views/notes/_comment.html.erb index e480ea57ec..3e5b3c56da 100644 --- a/app/views/notes/_comment.html.erb +++ b/app/views/notes/_comment.html.erb @@ -1,6 +1,6 @@ -
- <% if !current_user %> --
- <%= link_to new_user_session_path( return_to: request.path ), style: "text-decoration: none; color: black;" do %>
-
- <%= comment.likers.count %>
- <% end %>
- <% else %>
- <% str = "/comment/like?comment_id=#{comment.cid}&user_id=#{current_user.uid}" %>
-
-
- <%= link_to str, data: { method: "post", remote: true }, style: "text-decoration: none; color: black;" do %>
-
- <%= comment.likers.count %>
- <% end %>
- <% end %>
-
-
- <% if current_user && comment.uid == current_user.uid %> @@ -68,6 +50,24 @@ <% end %> + <% if current_user %> + ++ <% emoji_names, emoji_image_map = emoji_info %> + <% emoji_names.each do |e| %> +-
+ <% capitalized_emoji_name = e.split("-").map(&:capitalize).join %>
+ <% str = "/comment/like?comment_id=#{comment.cid}&user_id=#{current_user.uid}&emoji_type=#{capitalized_emoji_name}" %>
+ <%= link_to str, data: { method: "post", remote: true }, style: "padding: 0;" do %>
+
+ <% end %>
+
+ <% end %>
+
+ <% end %><%= raw render_comment_body(comment) %>
<% if comment.body.include?('?') %>Is this a question? Click here to post it to the Questions page. @@ -97,6 +97,20 @@
<%= @node.comments.length %> <%= t('notes._comments.comments') %>
-