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 ...@@ -20,7 +20,13 @@ class @AwardsHandler
handleClick: (e) => handleClick: (e) =>
e.preventDefault() e.preventDefault()
$emojiBtn = $(e.currentTarget) $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 emoji = $emojiBtn
.find(".icon") .find(".icon")
.data "emoji" .data "emoji"
...@@ -44,7 +50,9 @@ class @AwardsHandler ...@@ -44,7 +50,9 @@ class @AwardsHandler
$.get $addBtn.data('award-menu-url'), (response) => $.get $addBtn.data('award-menu-url'), (response) =>
$addBtn.removeClass "is-loading" $addBtn.removeClass "is-loading"
$addBtn.closest('.js-award-holder').append response $addBtn.closest('.js-award-holder').append response
@renderFrequentlyUsedBlock() @renderFrequentlyUsedBlock()
setTimeout => setTimeout =>
$(".emoji-menu").addClass "is-visible" $(".emoji-menu").addClass "is-visible"
$("#emoji_search").focus() $("#emoji_search").focus()
...@@ -56,14 +64,18 @@ class @AwardsHandler ...@@ -56,14 +64,18 @@ class @AwardsHandler
@postEmoji awardUrl, emoji, => @postEmoji awardUrl, emoji, =>
@addAwardToEmojiBar(emoji) @addAwardToEmojiBar(emoji)
$('.js-awards-block-current').removeClass 'js-awards-block-current'
$(".emoji-menu").removeClass "is-visible" $(".emoji-menu").removeClass "is-visible"
addAwardToEmojiBar: (emoji) -> addAwardToEmojiBar: (emoji) ->
@addEmojiToFrequentlyUsedList(emoji) @addEmojiToFrequentlyUsedList(emoji)
emoji = @normilizeEmojiName(emoji) emoji = @normilizeEmojiName(emoji)
if @exist(emoji) $emojiBtn = @findEmojiIcon(emoji)
if @isActive(emoji)
if $emojiBtn.length > 0
if @isActive($emojiBtn)
@decrementCounter(emoji) @decrementCounter(emoji)
else else
counter = @findEmojiIcon(emoji).siblings(".js-counter") counter = @findEmojiIcon(emoji).siblings(".js-counter")
...@@ -73,11 +85,8 @@ class @AwardsHandler ...@@ -73,11 +85,8 @@ class @AwardsHandler
else else
@createEmoji(emoji) @createEmoji(emoji)
exist: (emoji) -> isActive: ($emojiBtn) ->
@findEmojiIcon(emoji).length > 0 $emojiBtn.parent().hasClass("active")
isActive: (emoji) ->
@findEmojiIcon(emoji).parent().hasClass("active")
decrementCounter: (emoji) -> decrementCounter: (emoji) ->
counter = @findEmojiIcon(emoji).siblings(".js-counter") counter = @findEmojiIcon(emoji).siblings(".js-counter")
...@@ -134,11 +143,15 @@ class @AwardsHandler ...@@ -134,11 +143,15 @@ class @AwardsHandler
</button>" </button>"
emoji_node = $(buttonHtml) 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") .find(".emoji-icon")
.data("emoji", emoji) .data("emoji", emoji)
$('.award-control').tooltip() $('.award-control').tooltip()
$currentBlock = $('.js-awards-block-current')
if $currentBlock.is('.hidden')
$currentBlock.removeClass 'hidden'
resolveNameToCssClass: (emoji) -> resolveNameToCssClass: (emoji) ->
emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']") emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']")
...@@ -156,7 +169,7 @@ class @AwardsHandler ...@@ -156,7 +169,7 @@ class @AwardsHandler
callback.call() callback.call()
findEmojiIcon: (emoji) -> findEmojiIcon: (emoji) ->
$(".awards > .js-emoji-btn [data-emoji='#{emoji}']") $(".js-awards-block-current.awards > .js-emoji-btn [data-emoji='#{emoji}']")
scrollToAwards: -> scrollToAwards: ->
$('body, html').animate({ $('body, html').animate({
......
.awards.votes-block.js-votes-block{ data: { award_url: url_for([:toggle_emoji_award, @project.namespace.becomes(Namespace), @project, awardable]) } } - grouped_emojis = awardable.grouped_awards(inline)
- awards_sort(awardable.grouped_awards).each do |emoji, awards| .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) } %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) = emoji_icon(emoji)
%span.award-control-text.js-counter %span.award-control-text.js-counter
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
.note-header .note-header
- if note_editable?(note) - if note_editable?(note)
.note-actions .note-actions
= link_to '#', title: 'Edit comment', class: 'js-note-edit' do .award-menu-holder.note-action-award-holder.js-award-holder.js-award-action-btn{ data: { target: "##{dom_id(note)} .js-awards-block" } }
= icon('pencil-square-o')
.award-menu-holder.note-action-award-holder.js-award-holder.js-award-action-btn
= link_to '#', title: 'Award emoji', class: 'note-award-control js-add-award', data: { award_menu_url: emojis_path } do = 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('smile-o', {class: "award-control-icon award-control-icon-normal"})
= icon('spinner spin', {class: "award-control-icon award-control-icon-loading"}) = 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 = 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') = icon('trash-o')
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
= markdown(note.note, pipeline: :note, cache_key: [note, "note"]) = markdown(note.note, pipeline: :note, cache_key: [note, "note"])
- if note_editable - if note_editable
= render 'projects/notes/edit_form', note: note = 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) = edited_time_ago_with_tooltip(note, placement: 'bottom', html_class: 'note_edited_ago', include_author: true)
- if note.attachment.url - 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