From f021bc5c6aa79147940ee31e800f519962f4d806 Mon Sep 17 00:00:00 2001
From: Valery Sizov <valery@gitlab.com>
Date: Wed, 18 Nov 2015 15:43:53 +0200
Subject: [PATCH] add stats on hover

---
 app/assets/javascripts/awards_handler.coffee | 32 ++++++++++++++++++--
 app/helpers/issues_helper.rb                 |  8 +++++
 app/views/votes/_votes_block.html.haml       |  4 ++-
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee
index 8803c0cca2d..29b11b0cc58 100644
--- a/app/assets/javascripts/awards_handler.coffee
+++ b/app/assets/javascripts/awards_handler.coffee
@@ -13,6 +13,7 @@ class @AwardsHandler
         counter = @findEmojiIcon(emoji).siblings(".counter")
         counter.text(parseInt(counter.text()) + 1)
         counter.parent().addClass("active")
+        @addMeToAuthorList(emoji)
     else
       @createEmoji(emoji)
 
@@ -28,13 +29,38 @@ class @AwardsHandler
     if parseInt(counter.text()) > 1
       counter.text(parseInt(counter.text()) - 1)
       counter.parent().removeClass("active")
+      @removeMeFromAuthorList(emoji)
     else
-      counter.parent().remove()
+      award = counter.parent()
+      award.tooltip("destroy")
+      award.remove()
 
+  removeMeFromAuthorList: (emoji) ->
+    award_block = @findEmojiIcon(emoji).parent()
+    authors = award_block.attr("data-original-title").split(", ")
+    authors = _.without(authors, "me").join(", ")
+    award_block.attr("title", authors)
+    @resetTooltip(award_block)
+
+  addMeToAuthorList: (emoji) ->
+    award_block = @findEmojiIcon(emoji).parent()
+    authors = award_block.attr("data-original-title").split(", ")
+    authors.push("me")
+    award_block.attr("title", authors.join(", "))
+    @resetTooltip(award_block)
+
+  resetTooltip: (award) ->
+    award.tooltip("destroy")
+
+    # "destroy" call is asynchronous, this is why we need to set timeout.
+    setTimeout (->
+      award.tooltip()
+    ), 200
+    
 
   createEmoji: (emoji) ->
     nodes = []
-    nodes.push("<div class='award active'>")
+    nodes.push("<div class='award active' title='me'>")
     nodes.push("<div class='icon' data-emoji='" + emoji + "'>")
     nodes.push(@getImage(emoji))
     nodes.push("</div>")
@@ -43,6 +69,8 @@ class @AwardsHandler
 
     $(".awards-controls").before(nodes.join("\n"))
 
+    $(".award").tooltip()
+
   getImage: (emoji) ->
     $("li[data-emoji='" + emoji + "'").html()
 
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index ff3e0911954..3aa16b66944 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -92,6 +92,14 @@ module IssuesHelper
     url_to_image(emoji_path)
   end
 
+  def emoji_author_list(notes, current_user)
+    list = notes.map do |note|
+             note.author == current_user ? "me" : note.author.username
+           end
+
+    list.join(", ")
+  end
+
   # Required for Gitlab::Markdown::IssueReferenceFilter
   module_function :url_for_issue
 end
diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml
index 118a095181f..a2298f1813a 100644
--- a/app/views/votes/_votes_block.html.haml
+++ b/app/views/votes/_votes_block.html.haml
@@ -1,6 +1,6 @@
 .awards.votes-block
   - votable.notes.awards.grouped_awards.each do | vote |
-    .award{class: ("active" if vote.last.pluck(:author_id).include?(current_user.id))}
+    .award{class: ("active" if vote.last.pluck(:author_id).include?(current_user.id)), title: emoji_author_list(vote.last, current_user)}
       .icon{"data-emoji" => "#{vote.first}"}
         = image_tag url_to_emoji(vote.first), height: "20px", width: "20px"
       .counter
@@ -28,6 +28,8 @@
       emoji = $(this).find(".icon").data("emoji")
       awards_handler.addAward(emoji)
 
+    $(".award").tooltip()
+
     
 
       
\ No newline at end of file
-- 
2.30.9