From bcdc3694919f6cc9777dd982325469fb87468835 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Mon, 20 Jun 2016 00:06:57 +0100 Subject: Truncated user list in award emoji tooltips * Only the first 10 names are displayed * Further users are indicated by "and X more." * String "and X more" is appended to the array THEN join is called * An oxford comma seperates the last name from "and X more" * In coffeescript "me" is now always prepended * Tests included --- app/assets/javascripts/awards_handler.js | 2 +- app/helpers/issues_helper.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index 2c5b83e4f1e..c753972d171 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -223,7 +223,7 @@ if (origTitle) { users = origTitle.trim().split(', '); } - users.push('me'); + users.unshift('me'); awardBlock.attr('title', users.join(', ')); return this.resetTooltip(awardBlock); }; diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 2e82b44437b..15f08fd5918 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -114,9 +114,13 @@ module IssuesHelper end def award_user_list(awards, current_user) - awards.map do |award| + names = awards.first(10).map do |award| award.user == current_user ? 'me' : award.user.name - end.join(', ') + end + + names << "and #{awards.size - names.size} more." if awards.size > names.size + + names.join(', ') end def award_active_class(awards, current_user) -- cgit v1.2.1 From 4fbbb8e76550fcb8103cc1bf5c8536cf598db829 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Tue, 21 Jun 2016 23:22:03 +0100 Subject: Truncates 9-10 users with current user in front * If the current user is not in the list output will have 1-9 users * If the current user is in the list output will be "me, " + 0-9 users --- app/helpers/issues_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 15f08fd5918..e8081d452c4 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -114,10 +114,14 @@ module IssuesHelper end def award_user_list(awards, current_user) - names = awards.first(10).map do |award| + names = awards.map do |award| award.user == current_user ? 'me' : award.user.name end + # Take first 9 OR current user + first 9 + current_user_name = names.delete('me') + names = names.first(9).insert(0, current_user_name).compact + names << "and #{awards.size - names.size} more." if awards.size > names.size names.join(', ') -- cgit v1.2.1 From 1fc17a8a43a87af89358953364872d565d38b8e8 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Thu, 23 Jun 2016 20:02:11 +0100 Subject: Switch to using to_sentence to construct tooltips * Code in ruby now uses Array#to_sentence to construct award tooltips * Coffeescript uses a combination of regexes for the same result --- app/assets/javascripts/awards_handler.js | 19 ++++++++++++++----- app/helpers/issues_helper.rb | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index c753972d171..b06bad78305 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -1,5 +1,6 @@ (function() { this.AwardsHandler = (function() { + const FROM_SENTENCE_REGEX = /(?:, and | and |, )/; //For separating lists produced by ruby's Array#toSentence function AwardsHandler() { this.aliases = gl.emojiAliases(); $(document).off('click', '.js-add-award').on('click', '.js-add-award', (function(_this) { @@ -204,14 +205,22 @@ return $awardBlock.attr('data-original-title') || $awardBlock.attr('data-title') || ''; }; + AwardsHandler.prototype.toSentence = function(list) { + if(list.length <= 2){ + return list.join(' and '); + } + else{ + return list.slice(0, -1).join(', ') + ', and ' + list[list.length - 1]; + } + }; + AwardsHandler.prototype.removeMeFromUserList = function($emojiButton, emoji) { var authors, awardBlock, newAuthors, originalTitle; awardBlock = $emojiButton; originalTitle = this.getAwardTooltip(awardBlock); - authors = originalTitle.split(', '); + authors = originalTitle.split(FROM_SENTENCE_REGEX); authors.splice(authors.indexOf('me'), 1); - newAuthors = authors.join(', '); - awardBlock.closest('.js-emoji-btn').removeData('original-title').attr('data-original-title', newAuthors); + awardBlock.closest('.js-emoji-btn').removeData('original-title').attr('data-original-title', this.toSentence(authors)); return this.resetTooltip(awardBlock); }; @@ -221,10 +230,10 @@ origTitle = this.getAwardTooltip(awardBlock); users = []; if (origTitle) { - users = origTitle.trim().split(', '); + users = origTitle.trim().split(FROM_SENTENCE_REGEX); } users.unshift('me'); - awardBlock.attr('title', users.join(', ')); + awardBlock.attr('title', this.toSentence(users)); return this.resetTooltip(awardBlock); }; diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e8081d452c4..e5be8d2404a 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -122,9 +122,9 @@ module IssuesHelper current_user_name = names.delete('me') names = names.first(9).insert(0, current_user_name).compact - names << "and #{awards.size - names.size} more." if awards.size > names.size + names << "#{awards.size - names.size} more." if awards.size > names.size - names.join(', ') + names.to_sentence end def award_active_class(awards, current_user) -- cgit v1.2.1 From 6c1ed00afc98562e2c605aa3df313d26b3486da3 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Mon, 11 Jul 2016 19:53:07 +0100 Subject: Award tooltips refer to current user as "You" --- app/assets/javascripts/awards_handler.js | 16 ++++++++-------- app/helpers/issues_helper.rb | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index b06bad78305..adbe9786f4f 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -131,7 +131,7 @@ counter = $emojiButton.find('.js-counter'); counter.text(parseInt(counter.text()) + 1); $emojiButton.addClass('active'); - this.addMeToUserList(votesBlock, emoji); + this.addYouToUserList(votesBlock, emoji); return this.animateEmoji($emojiButton); } } else { @@ -177,11 +177,11 @@ counterNumber = parseInt(counter.text(), 10); if (counterNumber > 1) { counter.text(counterNumber - 1); - this.removeMeFromUserList($emojiButton, emoji); + this.removeYouFromUserList($emojiButton, emoji); } else if (emoji === 'thumbsup' || emoji === 'thumbsdown') { $emojiButton.tooltip('destroy'); counter.text('0'); - this.removeMeFromUserList($emojiButton, emoji); + this.removeYouFromUserList($emojiButton, emoji); if ($emojiButton.parents('.note').length) { this.removeEmoji($emojiButton); } @@ -214,17 +214,17 @@ } }; - AwardsHandler.prototype.removeMeFromUserList = function($emojiButton, emoji) { + AwardsHandler.prototype.removeYouFromUserList = function($emojiButton, emoji) { var authors, awardBlock, newAuthors, originalTitle; awardBlock = $emojiButton; originalTitle = this.getAwardTooltip(awardBlock); authors = originalTitle.split(FROM_SENTENCE_REGEX); - authors.splice(authors.indexOf('me'), 1); + authors.splice(authors.indexOf('You'), 1); awardBlock.closest('.js-emoji-btn').removeData('original-title').attr('data-original-title', this.toSentence(authors)); return this.resetTooltip(awardBlock); }; - AwardsHandler.prototype.addMeToUserList = function(votesBlock, emoji) { + AwardsHandler.prototype.addYouToUserList = function(votesBlock, emoji) { var awardBlock, origTitle, users; awardBlock = this.findEmojiIcon(votesBlock, emoji).parent(); origTitle = this.getAwardTooltip(awardBlock); @@ -232,7 +232,7 @@ if (origTitle) { users = origTitle.trim().split(FROM_SENTENCE_REGEX); } - users.unshift('me'); + users.unshift('You'); awardBlock.attr('title', this.toSentence(users)); return this.resetTooltip(awardBlock); }; @@ -249,7 +249,7 @@ AwardsHandler.prototype.createEmoji_ = function(votesBlock, emoji) { var $emojiButton, buttonHtml, emojiCssClass; emojiCssClass = this.resolveNameToCssClass(emoji); - buttonHtml = ""; + buttonHtml = ""; $emojiButton = $(buttonHtml); $emojiButton.insertBefore(votesBlock.find('.js-award-holder')).find('.emoji-icon').data('emoji', emoji); this.animateEmoji($emojiButton); diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e5be8d2404a..8b212b0327a 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -115,11 +115,11 @@ module IssuesHelper def award_user_list(awards, current_user) names = awards.map do |award| - award.user == current_user ? 'me' : award.user.name + award.user == current_user ? 'You' : award.user.name end # Take first 9 OR current user + first 9 - current_user_name = names.delete('me') + current_user_name = names.delete('You') names = names.first(9).insert(0, current_user_name).compact names << "#{awards.size - names.size} more." if awards.size > names.size -- cgit v1.2.1 From 9250953af7b3c781101fb982969ba4522fb87b30 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Tue, 12 Jul 2016 17:12:48 +0100 Subject: Fix duplicate "me" in award emoji tooltip * Works by explicitly deleting out-of-date data attributes * No longer directly assigns to data-original-title --- app/assets/javascripts/awards_handler.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index adbe9786f4f..6cde99127b5 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -220,7 +220,12 @@ originalTitle = this.getAwardTooltip(awardBlock); authors = originalTitle.split(FROM_SENTENCE_REGEX); authors.splice(authors.indexOf('You'), 1); - awardBlock.closest('.js-emoji-btn').removeData('original-title').attr('data-original-title', this.toSentence(authors)); + awardBlock + .closest('.js-emoji-btn') + .removeData('title') + .removeAttr('data-title') + .removeAttr('data-original-title') + .attr('title', this.toSentence(authors)); return this.resetTooltip(awardBlock); }; -- cgit v1.2.1 From d548f3ee27fd12b4bafd36b0d6f2b9890ac383b4 Mon Sep 17 00:00:00 2001 From: Jack Davison Date: Mon, 18 Jul 2016 21:10:28 +0100 Subject: Replace resetTooltip with bootstrap's fixTitle * resetTooltip totally destroyed and regenerated the tooltip while fixTitle simply replaces the text in the existing element. * resetTooltip also called an asyncronous function with no suitable callback resulting in a messy setTimout workaround. fixTitle is syncronous. --- app/assets/javascripts/awards_handler.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index 6cde99127b5..aee1c29eee3 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -220,13 +220,13 @@ originalTitle = this.getAwardTooltip(awardBlock); authors = originalTitle.split(FROM_SENTENCE_REGEX); authors.splice(authors.indexOf('You'), 1); - awardBlock + return awardBlock .closest('.js-emoji-btn') .removeData('title') .removeAttr('data-title') .removeAttr('data-original-title') - .attr('title', this.toSentence(authors)); - return this.resetTooltip(awardBlock); + .attr('title', this.toSentence(authors)) + .tooltip('fixTitle'); }; AwardsHandler.prototype.addYouToUserList = function(votesBlock, emoji) { @@ -238,17 +238,9 @@ users = origTitle.trim().split(FROM_SENTENCE_REGEX); } users.unshift('You'); - awardBlock.attr('title', this.toSentence(users)); - return this.resetTooltip(awardBlock); - }; - - AwardsHandler.prototype.resetTooltip = function(award) { - var cb; - award.tooltip('destroy'); - cb = function() { - return award.tooltip(); - }; - return setTimeout(cb, 200); + return awardBlock + .attr('title', this.toSentence(users)) + .tooltip('fixTitle'); }; AwardsHandler.prototype.createEmoji_ = function(votesBlock, emoji) { -- cgit v1.2.1