diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-01-11 00:08:46 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-01-11 00:08:46 +0400 |
commit | 9da4d06a87a302f3f37ca95ba5b6e89cc66c0a82 (patch) | |
tree | aa3d15cda5bcb5ddcf5b56334c498bd7f3ea3be5 /app | |
parent | c66bc99fb7d22d005cf0de687b9535f8bef52e23 (diff) |
per line comments display
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/projects.css.scss | 28 | ||||
-rw-r--r-- | app/controllers/commits_controller.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 17 | ||||
-rw-r--r-- | app/models/project.rb | 6 | ||||
-rw-r--r-- | app/views/commits/_text_file.html.haml | 7 |
5 files changed, 59 insertions, 1 deletions
diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 0b43f55789d..bb9428244f2 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -693,3 +693,31 @@ a.project-update.titled { top: 0; } } + +tr.line_notes_row { + &:hover { + background:none; + } + td { + margin:0px; + padding:0px; + border-bottom:1px solid #DEE2E3; + + + ul { + display:block; + list-style:none; + margin:0px; + padding:0px; + + li { + border-top:1px solid #DEE2E3; + padding:10px; + + .delete-note { + display:none; + } + } + } + } +} diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index f6a19cc7b40..a938461fed1 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -27,6 +27,8 @@ class CommitsController < ApplicationController @notes = project.commit_notes(@commit).fresh.limit(20) @note = @project.build_commit_note(@commit) + @line_notes = project.commit_line_notes(@commit) + respond_to do |format| format.html format.js { respond_with_notes } diff --git a/app/models/note.rb b/app/models/note.rb index e95df127e95..48cc2d80f8a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -53,6 +53,23 @@ class Note < ActiveRecord::Base noteable end end + + def line_file_id + @line_file_id ||= line_code.split("_")[1].to_i if line_code + end + + def line_type_id + @line_type_id ||= line_code.split("_").first if line_code + end + + def line_number + @line_number ||= line_code.split("_").last.to_i if line_code + end + + def for_line?(file_id, old_line, new_line) + line_file_id == file_id && + ((line_type_id == "NEW" && line_number == new_line) || (line_type_id == "OLD" && line_number == old_line )) + end end # == Schema Information # diff --git a/app/models/project.rb b/app/models/project.rb index 93637822a74..420b8d1ba3e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -166,7 +166,11 @@ class Project < ActiveRecord::Base end def commit_notes(commit) - notes.where(:noteable_id => commit.id, :noteable_type => "Commit") + notes.where(:noteable_id => commit.id, :noteable_type => "Commit", :line_code => nil) + end + + def commit_line_notes(commit) + notes.where(:noteable_id => commit.id, :noteable_type => "Commit").where("line_code not null") end def has_commits? diff --git a/app/views/commits/_text_file.html.haml b/app/views/commits/_text_file.html.haml index 954722b1f31..5a6d7e44891 100644 --- a/app/views/commits/_text_file.html.haml +++ b/app/views/commits/_text_file.html.haml @@ -19,6 +19,13 @@ %td.new_line = link_to raw(diff_line_class(line) == "old" ? " " : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}" %td.line_content{:class => diff_line_class(full_line)}= raw "#{full_line} " + - comments = @line_notes.select { |n| n.for_line?(index, line_old, line_new) }.sort_by(&:created_at).reverse + - unless comments.empty? + %tr.line_notes_row + %td{:colspan => 3} + %ul + - comments.each do |note| + = render :partial => "notes/show", :locals => {:note => note} - if line[0] == "+" - line_new += 1 - elsif line[0] == "-" |