From 8b6dba749a80fbdf94f1495dda8cf3cdad61a28b Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 13 Sep 2012 02:12:44 +0200 Subject: [PATCH 01/22] Reorder notes view elements --- app/assets/javascripts/note.js | 8 ++++---- app/assets/stylesheets/sections/notes.scss | 6 +++++- app/views/notes/_notes.html.haml | 9 ++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index 79ab086b..47b0e0f5 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -106,8 +106,8 @@ var NoteList = { type: "GET", url: this.notes_path, data: "?" + this.target_params, - complete: function(){ $('.status').removeClass("loading")}, - beforeSend: function() { $('.status').addClass("loading") }, + complete: function(){ $('.notes-status').removeClass("loading")}, + beforeSend: function() { $('.notes-status').addClass("loading") }, dataType: "script"}); }, @@ -136,8 +136,8 @@ var NoteList = { type: "GET", url: this.notes_path, data: "first_id=" + this.first_id + this.target_params, - complete: function(){ $('.status').removeClass("loading")}, - beforeSend: function() { $('.status').addClass("loading") }, + complete: function(){ $('.notes-status').removeClass("loading")}, + beforeSend: function() { $('.notes-status').addClass("loading") }, dataType: "script"}); }, diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 6a965fa4..b2f61d9b 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -10,7 +10,7 @@ padding:0px; } -#new_notes_list li:last-child{ +#notes-list li:last-child { border-bottom:1px solid #aaa; } @@ -71,6 +71,10 @@ } } +.notes-status { + margin: 18px; +} + p.notify_controls input{ margin: 5px; diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes.html.haml index e692e746..e5b1ea72 100644 --- a/app/views/notes/_notes.html.haml +++ b/app/views/notes/_notes.html.haml @@ -1,10 +1,9 @@ +%ul#notes-list +%ul#new_notes_list +.notes-status + - if can? current_user, :write_note, @project = render "notes/form" -.clear -%hr -%ul#new_notes_list -%ul#notes-list -.status :javascript From 6ffec9a298dd90275ec6b17d1e11554bd31b9f2c Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 13 Sep 2012 15:43:16 +0200 Subject: [PATCH 02/22] Update Note to load notes in the right order --- app/contexts/notes/load_context.rb | 23 ++++++++++++----------- app/models/note.rb | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb index c89a7d19..c026fc50 100644 --- a/app/contexts/notes/load_context.rb +++ b/app/contexts/notes/load_context.rb @@ -8,24 +8,25 @@ module Notes @notes = case target_type - when "commit" - then project.commit_notes(project.commit(target_id)).fresh.limit(20) - when "snippet" - then project.snippets.find(target_id).notes - when "wall" - then project.common_notes.order("created_at DESC").fresh.limit(50) + when "commit" + project.commit_notes(project.commit(target_id)).fresh.limit(20) when "issue" - then project.issues.find(target_id).notes.inc_author.order("created_at DESC").limit(20) + project.issues.find(target_id).notes.inc_author.fresh.limit(20) when "merge_request" - then project.merge_requests.find(target_id).notes.inc_author.order("created_at DESC").limit(20) + project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20) + when "snippet" + project.snippets.find(target_id).notes.fresh + when "wall" + # this is the only case, where the order is DESC + project.common_notes.order("created_at DESC").limit(50) when "wiki" - then project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] + project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] end @notes = if last_id - @notes.where("id > ?", last_id) + @notes.where("id < ?", last_id) elsif first_id - @notes.where("id < ?", first_id) + @notes.where("id > ?", first_id) else @notes end diff --git a/app/models/note.rb b/app/models/note.rb index 4c46c7df..9aad8949 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -36,7 +36,7 @@ class Note < ActiveRecord::Base scope :today, where("created_at >= :date", date: Date.today) scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) scope :since, lambda { |day| where("created_at >= :date", date: (day)) } - scope :fresh, order("created_at DESC") + scope :fresh, order("created_at ASC") scope :inc_author_project, includes(:project, :author) scope :inc_author, includes(:author) From 14164017533388dc2a0d0f43e05ee84badbf2223 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Thu, 13 Sep 2012 19:55:57 +0200 Subject: [PATCH 03/22] Fix markup --- app/assets/stylesheets/sections/notes.scss | 2 +- app/views/notes/_notes.html.haml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index b2f61d9b..8db88930 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -3,7 +3,7 @@ * */ #notes-list, -#new_notes_list { +#new-notes-list { display:block; list-style:none; margin:0px; diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes.html.haml index e5b1ea72..14e1e84b 100644 --- a/app/views/notes/_notes.html.haml +++ b/app/views/notes/_notes.html.haml @@ -1,11 +1,10 @@ %ul#notes-list -%ul#new_notes_list +%ul#new-notes-list .notes-status - if can? current_user, :write_note, @project = render "notes/form" - :javascript $(function(){ NoteList.init("#{tid}", "#{tt}", "#{project_notes_path(@project)}"); From e802d00996d6948e29f085d4de9409423e0d91a4 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 16:52:24 +0200 Subject: [PATCH 04/22] Completely redo loading of notes with JS --- app/assets/javascripts/note.js | 199 ++++++++++++++----------- app/contexts/notes/load_context.rb | 9 +- app/helpers/notes_helper.rb | 9 ++ app/views/notes/_create_common.js.haml | 3 +- app/views/notes/_load.js.haml | 14 +- 5 files changed, 134 insertions(+), 100 deletions(-) create mode 100644 app/helpers/notes_helper.rb diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index 47b0e0f5..ccc84ac9 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -4,9 +4,8 @@ var NoteList = { target_params: null, target_id: 0, target_type: null, - first_id: 0, - last_id: 0, - disable:false, + bottom_id: 0, + loading_more_disabled: false, init: function(tid, tt, path) { @@ -15,26 +14,23 @@ var NoteList = { this.target_type = tt; this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; - // get notes + // get initial set of notes this.getContent(); - // get new notes every n seconds - this.initRefresh(); - $('.delete-note').live('ajax:success', function() { $(this).closest('li').fadeOut(); }); - $(".note-form-holder").live("ajax:before", function(){ + $(".note-form-holder").on("ajax:before", function(){ $(".submit_note").disable() }) - $(".note-form-holder").live("ajax:complete", function(){ + $(".note-form-holder").on("ajax:complete", function(){ $(".submit_note").enable() }) disableButtonIfEmptyField(".note-text", ".submit_note"); - $(".note-text").live("focus", function(){ + $(".note-text").on("focus", function(){ $(this).css("height", "80px"); $('.note_advanced_opts').show(); }); @@ -44,64 +40,20 @@ var NoteList = { var filename = val.replace(/^.*[\\\/]/, ''); $(".file_name").text(filename); }); - }, /** - * Load new notes to fresh list called 'new_notes_list': - * - Replace 'new_notes_list' with new list every n seconds - * - Append new notes to this list after submit + * Handle loading the initial set of notes. + * And set up loading more notes when scrolling to the bottom of the page. */ - initRefresh: - function() { - // init timer - var intNew = setInterval("NoteList.getNew()", 10000); - }, - - replace: - function(html) { - $("#new_notes_list").html(html); - }, - - prepend: - function(id, html) { - if(id != this.last_id) { - $("#new_notes_list").prepend(html); - } - }, - - getNew: - function() { - // refersh notes list - $.ajax({ - type: "GET", - url: this.notes_path, - data: "last_id=" + this.last_id + this.target_params, - dataType: "script"}); - }, - - refresh: - function() { - // refersh notes list - $.ajax({ - type: "GET", - url: this.notes_path, - data: "first_id=" + this.first_id + "&last_id=" + this.last_id + this.target_params, - dataType: "script"}); - }, - /** - * Init load of notes: - * 1. Get content with ajax call - * 2. Set content of notes list with loaded one + * Gets an inital set of notes. */ - - - getContent: - function() { + getContent: + function() { $.ajax({ type: "GET", url: this.notes_path, @@ -111,10 +63,13 @@ var NoteList = { dataType: "script"}); }, + /** + * Called in response to getContent(). + * Replaces the content of #notes-list with the given html. + */ setContent: - function(fid, lid, html) { - this.last_id = lid; - this.first_id = fid; + function(last_id, html) { + this.bottom_id = last_id; $("#notes-list").html(html); // Init infinite scrolling @@ -123,54 +78,126 @@ var NoteList = { /** - * Paging for old notes when scroll to bottom: - * 1. Init scroll events with 'initLoadMore' - * 2. Load onlder notes with 'getOld' method - * 3. append old notes to bottom of list with 'append' + * Handle loading more notes when scrolling to the bottom of the page. + * The id of the last note in the list is in this.bottom_id. * + * Set up refreshing only new notes after all notes have been loaded. */ - getOld: + + + /** + * Initializes loading more notes when scrolling to the bottom of the page. + */ + initLoadMore: function() { + $(document).endlessScroll({ + bottomPixels: 400, + fireDelay: 1000, + fireOnce:true, + ceaseFire: function() { + return NoteList.loading_more_disabled; + }, + callback: function(i) { + NoteList.getMore(); + } + }); + }, + + /** + * Gets an additional set of notes. + */ + getMore: + function() { + // only load more notes if there are no "new" notes $('.loading').show(); $.ajax({ type: "GET", url: this.notes_path, - data: "first_id=" + this.first_id + this.target_params, + data: "loading_more=1&after_id=" + this.bottom_id + this.target_params, complete: function(){ $('.notes-status').removeClass("loading")}, beforeSend: function() { $('.notes-status').addClass("loading") }, dataType: "script"}); }, - append: + /** + * Called in response to getMore(). + * Append notes to #notes-list. + */ + appendMoreNotes: function(id, html) { - if(this.first_id == id) { - this.disable = true; - } else { - this.first_id = id; + if(id != this.bottom_id) { + this.bottom_id = id; $("#notes-list").append(html); } }, - initLoadMore: + /** + * Called in response to getMore(). + * Disables loading more notes when scrolling to the bottom of the page. + * Initalizes refreshing new notes. + */ + finishedLoadingMore: function() { - $(document).endlessScroll({ - bottomPixels: 400, - fireDelay: 1000, - fireOnce:true, - ceaseFire: function() { - return NoteList.disable; - }, - callback: function(i) { - NoteList.getOld(); + this.loading_more_disabled = true; + + // from now on only get new notes + this.initRefreshNew(); + }, + + + /** + * Handle refreshing and adding of new notes. + * + * New notes are all notes that are created after the site has been loaded. + * The "old" notes are in #notes-list the "new" ones will be in #new-notes-list. + * The id of the last "old" note is in this.bottom_id. + */ + + + /** + * Initializes getting new notes every n seconds. + */ + initRefreshNew: + function() { + setInterval("NoteList.getNew()", 10000); + }, + + /** + * Gets the new set of notes (i.e. all notes after ). + */ + getNew: + function() { + $.ajax({ + type: "GET", + url: this.notes_path, + data: "loading_new=1&after_id=" + this.bottom_id + this.target_params, + dataType: "script"}); + }, + + /** + * Called in response to getNew(). + * Replaces the content of #new-notes-list with the given html. + */ + replaceNewNotes: + function(html) { + $("#new-notes-list").html(html); + }, + + /** + * Adds a single note to #new-notes-list. + */ + appendNewNote: + function(id, html) { + if(id != this.bottom_id) { + $("#new-notes-list").append(html); } - }); } }; -var PerLineNotes = { +var PerLineNotes = { init: function() { - $(".line_note_link, .line_note_reply_link").live("click", function(e) { + $(".line_note_link, .line_note_reply_link").on("click", function(e) { var form = $(".per_line_form"); $(this).closest("tr").after(form); form.find("#note_line_code").val($(this).attr("line_code")); diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb index c026fc50..c2d7644b 100644 --- a/app/contexts/notes/load_context.rb +++ b/app/contexts/notes/load_context.rb @@ -3,8 +3,7 @@ module Notes def execute target_type = params[:target_type] target_id = params[:target_id] - first_id = params[:first_id] - last_id = params[:last_id] + after_id = params[:after_id] @notes = case target_type @@ -23,10 +22,8 @@ module Notes project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] end - @notes = if last_id - @notes.where("id < ?", last_id) - elsif first_id - @notes.where("id > ?", first_id) + @notes = if after_id + @notes.where("id > ?", after_id) else @notes end diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb new file mode 100644 index 00000000..28701661 --- /dev/null +++ b/app/helpers/notes_helper.rb @@ -0,0 +1,9 @@ +module NotesHelper + def loading_more_notes? + params[:loading_more].present? + end + + def loading_new_notes? + params[:loading_new].present? + end +end diff --git a/app/views/notes/_create_common.js.haml b/app/views/notes/_create_common.js.haml index e80eccb1..ce678585 100644 --- a/app/views/notes/_create_common.js.haml +++ b/app/views/notes/_create_common.js.haml @@ -5,7 +5,8 @@ $('.note-form-holder #preview-link').text('Preview'); $('.note-form-holder #preview-note').hide(); $('.note-form-holder').show(); - NoteList.prepend(#{note.id}, "#{escape_javascript(render partial: "notes/show", locals: {note: note})}"); + NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/show", note: note)}"); + - else :plain $(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}"); diff --git a/app/views/notes/_load.js.haml b/app/views/notes/_load.js.haml index c16a699a..8c735476 100644 --- a/app/views/notes/_load.js.haml +++ b/app/views/notes/_load.js.haml @@ -1,17 +1,17 @@ - unless @notes.blank? - - if params[:last_id] + - if loading_more_notes? :plain - NoteList.replace("#{escape_javascript(render(partial: 'notes/notes_list'))}"); + NoteList.appendMoreNotes(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); - - elsif params[:first_id] + - elsif loading_new_notes? :plain - NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(partial: 'notes/notes_list'))}"); + NoteList.replaceNewNotes("#{escape_javascript(render 'notes/notes_list')}"); - else :plain - NoteList.setContent(#{@notes.last.id}, #{@notes.first.id}, "#{escape_javascript(render(partial: 'notes/notes_list'))}"); + NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); - else - - if params[:first_id] + - if loading_more_notes? :plain - NoteList.append(#{params[:first_id]}, ""); + NoteList.finishedLoadingMore(); From 20e009a40a4fa5d7e5517833e14c16b32b461720 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 01:21:39 +0200 Subject: [PATCH 05/22] Update diff comments order and rendering --- app/views/commits/_text_file.html.haml | 4 ++-- app/views/notes/_create_common.js.haml | 2 +- app/views/notes/_per_line_show.html.haml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 0f6210f2..5dc8dbd3 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -18,9 +18,9 @@ %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line}  " - if @comments_allowed - - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at).reverse + - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) - unless comments.empty? - comments.each_with_index do |note, i| - = render "notes/reply_button", line_code: line_code if i.zero? = render "notes/per_line_show", note: note - @line_notes.reject!{ |n| n == note } + = render "notes/reply_button", line_code: line_code diff --git a/app/views/notes/_create_common.js.haml b/app/views/notes/_create_common.js.haml index ce678585..0a00bd40 100644 --- a/app/views/notes/_create_common.js.haml +++ b/app/views/notes/_create_common.js.haml @@ -9,5 +9,5 @@ - else :plain - $(".note-form-holder").replaceWith("#{escape_javascript(render('form'))}"); + $(".note-form-holder").replaceWith("#{escape_javascript(render 'form')}"); diff --git a/app/views/notes/_per_line_show.html.haml b/app/views/notes/_per_line_show.html.haml index cf1769c0..9d5a31a7 100644 --- a/app/views/notes/_per_line_show.html.haml +++ b/app/views/notes/_per_line_show.html.haml @@ -1,5 +1,5 @@ %tr.line_notes_row %td{colspan: 3} %ul - = render partial: "notes/show", locals: {note: note} + = render "notes/show", note: note From 653f7ec4fb57f84f471c8f2078c7534b1c085cc9 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 01:22:09 +0200 Subject: [PATCH 06/22] Update links for inline comments to use data-* attributes --- app/views/commits/_text_file.html.haml | 2 +- app/views/notes/_reply_button.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 5dc8dbd3..7a00eb45 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -13,7 +13,7 @@ %td.old_line = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code - if @comments_allowed - = link_to "", "#", class: "line_note_link", "line_code" => line_code, title: "Add note for this line" + = link_to "", "#", class: "line_note_link", data: { line_code: line_code }, title: "Add note for this line" %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line}  " diff --git a/app/views/notes/_reply_button.html.haml b/app/views/notes/_reply_button.html.haml index c981fb9f..42c737c7 100644 --- a/app/views/notes/_reply_button.html.haml +++ b/app/views/notes/_reply_button.html.haml @@ -1,4 +1,4 @@ %tr.line_notes_row.reply %td{colspan: 3} %i.icon-comment - = link_to "Reply", "#", class: "line_note_reply_link", "line_code" => line_code, title: "Add note for this line" + = link_to "Reply", "#", class: "line_note_reply_link", data: { line_code: line_code }, title: "Add note for this line" From cee230a158e72a973150a17034b58c869f7e9407 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 01:32:55 +0200 Subject: [PATCH 07/22] Update JS for adding and removing diff line notes --- app/assets/javascripts/note.js | 37 +++++++++++++++++++++++++--- app/views/notes/_create_line.js.haml | 19 +++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index ccc84ac9..7cbf44b9 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -17,8 +17,9 @@ var NoteList = { // get initial set of notes this.getContent(); - $('.delete-note').live('ajax:success', function() { - $(this).closest('li').fadeOut(); }); + $("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() { + $(this).closest('li').fadeOut(); + }); $(".note-form-holder").on("ajax:before", function(){ $(".submit_note").disable() @@ -197,13 +198,41 @@ var NoteList = { var PerLineNotes = { init: function() { - $(".line_note_link, .line_note_reply_link").on("click", function(e) { + /** + * Called when clicking on the "add note" or "reply" button for a diff line. + * + * Shows the note form below the line. + * Sets some hidden fields in the form. + */ + $(".diff_file_content").on("click", ".line_note_link, .line_note_reply_link", function(e) { var form = $(".per_line_form"); $(this).closest("tr").after(form); - form.find("#note_line_code").val($(this).attr("line_code")); + form.find("#note_line_code").val($(this).data("lineCode")); form.show(); return false; }); + disableButtonIfEmptyField(".line-note-text", ".submit_inline_note"); + + /** + * Called in response to successfully deleting a note on a diff line. + * + * Removes the actual note from view. + * Removes the reply button if the last note for that line has been removed. + */ + $(".diff_file_content").on("ajax:success", ".delete-note", function() { + var trNote = $(this).closest("tr"); + trNote.fadeOut(function() { + $(this).remove(); + }); + + // check if this is the last note for this line + // elements must really be removed for this to work reliably + var trLine = trNote.prev(); + var trRpl = trNote.next(); + if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) { + trRpl.fadeOut(function() { $(this).remove(); }); + } + }); } } diff --git a/app/views/notes/_create_line.js.haml b/app/views/notes/_create_line.js.haml index 662909f7..ab862b2f 100644 --- a/app/views/notes/_create_line.js.haml +++ b/app/views/notes/_create_line.js.haml @@ -1,8 +1,19 @@ - if note.valid? :plain + // hide and reset the form $(".per_line_form").hide(); $('.line-note-form-holder textarea').val(""); - $("a.line_note_reply_link[line_code='#{note.line_code}']").closest("tr").remove(); - var trEl = $(".#{note.line_code}").parent(); - trEl.after("#{escape_javascript(render partial: "notes/per_line_show", locals: {note: note})}"); - trEl.after("#{escape_javascript(render partial: "notes/reply_button", locals: {line_code: note.line_code})}"); + + // find the reply button for this line + // (might not be there if this is the first note) + var trRpl = $("a.line_note_reply_link[data-line-code='#{note.line_code}']").closest("tr"); + if (trRpl.size() == 0) { + // find the commented line ... + var trEl = $(".#{note.line_code}").parent(); + // ... and insert the note and the reply button after it + trEl.after("#{escape_javascript(render "notes/reply_button", line_code: note.line_code)}"); + trEl.after("#{escape_javascript(render "notes/per_line_show", note: note)}"); + } else { + // instert new note before reply button + trRpl.before("#{escape_javascript(render "notes/per_line_show", note: note)}"); + } From 61eb650db0eb05ee6436d662927cb963ec157b76 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 04:59:55 +0200 Subject: [PATCH 08/22] Rename 'notes/notes' partial to 'notes/notes_with_form' --- app/views/commits/show.html.haml | 2 +- app/views/issues/show.html.haml | 2 +- app/views/merge_requests/_show.html.haml | 2 +- app/views/merge_requests/show.js.haml | 2 +- .../notes/{_notes.html.haml => _notes_with_form.html.haml} | 0 app/views/projects/wall.html.haml | 2 +- app/views/snippets/show.html.haml | 2 +- app/views/wikis/show.html.haml | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename app/views/notes/{_notes.html.haml => _notes_with_form.html.haml} (100%) diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index e01f8ea5..d12fff96 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -1,6 +1,6 @@ = render "commits/commit_box" = render "commits/diffs", diffs: @commit.diffs -= render "notes/notes", tid: @commit.id, tt: "commit" += render "notes/notes_with_form", tid: @commit.id, tt: "commit" = render "notes/per_line_form" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index 9b1c72a3..0b72a820 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -61,4 +61,4 @@ = markdown @issue.description -.issue_notes#notes= render "notes/notes", tid: @issue.id, tt: "issue" +.issue_notes#notes= render "notes/notes_with_form", tid: @issue.id, tt: "issue" diff --git a/app/views/merge_requests/_show.html.haml b/app/views/merge_requests/_show.html.haml index f1b3fa9f..40b72190 100644 --- a/app/views/merge_requests/_show.html.haml +++ b/app/views/merge_requests/_show.html.haml @@ -16,7 +16,7 @@ Diff .merge_request_notes#notes{ class: (controller.action_name == 'show') ? "" : "hide" } - = render("notes/notes", tid: @merge_request.id, tt: "merge_request") + = render("notes/notes_with_form", tid: @merge_request.id, tt: "merge_request") .merge-request-diffs = render "merge_requests/show/diffs" if @diffs .status diff --git a/app/views/merge_requests/show.js.haml b/app/views/merge_requests/show.js.haml index 7a27b166..f44ccbb5 100644 --- a/app/views/merge_requests/show.js.haml +++ b/app/views/merge_requests/show.js.haml @@ -1,2 +1,2 @@ :plain - $(".merge-request-notes").html("#{escape_javascript(render("notes/notes", tid: @merge_request.id, tt: "merge_request"))}"); + $(".merge-request-notes").html("#{escape_javascript(render notes/notes_with_form", tid: @merge_request.id, tt: "merge_request")}"); diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes_with_form.html.haml similarity index 100% rename from app/views/notes/_notes.html.haml rename to app/views/notes/_notes_with_form.html.haml diff --git a/app/views/projects/wall.html.haml b/app/views/projects/wall.html.haml index 97765d7a..1a07bc3d 100644 --- a/app/views/projects/wall.html.haml +++ b/app/views/projects/wall.html.haml @@ -1,2 +1,2 @@ %div.wall_page - = render "notes/notes", tid: nil, tt: "wall" + = render "notes/notes_with_form", tid: nil, tt: "wall" diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml index 0800b81d..4188a9f1 100644 --- a/app/views/snippets/show.html.haml +++ b/app/views/snippets/show.html.haml @@ -17,4 +17,4 @@ %div{class: current_user.dark_scheme ? "black" : ""} = raw @snippet.colorize(options: { linenos: 'True'}) -= render "notes/notes", tid: @snippet.id, tt: "snippet" += render "notes/notes_with_form", tid: @snippet.id, tt: "snippet" diff --git a/app/views/wikis/show.html.haml b/app/views/wikis/show.html.haml index fc235227..579ea1b3 100644 --- a/app/views/wikis/show.html.haml +++ b/app/views/wikis/show.html.haml @@ -21,4 +21,4 @@ Delete this page %hr -.wiki_notes#notes= render "notes/notes", tid: @wiki.id, tt: "wiki" +.wiki_notes#notes= render "notes/notes_with_form", tid: @wiki.id, tt: "wiki" From 8fb70d924dbb089fdac89125664e3aa73212d8fc Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:00:21 +0200 Subject: [PATCH 09/22] Rename 'notes/create_*' partials --- .../{_create_common.js.haml => _create_common_note.js.haml} | 0 .../{_create_line.js.haml => _create_per_line_note.js.haml} | 0 app/views/notes/create.js.haml | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename app/views/notes/{_create_common.js.haml => _create_common_note.js.haml} (100%) rename app/views/notes/{_create_line.js.haml => _create_per_line_note.js.haml} (100%) diff --git a/app/views/notes/_create_common.js.haml b/app/views/notes/_create_common_note.js.haml similarity index 100% rename from app/views/notes/_create_common.js.haml rename to app/views/notes/_create_common_note.js.haml diff --git a/app/views/notes/_create_line.js.haml b/app/views/notes/_create_per_line_note.js.haml similarity index 100% rename from app/views/notes/_create_line.js.haml rename to app/views/notes/_create_per_line_note.js.haml diff --git a/app/views/notes/create.js.haml b/app/views/notes/create.js.haml index 8f631f38..03866591 100644 --- a/app/views/notes/create.js.haml +++ b/app/views/notes/create.js.haml @@ -1,7 +1,7 @@ - if @note.line_code - = render "create_line", note: @note + = render "create_per_line_note", note: @note - else - = render "create_common", note: @note + = render "create_common_note", note: @note -# Enable submit button :plain From 3c02c93f08019a73929de8e812424e581c58c62a Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:05:37 +0200 Subject: [PATCH 10/22] Remove 'notes/load' partial --- app/views/notes/_load.js.haml | 17 ----------------- app/views/notes/index.js.haml | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 app/views/notes/_load.js.haml diff --git a/app/views/notes/_load.js.haml b/app/views/notes/_load.js.haml deleted file mode 100644 index 8c735476..00000000 --- a/app/views/notes/_load.js.haml +++ /dev/null @@ -1,17 +0,0 @@ -- unless @notes.blank? - - if loading_more_notes? - :plain - NoteList.appendMoreNotes(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); - - - elsif loading_new_notes? - :plain - NoteList.replaceNewNotes("#{escape_javascript(render 'notes/notes_list')}"); - - - else - :plain - NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); - -- else - - if loading_more_notes? - :plain - NoteList.finishedLoadingMore(); diff --git a/app/views/notes/index.js.haml b/app/views/notes/index.js.haml index ee31c0b8..8c735476 100644 --- a/app/views/notes/index.js.haml +++ b/app/views/notes/index.js.haml @@ -1 +1,17 @@ -= render "notes/load" +- unless @notes.blank? + - if loading_more_notes? + :plain + NoteList.appendMoreNotes(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); + + - elsif loading_new_notes? + :plain + NoteList.replaceNewNotes("#{escape_javascript(render 'notes/notes_list')}"); + + - else + :plain + NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); + +- else + - if loading_more_notes? + :plain + NoteList.finishedLoadingMore(); From c02e3f2104d9dbb1bca01935fe7c0dfeacf53baf Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:08:40 +0200 Subject: [PATCH 11/22] Rename 'notes/form' partial to 'notes/common_form' --- app/views/notes/{_form.html.haml => _common_form.html.haml} | 0 app/views/notes/_notes_with_form.html.haml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename app/views/notes/{_form.html.haml => _common_form.html.haml} (100%) diff --git a/app/views/notes/_form.html.haml b/app/views/notes/_common_form.html.haml similarity index 100% rename from app/views/notes/_form.html.haml rename to app/views/notes/_common_form.html.haml diff --git a/app/views/notes/_notes_with_form.html.haml b/app/views/notes/_notes_with_form.html.haml index 14e1e84b..53716c1d 100644 --- a/app/views/notes/_notes_with_form.html.haml +++ b/app/views/notes/_notes_with_form.html.haml @@ -3,7 +3,7 @@ .notes-status - if can? current_user, :write_note, @project - = render "notes/form" + = render "notes/common_form" :javascript $(function(){ From 29c71f2fb95ba98513ff96939fd4a602b4a3bd6f Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:10:06 +0200 Subject: [PATCH 12/22] Rename 'notes/reply_button' partial to 'notes/per_line_reply_button' --- app/views/commits/_text_file.html.haml | 2 +- app/views/notes/_create_per_line_note.js.haml | 2 +- ..._reply_button.html.haml => _per_line_reply_button.html.haml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename app/views/notes/{_reply_button.html.haml => _per_line_reply_button.html.haml} (100%) diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 7a00eb45..f7dae301 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -23,4 +23,4 @@ - comments.each_with_index do |note, i| = render "notes/per_line_show", note: note - @line_notes.reject!{ |n| n == note } - = render "notes/reply_button", line_code: line_code + = render "notes/per_line_reply_button", line_code: line_code diff --git a/app/views/notes/_create_per_line_note.js.haml b/app/views/notes/_create_per_line_note.js.haml index ab862b2f..d7f0a0dc 100644 --- a/app/views/notes/_create_per_line_note.js.haml +++ b/app/views/notes/_create_per_line_note.js.haml @@ -11,7 +11,7 @@ // find the commented line ... var trEl = $(".#{note.line_code}").parent(); // ... and insert the note and the reply button after it - trEl.after("#{escape_javascript(render "notes/reply_button", line_code: note.line_code)}"); + trEl.after("#{escape_javascript(render "notes/per_line_reply_button", line_code: note.line_code)}"); trEl.after("#{escape_javascript(render "notes/per_line_show", note: note)}"); } else { // instert new note before reply button diff --git a/app/views/notes/_reply_button.html.haml b/app/views/notes/_per_line_reply_button.html.haml similarity index 100% rename from app/views/notes/_reply_button.html.haml rename to app/views/notes/_per_line_reply_button.html.haml From 4fc66ead4f50f76efb80e119bbedc7514602f57f Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:13:26 +0200 Subject: [PATCH 13/22] Rename 'notes/show' partial to 'notes/note' --- app/views/notes/_create_common_note.js.haml | 2 +- app/views/notes/{_show.html.haml => _note.html.haml} | 0 app/views/notes/_notes_list.html.haml | 2 +- app/views/notes/_per_line_show.html.haml | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename app/views/notes/{_show.html.haml => _note.html.haml} (100%) diff --git a/app/views/notes/_create_common_note.js.haml b/app/views/notes/_create_common_note.js.haml index 0a00bd40..bbebc247 100644 --- a/app/views/notes/_create_common_note.js.haml +++ b/app/views/notes/_create_common_note.js.haml @@ -5,7 +5,7 @@ $('.note-form-holder #preview-link').text('Preview'); $('.note-form-holder #preview-note').hide(); $('.note-form-holder').show(); - NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/show", note: note)}"); + NoteList.appendNewNote(#{note.id}, "#{escape_javascript(render "notes/note", note: note)}"); - else :plain diff --git a/app/views/notes/_show.html.haml b/app/views/notes/_note.html.haml similarity index 100% rename from app/views/notes/_show.html.haml rename to app/views/notes/_note.html.haml diff --git a/app/views/notes/_notes_list.html.haml b/app/views/notes/_notes_list.html.haml index 5673988d..e2c4bedc 100644 --- a/app/views/notes/_notes_list.html.haml +++ b/app/views/notes/_notes_list.html.haml @@ -1,4 +1,4 @@ - @notes.each do |note| - next unless note.author - = render partial: "notes/show", locals: {note: note} + = render "notes/note", note: note diff --git a/app/views/notes/_per_line_show.html.haml b/app/views/notes/_per_line_show.html.haml index 9d5a31a7..28bcd6e0 100644 --- a/app/views/notes/_per_line_show.html.haml +++ b/app/views/notes/_per_line_show.html.haml @@ -1,5 +1,5 @@ %tr.line_notes_row %td{colspan: 3} %ul - = render "notes/show", note: note + = render "notes/note", note: note From dd1b3177c999560818e8bbfb549630234f6ec9f0 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:19:38 +0200 Subject: [PATCH 14/22] Renamed 'notes/notes_list' partial to 'notes/notes' --- app/views/notes/{_notes_list.html.haml => _notes.html.haml} | 2 +- app/views/notes/index.js.haml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename app/views/notes/{_notes_list.html.haml => _notes.html.haml} (59%) diff --git a/app/views/notes/_notes_list.html.haml b/app/views/notes/_notes.html.haml similarity index 59% rename from app/views/notes/_notes_list.html.haml rename to app/views/notes/_notes.html.haml index e2c4bedc..adb5dfcb 100644 --- a/app/views/notes/_notes_list.html.haml +++ b/app/views/notes/_notes.html.haml @@ -1,4 +1,4 @@ - @notes.each do |note| - next unless note.author - = render "notes/note", note: note + = render "note", note: note diff --git a/app/views/notes/index.js.haml b/app/views/notes/index.js.haml index 8c735476..3d6859eb 100644 --- a/app/views/notes/index.js.haml +++ b/app/views/notes/index.js.haml @@ -1,15 +1,15 @@ - unless @notes.blank? - if loading_more_notes? :plain - NoteList.appendMoreNotes(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); + NoteList.appendMoreNotes(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes')}"); - elsif loading_new_notes? :plain - NoteList.replaceNewNotes("#{escape_javascript(render 'notes/notes_list')}"); + NoteList.replaceNewNotes("#{escape_javascript(render 'notes/notes')}"); - else :plain - NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes_list')}"); + NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes')}"); - else - if loading_more_notes? From c6d71b7b8e5e8dc22da9b8aab392196d1987fd68 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:21:58 +0200 Subject: [PATCH 15/22] Rename 'notes/per_line_show' partial to 'notes/per_line_note' --- app/views/commits/_text_file.html.haml | 2 +- app/views/notes/_create_per_line_note.js.haml | 4 ++-- .../{_per_line_show.html.haml => _per_line_note.html.haml} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename app/views/notes/{_per_line_show.html.haml => _per_line_note.html.haml} (100%) diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index f7dae301..7626a015 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -21,6 +21,6 @@ - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) - unless comments.empty? - comments.each_with_index do |note, i| - = render "notes/per_line_show", note: note + = render "notes/per_line_note", note: note - @line_notes.reject!{ |n| n == note } = render "notes/per_line_reply_button", line_code: line_code diff --git a/app/views/notes/_create_per_line_note.js.haml b/app/views/notes/_create_per_line_note.js.haml index d7f0a0dc..180960e3 100644 --- a/app/views/notes/_create_per_line_note.js.haml +++ b/app/views/notes/_create_per_line_note.js.haml @@ -12,8 +12,8 @@ var trEl = $(".#{note.line_code}").parent(); // ... and insert the note and the reply button after it trEl.after("#{escape_javascript(render "notes/per_line_reply_button", line_code: note.line_code)}"); - trEl.after("#{escape_javascript(render "notes/per_line_show", note: note)}"); + trEl.after("#{escape_javascript(render "notes/per_line_note", note: note)}"); } else { // instert new note before reply button - trRpl.before("#{escape_javascript(render "notes/per_line_show", note: note)}"); + trRpl.before("#{escape_javascript(render "notes/per_line_note", note: note)}"); } diff --git a/app/views/notes/_per_line_show.html.haml b/app/views/notes/_per_line_note.html.haml similarity index 100% rename from app/views/notes/_per_line_show.html.haml rename to app/views/notes/_per_line_note.html.haml From a3dbd990682f5f39d9c3e58858faf85b9b0a6179 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 17:02:09 +0200 Subject: [PATCH 16/22] Extract 'notes/per_line_note_link' partial --- app/views/commits/_text_file.html.haml | 2 +- app/views/notes/_per_line_note_link.html.haml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 app/views/notes/_per_line_note_link.html.haml diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 7626a015..22d2b9ed 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -13,7 +13,7 @@ %td.old_line = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code - if @comments_allowed - = link_to "", "#", class: "line_note_link", data: { line_code: line_code }, title: "Add note for this line" + = render "notes/per_line_note_link", line_code: line_code %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line}  " diff --git a/app/views/notes/_per_line_note_link.html.haml b/app/views/notes/_per_line_note_link.html.haml new file mode 100644 index 00000000..72b59a59 --- /dev/null +++ b/app/views/notes/_per_line_note_link.html.haml @@ -0,0 +1 @@ += link_to "", "#", class: "line_note_link", data: { line_code: line_code }, title: "Add note for this line" From e1ca155c95a41a9adfe984a3e3ba5c777c61acd8 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 16:57:08 +0200 Subject: [PATCH 17/22] Extract 'notes/per_line_notes_with_reply' partial --- app/views/commits/_text_file.html.haml | 5 +---- app/views/notes/_per_line_notes_with_reply.html.haml | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 app/views/notes/_per_line_notes_with_reply.html.haml diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 22d2b9ed..9f5b5345 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -20,7 +20,4 @@ - if @comments_allowed - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) - unless comments.empty? - - comments.each_with_index do |note, i| - = render "notes/per_line_note", note: note - - @line_notes.reject!{ |n| n == note } - = render "notes/per_line_reply_button", line_code: line_code + = render "notes/per_line_notes_with_reply", notes: comments diff --git a/app/views/notes/_per_line_notes_with_reply.html.haml b/app/views/notes/_per_line_notes_with_reply.html.haml new file mode 100644 index 00000000..1bcfc41f --- /dev/null +++ b/app/views/notes/_per_line_notes_with_reply.html.haml @@ -0,0 +1,3 @@ +- notes.each do |note| + = render "notes/per_line_note", note: note += render "notes/per_line_reply_button", line_code: notes.first.line_code From e63d7b6029142d100adca03e11ba0e33d9c2981c Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 05:56:12 +0200 Subject: [PATCH 18/22] Rename note.js to notes.js --- app/assets/javascripts/{note.js => notes.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/assets/javascripts/{note.js => notes.js} (100%) diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/notes.js similarity index 100% rename from app/assets/javascripts/note.js rename to app/assets/javascripts/notes.js From 7563abbe49fc16280877be89342d552e0609d57c Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 17:00:48 +0200 Subject: [PATCH 19/22] Add 'notes/reversed_notes_with_form' partial --- app/assets/stylesheets/sections/notes.scss | 14 ++++++++++++-- .../notes/_reversed_notes_with_form.html.haml | 11 +++++++++++ app/views/projects/wall.html.haml | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 app/views/notes/_reversed_notes_with_form.html.haml diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 8db88930..2db20f16 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -10,7 +10,10 @@ padding:0px; } -#notes-list li:last-child { +#new-notes-list:not(.reversed) { + border-top:1px solid #aaa; +} +#new-notes-list.reversed { border-bottom:1px solid #aaa; } @@ -48,7 +51,6 @@ .note { padding: 8px 0; - border-bottom: 1px solid #eee; overflow: hidden; display: block; img {float: left; margin-right: 10px;} @@ -70,6 +72,14 @@ .delete-note { display:block; } } } +#notes-list:not(.reversed) .note, +#new-notes-list:not(.reversed) .note { + border-bottom: 1px solid #eee; +} +#notes-list.reversed .note, +#new-notes-list.reversed .note { + border-top: 1px solid #eee; +} .notes-status { margin: 18px; diff --git a/app/views/notes/_reversed_notes_with_form.html.haml b/app/views/notes/_reversed_notes_with_form.html.haml new file mode 100644 index 00000000..05f01847 --- /dev/null +++ b/app/views/notes/_reversed_notes_with_form.html.haml @@ -0,0 +1,11 @@ +- if can? current_user, :write_note, @project + = render "notes/common_form" + +%ul.reversed#new-notes-list +%ul.reversed#notes-list +.notes-status + +:javascript + $(function(){ + NoteList.init("#{tid}", "#{tt}", "#{project_notes_path(@project)}"); + }); \ No newline at end of file diff --git a/app/views/projects/wall.html.haml b/app/views/projects/wall.html.haml index 1a07bc3d..591a8cd0 100644 --- a/app/views/projects/wall.html.haml +++ b/app/views/projects/wall.html.haml @@ -1,2 +1,2 @@ %div.wall_page - = render "notes/notes_with_form", tid: nil, tt: "wall" + = render "notes/reversed_notes_with_form", tid: nil, tt: "wall" From 07eec9c66a910b5a808852f498e1dc9c88b701d2 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Fri, 14 Sep 2012 17:01:34 +0200 Subject: [PATCH 20/22] Update Notes JS for reversed notes --- app/assets/javascripts/notes.js | 27 ++++++++++++++++++++------- app/contexts/notes/load_context.rb | 7 +++++-- app/models/note.rb | 2 +- app/views/notes/index.js.haml | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 7cbf44b9..81bb1d6d 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -4,14 +4,17 @@ var NoteList = { target_params: null, target_id: 0, target_type: null, + top_id: 0, bottom_id: 0, loading_more_disabled: false, + reversed: false, init: function(tid, tt, path) { this.notes_path = path + ".js"; this.target_id = tid; this.target_type = tt; + this.reversed = $("#notes-list").hasClass("reversed"); this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; // get initial set of notes @@ -69,12 +72,18 @@ var NoteList = { * Replaces the content of #notes-list with the given html. */ setContent: - function(last_id, html) { + function(first_id, last_id, html) { + this.top_id = first_id; this.bottom_id = last_id; $("#notes-list").html(html); - // Init infinite scrolling + // init infinite scrolling this.initLoadMore(); + + // init getting new notes + if (this.reversed) { + this.initRefreshNew(); + } }, @@ -114,7 +123,7 @@ var NoteList = { $.ajax({ type: "GET", url: this.notes_path, - data: "loading_more=1&after_id=" + this.bottom_id + this.target_params, + data: "loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id + this.target_params, complete: function(){ $('.notes-status').removeClass("loading")}, beforeSend: function() { $('.notes-status').addClass("loading") }, dataType: "script"}); @@ -142,7 +151,9 @@ var NoteList = { this.loading_more_disabled = true; // from now on only get new notes - this.initRefreshNew(); + if (!this.reversed) { + this.initRefreshNew(); + } }, @@ -164,14 +175,14 @@ var NoteList = { }, /** - * Gets the new set of notes (i.e. all notes after ). + * Gets the new set of notes. */ getNew: function() { $.ajax({ type: "GET", url: this.notes_path, - data: "loading_new=1&after_id=" + this.bottom_id + this.target_params, + data: "loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id) + this.target_params, dataType: "script"}); }, @@ -189,7 +200,9 @@ var NoteList = { */ appendNewNote: function(id, html) { - if(id != this.bottom_id) { + if (this.reversed) { + $("#new-notes-list").prepend(html); + } else { $("#new-notes-list").append(html); } } diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb index c2d7644b..6d26e16a 100644 --- a/app/contexts/notes/load_context.rb +++ b/app/contexts/notes/load_context.rb @@ -4,6 +4,7 @@ module Notes target_type = params[:target_type] target_id = params[:target_id] after_id = params[:after_id] + before_id = params[:before_id] @notes = case target_type @@ -17,14 +18,16 @@ module Notes project.snippets.find(target_id).notes.fresh when "wall" # this is the only case, where the order is DESC - project.common_notes.order("created_at DESC").limit(50) + project.common_notes.order("created_at DESC, id DESC").limit(50) when "wiki" project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] end @notes = if after_id @notes.where("id > ?", after_id) - else + elsif before_id + @notes.where("id < ?", before_id) + else @notes end end diff --git a/app/models/note.rb b/app/models/note.rb index 9aad8949..34edb94e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -36,7 +36,7 @@ class Note < ActiveRecord::Base scope :today, where("created_at >= :date", date: Date.today) scope :last_week, where("created_at >= :date", date: (Date.today - 7.days)) scope :since, lambda { |day| where("created_at >= :date", date: (day)) } - scope :fresh, order("created_at ASC") + scope :fresh, order("created_at ASC, id ASC") scope :inc_author_project, includes(:project, :author) scope :inc_author, includes(:author) diff --git a/app/views/notes/index.js.haml b/app/views/notes/index.js.haml index 3d6859eb..3814dbd4 100644 --- a/app/views/notes/index.js.haml +++ b/app/views/notes/index.js.haml @@ -9,7 +9,7 @@ - else :plain - NoteList.setContent(#{@notes.last.id}, "#{escape_javascript(render 'notes/notes')}"); + NoteList.setContent(#{@notes.first.id}, #{@notes.last.id}, "#{escape_javascript(render 'notes/notes')}"); - else - if loading_more_notes? From 9159be3a50e3bc94f30f85d9640eeac212bf0948 Mon Sep 17 00:00:00 2001 From: randx Date: Sat, 15 Sep 2012 09:49:21 +0300 Subject: [PATCH 21/22] Fix MR diff comments. Fix wiki comments loading error --- app/assets/stylesheets/sections/notes.scss | 4 ++-- app/contexts/notes/load_context.rb | 2 +- app/models/project.rb | 4 ++++ app/models/wiki.rb | 1 - app/views/merge_requests/diffs.html.haml | 4 ++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 2db20f16..148807d6 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -14,7 +14,7 @@ border-top:1px solid #aaa; } #new-notes-list.reversed { - border-bottom:1px solid #aaa; + border-bottom:1px solid #ccc; } .issue_notes, @@ -227,7 +227,7 @@ td .line_note_link { } } -.note-text { +.note-text { border: 1px solid #aaa; box-shadow:none; } diff --git a/app/contexts/notes/load_context.rb b/app/contexts/notes/load_context.rb index 6d26e16a..f92a7801 100644 --- a/app/contexts/notes/load_context.rb +++ b/app/contexts/notes/load_context.rb @@ -20,7 +20,7 @@ module Notes # this is the only case, where the order is DESC project.common_notes.order("created_at DESC, id DESC").limit(50) when "wiki" - project.wikis.reverse.map {|w| w.notes.fresh }.flatten[0..20] + project.wiki_notes.limit(20) end @notes = if after_id diff --git a/app/models/project.rb b/app/models/project.rb index 4de836c7..56d5d791 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -171,6 +171,10 @@ class Project < ActiveRecord::Base end end + def wiki_notes + Note.where(noteable_id: wikis.map(&:id), noteable_type: 'Wiki', project_id: self.id) + end + def project_id self.id end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 3c4952cd..ebb1ff49 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -28,7 +28,6 @@ class Wiki < ActiveRecord::Base end new_wiki end - end end # == Schema Information diff --git a/app/views/merge_requests/diffs.html.haml b/app/views/merge_requests/diffs.html.haml index 176b19bc..a755491c 100644 --- a/app/views/merge_requests/diffs.html.haml +++ b/app/views/merge_requests/diffs.html.haml @@ -1,2 +1,6 @@ = render "show" +:javascript + $(function(){ + PerLineNotes.init(); + }); From 348def03449f8f92fc1b568df7ad2fef40343587 Mon Sep 17 00:00:00 2001 From: randx Date: Sat, 15 Sep 2012 09:58:16 +0300 Subject: [PATCH 22/22] Init mr comments when naviagate via ajax to diff --- app/views/merge_requests/diffs.js.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/merge_requests/diffs.js.haml b/app/views/merge_requests/diffs.js.haml index b147e5be..98539985 100644 --- a/app/views/merge_requests/diffs.js.haml +++ b/app/views/merge_requests/diffs.js.haml @@ -1,4 +1,7 @@ :plain $(".merge-request-diffs").html("#{escape_javascript(render(partial: "merge_requests/show/diffs"))}"); + $(function(){ + PerLineNotes.init(); + });