Commit b6de0d28 authored by Valery Sizov's avatar Valery Sizov

Emoji picker: better alias handling

parent 2803b6e8
...@@ -76,7 +76,7 @@ class @AwardsHandler ...@@ -76,7 +76,7 @@ class @AwardsHandler
nodes = [] nodes = []
nodes.push("<div class='award active' title='me'>") 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 class='counter'>1</div>")
nodes.push("</div>") nodes.push("</div>")
...@@ -85,13 +85,19 @@ class @AwardsHandler ...@@ -85,13 +85,19 @@ class @AwardsHandler
$(".award").tooltip() $(".award").tooltip()
resolveNameToCssClass: (emoji) -> 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) -> postEmoji: (emoji, callback) ->
$.post @post_emoji_url, { note: { $.post @post_emoji_url, { note: {
note: ":" + emoji + ":" note: ":#{emoji}:"
noteable_type: @noteable_type noteable_type: @noteable_type
noteable_id: @noteable_id noteable_id: @noteable_id
}},(data) -> }},(data) ->
...@@ -99,7 +105,7 @@ class @AwardsHandler ...@@ -99,7 +105,7 @@ class @AwardsHandler
callback.call() callback.call()
findEmojiIcon: (emoji) -> findEmojiIcon: (emoji) ->
$(".award [data-emoji='" + emoji + "']") $(".award [data-emoji='#{emoji}']")
scrollToAwards: -> scrollToAwards: ->
$('body, html').animate({ $('body, html').animate({
......
...@@ -94,12 +94,13 @@ module IssuesHelper ...@@ -94,12 +94,13 @@ module IssuesHelper
end.sort.to_sentence(last_word_connector: ', or ') end.sort.to_sentence(last_word_connector: ', or ')
end end
def emoji_icon(name, unicode = nil) def emoji_icon(name, unicode = nil, aliases = [])
unicode ||= Emoji.emoji_filename(name) unicode ||= Emoji.emoji_filename(name)
content_tag :div, "", content_tag :div, "",
class: "icon emoji-icon emoji-#{unicode}", class: "icon emoji-icon emoji-#{unicode}",
"data-emoji" => name, "data-emoji" => name,
"data-aliases" => aliases.join(" "),
"data-unicode-name" => unicode "data-unicode-name" => unicode
end end
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
%ul %ul
- emojis.each do |emoji| - emojis.each do |emoji|
%li %li
= emoji_icon(emoji["name"], emoji["unicode"]) = emoji_icon(emoji["name"], emoji["unicode"], emoji["aliases"])
- if current_user - if current_user
:coffeescript :coffeescript
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}" post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class.name.underscore}" noteable_type = "#{votable.class.name.underscore}"
noteable_id = "#{votable.id}" noteable_id = "#{votable.id}"
aliases = #{AwardEmoji::ALIASES.to_json} aliases = #{AwardEmoji.aliases.to_json}
window.awards_handler = new AwardsHandler( window.awards_handler = new AwardsHandler(
post_emoji_url, 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 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
......
This diff is collapsed.
This diff is collapsed.
class AwardEmoji 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 = { CATEGORIES = {
other: "Other", other: "Other",
objects: "Objects", objects: "Objects",
...@@ -46,17 +15,15 @@ class AwardEmoji ...@@ -46,17 +15,15 @@ class AwardEmoji
}.with_indifferent_access }.with_indifferent_access
def self.normilize_emoji_name(name) def self.normilize_emoji_name(name)
ALIASES[name] || name aliases[name] || name
end end
def self.emoji_by_category def self.emoji_by_category
unless @emoji_by_category unless @emoji_by_category
@emoji_by_category = {} @emoji_by_category = {}
emojis_added = []
Emoji.emojis.each do |emoji_name, data| emojis.each do |emoji_name, data|
next if emojis_added.include?(data["name"]) data["name"] = emoji_name
emojis_added << data["name"]
@emoji_by_category[data["category"]] ||= [] @emoji_by_category[data["category"]] ||= []
@emoji_by_category[data["category"]] << data @emoji_by_category[data["category"]] << data
...@@ -67,4 +34,18 @@ class AwardEmoji ...@@ -67,4 +34,18 @@ class AwardEmoji
@emoji_by_category @emoji_by_category
end 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 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