aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-27 08:59:49 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-27 09:29:32 +0200
commit7c5db32e248986472ae759970dd7070b63df66b2 (patch)
treed3d7cd3bfd3c832079c3b406548e05d1ac22b620
parentd4b1a3c4fa3c06c32a8e9a5a9b635dbc232a33ea (diff)
downloadsonarqube-7c5db32e248986472ae759970dd7070b63df66b2.tar.gz
sonarqube-7c5db32e248986472ae759970dd7070b63df66b2.zip
SONAR-2327 Provide a new "Reviews" service
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb18
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb36
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 => "<b>Cannot delete the comment</b> : 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 %>
</span>
<% end %>
</h4>
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) -%>
</div>
<% end %>
- <% review.comments.each do |comment| %>
+ <%
+ review.comments.each_with_index do |comment, comment_index|
+ is_last_comment=(comment_index==review.comments.size-1)
+ %>
<div class="discussionComment">
- <h4><%= image_tag("reviews/comment.png") -%> &nbsp;<b><%= comment.user.name -%></b> (<%= distance_of_time_in_words_to_now(comment.created_at) -%>)</h4>
- <%= markdown_to_html(comment.text) -%>
+ <h4>
+ <%= image_tag("reviews/comment.png") -%> &nbsp;<b><%= comment.user.name -%></b> (<%= distance_of_time_in_words_to_now(comment.created_at) -%>)
+ <% if is_last_comment && current_user && current_user.id == comment.user_id %>
+ <span class="actions" id="editActions">
+ &nbsp;&nbsp;
+ <%= image_tag("sep12.png") -%>
+ &nbsp;&nbsp;
+ <%= 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 %>
+ </span>
+ <% end %>
+ </h4>
+ <% if is_last_comment %>
+ <div id="lastComment">
+ <%= markdown_to_html(comment.text) -%>
+ </div>
+ <% else %>
+ <%= markdown_to_html(comment.text) -%>
+ <% end %>
</div>
<% end %>
</div>
@@ -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();" -%>
</div>
<% end %>