From 7c5db32e248986472ae759970dd7070b63df66b2 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 27 Apr 2011 08:59:49 +0200 Subject: [PATCH] SONAR-2327 Provide a new "Reviews" service --- .../app/controllers/reviews_controller.rb | 18 ++++++++++ .../app/views/resource/_violation.html.erb | 9 ++--- .../app/views/reviews/_review.html.erb | 36 ++++++++++++++++--- 3 files changed, 55 insertions(+), 8 deletions(-) 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 894a6a48129..74311837a18 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 @@ -61,6 +61,9 @@ class ReviewsController < ApplicationController # GET def comment_form @review = Review.find (params[:id]) + if !params[:comment_id].blank? && @review + @comment = @review.comments.find(params[:comment_id]) + end render :partial => 'reviews/comment_form' end @@ -113,6 +116,21 @@ class ReviewsController < ApplicationController render :partial => "reviews/show" end + # POST + def delete_comment + @review = Review.find (params[:id]) + unless current_user + render :text => "Cannot delete the comment : access denied." + return + end + + if @review + comment=@review.comments.find(params[:comment_id].to_i) + comment.delete if comment + end + render :partial => "reviews/show" + 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 7231e3aa75f..70e0c63094b 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 @@ -78,12 +78,13 @@ <%= link_to_remote "Edit", :url => { :controller => "reviews", :action => "violation_comment_form", :comment_id => review_comment.id, :id => violation.id }, :update => "lastComment" + violation.id.to_s, - :complete => "$('reviewForm#{violation.id}').hide();$('vActions#{violation.id}').hide();$('commentText#{violation.id}').focus();" -%> - - <%= link_to_remote "Delete", + :complete => "$('reviewForm#{violation.id}').hide();$('vActions#{violation.id}').hide();$('commentAction#{violation.id}').hide();$('commentText#{violation.id}').focus();" -%> + <% unless comment_index == 0 %> + <%= link_to_remote "Delete", :url => { :controller => "reviews", :action => "violation_delete_comment", :comment_id => review_comment.id, :id => violation.id }, :update => "vId" + violation.id.to_s, - :confirm => "Do you want to delete this comment ?" -%> + :confirm => "Do you want to delete this comment ?" -%> + <% end %> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb index 6b9ea44532b..bc87b3a9ad1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb @@ -88,10 +88,38 @@ <%= h(review.rule_failure.message) -%> <% end %> - <% review.comments.each do |comment| %> + <% + review.comments.each_with_index do |comment, comment_index| + is_last_comment=(comment_index==review.comments.size-1) + %>
-

<%= image_tag("reviews/comment.png") -%>  <%= comment.user.name -%> (<%= distance_of_time_in_words_to_now(comment.created_at) -%>)

- <%= markdown_to_html(comment.text) -%> +

+ <%= image_tag("reviews/comment.png") -%>  <%= comment.user.name -%> (<%= distance_of_time_in_words_to_now(comment.created_at) -%>) + <% if is_last_comment && current_user && current_user.id == comment.user_id %> + +    + <%= image_tag("sep12.png") -%> +    + <%= link_to_remote "Edit", + :url => { :controller => "reviews", :action => "comment_form", :comment_id => comment.id, :id => review.id }, + :update => "lastComment", + :complete => "$('rActions').hide();$('commentAction').hide();$('editActions').hide();$('commentText').focus();" -%> + <% unless comment_index == 0 %> + <%= link_to_remote "Delete", + :url => { :controller => "reviews", :action => "delete_comment", :comment_id => comment.id, :id => review.id }, + :update => "review", + :confirm => "Do you want to delete this comment ?" -%> + <% end %> + + <% end %> +

+ <% if is_last_comment %> +
+ <%= markdown_to_html(comment.text) -%> +
+ <% else %> + <%= markdown_to_html(comment.text) -%> + <% end %>
<% end %> @@ -102,7 +130,7 @@ <%= link_to_remote "Add comment", :url => { :controller => "reviews", :action => "comment_form", :id => review.id }, :update => "reviewForm", - :complete => "$('rActions').hide();$('commentAction').hide();$('reviewForm').show();$('commentText').focus()" -%> + :complete => "$('rActions').hide();$('commentAction').hide();$('reviewForm').show();$('commentText').focus();$('editActions').hide();" -%> <% end %> -- 2.39.5