Commit c4a7824a8c6487b24379f7f85c26f182bbc1dee9

Authored by Riyad Preukschas
1 parent 140652e9

Fix wall notes

app/assets/javascripts/notes.js
... ... @@ -267,6 +267,7 @@ var NoteList = {
267 267 NoteList.bottom_id = newNoteIds.last();
268 268 $("#notes-list").html(html);
269 269  
  270 + // for the wall
270 271 if (NoteList.reversed) {
271 272 // init infinite scrolling
272 273 NoteList.initLoadMore();
... ... @@ -352,6 +353,8 @@ var NoteList = {
352 353  
353 354 /**
354 355 * Initializes getting new notes every n seconds.
  356 + *
  357 + * Note: only used on wall.
355 358 */
356 359 initRefreshNew: function() {
357 360 setInterval("NoteList.getNew()", 10000);
... ... @@ -359,6 +362,8 @@ var NoteList = {
359 362  
360 363 /**
361 364 * Gets the new set of notes.
  365 + *
  366 + * Note: only used on wall.
362 367 */
363 368 getNew: function() {
364 369 $.ajax({
... ... @@ -371,6 +376,8 @@ var NoteList = {
371 376 /**
372 377 * Called in response to getNew().
373 378 * Replaces the content of #new-notes-list with the given html.
  379 + *
  380 + * Note: only used on wall.
374 381 */
375 382 replaceNewNotes: function(newNoteIds, html) {
376 383 $("#new-notes-list").html(html);
... ... @@ -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 390 appendNewNote: function(id, html) {
384 391 $("#notes-list").append(html);
... ... @@ -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 398 appendNewDiscussionNote: function(discussionId, diffRowHtml, noteHtml) {
392 399 // is this the first note of discussion?
... ... @@ -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 422 * Recalculates the votes and updates them (if they are displayed at all).
407 423 *
408 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 71  
72 72 # Helps to distinguish e.g. commit notes in mr notes list
73 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 76 end
76 77 end
... ...
app/helpers/notes_helper.rb
1 1 module NotesHelper
2 2 # Helps to distinguish e.g. commit notes in mr notes list
3 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 6 end
6 7  
7 8 def note_target_fields
... ...
app/models/note.rb
... ... @@ -115,6 +115,10 @@ class Note < ActiveRecord::Base
115 115 for_merge_request? && for_diff_line?
116 116 end
117 117  
  118 + def for_wall?
  119 + noteable_type.blank?
  120 + end
  121 +
118 122 # override to return commits, which are not active record
119 123 def noteable
120 124 if for_commit?
... ...
app/views/notes/_create_common_note.js.haml
1 1 - if note.valid?
  2 + - if note.for_wall?
  3 + NoteList.appendNewWallNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}");
  4 + - else
2 5 NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}");
3 6  
4 7 - else
... ...