Commit 6cf000ff52f34d0dd1afc823985adbe072c23515

Authored by Dmitriy Zaporozhets
2 parents c8b955a4 7f92534f

Merge branch 'per_line_comment'

Conflicts:
	app/assets/stylesheets/projects.css.scss
1 .bundle 1 .bundle
2 .rbx/ 2 .rbx/
3 db/*.sqlite3 3 db/*.sqlite3
  4 +db/*.sqlite3-journal
4 log/*.log 5 log/*.log
5 tmp/ 6 tmp/
6 .sass-cache/ 7 .sass-cache/
@@ -9,3 +10,4 @@ coverage/* @@ -9,3 +10,4 @@ coverage/*
9 public/uploads/ 10 public/uploads/
10 .rvmrc 11 .rvmrc
11 .directory 12 .directory
  13 +nohup.out
@@ -16,7 +16,7 @@ gem "six" @@ -16,7 +16,7 @@ gem "six"
16 gem "therubyracer" 16 gem "therubyracer"
17 gem "faker" 17 gem "faker"
18 gem "seed-fu", "~> 2.1.0" 18 gem "seed-fu", "~> 2.1.0"
19 -gem "pygments.rb", "0.2.3" 19 +gem "pygments.rb", "0.2.4"
20 gem "thin" 20 gem "thin"
21 gem "git" 21 gem "git"
22 gem "acts_as_list" 22 gem "acts_as_list"
@@ -145,8 +145,8 @@ GEM @@ -145,8 +145,8 @@ GEM
145 orm_adapter (0.0.5) 145 orm_adapter (0.0.5)
146 polyglot (0.3.3) 146 polyglot (0.3.3)
147 posix-spawn (0.3.6) 147 posix-spawn (0.3.6)
148 - pygments.rb (0.2.3)  
149 - rubypython (>= 0.5.1) 148 + pygments.rb (0.2.4)
  149 + rubypython (~> 0.5.3)
150 rack (1.3.5) 150 rack (1.3.5)
151 rack-cache (1.1) 151 rack-cache (1.1)
152 rack (>= 0.4) 152 rack (>= 0.4)
@@ -306,7 +306,7 @@ DEPENDENCIES @@ -306,7 +306,7 @@ DEPENDENCIES
306 kaminari 306 kaminari
307 launchy 307 launchy
308 letter_opener 308 letter_opener
309 - pygments.rb (= 0.2.3) 309 + pygments.rb (= 0.2.4)
310 rails (= 3.1.1) 310 rails (= 3.1.1)
311 rails-footnotes (~> 3.7.5) 311 rails-footnotes (~> 3.7.5)
312 rdiscount 312 rdiscount
app/assets/images/add_comment.png 0 → 100644

823 Bytes

app/assets/javascripts/application.js
@@ -82,3 +82,5 @@ function showMenu() { @@ -82,3 +82,5 @@ function showMenu() {
82 function resetMenu() { 82 function resetMenu() {
83 $(this).removeClass("hover"); 83 $(this).removeClass("hover");
84 } 84 }
  85 +
  86 +
app/assets/stylesheets/commits.css.scss
@@ -96,3 +96,13 @@ ul.bordered-list { @@ -96,3 +96,13 @@ ul.bordered-list {
96 } 96 }
97 97
98 ul.bordered-list li:last-child { border:none } 98 ul.bordered-list li:last-child { border:none }
  99 +
  100 +.line_holder {
  101 + cursor:pointer;
  102 +
  103 + &:hover {
  104 + td {
  105 + background: #FFFFCF !important;
  106 + }
  107 + }
  108 +}
app/assets/stylesheets/projects.css.scss
@@ -726,3 +726,31 @@ a.project-update.titled { @@ -726,3 +726,31 @@ a.project-update.titled {
726 float:left; 726 float:left;
727 } 727 }
728 } 728 }
  729 +
  730 +tr.line_notes_row {
  731 + &:hover {
  732 + background:none;
  733 + }
  734 + td {
  735 + margin:0px;
  736 + padding:0px;
  737 + border-bottom:1px solid #DEE2E3;
  738 +
  739 +
  740 + ul {
  741 + display:block;
  742 + list-style:none;
  743 + margin:0px;
  744 + padding:0px;
  745 +
  746 + li {
  747 + border-top:1px solid #DEE2E3;
  748 + padding:10px;
  749 +
  750 + .delete-note {
  751 + display:none;
  752 + }
  753 + }
  754 + }
  755 + }
  756 +}
app/controllers/commits_controller.rb
@@ -27,6 +27,8 @@ class CommitsController < ApplicationController @@ -27,6 +27,8 @@ class CommitsController < ApplicationController
27 @notes = project.commit_notes(@commit).fresh.limit(20) 27 @notes = project.commit_notes(@commit).fresh.limit(20)
28 @note = @project.build_commit_note(@commit) 28 @note = @project.build_commit_note(@commit)
29 29
  30 + @line_notes = project.commit_line_notes(@commit)
  31 +
30 respond_to do |format| 32 respond_to do |format|
31 format.html 33 format.html
32 format.js { respond_with_notes } 34 format.js { respond_with_notes }
app/helpers/commits_helper.rb
@@ -42,4 +42,11 @@ module CommitsHelper @@ -42,4 +42,11 @@ module CommitsHelper
42 preserve out 42 preserve out
43 end 43 end
44 44
  45 + def build_line_code(line, index, line_new, line_old)
  46 + if diff_line_class(line) == "new"
  47 + "NEW_#{index}_#{line_new}"
  48 + else
  49 + "OLD_#{index}_#{line_old}"
  50 + end
  51 + end
45 end 52 end
app/models/note.rb
@@ -53,6 +53,23 @@ class Note < ActiveRecord::Base @@ -53,6 +53,23 @@ class Note < ActiveRecord::Base
53 noteable 53 noteable
54 end 54 end
55 end 55 end
  56 +
  57 + def line_file_id
  58 + @line_file_id ||= line_code.split("_")[1].to_i if line_code
  59 + end
  60 +
  61 + def line_type_id
  62 + @line_type_id ||= line_code.split("_").first if line_code
  63 + end
  64 +
  65 + def line_number
  66 + @line_number ||= line_code.split("_").last.to_i if line_code
  67 + end
  68 +
  69 + def for_line?(file_id, old_line, new_line)
  70 + line_file_id == file_id &&
  71 + ((line_type_id == "NEW" && line_number == new_line) || (line_type_id == "OLD" && line_number == old_line ))
  72 + end
56 end 73 end
57 # == Schema Information 74 # == Schema Information
58 # 75 #
app/models/project.rb
@@ -166,7 +166,11 @@ class Project < ActiveRecord::Base @@ -166,7 +166,11 @@ class Project < ActiveRecord::Base
166 end 166 end
167 167
168 def commit_notes(commit) 168 def commit_notes(commit)
169 - notes.where(:noteable_id => commit.id, :noteable_type => "Commit") 169 + notes.where(:noteable_id => commit.id, :noteable_type => "Commit", :line_code => nil)
  170 + end
  171 +
  172 + def commit_line_notes(commit)
  173 + notes.where(:noteable_id => commit.id, :noteable_type => "Commit").where("line_code not null")
170 end 174 end
171 175
172 def has_commits? 176 def has_commits?
app/views/commits/_text_file.html.haml
@@ -18,7 +18,11 @@ @@ -18,7 +18,11 @@
18 = link_to raw(diff_line_class(line) == "new" ? " " : line_old), "#OLD#{index}-#{line_old}", :id => "OLD#{index}-#{line_old}" 18 = link_to raw(diff_line_class(line) == "new" ? " " : line_old), "#OLD#{index}-#{line_old}", :id => "OLD#{index}-#{line_old}"
19 %td.new_line 19 %td.new_line
20 = link_to raw(diff_line_class(line) == "old" ? " " : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}" 20 = link_to raw(diff_line_class(line) == "old" ? " " : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}"
21 - %td.line_content{:class => diff_line_class(full_line)}= raw "#{full_line}  " 21 + %td.line_content{:class => "#{diff_line_class(full_line)} #{build_line_code(line, index, line_new, line_old)}", "line_code" => build_line_code(line, index, line_new, line_old)}= raw "#{full_line}  "
  22 + - comments = @line_notes.select { |n| n.for_line?(index, line_old, line_new) }.sort_by(&:created_at).reverse
  23 + - unless comments.empty?
  24 + - comments.each do |note|
  25 + = render "notes/per_line_show", :note => note
22 - if line[0] == "+" 26 - if line[0] == "+"
23 - line_new += 1 27 - line_new += 1
24 - elsif line[0] == "-" 28 - elsif line[0] == "-"
app/views/commits/show.html.haml
@@ -24,3 +24,15 @@ @@ -24,3 +24,15 @@
24 24
25 = render "commits/diff" 25 = render "commits/diff"
26 = render "notes/notes" 26 = render "notes/notes"
  27 += render "notes/per_line_form"
  28 +
  29 +
  30 +:javascript
  31 + $(document).ready(function(){
  32 + $(".line_content").live("dblclick", function(e) {
  33 + var form = $(".per_line_form");
  34 + $(this).parent().after(form);
  35 + form.find("#note_line_code").val($(this).attr("line_code"));
  36 + form.show();
  37 + });
  38 + });
app/views/notes/_per_line_form.html.haml 0 → 100644
@@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
  1 +%table{:style => "display:none;"}
  2 + %tr.per_line_form
  3 + %td{:colspan => 3 }
  4 + %div
  5 + = form_for [@project, @note], :remote => "true", :multipart => true do |f|
  6 + -if @note.errors.any?
  7 + .errors.error
  8 + - @note.errors.full_messages.each do |msg|
  9 + %div= msg
  10 +
  11 + = f.hidden_field :noteable_id
  12 + = f.hidden_field :noteable_type
  13 + = f.hidden_field :line_code
  14 +
  15 + %div
  16 + = f.label :note
  17 + %cite.cgray markdown supported
  18 + %br
  19 + %br
  20 + = f.text_area :note, :size => 255
  21 +
  22 + %p.notify_controls
  23 + %span Notify:
  24 + = check_box_tag :notify, 1, @note.noteable_type != "Commit"
  25 + = label_tag :notify, "Project team"
  26 +
  27 + -if @note.noteable_type == "Commit"
  28 + = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
  29 + = label_tag :notify_author, "Commit author"
  30 +
  31 + .clear
  32 + %br
  33 + = f.submit 'Add note', :class => "grey-button", :id => "submit_note"
  34 +
app/views/notes/_per_line_show.html.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +%tr.line_notes_row
  2 + %td{:colspan => 3}
  3 + %ul
  4 + = render :partial => "notes/show", :locals => {:note => note}
  5 +
app/views/notes/create.js.haml
1 - if @note.valid? 1 - if @note.valid?
2 - :plain  
3 - $("#new_note .errors").remove();  
4 - $('#note_note').val("");  
5 - NoteList.prepend(#{@note.id}, "#{escape_javascript(render :partial => "notes/show", :locals => {:note => @note})}"); 2 + - if @note.line_code
  3 + :plain
  4 + $(".per_line_form").hide();
  5 + $('#new_note textarea').val("");
  6 + $(".#{@note.line_code}").parent().after("#{escape_javascript(render :partial => "notes/per_line_show", :locals => {:note => @note})}");
  7 + - else
  8 + :plain
  9 + $("#new_note .errors").remove();
  10 + $('#new_note textarea').val("");
  11 + NoteList.prepend(#{@note.id}, "#{escape_javascript(render :partial => "notes/show", :locals => {:note => @note})}");
6 - else 12 - else
7 - :plain  
8 - $("#new_note").replaceWith("#{escape_javascript(render('form'))}"); 13 + - unless @note.line_code
  14 + :plain
  15 + $("#new_note").replaceWith("#{escape_javascript(render('form'))}");
9 16
10 :plain 17 :plain
11 $("#submit_note").removeAttr("disabled"); 18 $("#submit_note").removeAttr("disabled");
db/migrate/20120110180749_add_line_number_to_note.rb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +class AddLineNumberToNote < ActiveRecord::Migration
  2 + def change
  3 + add_column :notes, :line_code, :string, :null => true
  4 + end
  5 +end
@@ -11,7 +11,19 @@ @@ -11,7 +11,19 @@
11 # 11 #
12 # It's strongly recommended to check this file into your version control system. 12 # It's strongly recommended to check this file into your version control system.
13 13
14 -ActiveRecord::Schema.define(:version => 20111220190817) do 14 +ActiveRecord::Schema.define(:version => 20120110180749) do
  15 +
  16 + create_table "features", :force => true do |t|
  17 + t.string "name"
  18 + t.string "branch_name"
  19 + t.integer "assignee_id"
  20 + t.integer "author_id"
  21 + t.integer "project_id"
  22 + t.datetime "created_at"
  23 + t.datetime "updated_at"
  24 + t.string "version"
  25 + t.integer "status", :default => 0, :null => false
  26 + end
15 27
16 create_table "issues", :force => true do |t| 28 create_table "issues", :force => true do |t|
17 t.string "title" 29 t.string "title"
@@ -56,6 +68,7 @@ ActiveRecord::Schema.define(:version =&gt; 20111220190817) do @@ -56,6 +68,7 @@ ActiveRecord::Schema.define(:version =&gt; 20111220190817) do
56 t.datetime "updated_at" 68 t.datetime "updated_at"
57 t.integer "project_id" 69 t.integer "project_id"
58 t.string "attachment" 70 t.string "attachment"
  71 + t.string "line_code"
59 end 72 end
60 73
61 create_table "projects", :force => true do |t| 74 create_table "projects", :force => true do |t|