]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-1973] Make it possible to edit the last comment
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 15 Apr 2011 08:58:49 +0000 (10:58 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:57:56 +0000 (08:57 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs [new file with mode: 0644]

index 05151fca0173931aecc11413d449ae97f9543321..39207c27671a65fb95fa530d1fc855017b30ce74 100644 (file)
@@ -57,6 +57,10 @@ class ReviewsController < ApplicationController
     @review_comment.review_id = params[:review_id]\r
     @review_comment.review_text = ""\r
     @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+    if params[:update_comment]\r
+      @update_comment = "true"\r
+      @review_comment.review_text = params[:review_text]\r
+    end\r
     render :partial => "form_comment"\r
   end\r
 \r
@@ -107,6 +111,24 @@ class ReviewsController < ApplicationController
     render "create_comment_result"\r
   end\r
 \r
+  def update_comment\r
+    review = Review.find params[:review_comment][:review_id]\r
+    @review_comment = review.review_comments.last\r
+    unless current_user && current_user.id == @review_comment.user_id\r
+      render :text => "<b>Cannot modify the comment</b> : access denied."\r
+      return\r
+    end\r
+\r
+    @review_comment.review_text = params[:review_comment][:review_text]\r
+    @review_comment.created_at = DateTime.now\r
+    @rule_failure_permanent_id = params[:rule_failure_permanent_id]\r
+    if @review_comment.valid?\r
+      @review_comment.save\r
+      @reviews = find_reviews_for_rule_failure @rule_failure_permanent_id\r
+    end\r
+    render "update_comment_result"\r
+  end\r
+\r
   ## -------------- PRIVATE -------------- ##\r
   private\r
 \r
index f15ed482af9c2162ccd5f73c3a6fb2a95e57fd07..8d5b25accd3a5bdd1e7082d19f372fc14eb92313 100644 (file)
@@ -4,8 +4,15 @@
             :id => "commentText" + @review_comment.review_id.to_s,\r
             :style => "width:100%" %>\r
       <br/>\r
-      <%= submit_to_remote 'create_btn', 'Post', \r
-                     :url => { :action => 'create_comment', :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+      <% if @update_comment %>\r
+        <%= submit_to_remote 'create_btn', 'Update', \r
+                     :url => { :action => 'update_comment', \r
+                               :rule_failure_permanent_id => @rule_failure_permanent_id } %>      \r
+      <% else %>\r
+        <%= submit_to_remote 'create_btn', 'Post', \r
+                     :url => { :action => 'create_comment', \r
+                               :rule_failure_permanent_id => @rule_failure_permanent_id } %>\r
+      <% end %>\r
       <%= submit_to_remote 'cancel_btn', 'Cancel', \r
                      :url => { :action => 'list', :rule_failure_permanent_id => @rule_failure_permanent_id.to_s },\r
                      :update => { :success => "reviewFailure" + @rule_failure_permanent_id.to_s } %>\r
index 41788df91b9fee5a18a85398163867a93125e322..36f3b97f88c507a02cdf368a9c3e89d9565bd657 100644 (file)
@@ -1,6 +1,3 @@
-<%\r
-  last_comment_user_id = -1\r
-%>\r
   <div id="review<%= review.id -%>">\r
          <div>\r
        <b>Review #<%= review.id -%> - <%= h(review.title) -%></b>\r
@@ -9,9 +6,9 @@
       </div>\r
       \r
       <div style="margin-top: 10px; margin-left: 20px">\r
-        <% unless review.review_comments.blank? \r
+        <% unless review.review_comments.blank?\r
+             last_comment = review.review_comments.last\r
                     review.review_comments.each do |review_comment|\r
-                      last_comment_user_id = review_comment.user_id\r
                %>\r
         <table style="width:100%; margin-bottom: 3px">\r
                  <tr style="border: solid 1px grey; background-color: #F7F7F7">\r
                  </tr>\r
                  <tr style="border: solid 1px grey;">\r
                    <td colspan="2" style="padding: 5px;">\r
-                     <%= h(review_comment.review_text) -%>\r
+                     <% if review_comment == last_comment %>\r
+                       <div id="lastComment<%= review.id -%>">\r
+                         <%= h(review_comment.review_text) -%>\r
+                       </div>\r
+                     <% else %>\r
+                       <%= h(review_comment.review_text) -%>\r
+                     <% end %>\r
                    </td>\r
                  </tr>\r
                </table>\r
       \r
         <% if current_user %>\r
            <div style="text-align: right; padding: 5px">\r
-             <% if current_user.id == last_comment_user_id %>\r
+             <% if current_user.id == review.review_comments.last.user_id %>\r
                <%= image_tag("pencil.png") -%>\r
                <%= link_to_remote "Edit my last comment", \r
-                  :url => { :controller => "reviews", :action => "form_comment", :review_id => review.id, :rule_failure_permanent_id => review.rule_failure_permanent_id },\r
-                  :update => "createComment" + review.id.to_s, \r
+                  :url => { :controller => "reviews", :action => "form_comment", \r
+                            :review_id => review.id, \r
+                            :rule_failure_permanent_id => review.rule_failure_permanent_id,\r
+                            :review_text => review.review_comments.last.review_text,\r
+                            :update_comment => "true" },\r
+                  :update => "lastComment" + review.id.to_s, \r
                   :complete => "$('commentText" + review.id.to_s + "').focus()" -%>\r
                &nbsp;\r
              <% end %>\r
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/update_comment_result.js.rjs
new file mode 100644 (file)
index 0000000..f127394
--- /dev/null
@@ -0,0 +1,6 @@
+if @reviews\r
+  page.replace_html "reviewFailure" + @rule_failure_permanent_id.to_s, :partial => "list", :locals => { :reviews => @reviews }\r
+else\r
+  @update_comment = "true"\r
+  page.replace_html "lastComment" + @review_comment.review_id.to_s, :partial => "form_comment"\r
+end
\ No newline at end of file