Commit c4a7824a8c6487b24379f7f85c26f182bbc1dee9

Authored by Riyad Preukschas
1 parent 140652e9

Fix wall notes

app/assets/javascripts/notes.js
@@ -267,6 +267,7 @@ var NoteList = { @@ -267,6 +267,7 @@ var NoteList = {
267 NoteList.bottom_id = newNoteIds.last(); 267 NoteList.bottom_id = newNoteIds.last();
268 $("#notes-list").html(html); 268 $("#notes-list").html(html);
269 269
  270 + // for the wall
270 if (NoteList.reversed) { 271 if (NoteList.reversed) {
271 // init infinite scrolling 272 // init infinite scrolling
272 NoteList.initLoadMore(); 273 NoteList.initLoadMore();
@@ -352,6 +353,8 @@ var NoteList = { @@ -352,6 +353,8 @@ var NoteList = {
352 353
353 /** 354 /**
354 * Initializes getting new notes every n seconds. 355 * Initializes getting new notes every n seconds.
  356 + *
  357 + * Note: only used on wall.
355 */ 358 */
356 initRefreshNew: function() { 359 initRefreshNew: function() {
357 setInterval("NoteList.getNew()", 10000); 360 setInterval("NoteList.getNew()", 10000);
@@ -359,6 +362,8 @@ var NoteList = { @@ -359,6 +362,8 @@ var NoteList = {
359 362
360 /** 363 /**
361 * Gets the new set of notes. 364 * Gets the new set of notes.
  365 + *
  366 + * Note: only used on wall.
362 */ 367 */
363 getNew: function() { 368 getNew: function() {
364 $.ajax({ 369 $.ajax({
@@ -371,6 +376,8 @@ var NoteList = { @@ -371,6 +376,8 @@ var NoteList = {
371 /** 376 /**
372 * Called in response to getNew(). 377 * Called in response to getNew().
373 * Replaces the content of #new-notes-list with the given html. 378 * Replaces the content of #new-notes-list with the given html.
  379 + *
  380 + * Note: only used on wall.
374 */ 381 */
375 replaceNewNotes: function(newNoteIds, html) { 382 replaceNewNotes: function(newNoteIds, html) {
376 $("#new-notes-list").html(html); 383 $("#new-notes-list").html(html);
@@ -378,7 +385,7 @@ var NoteList = { @@ -378,7 +385,7 @@ var NoteList = {
378 }, 385 },
379 386
380 /** 387 /**
381 - * Adds a single common note to #(new-)notes-list. 388 + * Adds a single common note to #notes-list.
382 */ 389 */
383 appendNewNote: function(id, html) { 390 appendNewNote: function(id, html) {
384 $("#notes-list").append(html); 391 $("#notes-list").append(html);
@@ -386,7 +393,7 @@ var NoteList = { @@ -386,7 +393,7 @@ var NoteList = {
386 }, 393 },
387 394
388 /** 395 /**
389 - * Adds a single discussion note to #(new-)notes-list. 396 + * Adds a single discussion note to #notes-list.
390 */ 397 */
391 appendNewDiscussionNote: function(discussionId, diffRowHtml, noteHtml) { 398 appendNewDiscussionNote: function(discussionId, diffRowHtml, noteHtml) {
392 // is this the first note of discussion? 399 // is this the first note of discussion?
@@ -403,6 +410,15 @@ var NoteList = { @@ -403,6 +410,15 @@ var NoteList = {
403 }, 410 },
404 411
405 /** 412 /**
  413 + * Adds a single wall note to #new-notes-list.
  414 + *
  415 + * Note: only used on wall.
  416 + */
  417 + appendNewWallNote: function(id, html) {
  418 + $("#new-notes-list").prepend(html);
  419 + },
  420 +
  421 + /**
406 * Recalculates the votes and updates them (if they are displayed at all). 422 * Recalculates the votes and updates them (if they are displayed at all).
407 * 423 *
408 * Assumes all relevant notes are displayed (i.e. there are no more notes to 424 * Assumes all relevant notes are displayed (i.e. there are no more notes to
app/controllers/notes_controller.rb
@@ -71,6 +71,7 @@ class NotesController < ProjectResourceController @@ -71,6 +71,7 @@ class NotesController < ProjectResourceController
71 71
72 # Helps to distinguish e.g. commit notes in mr notes list 72 # Helps to distinguish e.g. commit notes in mr notes list
73 def note_for_main_target?(note) 73 def note_for_main_target?(note)
74 - @target_type.camelize == note.noteable_type && !note.for_diff_line? 74 + note.for_wall? ||
  75 + (@target_type.camelize == note.noteable_type && !note.for_diff_line?)
75 end 76 end
76 end 77 end
app/helpers/notes_helper.rb
1 module NotesHelper 1 module NotesHelper
2 # Helps to distinguish e.g. commit notes in mr notes list 2 # Helps to distinguish e.g. commit notes in mr notes list
3 def note_for_main_target?(note) 3 def note_for_main_target?(note)
4 - @target_type.camelize == note.noteable_type && !note.for_diff_line? 4 + note.for_wall? ||
  5 + (@target_type.camelize == note.noteable_type && !note.for_diff_line?)
5 end 6 end
6 7
7 def note_target_fields 8 def note_target_fields
app/models/note.rb
@@ -115,6 +115,10 @@ class Note < ActiveRecord::Base @@ -115,6 +115,10 @@ class Note < ActiveRecord::Base
115 for_merge_request? && for_diff_line? 115 for_merge_request? && for_diff_line?
116 end 116 end
117 117
  118 + def for_wall?
  119 + noteable_type.blank?
  120 + end
  121 +
118 # override to return commits, which are not active record 122 # override to return commits, which are not active record
119 def noteable 123 def noteable
120 if for_commit? 124 if for_commit?
app/views/notes/_create_common_note.js.haml
1 - if note.valid? 1 - if note.valid?
  2 + - if note.for_wall?
  3 + NoteList.appendNewWallNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}");
  4 + - else
2 NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}"); 5 NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}");
3 6
4 - else 7 - else