Commit 5bf3a898edbbd0fc4f7a4557f6ffaea8ffabfbc7

Authored by Dmitriy Zaporozhets
1 parent 1752c6dc

Remove wall from basic notes logic

app/assets/javascripts/notes.js
... ... @@ -4,31 +4,16 @@ var NoteList = {
4 4 target_params: null,
5 5 target_id: 0,
6 6 target_type: null,
7   - top_id: 0,
8   - bottom_id: 0,
9 7 loading_more_disabled: false,
10   - reversed: false,
11 8  
12 9 init: function(tid, tt, path) {
13 10 NoteList.notes_path = path + ".js";
14 11 NoteList.target_id = tid;
15 12 NoteList.target_type = tt;
16   - NoteList.reversed = $("#notes-list").is(".reversed");
17 13 NoteList.target_params = "target_type=" + NoteList.target_type + "&target_id=" + NoteList.target_id;
18 14  
19 15 NoteList.setupMainTargetNoteForm();
20 16  
21   - if(NoteList.reversed) {
22   - var form = $(".js-main-target-form");
23   - form.find(".note-form-actions").hide();
24   - var textarea = form.find(".js-note-text");
25   - textarea.css("height", "40px");
26   - textarea.on("focus", function(){
27   - textarea.css("height", "80px");
28   - form.find(".note-form-actions").show();
29   - });
30   - }
31   -
32 17 // get initial set of notes
33 18 NoteList.getContent();
34 19  
... ... @@ -344,128 +329,11 @@ var NoteList = {
344 329 * Replaces the content of #notes-list with the given html.
345 330 */
346 331 setContent: function(newNoteIds, html) {
347   - NoteList.top_id = newNoteIds.first();
348   - NoteList.bottom_id = newNoteIds.last();
349 332 $("#notes-list").html(html);
350   -
351   - // for the wall
352   - if (NoteList.reversed) {
353   - // init infinite scrolling
354   - NoteList.initLoadMore();
355   -
356   - // init getting new notes
357   - NoteList.initRefreshNew();
358   - }
359 333 },
360 334  
361 335  
362 336 /**
363   - * Handle loading more notes when scrolling to the bottom of the page.
364   - * The id of the last note in the list is in NoteList.bottom_id.
365   - *
366   - * Set up refreshing only new notes after all notes have been loaded.
367   - */
368   -
369   -
370   - /**
371   - * Initializes loading more notes when scrolling to the bottom of the page.
372   - */
373   - initLoadMore: function() {
374   - $(document).endlessScroll({
375   - bottomPixels: 400,
376   - fireDelay: 1000,
377   - fireOnce:true,
378   - ceaseFire: function() {
379   - return NoteList.loading_more_disabled;
380   - },
381   - callback: function(i) {
382   - NoteList.getMore();
383   - }
384   - });
385   - },
386   -
387   - /**
388   - * Gets an additional set of notes.
389   - */
390   - getMore: function() {
391   - // only load more notes if there are no "new" notes
392   - $('.loading').show();
393   - $.ajax({
394   - url: NoteList.notes_path,
395   - data: NoteList.target_params + "&loading_more=1&" + (NoteList.reversed ? "before_id" : "after_id") + "=" + NoteList.bottom_id,
396   - complete: function(){ $('.js-notes-busy').removeClass("loading")},
397   - beforeSend: function() { $('.js-notes-busy').addClass("loading") },
398   - dataType: "script"
399   - });
400   - },
401   -
402   - /**
403   - * Called in response to getMore().
404   - * Append notes to #notes-list.
405   - */
406   - appendMoreNotes: function(newNoteIds, html) {
407   - var lastNewNoteId = newNoteIds.last();
408   - if(lastNewNoteId != NoteList.bottom_id) {
409   - NoteList.bottom_id = lastNewNoteId;
410   - $("#notes-list").append(html);
411   - }
412   - },
413   -
414   - /**
415   - * Called in response to getMore().
416   - * Disables loading more notes when scrolling to the bottom of the page.
417   - */
418   - finishedLoadingMore: function() {
419   - NoteList.loading_more_disabled = true;
420   -
421   - // make sure we are up to date
422   - NoteList.updateVotes();
423   - },
424   -
425   -
426   - /**
427   - * Handle refreshing and adding of new notes.
428   - *
429   - * New notes are all notes that are created after the site has been loaded.
430   - * The "old" notes are in #notes-list the "new" ones will be in #new-notes-list.
431   - * The id of the last "old" note is in NoteList.bottom_id.
432   - */
433   -
434   -
435   - /**
436   - * Initializes getting new notes every n seconds.
437   - *
438   - * Note: only used on wall.
439   - */
440   - initRefreshNew: function() {
441   - setInterval("NoteList.getNew()", 10000);
442   - },
443   -
444   - /**
445   - * Gets the new set of notes.
446   - *
447   - * Note: only used on wall.
448   - */
449   - getNew: function() {
450   - $.ajax({
451   - url: NoteList.notes_path,
452   - data: NoteList.target_params + "&loading_new=1&after_id=" + (NoteList.reversed ? NoteList.top_id : NoteList.bottom_id),
453   - dataType: "script"
454   - });
455   - },
456   -
457   - /**
458   - * Called in response to getNew().
459   - * Replaces the content of #new-notes-list with the given html.
460   - *
461   - * Note: only used on wall.
462   - */
463   - replaceNewNotes: function(newNoteIds, html) {
464   - $("#new-notes-list").html(html);
465   - NoteList.updateVotes();
466   - },
467   -
468   - /**
469 337 * Adds a single common note to #notes-list.
470 338 */
471 339 appendNewNote: function(id, html) {
... ... @@ -498,15 +366,6 @@ var NoteList = {
498 366 },
499 367  
500 368 /**
501   - * Adds a single wall note to #new-notes-list.
502   - *
503   - * Note: only used on wall.
504   - */
505   - appendNewWallNote: function(id, html) {
506   - $("#new-notes-list").prepend(html);
507   - },
508   -
509   - /**
510 369 * Called in response the main target form has been successfully submitted.
511 370 *
512 371 * Removes any errors.
... ...
app/contexts/notes/load_context.rb
... ... @@ -3,8 +3,6 @@ module Notes
3 3 def execute
4 4 target_type = params[:target_type]
5 5 target_id = params[:target_id]
6   - after_id = params[:after_id]
7   - before_id = params[:before_id]
8 6  
9 7  
10 8 @notes = case target_type
... ... @@ -16,17 +14,6 @@ module Notes
16 14 project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh
17 15 when "snippet"
18 16 project.snippets.find(target_id).notes.fresh
19   - when "wall"
20   - # this is the only case, where the order is DESC
21   - project.notes.common.inc_author_project.order("created_at DESC, id DESC").limit(50)
22   - end
23   -
24   - @notes = if after_id
25   - @notes.where("id > ?", after_id)
26   - elsif before_id
27   - @notes.where("id < ?", before_id)
28   - else
29   - @notes
30 17 end
31 18 end
32 19 end
... ...
app/views/notes/_reversed_notes_with_form.html.haml
... ... @@ -1,12 +0,0 @@
1   -.js-main-target-form
2   -- if can? current_user, :write_note, @project
3   - = render "notes/form"
4   -
5   -%ul#new-notes-list.reversed.notes
6   -%ul#notes-list.reversed.notes
7   -.notes-busy.js-notes-busy
8   -
9   -:javascript
10   - $(function(){
11   - NoteList.init("#{@target_id}", "#{@target_type}", "#{project_notes_path(@project)}");
12   - });
app/views/notes/create.js.haml
... ... @@ -2,10 +2,7 @@
2 2 var noteHtml = "#{escape_javascript(render "notes/note", note: @note)}";
3 3  
4 4 - if note_for_main_target?(@note)
5   - - if @note.for_wall?
6   - NoteList.appendNewWallNote(#{@note.id}, noteHtml);
7   - - else
8   - NoteList.appendNewNote(#{@note.id}, noteHtml);
  5 + NoteList.appendNewNote(#{@note.id}, noteHtml);
9 6 - else
10 7 :plain
11 8 var firstDiscussionNoteHtml = "#{escape_javascript(render "notes/diff_notes_with_reply", notes: [@note])}";
... ... @@ -18,4 +15,4 @@
18 15 - if note_for_main_target?(@note)
19 16 NoteList.errorsOnForm(errorsHtml);
20 17 - else
21   - NoteList.errorsOnForm(errorsHtml, "#{@note.discussion_id}");
22 18 \ No newline at end of file
  19 + NoteList.errorsOnForm(errorsHtml, "#{@note.discussion_id}");
... ...
app/views/notes/index.js.haml
1 1 - unless @notes.blank?
2 2 var notesHtml = "#{escape_javascript(render 'notes/notes')}";
3 3 - new_note_ids = @notes.map(&:id)
4   - - if loading_more_notes?
5   - NoteList.appendMoreNotes(#{new_note_ids}, notesHtml);
6   -
7   - - elsif loading_new_notes?
8   - NoteList.replaceNewNotes(#{new_note_ids}, notesHtml);
9   -
10   - - else
11   - NoteList.setContent(#{new_note_ids}, notesHtml);
12   -
13   -- else
14   - - if loading_more_notes?
15   - NoteList.finishedLoadingMore();
  4 + NoteList.setContent(#{new_note_ids}, notesHtml);
... ...