Anonymous avatar Anonymous committed 531ef45

add notification message when a new review is posted. Make sure notification is not displayed to the author who obviously know he has made a review.

Comments (0)

Files changed (5)

static/css/src/colors.css

     color: #899834;
 }
 
+#notify-snippet {
+    color: #303030;
+    background: #f8f8f8;
+    border-color: #899834;
+}
+

static/css/src/layout.css

 }
 
 section.hidden,
+div.hidden,
 .hidden {
     display: none;
 }
     padding-left: 18px;
     color: #303030;
 }
+#notify-snippet {
+    display: block;
+    float: left;
+    z-index: 2;
+    padding: 0.3em;
+    border: 1px solid;
+    margin-top: -2px;
+}
+
+
+#notify-snippet.hidden {
+    display: none;
+}

static/css/src/typography.css

 span.reviewflag.new {
     font-weight: bold;
 }
+
+#notify-snippet {
+    font-weight: bold;
+    font-size: 0.8em;
+}

static/js/src/review.js

         var self = this;
 
         this._reviews = {};
+        this.latest_add = null;
 
         // init comments-flags
         document.querySelectorAll('.review-flag').forEach(function(el) {
         stomp.connect('localhost', 61613);
     },
 
+    _notify: function(txt) {
+        var notification_zone = document.querySelector('#notify-snippet');
+        notification_zone.innerHTML = txt;
+        if (notification_zone.classList.has('hidden'))
+            notification_zone.classList.remove('hidden');
+        setTimeout(function() {
+            notification_zone.classList.add('hidden');
+        }, 10000);
+    },
+
     handle_messages: function(frame) {
-        message = base2.JSON.parse(frame.body);
+
+        
+
+        var message = base2.JSON.parse(frame.body);
+        var me = false;
         if (message.type == 'review') {
+            if (this.latest_add && this.latest_add.nb_line == message.nb_line &&
+                    this.latest_add.reviews_count == message.reviews_count)
+                me = true;
+
             var row = this._reviews[message.nb_line] || null;
             if (!row) {
                 var row = this._numRow(message.nb_line);
                 this._reviews[message.nb_line] = row;
             }
             var td = row.querySelector('td');
-            var reviewflag = td.querySelector('span.reviewflag')
+            var reviewflag = td.querySelector('span.reviewflag');
+            var notify = false;
             if (!reviewflag) {
                 var span = document.createElement('span');
                 span.classList.add('reviewflag');
-                span.classList.add('new');
+                if (!me)
+                    span.classList.add('new');
                 span.appendChild(document.createTextNode(message.reviews_count));
                 td.appendChild(span);
+                notify = true;
             } else {
                 line_count = parseInt(reviewflag.innerHTML);
                 if (line_count < message.reviews_count) {
                     reviewflag.innerHTML = message.reviews_count;
-                    if (!reviewflag.classList.has('new'))
+                    if (!reviewflag.classList.has('new') && !me)
                         reviewflag.classList.add('new');
+                    notify = true;
                 }
             }
+
+            // display notification message
+            if (notify && !me) {
+                var txt = 'a new review has been added to line <a href="#'+
+                    message.nb_line+'">#'+message.nb_line+'</a>.';
+                this._notify(txt);
+            }
         }
 
 
         var textarea = this.divComment.querySelector("textarea");
         var new_review_txt = textarea.value;
         if (new_review_txt) {
-            var reviews_list =self.divComment.querySelector("#reviews-list");
+            var lineNumber = this._lineNumberForRow(this.currentRow);
+            var reviews_list = this.divComment.querySelector("#reviews-list");
             var ul = reviews_list.querySelector('ul');
-            nb_lines = 0;
+            var nb_lines = 0;
             if (ul) 
                 nb_lines = ul.querySelectorAll('li').length;
+            
+            // record latest add
+            this.latest_add = { 
+                nb_line: lineNumber, 
+                reviews_count: nb_lines + 1 
+            }; 
 
             new Ajax.request({
                 url: url,
                 success: function(data) {
                     if (data["ok"]) {
                         
+                         
+                        
                         // refresh reviews list
                         if (!ul) { 
                             ul = document.createElement('ul');
                             }
                         }
                         // update number of reviews in review flag
-                        var lineNumber = self._lineNumberForRow(self.currentRow);
-                        self._reviews[lineNumber] = self.currentRow;
+                        /*self._reviews[lineNumber] = self.currentRow;
                         var span_count = self.currentRow.querySelector('span.reviewflag');
                         line_count = parseInt(span_count.innerHTML);
                         if (line_count < data['count'])
                             span_count.innerHTML = data['count'];
                         
                         if (!self.currentRow.classList.has('hasreview'))
-                            self.currentRow.classList.add('hasreview');
+                            self.currentRow.classList.add('hasreview');*/
 
                         // reset textarea
                         textarea.value = '';
                         textarea.focus();
                         localizeDates();
+                    } else {
+                        self.latest_add = null;
                     }
                 }
                     

templates/paste/view.html

 
             </div>
             <div id="actions">
-                <div id="notify-snippet"></div>
+                <div id="notify-snippet" class="hidden"></div>
                 <form id="factions" action="{{ url_for('settings') }}" method="post">
                     <ul>
                         <li class="first">
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.