]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2327 Provide a new "Reviews" service
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 27 Apr 2011 06:59:49 +0000 (08:59 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 27 Apr 2011 07:29:32 +0000 (09:29 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb

index 894a6a481297b83a9e36633659daaa82fb9da5bd..74311837a18472dda117b7791f78050af70c5562 100644 (file)
@@ -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
+
 
   #
   #
index 7231e3aa75feae3f11ad1fdd62cd90b3e0c9288c..70e0c63094b233eab44eb07ca15d764ef5d6c66f 100644 (file)
         <%= 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> 
index 6b9ea44532b52e0025d22f24ab7a08559493461a..bc87b3a9ad12410fccd88ebd5b3cb03378f5cc7c 100644 (file)
            <%= 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>
     <%= 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 %>