Commit f598cc789789bcde01e3c703d9149204247c0a46
1 parent
bda7fe38
Exists in
master
and in
4 other branches
change logic on line_code
Showing
9 changed files
with
54 additions
and
21 deletions
Show diff stats
app/assets/javascripts/notes.js
@@ -71,6 +71,10 @@ var NoteList = { | @@ -71,6 +71,10 @@ var NoteList = { | ||
71 | $(document).on("click", | 71 | $(document).on("click", |
72 | ".js-choose-note-attachment-button", | 72 | ".js-choose-note-attachment-button", |
73 | NoteList.chooseNoteAttachment); | 73 | NoteList.chooseNoteAttachment); |
74 | + | ||
75 | + $(document).on("click", | ||
76 | + ".js-show-outdated-discussion", | ||
77 | + function(e) { $(this).next('.outdated-discussion').show(); e.preventDefault() }); | ||
74 | }, | 78 | }, |
75 | 79 | ||
76 | 80 |
app/assets/stylesheets/sections/notes.scss
@@ -79,7 +79,7 @@ ul.notes { | @@ -79,7 +79,7 @@ ul.notes { | ||
79 | margin-top: 3px; | 79 | margin-top: 3px; |
80 | } | 80 | } |
81 | .attachment { | 81 | .attachment { |
82 | - font-size: 16px; | 82 | + font-size: 14px; |
83 | margin-top: -20px; | 83 | margin-top: -20px; |
84 | 84 | ||
85 | .icon-attachment { | 85 | .icon-attachment { |
@@ -92,7 +92,6 @@ ul.notes { | @@ -92,7 +92,6 @@ ul.notes { | ||
92 | } | 92 | } |
93 | .note-body { | 93 | .note-body { |
94 | margin-left: 45px; | 94 | margin-left: 45px; |
95 | - padding-top: 5px; | ||
96 | } | 95 | } |
97 | .note-header { | 96 | .note-header { |
98 | padding-bottom: 5px; | 97 | padding-bottom: 5px; |
@@ -284,7 +283,7 @@ ul.notes { | @@ -284,7 +283,7 @@ ul.notes { | ||
284 | font-size: 24px; | 283 | font-size: 24px; |
285 | padding: 4px; | 284 | padding: 4px; |
286 | position: absolute; | 285 | position: absolute; |
287 | - right: 0; | 286 | + right: 10px; |
288 | } | 287 | } |
289 | .note_preview { | 288 | .note_preview { |
290 | background: #f5f5f5; | 289 | background: #f5f5f5; |
@@ -307,3 +306,9 @@ ul.notes { | @@ -307,3 +306,9 @@ ul.notes { | ||
307 | .notes-busy { | 306 | .notes-busy { |
308 | margin: 18px; | 307 | margin: 18px; |
309 | } | 308 | } |
309 | + | ||
310 | +.note-image-attach { | ||
311 | + @extend .span4; | ||
312 | + @extend .thumbnail; | ||
313 | + margin-left: 45px; | ||
314 | +} |
app/helpers/commits_helper.rb
@@ -9,11 +9,13 @@ module CommitsHelper | @@ -9,11 +9,13 @@ module CommitsHelper | ||
9 | end | 9 | end |
10 | end | 10 | end |
11 | 11 | ||
12 | - def build_line_anchor(index, line_new, line_old) | ||
13 | - "#{index}_#{line_old}_#{line_new}" | 12 | + def build_line_anchor(diff, line_new, line_old) |
13 | + "#{hexdigest(diff.new_path)}_#{line_old}_#{line_new}" | ||
14 | end | 14 | end |
15 | 15 | ||
16 | - def each_diff_line(diff_arr, index) | 16 | + def each_diff_line(diff, index) |
17 | + diff_arr = diff.diff.lines.to_a | ||
18 | + | ||
17 | line_old = 1 | 19 | line_old = 1 |
18 | line_new = 1 | 20 | line_new = 1 |
19 | type = nil | 21 | type = nil |
@@ -39,7 +41,7 @@ module CommitsHelper | @@ -39,7 +41,7 @@ module CommitsHelper | ||
39 | next | 41 | next |
40 | else | 42 | else |
41 | type = identification_type(line) | 43 | type = identification_type(line) |
42 | - line_code = build_line_anchor(index, line_new, line_old) | 44 | + line_code = build_line_anchor(diff, line_new, line_old) |
43 | yield(full_line, type, line_code, line_new, line_old) | 45 | yield(full_line, type, line_code, line_new, line_old) |
44 | end | 46 | end |
45 | 47 |
app/helpers/notes_helper.rb
@@ -17,7 +17,7 @@ module NotesHelper | @@ -17,7 +17,7 @@ module NotesHelper | ||
17 | end | 17 | end |
18 | 18 | ||
19 | def link_to_merge_request_diff_line_note(note) | 19 | def link_to_merge_request_diff_line_note(note) |
20 | - if note.for_merge_request_diff_line? | 20 | + if note.for_merge_request_diff_line? and note.diff |
21 | link_to "#{note.diff_file_name}:L#{note.diff_new_line}", diffs_project_merge_request_path(note.project, note.noteable_id, anchor: note.line_code) | 21 | link_to "#{note.diff_file_name}:L#{note.diff_new_line}", diffs_project_merge_request_path(note.project, note.noteable_id, anchor: note.line_code) |
22 | end | 22 | end |
23 | end | 23 | end |
app/models/note.rb
@@ -33,7 +33,7 @@ class Note < ActiveRecord::Base | @@ -33,7 +33,7 @@ class Note < ActiveRecord::Base | ||
33 | delegate :name, :email, to: :author, prefix: true | 33 | delegate :name, :email, to: :author, prefix: true |
34 | 34 | ||
35 | validates :note, :project, presence: true | 35 | validates :note, :project, presence: true |
36 | - validates :line_code, format: { with: /\A\d+_\d+_\d+\Z/ }, allow_blank: true | 36 | + validates :line_code, format: { with: /\A[a-z0-9]+_\d+_\d+\Z/ }, allow_blank: true |
37 | validates :attachment, file_size: { maximum: 10.megabytes.to_i } | 37 | validates :attachment, file_size: { maximum: 10.megabytes.to_i } |
38 | 38 | ||
39 | validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } | 39 | validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' } |
@@ -69,11 +69,17 @@ class Note < ActiveRecord::Base | @@ -69,11 +69,17 @@ class Note < ActiveRecord::Base | ||
69 | end | 69 | end |
70 | 70 | ||
71 | def diff | 71 | def diff |
72 | - noteable.diffs[diff_file_index] | 72 | + if noteable.diffs.present? |
73 | + noteable.diffs.select do |d| | ||
74 | + if d.b_path | ||
75 | + Digest::SHA1.hexdigest(d.b_path) == diff_file_index | ||
76 | + end | ||
77 | + end.first | ||
78 | + end | ||
73 | end | 79 | end |
74 | 80 | ||
75 | def diff_file_index | 81 | def diff_file_index |
76 | - line_code.split('_')[0].to_i | 82 | + line_code.split('_')[0] |
77 | end | 83 | end |
78 | 84 | ||
79 | def diff_file_name | 85 | def diff_file_name |
@@ -85,7 +91,7 @@ class Note < ActiveRecord::Base | @@ -85,7 +91,7 @@ class Note < ActiveRecord::Base | ||
85 | end | 91 | end |
86 | 92 | ||
87 | def discussion_id | 93 | def discussion_id |
88 | - @discussion_id ||= [:discussion, noteable_type.underscore, noteable_id, line_code].join("-").to_sym | 94 | + @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id, line_code].join("-").to_sym |
89 | end | 95 | end |
90 | 96 | ||
91 | # Returns true if this is a downvote note, | 97 | # Returns true if this is a downvote note, |
app/views/commits/_text_diff.html.haml
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | %a.supp_diff_link Diff suppressed. Click to show | 3 | %a.supp_diff_link Diff suppressed. Click to show |
4 | 4 | ||
5 | %table{class: "#{'hide' if too_big}"} | 5 | %table{class: "#{'hide' if too_big}"} |
6 | - - each_diff_line(diff.diff.lines.to_a, index) do |line, type, line_code, line_new, line_old| | 6 | + - each_diff_line(diff, index) do |line, type, line_code, line_new, line_old| |
7 | %tr.line_holder{ id: line_code } | 7 | %tr.line_holder{ id: line_code } |
8 | - if type == "match" | 8 | - if type == "match" |
9 | %td.old_line= "..." | 9 | %td.old_line= "..." |
app/views/notes/_discussion.html.haml
@@ -12,8 +12,15 @@ | @@ -12,8 +12,15 @@ | ||
12 | %div | 12 | %div |
13 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" | 13 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" |
14 | - if note.for_merge_request? | 14 | - if note.for_merge_request? |
15 | - started a discussion on this merge request diff | ||
16 | - = link_to_merge_request_diff_line_note(note) | 15 | + - if note.diff |
16 | + started a discussion on this merge request diff | ||
17 | + = link_to_merge_request_diff_line_note(note) | ||
18 | + - else | ||
19 | + started | ||
20 | + %strong | ||
21 | + %i.icon-remove | ||
22 | + outdated | ||
23 | + discussion on this merge request diff | ||
17 | - elsif note.for_commit? | 24 | - elsif note.for_commit? |
18 | started a discussion on commit | 25 | started a discussion on commit |
19 | #{link_to note.noteable.short_id, project_commit_path(@project, note.noteable)} | 26 | #{link_to note.noteable.short_id, project_commit_path(@project, note.noteable)} |
@@ -29,8 +36,17 @@ | @@ -29,8 +36,17 @@ | ||
29 | ago | 36 | ago |
30 | .discussion-body | 37 | .discussion-body |
31 | - if note.for_diff_line? | 38 | - if note.for_diff_line? |
32 | - .content | ||
33 | - .diff_file= render "notes/discussion_diff", discussion_notes: discussion_notes, note: note | 39 | + - if note.diff |
40 | + .content | ||
41 | + .diff_file= render "notes/discussion_diff", discussion_notes: discussion_notes, note: note | ||
42 | + - else | ||
43 | + = link_to 'show outdated discussion', '#', class: 'js-show-outdated-discussion' | ||
44 | + %div.hide.outdated-discussion | ||
45 | + .content | ||
46 | + .notes{ rel: discussion_notes.first.discussion_id } | ||
47 | + = render discussion_notes | ||
48 | + | ||
49 | + | ||
34 | - else | 50 | - else |
35 | .content | 51 | .content |
36 | .notes{ rel: discussion_notes.first.discussion_id } | 52 | .notes{ rel: discussion_notes.first.discussion_id } |
app/views/notes/_discussion_diff.html.haml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | %br/ | 9 | %br/ |
10 | .diff_file_content | 10 | .diff_file_content |
11 | %table | 11 | %table |
12 | - - each_diff_line(diff.diff.lines.to_a, note.diff_file_index) do |line, type, line_code, line_new, line_old| | 12 | + - each_diff_line(diff, note.diff_file_index) do |line, type, line_code, line_new, line_old| |
13 | %tr.line_holder{ id: line_code } | 13 | %tr.line_holder{ id: line_code } |
14 | - if type == "match" | 14 | - if type == "match" |
15 | %td.old_line= "..." | 15 | %td.old_line= "..." |
app/views/notes/_note.html.haml
@@ -6,8 +6,8 @@ | @@ -6,8 +6,8 @@ | ||
6 | Link here | 6 | Link here |
7 | | 7 | |
8 | - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) | 8 | - if(note.author_id == current_user.id) || can?(current_user, :admin_note, @project) |
9 | - = link_to project_note_path(@project, note), title: "Remove comment", method: :delete, confirm: 'Are you sure?', remote: true, class: "danger js-note-delete" do | ||
10 | - %i.icon-remove-circle | 9 | + = link_to project_note_path(@project, note), title: "Remove comment", method: :delete, confirm: 'Are you sure you want to remove comment?', remote: true, class: "danger js-note-delete" do |
10 | + %i.icon-trash.cred | ||
11 | = image_tag gravatar_icon(note.author.email), class: "avatar s32" | 11 | = image_tag gravatar_icon(note.author.email), class: "avatar s32" |
12 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" | 12 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" |
13 | %span.note-last-update | 13 | %span.note-last-update |
@@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
29 | = markdown(note.note) | 29 | = markdown(note.note) |
30 | - if note.attachment.url | 30 | - if note.attachment.url |
31 | - if note.attachment.image? | 31 | - if note.attachment.image? |
32 | - = image_tag note.attachment.url, class: 'thumbnail span4' | 32 | + = image_tag note.attachment.url, class: 'note-image-attach' |
33 | .attachment.right | 33 | .attachment.right |
34 | = link_to note.attachment.url, target: "_blank" do | 34 | = link_to note.attachment.url, target: "_blank" do |
35 | %i.icon-attachment | 35 | %i.icon-attachment |