]> source.dussan.org Git - sonarqube.git/commitdiff
[SONAR-1973] Add/list reviews&comments
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 6 Apr 2011 17:10:39 +0000 (19:10 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Apr 2011 06:49:56 +0000 (08:49 +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/_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_form_comment.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_list.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_view.html.erb

index 36e2c12a22c291fcba72ac29bb3c1956617bb52b..5c1eb333c9a65746675a86db768180025549f898 100644 (file)
@@ -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
index 678064fd2657df5164b653e8b09f9de8531883e4..5353f9b7dc11fb9fe6e47fce622e668e309f52ca 100644 (file)
@@ -5,7 +5,7 @@
       <td width="30px" valign="top">
        <% 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 %>
       </td>
                %>
                  <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
                <% end %>
-                       
-               <div id="review<%= violation.id -%>" style="padding:5px; background:white">
-                 <% unless violation.reviews.blank? 
-                      violation.reviews.each do |review|
-                 %>
-                   <%= render :partial => "reviews/view", :locals => { :review => review } %>
-                 <% 
-                      end
-                    end
-                 %>
+               
+               <div id="reviewFailure<%= violation.id -%>" style="padding:5px; background:white">
+                 <%= render :partial => "reviews/list", :locals => { :reviews => violation.reviews } %>
                </div>
       </td>
       
index 334699da652b698a8cdd5baebf26955145716568..66539b0c43e579f6d1965806ef266b7e3f33832b 100644 (file)
@@ -1,4 +1,5 @@
-<% form_for :review, @review, :url => { :action => 'create', :id => @review.id } do |f| %>
+<h3>Create a new review</h3>
+<% form_for :review, @review do |f| %>
       <%= f.hidden_field :rule_failure_id %>
       Review by: <%= @review.user.login -%>
       <br/>
@@ -15,9 +16,9 @@
       <%= text_area :review_comment, :review_text, :rows => 10 %>
       <br/>
       <%= 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 (file)
index 0000000..b2ed06f
--- /dev/null
@@ -0,0 +1,15 @@
+<% form_for :review_comment, @review_comment do |f| %>
+      <%= f.hidden_field :review_id %>
+      Review by: <%= :user -%>
+      <br/>
+      Comment:
+      <br/>
+      <%= f.text_area :review_text, :rows => 10 %>
+      <br/>
+      <%= 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 (file)
index 0000000..2fbbd00
--- /dev/null
@@ -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
index 32dc6c4ed7bbf4070b2d82c58d4ab8cf1a74a333..29c962254143f7615449134261442246b3a73983 100644 (file)
@@ -1,4 +1,4 @@
-<div>
+  <div id="review<%= review.id -%>" style="border:solid 1px black; margin:2px">
       User name: <%= h(review.user.name) -%>
       <br/>
       Status: <%= h(review.status) -%>
@@ -8,15 +8,26 @@
       External Link: <%= h(review.external_link) -%>
       <br/>
       
-                 <% unless review.review_comments.blank? 
-                      review.review_comments.each do |review_comment|
-                 %>
+      <div>
+        <% unless review.review_comments.blank? 
+                    review.review_comments.each do |review_comment|
+               %>
+               <div id="commentReview" style="border:solid 1px grey; margin:2px">
                    <%= l review_comment.created_at -%>, by <%= h(review_comment.user.name) -%>
                    ยป 
                    <%= h(review_comment.review_text) -%>
             <br/>
-                 <% 
-                      end
+        </div>
+               <% 
                     end
-                 %>
-</div>
\ No newline at end of file
+                  end
+               %>
+      </div>
+      
+      <%= 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 }) -%>
+       <div id="createComment<%= review.id -%>">
+       
+       </div>
+  </div>