From d41d8ffb02fa74fd4571603548bd7e401ec99e0c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 24 Feb 2012 22:19:47 +0200 Subject: [PATCH] Reply button, Comments for Merge Request diff --- app/assets/stylesheets/common.scss | 7 +++++++ app/assets/stylesheets/notes.css.scss | 19 ++++++++++++++++++- app/controllers/merge_requests_controller.rb | 4 +++- app/views/commits/_text_file.html.haml | 3 ++- app/views/commits/show.html.haml | 2 +- app/views/commits/show.js.haml | 1 - app/views/issues/show.html.haml | 1 - app/views/merge_requests/show.html.haml | 15 ++++++++++++--- app/views/notes/_notes.html.haml | 2 ++ app/views/notes/_reply_button.html.haml | 3 +++ app/views/notes/_show.html.haml | 2 +- app/views/notes/create.js.haml | 5 ++++- app/views/projects/wall.html.haml | 4 ---- 13 files changed, 53 insertions(+), 15 deletions(-) delete mode 100644 app/views/commits/show.js.haml create mode 100644 app/views/notes/_reply_button.html.haml diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 9fd0f2ea..2ae0217a 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -374,3 +374,10 @@ table a code { .btn.padded { margin-right:3px; } + +.loading { + margin:20px auto; + background: url(ajax-loader-facebook.gif) no-repeat center center; + width:40px; + height:40px; +} diff --git a/app/assets/stylesheets/notes.css.scss b/app/assets/stylesheets/notes.css.scss index d264e5cf..b13ffcda 100644 --- a/app/assets/stylesheets/notes.css.scss +++ b/app/assets/stylesheets/notes.css.scss @@ -30,7 +30,10 @@ } } -.note .delete-note { display:none; } +.note .delete-note { + display:none; + float:right; +} .note:hover .delete-note { display:block; } .note {padding: 10px 0; border-bottom: 1px solid #eee; overflow: hidden; display: block;} .note img{float: left; margin-right: 10px;} @@ -53,6 +56,20 @@ p.notify_controls span{ tr.line_notes_row { border-bottom:1px solid #DDD; + &.reply { + background:#eee; + + td { + padding:7px 10px; + } + a.line_note_reply_link { + @include round-borders-all(4px); + border-color:#aaa; + background: #bbb; + padding: 3px 20px; + color: white; + } + } ul { margin:0; li { diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 3ae25940..cfb9e6dc 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -58,7 +58,9 @@ class MergeRequestsController < ApplicationController def diffs @diffs = @merge_request.diffs @commit = @merge_request.last_commit - @line_notes = [] + + @comments_allowed = true + @line_notes = @merge_request.notes.where("line_code is not null") end def new diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index a9b3f65a..441bdf2c 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -16,6 +16,7 @@ - if @comments_allowed - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at).reverse - unless comments.empty? - - comments.each do |note| + - 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 } diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 5f055c28..9c1df54e 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -27,7 +27,7 @@ :javascript $(document).ready(function(){ - $(".line_note_link").live("click", function(e) { + $(".line_note_link, .line_note_reply_link").live("click", function(e) { var form = $(".per_line_form"); $(this).parent().parent().after(form); form.find("#note_line_code").val($(this).attr("line_code")); diff --git a/app/views/commits/show.js.haml b/app/views/commits/show.js.haml deleted file mode 100644 index ee31c0b8..00000000 --- a/app/views/commits/show.js.haml +++ /dev/null @@ -1 +0,0 @@ -= render "notes/load" diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index ace1d1e3..cba08650 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -42,4 +42,3 @@ .issue_notes= render "notes/notes", :tid => @issue.id, :tt => "issue" - diff --git a/app/views/merge_requests/show.html.haml b/app/views/merge_requests/show.html.haml index 4acc748e..e725c198 100644 --- a/app/views/merge_requests/show.html.haml +++ b/app/views/merge_requests/show.html.haml @@ -64,9 +64,6 @@ .merge-request-notes .merge_request_notes= render "notes/notes", :tid => @merge_request.id, :tt => "merge_request" - .loading{ :style => "display:none;"} - %center= image_tag "ajax-loader.gif" - .clear .merge-request-diffs @@ -75,3 +72,15 @@ $(function(){ MergeRequest.init(); }) + += render "notes/per_line_form" +:javascript + $(document).ready(function(){ + $(".line_note_link, .line_note_reply_link").live("click", function(e) { + var form = $(".per_line_form"); + $(this).parent().parent().after(form); + form.find("#note_line_code").val($(this).attr("line_code")); + form.show(); + return false; + }); + }); diff --git a/app/views/notes/_notes.html.haml b/app/views/notes/_notes.html.haml index fb589c32..51c861ab 100644 --- a/app/views/notes/_notes.html.haml +++ b/app/views/notes/_notes.html.haml @@ -3,6 +3,8 @@ .clear %hr %ul#notes-list +.loading + :javascript $('.delete-note').live('ajax:success', function() { diff --git a/app/views/notes/_reply_button.html.haml b/app/views/notes/_reply_button.html.haml new file mode 100644 index 00000000..f53b8c8d --- /dev/null +++ b/app/views/notes/_reply_button.html.haml @@ -0,0 +1,3 @@ +%tr.line_notes_row.reply + %td{:colspan => 3} + = link_to "Reply", "#", :class => "line_note_reply_link", "line_code" => line_code, :title => "Add note for this line" diff --git a/app/views/notes/_show.html.haml b/app/views/notes/_show.html.haml index d91fea04..6da1d590 100644 --- a/app/views/notes/_show.html.haml +++ b/app/views/notes/_show.html.haml @@ -6,7 +6,7 @@ = time_ago_in_words(note.updated_at) ago - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) - = link_to "Remove", [@project, note], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "cred delete-note right" + %strong= link_to "Remove", [@project, note], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "cred delete-note btn small" %div.note-title = markdown(note.note) diff --git a/app/views/notes/create.js.haml b/app/views/notes/create.js.haml index b81ea5b0..646b491d 100644 --- a/app/views/notes/create.js.haml +++ b/app/views/notes/create.js.haml @@ -3,7 +3,10 @@ :plain $(".per_line_form").hide(); $('#new_note textarea').val(""); - $(".#{@note.line_code}").parent().after("#{escape_javascript(render :partial => "notes/per_line_show", :locals => {:note => @note})}"); + $("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})}"); - else :plain $("#new_note .errors").remove(); diff --git a/app/views/projects/wall.html.haml b/app/views/projects/wall.html.haml index f6c59e47..bd538e8f 100644 --- a/app/views/projects/wall.html.haml +++ b/app/views/projects/wall.html.haml @@ -1,6 +1,2 @@ %div.wall_page = render "notes/notes", :tid => nil, :tt => "wall" - -.loading{ :style => "display:none;"} - %center= image_tag "ajax-loader.gif" -