Commit f2f2e072 authored by Phil Hughes's avatar Phil Hughes Committed by Fatih Acet

Shows the bar on notes if a new award is added

Correctly adds/removes awards in notes

# Conflicts:
#	app/models/concerns/awardable.rb
#	app/views/projects/issues/show.html.haml
#	app/views/projects/merge_requests/_show.html.haml
parent 0b45cf55
......@@ -20,7 +20,13 @@ class @AwardsHandler
handleClick: (e) =>
e.preventDefault()
$emojiBtn = $(e.currentTarget)
awardUrl = $emojiBtn.closest('.js-votes-block').data 'award-url'
$votesBlock = $($emojiBtn.closest('.js-award-holder').data('target'))
if $votesBlock.length is 0
$votesBlock = $emojiBtn.closest('.js-awards-block')
$votesBlock.addClass 'js-awards-block-current'
awardUrl = $votesBlock.data 'award-url'
emoji = $emojiBtn
.find(".icon")
.data "emoji"
......@@ -44,7 +50,9 @@ class @AwardsHandler
$.get $addBtn.data('award-menu-url'), (response) =>
$addBtn.removeClass "is-loading"
$addBtn.closest('.js-award-holder').append response
@renderFrequentlyUsedBlock()
setTimeout =>
$(".emoji-menu").addClass "is-visible"
$("#emoji_search").focus()
......@@ -56,14 +64,18 @@ class @AwardsHandler
@postEmoji awardUrl, emoji, =>
@addAwardToEmojiBar(emoji)
$('.js-awards-block-current').removeClass 'js-awards-block-current'
$(".emoji-menu").removeClass "is-visible"
addAwardToEmojiBar: (emoji) ->
@addEmojiToFrequentlyUsedList(emoji)
emoji = @normilizeEmojiName(emoji)
if @exist(emoji)
if @isActive(emoji)
$emojiBtn = @findEmojiIcon(emoji)
if $emojiBtn.length > 0
if @isActive($emojiBtn)
@decrementCounter(emoji)
else
counter = @findEmojiIcon(emoji).siblings(".js-counter")
......@@ -73,11 +85,8 @@ class @AwardsHandler
else
@createEmoji(emoji)
exist: (emoji) ->
@findEmojiIcon(emoji).length > 0
isActive: (emoji) ->
@findEmojiIcon(emoji).parent().hasClass("active")
isActive: ($emojiBtn) ->
$emojiBtn.parent().hasClass("active")
decrementCounter: (emoji) ->
counter = @findEmojiIcon(emoji).siblings(".js-counter")
......@@ -134,11 +143,15 @@ class @AwardsHandler
</button>"
emoji_node = $(buttonHtml)
.insertBefore(".js-award-holder:not(.js-award-action-btn)")
.insertBefore(".js-awards-block-current .js-award-holder:not(.js-award-action-btn)")
.find(".emoji-icon")
.data("emoji", emoji)
$('.award-control').tooltip()
$currentBlock = $('.js-awards-block-current')
if $currentBlock.is('.hidden')
$currentBlock.removeClass 'hidden'
resolveNameToCssClass: (emoji) ->
emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']")
......@@ -156,7 +169,7 @@ class @AwardsHandler
callback.call()
findEmojiIcon: (emoji) ->
$(".awards > .js-emoji-btn [data-emoji='#{emoji}']")
$(".js-awards-block-current.awards > .js-emoji-btn [data-emoji='#{emoji}']")
scrollToAwards: ->
$('body, html').animate({
......
.awards.votes-block.js-votes-block{ data: { award_url: url_for([:toggle_emoji_award, @project.namespace.becomes(Namespace), @project, awardable]) } }
- awards_sort(awardable.grouped_awards).each do |emoji, awards|
- grouped_emojis = awardable.grouped_awards(inline)
.awards.js-awards-block{ class: ("hidden" if !inline && grouped_emojis.size == 0), data: { award_url: url_for([:toggle_emoji_award, @project.namespace.becomes(Namespace), @project, awardable]) } }
- awards_sort(grouped_emojis).each do |emoji, awards|
%button.btn.award-control.js-emoji-btn.has-tooltip{ type: "button", class: (award_active_class(awards, current_user)), title: award_user_list(awards, current_user) }
= emoji_icon(emoji)
%span.award-control-text.js-counter
......
......@@ -11,14 +11,14 @@
.note-header
- if note_editable?(note)
.note-actions
= link_to '#', title: 'Edit comment', class: 'js-note-edit' do
= icon('pencil-square-o')
.award-menu-holder.note-action-award-holder.js-award-holder.js-award-action-btn
.award-menu-holder.note-action-award-holder.js-award-holder.js-award-action-btn{ data: { target: "##{dom_id(note)} .js-awards-block" } }
= link_to '#', title: 'Award emoji', class: 'note-award-control js-add-award', data: { award_menu_url: emojis_path } do
= icon('smile-o', {class: "award-control-icon award-control-icon-normal"})
= icon('spinner spin', {class: "award-control-icon award-control-icon-loading"})
= link_to '#', title: 'Edit comment', class: 'js-note-edit' do
= icon('pencil-square-o')
= link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'js-note-delete danger' do
= icon('trash-o')
......@@ -38,7 +38,7 @@
= markdown(note.note, pipeline: :note, cache_key: [note, "note"])
- if note_editable
= render 'projects/notes/edit_form', note: note
= render 'emoji_awards/awards_block', awardable: note
= render 'emoji_awards/awards_block', awardable: note, inline: false
= edited_time_ago_with_tooltip(note, placement: 'bottom', html_class: 'note_edited_ago', include_author: true)
- if note.attachment.url
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment