From: Fabrice Bellingard Date: Wed, 6 Apr 2011 17:10:39 +0000 (+0200) Subject: [SONAR-1973] Add/list reviews&comments X-Git-Tag: 2.8~200 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dcba2ad8611d097d182d97b064dd8a0195e4f3a6;p=sonarqube.git [SONAR-1973] Add/list reviews&comments --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 36e2c12a22c..5c1eb333c9a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -25,6 +25,11 @@ class ReviewsController < ApplicationController def index end + def list + reviews = Review.find :all, :conditions => ['rule_failure_id=?', params[:rule_failure_id]] + render :partial => "list", :locals => { :reviews => reviews }, :layout => false + end + def form @review = Review.new @review.rule_failure_id = params[:violation_id] @@ -36,19 +41,35 @@ class ReviewsController < ApplicationController render "_form", :layout => false end + def formComment + @review_comment = ReviewComment.new + @review_comment.user = current_user + @review_comment.review_id = params[:review_id] + @review_comment.review_text = "" + @rule_failure_id = params[:rule_failure_id] + render "_form_comment", :layout => false + end + def create review = Review.new(params[:review]) review.user = current_user review.save + #review.review_comments.create(params[:review_comment]) review_comment = ReviewComment.new(params[:review_comment]) review_comment.user = current_user review_comment.review_id = review.id review_comment.save - render "create", :layout => false + + params[:rule_failure_id] = review.rule_failure_id + list end - def cancel_create - render :nothing => true + def createComment + review_comment = ReviewComment.new(params[:review_comment]) + review_comment.user = current_user + review_comment.save + + list end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index 678064fd265..5353f9b7dc1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -5,7 +5,7 @@ <% if current_user %> <%= link_to_remote(image_tag("add.png"), - :update => "review" + violation.id.to_s , + :update => "reviewFailure" + violation.id.to_s, :url => { :controller => "reviews", :action => "form", :violation_id => violation.id }) -%> <% end %> @@ -22,16 +22,9 @@ %> <%= duration==0 ? 'today' : "#{duration} days ago" -%> <% end %> - -
- <% unless violation.reviews.blank? - violation.reviews.each do |review| - %> - <%= render :partial => "reviews/view", :locals => { :review => review } %> - <% - end - end - %> + +
+ <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb index 334699da652..66539b0c43e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form.html.erb @@ -1,4 +1,5 @@ -<% form_for :review, @review, :url => { :action => 'create', :id => @review.id } do |f| %> +

Create a new review

+<% form_for :review, @review do |f| %> <%= f.hidden_field :rule_failure_id %> Review by: <%= @review.user.login -%>
@@ -15,9 +16,9 @@ <%= text_area :review_comment, :review_text, :rows => 10 %>
<%= submit_to_remote 'create_btn', 'Create review', - :url => { :action => 'create', :id => @review.id }, - :update => { :success => "review" + @review.rule_failure_id.to_s, :failure => "fail" } %> + :url => { :action => 'create' }, + :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s, :failure => "fail" } %> <%= submit_to_remote 'cancel_btn', 'Cancel', - :url => { :action => 'cancel_create' }, - :update => { :success => "review" + @review.rule_failure_id.to_s } %> + :url => { :action => 'list', :rule_failure_id => @review.rule_failure_id.to_s }, + :update => { :success => "reviewFailure" + @review.rule_failure_id.to_s } %> <% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb new file mode 100644 index 00000000000..b2ed06f0555 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb @@ -0,0 +1,15 @@ +<% form_for :review_comment, @review_comment do |f| %> + <%= f.hidden_field :review_id %> + Review by: <%= :user -%> +
+ Comment: +
+ <%= f.text_area :review_text, :rows => 10 %> +
+ <%= submit_to_remote 'create_btn', 'Add comment', + :url => { :action => 'createComment', :rule_failure_id => @rule_failure_id }, + :update => { :success => "reviewFailure" + @rule_failure_id.to_s, :failure => "fail" } %> + <%= submit_to_remote 'cancel_btn', 'Cancel', + :url => { :action => 'list', :rule_failure_id => @rule_failure_id.to_s }, + :update => { :success => "reviewFailure" + @rule_failure_id.to_s } %> +<% end %> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb new file mode 100644 index 00000000000..2fbbd000238 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb @@ -0,0 +1,11 @@ +<% + unless reviews.blank? + reviews.each do |review| +%> + + <%= render :partial => "reviews/view", :locals => { :review => review } %> + +<% + end + end +%> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb index 32dc6c4ed7b..29c96225414 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb @@ -1,4 +1,4 @@ -
+
User name: <%= h(review.user.name) -%>
Status: <%= h(review.status) -%> @@ -8,15 +8,26 @@ External Link: <%= h(review.external_link) -%>
- <% unless review.review_comments.blank? - review.review_comments.each do |review_comment| - %> +
+ <% unless review.review_comments.blank? + review.review_comments.each do |review_comment| + %> +
<%= l review_comment.created_at -%>, by <%= h(review_comment.user.name) -%> » <%= h(review_comment.review_text) -%>
- <% - end +
+ <% end - %> -
\ No newline at end of file + end + %> +
+ + <%= link_to_remote("Add a comment", + :update => "createComment" + review.id.to_s, + :url => { :controller => "reviews", :action => "formComment", :review_id => review.id, :rule_failure_id => review.rule_failure_id }) -%> +
+ +
+