From 9da4d06a87a302f3f37ca95ba5b6e89cc66c0a82 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 10 Jan 2012 22:08:46 +0200 Subject: [PATCH 1/3] per line comments display --- app/assets/stylesheets/projects.css.scss | 28 +++++++++++++++++++ app/controllers/commits_controller.rb | 2 ++ app/models/note.rb | 17 +++++++++++ app/models/project.rb | 6 +++- app/views/commits/_text_file.html.haml | 7 +++++ .../20120110180749_add_line_number_to_note.rb | 5 ++++ db/schema.rb | 15 +++++++++- 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20120110180749_add_line_number_to_note.rb diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 0b43f557..bb942824 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 f6a19cc7..a938461f 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 e95df127..48cc2d80 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 93637822..420b8d1b 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 954722b1..5a6d7e44 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] == "-" diff --git a/db/migrate/20120110180749_add_line_number_to_note.rb b/db/migrate/20120110180749_add_line_number_to_note.rb new file mode 100644 index 00000000..9bdcce3c --- /dev/null +++ b/db/migrate/20120110180749_add_line_number_to_note.rb @@ -0,0 +1,5 @@ +class AddLineNumberToNote < ActiveRecord::Migration + def change + add_column :notes, :line_code, :string, :null => true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3014579c..935f108a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,19 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111220190817) do +ActiveRecord::Schema.define(:version => 20120110180749) do + + create_table "features", :force => true do |t| + t.string "name" + t.string "branch_name" + t.integer "assignee_id" + t.integer "author_id" + t.integer "project_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "version" + t.integer "status", :default => 0, :null => false + end create_table "issues", :force => true do |t| t.string "title" @@ -56,6 +68,7 @@ ActiveRecord::Schema.define(:version => 20111220190817) do t.datetime "updated_at" t.integer "project_id" t.string "attachment" + t.string "line_code" end create_table "projects", :force => true do |t| From 99bb4a153dc281c859073e0ddfd7c853e07ffe85 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 12 Jan 2012 00:26:01 +0200 Subject: [PATCH 2/3] per line comments w/o tests & with dirty code --- app/assets/images/add_comment.png | Bin 0 -> 823 bytes app/assets/javascripts/application.js | 2 + app/assets/stylesheets/commits.css.scss | 10 + app/helpers/commits_helper.rb | 7 + app/views/commits/_text_file.html.haml | 9 +- app/views/commits/show.html.haml | 12 + app/views/notes/_per_line_form.html.haml | 34 + app/views/notes/_per_line_show.html.haml | 5 + app/views/notes/create.js.haml | 19 +- db/test.sqlite3-journal | Bin 0 -> 6704 bytes nohup.out | 55305 +++++++++++++++++++++ 11 files changed, 55391 insertions(+), 12 deletions(-) create mode 100644 app/assets/images/add_comment.png create mode 100644 app/views/notes/_per_line_form.html.haml create mode 100644 app/views/notes/_per_line_show.html.haml create mode 100644 db/test.sqlite3-journal create mode 100644 nohup.out diff --git a/app/assets/images/add_comment.png b/app/assets/images/add_comment.png new file mode 100644 index 0000000000000000000000000000000000000000..1992303e7697ab615f6e21adb07a4dbe16ee2820 GIT binary patch literal 823 zcmV-71IYY|P)eIzihB zNMCqPCjcgBIsq^NumMa^c;%&Gg3=9O1DJsNq(gG4^Fe(6N;v6Mq$E!MKi{2W$8DU? zXI5u>U^Tbe1881;Y&IL&@ql~GJ>uT+NY|eGiu;WF;rd{&*UOE77WXMO6niF~;q%7$ z{8Q9ZI0fM31RJP=#i*xM1i(f7bH!5q8Fl3X7*|ld2w{{3AgEB-r`Z^F{vQQ2i$7ur zg72_6iPiaudz*WRJr!wu7HE4e1E3@HcQ_O+bI$w0zgwXeMc88V6YkU^K0X+FN22tbBMChB`9D9;7sA?+sJJSpWkuw=~&=x>!>I zn3c@+GB(FFa|QqmZ6Aim^C6BfP5>B`xaKVJGWEtffQ4+jX~?z|sh|pA%BN6c9(ppsrKYkVX7A)s0Htadw)b#geezA`-a5#8R0?<<*V?*0E9jxToKkW7g#XK zCuky@Qj5O^K()XD;rY$IOVnN$+oSp*lB5BkT;jUy$oNzM0oQ#o`W-8ObT+RJ%!nf_ zLf>QiASP`w6=roEtnRvYr5&%+NCa@e@EvQoaR)=#_6`*2;8Ru+oG_wKP7Ydv`f^8s zu!0bhv{|DJ0EEa3roz#4;YZZ*%2F0_v)%(HLhdFW_V{Io>m=*Myzc@)ZO-HyA8!4k z3p2N+YotuA3Ogy@6aZ(%n*iXnc-;V;7q1h57vgmR@J7520A7iw2H>4|N&sGprvl)u zcnSbsi!U-4$TFB-u9@f7xc~2P&Fv1L?f`xT7y##pj_88rk2e4S002ovPDHLkV1gbD BYH "OLD#{index}-#{line_old}" %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}  " + %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}  " - 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} + - comments.each do |note| + = render "notes/per_line_show", :note => note - if line[0] == "+" - line_new += 1 - elsif line[0] == "-" diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 44b7b8fa..42f72634 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -24,3 +24,15 @@ = render "commits/diff" = render "notes/notes" += render "notes/per_line_form" + + +:javascript + $(document).ready(function(){ + $(".line_content").live("click", function(e) { + var form = $(".per_line_form"); + $(this).parent().after(form); + form.find("#note_line_code").val($(this).attr("line_code")); + form.show(); + }); + }); diff --git a/app/views/notes/_per_line_form.html.haml b/app/views/notes/_per_line_form.html.haml new file mode 100644 index 00000000..13818113 --- /dev/null +++ b/app/views/notes/_per_line_form.html.haml @@ -0,0 +1,34 @@ +%table{:style => "display:none;"} + %tr.per_line_form + %td{:colspan => 3 } + %div + = form_for [@project, @note], :remote => "true", :multipart => true do |f| + -if @note.errors.any? + .errors.error + - @note.errors.full_messages.each do |msg| + %div= msg + + = f.hidden_field :noteable_id + = f.hidden_field :noteable_type + = f.hidden_field :line_code + + %div + = f.label :note + %cite.cgray markdown supported + %br + %br + = f.text_area :note, :size => 255 + + %p.notify_controls + %span Notify: + = check_box_tag :notify, 1, @note.noteable_type != "Commit" + = label_tag :notify, "Project team" + + -if @note.noteable_type == "Commit" + = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" + = label_tag :notify_author, "Commit author" + + .clear + %br + = f.submit 'Add note', :class => "grey-button", :id => "submit_note" + diff --git a/app/views/notes/_per_line_show.html.haml b/app/views/notes/_per_line_show.html.haml new file mode 100644 index 00000000..45e6825e --- /dev/null +++ b/app/views/notes/_per_line_show.html.haml @@ -0,0 +1,5 @@ +%tr.line_notes_row + %td{:colspan => 3} + %ul + = render :partial => "notes/show", :locals => {:note => note} + diff --git a/app/views/notes/create.js.haml b/app/views/notes/create.js.haml index cf804493..b81ea5b0 100644 --- a/app/views/notes/create.js.haml +++ b/app/views/notes/create.js.haml @@ -1,11 +1,18 @@ - if @note.valid? - :plain - $("#new_note .errors").remove(); - $('#note_note').val(""); - NoteList.prepend(#{@note.id}, "#{escape_javascript(render :partial => "notes/show", :locals => {:note => @note})}"); + - if @note.line_code + :plain + $(".per_line_form").hide(); + $('#new_note textarea').val(""); + $(".#{@note.line_code}").parent().after("#{escape_javascript(render :partial => "notes/per_line_show", :locals => {:note => @note})}"); + - else + :plain + $("#new_note .errors").remove(); + $('#new_note textarea').val(""); + NoteList.prepend(#{@note.id}, "#{escape_javascript(render :partial => "notes/show", :locals => {:note => @note})}"); - else - :plain - $("#new_note").replaceWith("#{escape_javascript(render('form'))}"); + - unless @note.line_code + :plain + $("#new_note").replaceWith("#{escape_javascript(render('form'))}"); :plain $("#submit_note").removeAttr("disabled"); diff --git a/db/test.sqlite3-journal b/db/test.sqlite3-journal new file mode 100644 index 0000000000000000000000000000000000000000..7a141a08c00730220fa4c848bf10e6da9d423889 GIT binary patch literal 6704 zcmZQzK!D?xGv5Pw(hLktK#Bz+G0GawAt1~J^4(~359c@@_1kC&;0yt1xi2zW4&V%; zQHjwI81^9mEeC{nK|URA4-EVG9`)d82w)2VXgR>l%Y21_jd>OW^B3mb%G2dsN z1>}x`(GVC7fdL2s=F<$K5Nm}vm^B%5Q;X75 Date: Thu, 12 Jan 2012 00:33:54 +0200 Subject: [PATCH 3/3] pybments.rb version up. gitignore improved --- .gitignore | 2 + Gemfile | 2 +- Gemfile.lock | 6 +- db/test.sqlite3-journal | Bin 6704 -> 0 bytes nohup.out | 55305 -------------------------------------- 5 files changed, 6 insertions(+), 55309 deletions(-) delete mode 100644 db/test.sqlite3-journal delete mode 100644 nohup.out diff --git a/.gitignore b/.gitignore index a6828714..74111a22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .bundle .rbx/ db/*.sqlite3 +db/*.sqlite3-journal log/*.log tmp/ .sass-cache/ @@ -9,3 +10,4 @@ coverage/* public/uploads/ .rvmrc .directory +nohup.out diff --git a/Gemfile b/Gemfile index e240fa65..603ef857 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem "six" gem "therubyracer" gem "faker" gem "seed-fu", "~> 2.1.0" -gem "pygments.rb", "0.2.3" +gem "pygments.rb", "0.2.4" gem "thin" gem "git" gem "acts_as_list" diff --git a/Gemfile.lock b/Gemfile.lock index 86a69981..25b7ee37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,8 +142,8 @@ GEM orm_adapter (0.0.5) polyglot (0.3.3) posix-spawn (0.3.6) - pygments.rb (0.2.3) - rubypython (>= 0.5.1) + pygments.rb (0.2.4) + rubypython (~> 0.5.3) rack (1.3.5) rack-cache (1.1) rack (>= 0.4) @@ -300,7 +300,7 @@ DEPENDENCIES kaminari launchy letter_opener - pygments.rb (= 0.2.3) + pygments.rb (= 0.2.4) rails (= 3.1.1) rails-footnotes (~> 3.7.5) rdiscount diff --git a/db/test.sqlite3-journal b/db/test.sqlite3-journal deleted file mode 100644 index 7a141a08c00730220fa4c848bf10e6da9d423889..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6704 zcmZQzK!D?xGv5Pw(hLktK#Bz+G0GawAt1~J^4(~359c@@_1kC&;0yt1xi2zW4&V%; zQHjwI81^9mEeC{nK|URA4-EVG9`)d82w)2VXgR>l%Y21_jd>OW^B3mb%G2dsN z1>}x`(GVC7fdL2s=F<$K5Nm}vm^B%5Q;X75