From 674cbe1534442f2149a3b787a24b5db3cb581d55 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 25 Jun 2014 11:40:33 +0300 Subject: Fix diff comments toggle button Signed-off-by: Dmitriy Zaporozhets --- app/assets/javascripts/application.js.coffee | 8 +++++++ app/views/projects/commits/_diffs.html.haml | 4 ++-- .../_diff_notes_with_reply_parallel.html.haml | 6 +++-- .../projects/notes/_discussion_diff.html.haml | 26 ---------------------- .../projects/notes/discussions/_active.html.haml | 2 +- .../projects/notes/discussions/_commit.html.haml | 2 +- .../projects/notes/discussions/_diff.html.haml | 26 ++++++++++++++++++++++ .../projects/notes/discussions/_outdated.html.haml | 2 +- features/steps/project/merge_requests.rb | 8 +++---- 9 files changed, 46 insertions(+), 38 deletions(-) delete mode 100644 app/views/projects/notes/_discussion_diff.html.haml create mode 100644 app/views/projects/notes/discussions/_diff.html.haml diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 9bcd8f0a171..5b124554c38 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -143,6 +143,14 @@ $ -> $(@).next('table').show() $(@).remove() + # Show/hide comments on diff + $("body").on "click", ".js-toggle-diff-comments", (e) -> + $(@).find('i'). + toggleClass('icon-chevron-down'). + toggleClass('icon-chevron-up') + $(@).closest(".diff-file").find(".notes_holder").toggle() + e.preventDefault() + (($) -> # Disable an element and add the 'disabled' Bootstrap class $.fn.extend disable: -> diff --git a/app/views/projects/commits/_diffs.html.haml b/app/views/projects/commits/_diffs.html.haml index a62f50776fa..fcdb40468d9 100644 --- a/app/views/projects/commits/_diffs.html.haml +++ b/app/views/projects/commits/_diffs.html.haml @@ -45,7 +45,7 @@ - file = project.repository.blob_at(@commit.id, diff.new_path) - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file - next unless file - .diff-file.js-toggle-container{id: "diff-#{i}"} + .diff-file{id: "diff-#{i}"} .diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"} - if diff.deleted_file %span= diff.old_path @@ -61,7 +61,7 @@ %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" .diff-btn-group - = link_to "#", class: "js-toggle-button btn btn-small" do + = link_to "#", class: "js-toggle-diff-comments btn btn-small" do %i.icon-chevron-down Diff comments   diff --git a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml index 279b04e5047..8adf903a9a1 100644 --- a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml +++ b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml @@ -12,7 +12,8 @@ %ul.notes{ rel: note1.discussion_id } = render notes1 - = link_to_reply_diff(note1) + .discussion-reply-holder + = link_to_reply_diff(note1) - else %td= "" %td= "" @@ -26,7 +27,8 @@ %ul.notes{ rel: note2.discussion_id } = render notes2 - = link_to_reply_diff(note2) + .discussion-reply-holder + = link_to_reply_diff(note2) - else %td= "" %td= "" diff --git a/app/views/projects/notes/_discussion_diff.html.haml b/app/views/projects/notes/_discussion_diff.html.haml deleted file mode 100644 index 26c5494f466..00000000000 --- a/app/views/projects/notes/_discussion_diff.html.haml +++ /dev/null @@ -1,26 +0,0 @@ -- diff = note.diff -- if diff - .diff-file - .diff-header - - if diff.deleted_file - %span= diff.old_path - - else - %span= diff.new_path - - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode - %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" - %br/ - .diff-content - %table - - each_diff_line_near(diff, note.diff_file_index, note.line_code) do |line, type, line_code, line_new, line_old| - %tr.line_holder{ id: line_code } - - if type == "match" - %td.old_line= "..." - %td.new_line= "..." - %td.line_content.matched= line - - else - %td.old_line= raw(type == "new" ? " " : line_old) - %td.new_line= raw(type == "old" ? " " : line_new) - %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line}  " - - - if line_code == note.line_code - = render "projects/notes/diff_notes_with_reply", notes: discussion_notes diff --git a/app/views/projects/notes/discussions/_active.html.haml b/app/views/projects/notes/discussions/_active.html.haml index c242e68ee73..ef296b35dd5 100644 --- a/app/views/projects/notes/discussions/_active.html.haml +++ b/app/views/projects/notes/discussions/_active.html.haml @@ -18,4 +18,4 @@ %span.discussion-last-update #{time_ago_with_tooltip(last_note.updated_at, 'bottom', 'discussion_updated_ago')} .discussion-body.js-toggle-content - = render "projects/notes/discussion_diff", discussion_notes: discussion_notes, note: note + = render "projects/notes/discussions/diff", discussion_notes: discussion_notes, note: note diff --git a/app/views/projects/notes/discussions/_commit.html.haml b/app/views/projects/notes/discussions/_commit.html.haml index f8ec4e972e0..78460974a9b 100644 --- a/app/views/projects/notes/discussions/_commit.html.haml +++ b/app/views/projects/notes/discussions/_commit.html.haml @@ -18,7 +18,7 @@ #{time_ago_with_tooltip(last_note.updated_at, 'bottom', 'discussion_updated_ago')} .discussion-body.js-toggle-content - if note.for_diff_line? - = render "projects/notes/discussion_diff", discussion_notes: discussion_notes, note: note + = render "projects/notes/discussions/diff", discussion_notes: discussion_notes, note: note - else .panel.panel-default .notes{ rel: discussion_notes.first.discussion_id } diff --git a/app/views/projects/notes/discussions/_diff.html.haml b/app/views/projects/notes/discussions/_diff.html.haml new file mode 100644 index 00000000000..26c5494f466 --- /dev/null +++ b/app/views/projects/notes/discussions/_diff.html.haml @@ -0,0 +1,26 @@ +- diff = note.diff +- if diff + .diff-file + .diff-header + - if diff.deleted_file + %span= diff.old_path + - else + %span= diff.new_path + - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode + %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" + %br/ + .diff-content + %table + - each_diff_line_near(diff, note.diff_file_index, note.line_code) do |line, type, line_code, line_new, line_old| + %tr.line_holder{ id: line_code } + - if type == "match" + %td.old_line= "..." + %td.new_line= "..." + %td.line_content.matched= line + - else + %td.old_line= raw(type == "new" ? " " : line_old) + %td.new_line= raw(type == "old" ? " " : line_new) + %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw "#{line}  " + + - if line_code == note.line_code + = render "projects/notes/diff_notes_with_reply", notes: discussion_notes diff --git a/app/views/projects/notes/discussions/_outdated.html.haml b/app/views/projects/notes/discussions/_outdated.html.haml index 51ee0cc9d3f..67c29be8ac1 100644 --- a/app/views/projects/notes/discussions/_outdated.html.haml +++ b/app/views/projects/notes/discussions/_outdated.html.haml @@ -17,4 +17,4 @@ %span.discussion-last-update #{time_ago_with_tooltip(last_note.updated_at, 'bottom', 'discussion_updated_ago')} .discussion-body.js-toggle-content.hide - = render "projects/notes/discussion_diff", discussion_notes: discussion_notes, note: note + = render "projects/notes/discussions/diff", discussion_notes: discussion_notes, note: note diff --git a/features/steps/project/merge_requests.rb b/features/steps/project/merge_requests.rb index c98f160ad2e..b0a6e530e8a 100644 --- a/features/steps/project/merge_requests.rb +++ b/features/steps/project/merge_requests.rb @@ -131,8 +131,8 @@ class ProjectMergeRequests < Spinach::FeatureSteps end step 'I should see a discussion has started on line 185' do - page.should have_content "#{current_user.name} started a discussion on this merge request diff" - page.should have_content "app/assets/stylesheets/tree.scss:L185" + page.should have_content "#{current_user.name} started a discussion" + page.should have_content "app/assets/stylesheets/tree.scss" page.should have_content "Line is wrong" end @@ -257,9 +257,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps click_button "Add Comment" end - within ".note-text" do - page.should have_content message - end + page.should have_content message end def init_diff_note_first_file -- cgit v1.2.1