You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2018/12/12 16:32:24 UTC

[3/5] allura git commit: [#8263] Identify current selected emoji of comment

[#8263] Identify current selected emoji of comment


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2d72026f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2d72026f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2d72026f

Branch: refs/heads/master
Commit: 2d72026f94b5e499479e103ace829b8ec5c6adf2
Parents: 4115536
Author: Shalitha Suranga <sh...@gmail.com>
Authored: Wed Nov 28 08:54:15 2018 +0530
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Dec 12 16:32:04 2018 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py                    |  4 ++++
 Allura/allura/lib/utils.py                          | 10 +++++++++-
 Allura/allura/lib/widgets/resources/js/reactions.js |  4 ++--
 Allura/allura/templates/widgets/post_widget.html    |  2 +-
 4 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2d72026f/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 974b682..6856245 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -619,6 +619,10 @@ class Globals(object):
         """Coverts emoji codes to unicode emojis"""
         return emoji.emojize(text, use_aliases=True)
 
+    def get_current_reaction(self, d):
+        """Return current selected reaction for given react_users dict"""
+        return utils.get_key_from_value(d, c.user.username)
+
 
 class Icon(object):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/2d72026f/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index feaf25a..dbc83c9 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -784,4 +784,12 @@ def get_reactions_json():
     j = OrderedDict()
     for em in get_reaction_emoji_list():
         j[em] =  pylons.app_globals.emojize(em)
-    return json.dumps(j)
\ No newline at end of file
+    return json.dumps(j)
+
+
+def get_key_from_value(d, val):
+    """ Get key from given value. return empty str if not exists """
+    for k, v in d.items():
+        if val in v:
+            return k
+    return ''
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/2d72026f/Allura/allura/lib/widgets/resources/js/reactions.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/reactions.js b/Allura/allura/lib/widgets/resources/js/reactions.js
index 50fb674..1f9d1c2 100644
--- a/Allura/allura/lib/widgets/resources/js/reactions.js
+++ b/Allura/allura/lib/widgets/resources/js/reactions.js
@@ -42,10 +42,10 @@ $('.reaction-button').each(function() {
     var btnId = $(this).attr('id');
     $(this).click(function(e) {
         e.preventDefault();
-
+        var currentemoji = $(this).data('currentreact');
         var emohtml = '';
         for(var emo in global_reactions) {
-            emohtml += '<span class=\'emoji_button\' data-emoji=\'' + emo + '\'>' + 
+            emohtml += '<span class=\'emoji_button' + (currentemoji == emo ? ' current' : '') +  '\' data-emoji=\'' + emo + '\'>' + 
             twemoji.parse(global_reactions[emo]) + '</span>';
         }
         var tooltiptext = '<div class="post-reactions-list">' + emohtml + '</div>';

http://git-wip-us.apache.org/repos/asf/allura/blob/2d72026f/Allura/allura/templates/widgets/post_widget.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/post_widget.html b/Allura/allura/templates/widgets/post_widget.html
index fc3f555..c65768e 100644
--- a/Allura/allura/templates/widgets/post_widget.html
+++ b/Allura/allura/templates/widgets/post_widget.html
@@ -56,7 +56,7 @@
 
             <div class="tools">
             {% if not c.user.is_anonymous() %}
-                <a href="#" id="react_{{value.slug.replace('/','_')}}" data-commentlink="{{value.url()}}" class="reaction-button icon btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"{%if value.status == 'pending'%} style="display:none"{%endif%}>
+                <a href="#" id="react_{{value.slug.replace('/','_')}}" data-commentlink="{{value.url()}}" data-currentreact="{{ g.get_current_reaction(value.react_users) }}" class="reaction-button icon btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"{%if value.status == 'pending'%} style="display:none"{%endif%}>
                     <span><i class="fa fa-smile-o" aria-hidden="true"></i></span></a>
             {% endif %}
             {% if (h.has_access(value.thread, 'post')() and value.status == 'ok') or moderator %}