Commit e622259d authored by Valery Sizov's avatar Valery Sizov

Merge branch 'emoji-picker-fix' into 'master'

Emoji picker: better alias handling

related to https://gitlab.com/gitlab-org/gitlab-ce/issues/3576

See merge request !2198
parents 75c3a2f8 09c5968f
......@@ -76,7 +76,7 @@ class @AwardsHandler
nodes = []
nodes.push("<div class='award active' title='me'>")
nodes.push("<div class='icon emoji-icon " + emojiCssClass + "' data-emoji='" + emoji + "'></div>")
nodes.push("<div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div>")
nodes.push("<div class='counter'>1</div>")
nodes.push("</div>")
......@@ -85,13 +85,19 @@ class @AwardsHandler
$(".award").tooltip()
resolveNameToCssClass: (emoji) ->
unicodeName = $(".emoji-menu-content [data-emoji='?']".replace("?", emoji)).data("unicode-name")
emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']")
"emoji-" + unicodeName
if emoji_icon.length > 0
unicodeName = emoji_icon.data("unicode-name")
else
# Find by alias
unicodeName = $(".emoji-menu-content [data-aliases*=':#{emoji}:']").data("unicode-name")
"emoji-#{unicodeName}"
postEmoji: (emoji, callback) ->
$.post @post_emoji_url, { note: {
note: ":" + emoji + ":"
note: ":#{emoji}:"
noteable_type: @noteable_type
noteable_id: @noteable_id
}},(data) ->
......@@ -99,7 +105,7 @@ class @AwardsHandler
callback.call()
findEmojiIcon: (emoji) ->
$(".award [data-emoji='" + emoji + "']")
$(".award [data-emoji='#{emoji}']")
scrollToAwards: ->
$('body, html').animate({
......
......@@ -94,12 +94,13 @@ module IssuesHelper
end.sort.to_sentence(last_word_connector: ', or ')
end
def emoji_icon(name, unicode = nil)
def emoji_icon(name, unicode = nil, aliases = [])
unicode ||= Emoji.emoji_filename(name)
content_tag :div, "",
class: "icon emoji-icon emoji-#{unicode}",
"data-emoji" => name,
"data-aliases" => aliases.join(" "),
"data-unicode-name" => unicode
end
......
......@@ -16,14 +16,14 @@
%ul
- emojis.each do |emoji|
%li
= emoji_icon(emoji["name"], emoji["unicode"])
= emoji_icon(emoji["name"], emoji["unicode"], emoji["aliases"])
- if current_user
:coffeescript
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class.name.underscore}"
noteable_id = "#{votable.id}"
aliases = #{AwardEmoji::ALIASES.to_json}
aliases = #{AwardEmoji.aliases.to_json}
window.awards_handler = new AwardsHandler(
post_emoji_url,
......
# Migration type: online without errors (works on previous version and new one)
class RenameEmojis < ActiveRecord::Migration
def up
# Renames aliases to main names
execute("UPDATE notes SET note ='thumbsup' WHERE is_award = true AND note = '+1'")
execute("UPDATE notes SET note ='thumbsdown' WHERE is_award = true AND note = '-1'")
execute("UPDATE notes SET note ='poop' WHERE is_award = true AND note = 'shit'")
end
def down
execute("UPDATE notes SET note ='+1' WHERE is_award = true AND note = 'thumbsup'")
execute("UPDATE notes SET note ='-1' WHERE is_award = true AND note = 'thumbsdown'")
execute("UPDATE notes SET note ='shit' WHERE is_award = true AND note = 'poop'")
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151210125932) do
ActiveRecord::Schema.define(version: 20151224123230) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
This diff is collapsed.
This diff is collapsed.
class AwardEmoji
ALIASES = {
pout: "rage",
satisfied: "laughing",
hankey: "shit",
poop: "shit",
collision: "boom",
thumbsup: "+1",
thumbsdown: "-1",
punch: "facepunch",
raised_hand: "hand",
running: "runner",
ng_woman: "no_good",
shoe: "mans_shoe",
tshirt: "shirt",
honeybee: "bee",
flipper: "dolphin",
paw_prints: "feet",
waxing_gibbous_moon: "moon",
telephone: "phone",
knife: "hocho",
envelope: "email",
pencil: "memo",
open_book: "book",
sailboat: "boat",
red_car: "car",
lantern: "izakaya_lantern",
uk: "gb",
heavy_exclamation_mark: "exclamation",
squirrel: "shipit"
}.with_indifferent_access
CATEGORIES = {
other: "Other",
objects: "Objects",
......@@ -46,17 +15,15 @@ class AwardEmoji
}.with_indifferent_access
def self.normilize_emoji_name(name)
ALIASES[name] || name
aliases[name] || name
end
def self.emoji_by_category
unless @emoji_by_category
@emoji_by_category = {}
emojis_added = []
Emoji.emojis.each do |emoji_name, data|
next if emojis_added.include?(data["name"])
emojis_added << data["name"]
emojis.each do |emoji_name, data|
data["name"] = emoji_name
@emoji_by_category[data["category"]] ||= []
@emoji_by_category[data["category"]] << data
......@@ -67,4 +34,18 @@ class AwardEmoji
@emoji_by_category
end
def self.emojis
@emojis ||= begin
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'index.json' )
JSON.parse(File.read(json_path))
end
end
def self.aliases
@aliases ||= begin
json_path = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json' )
JSON.parse(File.read(json_path))
end
end
end
......@@ -164,8 +164,8 @@ describe Note, models: true do
let(:issue) { create :issue }
it "converts aliases to actual name" do
note = create :note, note: ":thumbsup:", noteable: issue
expect(note.reload.note).to eq("+1")
note = create :note, note: ":+1:", noteable: issue
expect(note.reload.note).to eq("thumbsup")
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