Commit fd231ff9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'revert_votes_back' into 'master'

Revert vote buttons back to issue and MR pages

https://gitlab.com/gitlab-org/gitlab-ce/issues/3672



/cc @dzaporozhets @JobV 


![joxi_screenshot_1450809309400](/uploads/379a75505e0d5f24e743aa0a6a6684e2/joxi_screenshot_1450809309400.png)


See merge request !2206
parents 7d5b51f3 c79ffa01
...@@ -9,6 +9,7 @@ v 8.4.0 (unreleased) ...@@ -9,6 +9,7 @@ v 8.4.0 (unreleased)
- Add "Frequently used" category to emoji picker - Add "Frequently used" category to emoji picker
- Add CAS support (tduehr) - Add CAS support (tduehr)
- Add link to merge request on build detail page. - Add link to merge request on build detail page.
- Revert back upvote and downvote button to the issue and MR pages
v 8.3.2 (unreleased) v 8.3.2 (unreleased)
- Enable "Add key" button when user fills in a proper key - Enable "Add key" button when user fills in a proper key
......
...@@ -43,15 +43,19 @@ class @AwardsHandler ...@@ -43,15 +43,19 @@ class @AwardsHandler
decrementCounter: (emoji) -> decrementCounter: (emoji) ->
counter = @findEmojiIcon(emoji).siblings(".counter") counter = @findEmojiIcon(emoji).siblings(".counter")
emojiIcon = counter.parent()
if parseInt(counter.text()) > 1 if parseInt(counter.text()) > 1
counter.text(parseInt(counter.text()) - 1) counter.text(parseInt(counter.text()) - 1)
counter.parent().removeClass("active") emojiIcon.removeClass("active")
@removeMeFromAuthorList(emoji) @removeMeFromAuthorList(emoji)
else if emoji =="thumbsup" || emoji == "thumbsdown"
emojiIcon.tooltip("destroy")
counter.text(0)
emojiIcon.removeClass("active")
else else
award = counter.parent() emojiIcon.tooltip("destroy")
award.tooltip("destroy") emojiIcon.remove()
award.remove()
removeMeFromAuthorList: (emoji) -> removeMeFromAuthorList: (emoji) ->
award_block = @findEmojiIcon(emoji).parent() award_block = @findEmojiIcon(emoji).parent()
...@@ -127,9 +131,6 @@ class @AwardsHandler ...@@ -127,9 +131,6 @@ class @AwardsHandler
getFrequentlyUsedEmojis: -> getFrequentlyUsedEmojis: ->
frequently_used_emojis = ($.cookie('frequently_used_emojis') || "").split(",") frequently_used_emojis = ($.cookie('frequently_used_emojis') || "").split(",")
frequently_used_emojis = ["thumbsup", "thumbsdown"].concat(frequently_used_emojis)
_.compact(_.uniq(frequently_used_emojis)) _.compact(_.uniq(frequently_used_emojis))
renderFrequentlyUsedBlock: -> renderFrequentlyUsedBlock: ->
......
...@@ -120,6 +120,18 @@ module IssuesHelper ...@@ -120,6 +120,18 @@ module IssuesHelper
end end
end end
def awards_sort(awards)
awards.sort_by do |award, notes|
if award == "thumbsup"
0
elsif award == "thumbsdown"
1
else
2
end
end.to_h
end
# Required for Banzai::Filter::IssueReferenceFilter # Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue module_function :url_for_issue
end end
...@@ -107,9 +107,16 @@ class Note < ActiveRecord::Base ...@@ -107,9 +107,16 @@ class Note < ActiveRecord::Base
end end
def grouped_awards def grouped_awards
notes = {}
awards.select(:note).distinct.map do |note| awards.select(:note).distinct.map do |note|
[ note.note, where(note: note.note) ] notes[note.note] = where(note: note.note)
end end
notes["thumbsup"] ||= Note.none
notes["thumbsdown"] ||= Note.none
notes
end end
end end
......
.awards.votes-block .awards.votes-block
- votable.notes.awards.grouped_awards.each do |emoji, notes| - awards_sort(votable.notes.awards.grouped_awards).each do |emoji, notes|
.award{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user)} .award{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user)}
= emoji_icon(emoji) = emoji_icon(emoji)
.counter .counter
......
...@@ -15,15 +15,17 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps ...@@ -15,15 +15,17 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps
end end
step 'I click to emoji in the picker' do step 'I click to emoji in the picker' do
page.within '.emoji-menu' do page.within '.emoji-menu-content' do
page.first('.emoji-icon').click page.first('.emoji-icon').click
end end
end end
step 'I can remove it by clicking to icon' do step 'I can remove it by clicking to icon' do
page.within '.awards' do page.within '.awards' do
page.first('.award').click expect do
expect(page).to_not have_selector '.award' page.find('.award.active').click
sleep 0.1
end.to change{ page.all(".award").size }.from(3).to(2)
end end
end end
...@@ -37,7 +39,7 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps ...@@ -37,7 +39,7 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps
step 'I have award added' do step 'I have award added' do
page.within '.awards' do page.within '.awards' do
expect(page).to have_selector '.award' expect(page).to have_selector '.award'
expect(page.find('.award .counter')).to have_content '1' expect(page.find('.award.active .counter')).to have_content '1'
end end
end end
......
...@@ -141,4 +141,11 @@ describe IssuesHelper do ...@@ -141,4 +141,11 @@ describe IssuesHelper do
expect(note_active_class(Note.all, @note.author)).to eq("active") expect(note_active_class(Note.all, @note.author)).to eq("active")
end end
end end
describe "#awards_sort" do
it "sorts a hash so thumbsup and thumbsdown are always on top" do
data = { "thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value" }
expect(awards_sort(data).keys).to eq(["thumbsup", "thumbsdown", "lifter"])
end
end
end end
...@@ -137,9 +137,14 @@ describe Note, models: true do ...@@ -137,9 +137,14 @@ describe Note, models: true do
create :note, note: "smile", is_award: true create :note, note: "smile", is_award: true
end end
it "returns grouped array of notes" do it "returns grouped hash of notes" do
expect(Note.grouped_awards.first.first).to eq("smile") expect(Note.grouped_awards.keys.size).to eq(3)
expect(Note.grouped_awards.first.last).to match_array(Note.all) expect(Note.grouped_awards["smile"]).to match_array(Note.all)
end
it "returns thumbsup and thumbsdown always" do
expect(Note.grouped_awards["thumbsup"]).to match_array(Note.none)
expect(Note.grouped_awards["thumbsdown"]).to match_array(Note.none)
end end
end end
......
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