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 | 71 | $(document).on("click", |
72 | 72 | ".js-choose-note-attachment-button", |
73 | 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 | 79 | margin-top: 3px; |
80 | 80 | } |
81 | 81 | .attachment { |
82 | - font-size: 16px; | |
82 | + font-size: 14px; | |
83 | 83 | margin-top: -20px; |
84 | 84 | |
85 | 85 | .icon-attachment { |
... | ... | @@ -92,7 +92,6 @@ ul.notes { |
92 | 92 | } |
93 | 93 | .note-body { |
94 | 94 | margin-left: 45px; |
95 | - padding-top: 5px; | |
96 | 95 | } |
97 | 96 | .note-header { |
98 | 97 | padding-bottom: 5px; |
... | ... | @@ -284,7 +283,7 @@ ul.notes { |
284 | 283 | font-size: 24px; |
285 | 284 | padding: 4px; |
286 | 285 | position: absolute; |
287 | - right: 0; | |
286 | + right: 10px; | |
288 | 287 | } |
289 | 288 | .note_preview { |
290 | 289 | background: #f5f5f5; |
... | ... | @@ -307,3 +306,9 @@ ul.notes { |
307 | 306 | .notes-busy { |
308 | 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 | 9 | end |
10 | 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 | 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 | 19 | line_old = 1 |
18 | 20 | line_new = 1 |
19 | 21 | type = nil |
... | ... | @@ -39,7 +41,7 @@ module CommitsHelper |
39 | 41 | next |
40 | 42 | else |
41 | 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 | 45 | yield(full_line, type, line_code, line_new, line_old) |
44 | 46 | end |
45 | 47 | ... | ... |
app/helpers/notes_helper.rb
... | ... | @@ -17,7 +17,7 @@ module NotesHelper |
17 | 17 | end |
18 | 18 | |
19 | 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 | 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 | 22 | end |
23 | 23 | end | ... | ... |
app/models/note.rb
... | ... | @@ -33,7 +33,7 @@ class Note < ActiveRecord::Base |
33 | 33 | delegate :name, :email, to: :author, prefix: true |
34 | 34 | |
35 | 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 | 37 | validates :attachment, file_size: { maximum: 10.megabytes.to_i } |
38 | 38 | |
39 | 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 | 69 | end |
70 | 70 | |
71 | 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 | 79 | end |
74 | 80 | |
75 | 81 | def diff_file_index |
76 | - line_code.split('_')[0].to_i | |
82 | + line_code.split('_')[0] | |
77 | 83 | end |
78 | 84 | |
79 | 85 | def diff_file_name |
... | ... | @@ -85,7 +91,7 @@ class Note < ActiveRecord::Base |
85 | 91 | end |
86 | 92 | |
87 | 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 | 95 | end |
90 | 96 | |
91 | 97 | # Returns true if this is a downvote note, | ... | ... |
app/views/commits/_text_diff.html.haml
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | %a.supp_diff_link Diff suppressed. Click to show |
4 | 4 | |
5 | 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 | 7 | %tr.line_holder{ id: line_code } |
8 | 8 | - if type == "match" |
9 | 9 | %td.old_line= "..." | ... | ... |
app/views/notes/_discussion.html.haml
... | ... | @@ -12,8 +12,15 @@ |
12 | 12 | %div |
13 | 13 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" |
14 | 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 | 24 | - elsif note.for_commit? |
18 | 25 | started a discussion on commit |
19 | 26 | #{link_to note.noteable.short_id, project_commit_path(@project, note.noteable)} |
... | ... | @@ -29,8 +36,17 @@ |
29 | 36 | ago |
30 | 37 | .discussion-body |
31 | 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 | 50 | - else |
35 | 51 | .content |
36 | 52 | .notes{ rel: discussion_notes.first.discussion_id } | ... | ... |
app/views/notes/_discussion_diff.html.haml
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | %br/ |
10 | 10 | .diff_file_content |
11 | 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 | 13 | %tr.line_holder{ id: line_code } |
14 | 14 | - if type == "match" |
15 | 15 | %td.old_line= "..." | ... | ... |
app/views/notes/_note.html.haml
... | ... | @@ -6,8 +6,8 @@ |
6 | 6 | Link here |
7 | 7 | |
8 | 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 | 11 | = image_tag gravatar_icon(note.author.email), class: "avatar s32" |
12 | 12 | = link_to note.author_name, project_team_member_path(@project, @project.team_member_by_id(note.author)), class: "note-author" |
13 | 13 | %span.note-last-update |
... | ... | @@ -29,7 +29,7 @@ |
29 | 29 | = markdown(note.note) |
30 | 30 | - if note.attachment.url |
31 | 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 | 33 | .attachment.right |
34 | 34 | = link_to note.attachment.url, target: "_blank" do |
35 | 35 | %i.icon-attachment | ... | ... |