]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2327 Provide a new "Reviews" service
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 26 Apr 2011 17:09:32 +0000 (19:09 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Tue, 26 Apr 2011 17:09:32 +0000 (19:09 +0200)
14 files changed:
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/_assign_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_comment_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_violation_false_positive_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb
sonar-server/src/main/webapp/images/status/CLOSED.png [new file with mode: 0644]
sonar-server/src/main/webapp/images/status/OPEN.png [new file with mode: 0644]
sonar-server/src/main/webapp/images/status/closed.png [deleted file]
sonar-server/src/main/webapp/images/status/open.png [deleted file]
sonar-server/src/main/webapp/stylesheets/style.css

index 05ce979a1c326b9ec3bc0178bcb2e8eb176efe6f..03472fde20166e687ad8bcb78848ed69717d46a3 100644 (file)
@@ -22,7 +22,10 @@ class ReviewsController < ApplicationController
 
   SECTION=Navigation::SECTION_HOME
 
-  verify :method => :post, :only => [:violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], :redirect_to => {:action => :error_not_post}
+  verify :method => :post, 
+         :only => [:assign, :comment_form, :flag_as_false_positive, 
+                   :violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], 
+         :redirect_to => {:action => :error_not_post}
   helper(:reviews,:markdown)
 
   def index
@@ -35,6 +38,81 @@ class ReviewsController < ApplicationController
     render :partial => 'reviews/show'
   end
 
+  # GET
+  def assign_form
+    @user_options = options_for_users()
+    render :partial => "assign_form"
+  end
+
+  # POST
+  def assign
+    @review = Review.find (params[:id])
+    unless current_user
+      render :text => "<b>Cannot edit the review</b> : access denied."
+      return
+    end
+
+    @review.assignee = User.find params[:assignee_id]
+    @review.save
+
+    render :partial => 'reviews/show'
+  end
+
+  # GET
+  def comment_form
+    @review = Review.find (params[:id])
+    render :partial => 'reviews/comment_form'
+  end
+
+  # POST
+  def save_comment
+    @review = Review.find (params[:id])
+    unless current_user
+      render :text => "<b>Cannot create the comment</b> : access denied."
+      return
+    end
+
+    if params[:comment_id]
+      comment = @review.comments.find(params[:comment_id].to_i)
+      if comment
+        comment.text=params[:text]
+        comment.save!
+      end
+    else
+      @review.comments.create!(:user => current_user, :text => params[:text])
+    end
+
+    render :partial => "reviews/show"
+  end
+
+  # GET
+  def false_positive_form
+    render :partial => 'reviews/false_positive_form'
+  end
+
+  # POST
+  def flag_as_false_positive
+    @review = Review.find (params[:id])
+    unless current_user
+      render :text => "<b>Cannot create the comment</b> : access denied."
+      return
+    end
+    
+    RuleFailure.find( :all, :conditions => [ "permanent_id = ?", @review.rule_failure_permanent_id ] ).each do |violation|
+      violation.switched_off=true
+      violation.save!
+    end
+
+    @review.review_type = Review::TYPE_FALSE_POSITIVE
+    @review.status = Review::STATUS_CLOSED
+    @review.save!
+    unless params[:comment].blank?
+      @review.comments.create(:review_text => params[:comment], :user_id => current_user.id)
+    end
+
+    render :partial => "reviews/show"
+  end
+
 
   #
   #
index 6dd08dd9fb6c46d8f8d0d3187c20f6ed320be49c..7231e3aa75feae3f11ad1fdd62cd90b3e0c9288c 100644 (file)
@@ -53,7 +53,7 @@
         <%= link_to_remote (violation.false_positive? ? "Unflag false-positive" : "Flag as false-positive"),
                        :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.false_positive? },
                        :update => "reviewForm" + violation.id.to_s,
-                       :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('reviewText" + violation.id.to_s + "').focus();" -%>
+                       :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('commentText" + violation.id.to_s + "').focus();" -%>
     </span>
     <% end %>
     
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_assign_form.html.erb
new file mode 100644 (file)
index 0000000..7aff44c
--- /dev/null
@@ -0,0 +1,12 @@
+<% form_tag :html => {:style => "display:inline"} do %>
+  <%= hidden_field_tag :id, params[:review_id] -%>
+  <%= select_tag "assignee_id", options_for_select(@user_options, current_user.id.to_s)  %>
+  &nbsp;&nbsp;
+  <%= submit_to_remote "submit_btn", "Assign", 
+         :url => { :action => 'assign' },
+         :update => "review" -%>
+  &nbsp;&nbsp;
+  <%= link_to_remote 'Cancel', 
+         :url => { :action => 'show', :id => params[:review_id] },
+         :update => "review" %>
+<% end %>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_comment_form.html.erb
new file mode 100644 (file)
index 0000000..6cb2a2b
--- /dev/null
@@ -0,0 +1,39 @@
+<%
+  button=(@comment ? 'Update comment' : 'Add comment')
+%>
+<form method="POST" action="save_comment">
+  <input type="hidden" name="id" value="<%= params[:id] -%>"/>
+  <% if @comment %>
+    <input type="hidden" name="comment_id" value="<%= @comment.id -%>"/>
+  <% end %>
+
+  <table class="width100">
+    <tr>
+      <td style="vertical-align:top">
+        <textarea id="commentText" rows="8" name="text" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"><%= @comment.text if @comment -%></textarea>
+        <br/>
+        <%= submit_to_remote "submit_btn", button, :url => { :action => 'save_comment'}, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%>
+        <%= link_to_remote 'Cancel', :url => {:action => 'show', :id => params[:id]}, :update => 'review' -%>
+      </td>
+      <td class="sep"></td>
+      <td style="vertical-align:top;width: 90px">
+        <h3>Help Tips</h3>
+        <table>
+          <tr>
+            <td>*bold*</td>
+            <td class="sep"></td>
+            <td><b>bold</b></td>
+          </tr>
+          <tr>
+            <td>''code''</td>
+            <td class="sep"></td>
+            <td><code>code</code></td>
+          </tr>
+          <tr>
+            <td colspan="3">* Bulleted point</td>
+          </tr>
+        </table>
+      </td>
+    </tr>
+  </table>
+</form>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_false_positive_form.html.erb
new file mode 100644 (file)
index 0000000..6cc844c
--- /dev/null
@@ -0,0 +1,7 @@
+<form method="POST" action="violation_flag_as_false_positive">
+  <input type="hidden" name="id" value="<%= params[:id] -%>"/>
+  <h3>Why is it a false-positive ?</h3>
+  <textarea id="commentText" rows="8" name="comment" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"></textarea>
+  <%= submit_to_remote "submit_btn", "Flag as false-positive", :url => { :action => 'flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'review' -%>
+  <%= link_to_remote 'Cancel', :url => {:action => 'show', :id => params[:id]}, :update => 'review' -%>
+</form>
index f9b6a8cd35a428163c4227e0bdcfe433d7a6ba56..bf7b8b55f2ea57e8c91131661cd02aa7f8cbe9b2 100644 (file)
@@ -2,6 +2,25 @@
   <div class="reportTitle">
     <div style="float: right"><span class="violation_date">#<%= review.id.to_s -%></span></div>  
     <h2><%= h(review.title) -%></h2>
+    
+    <% if current_user && review.status != "CLOSED" %>
+    <span class="actions" id="rActions">
+        &nbsp;
+        <%= image_tag("sep12.png") -%>
+        &nbsp;
+        <%= link_to_remote (review.assignee_id ? "Reassign" : "Assign"),  
+                       :url => { :controller => "reviews", :action => "assign_form", :review_id => review.id},
+                       :update => "assignForm",
+                       :complete => "$('rActions').hide(); $('commentAction').hide(); $('assignee_id').focus();" -%>
+      
+        &nbsp;
+        <%= link_to_remote ("Flag as false-positive"),
+                       :url => { :controller => "reviews", :action => "false_positive_form", :id => review.id },
+                       :update => "reviewForm",
+                       :complete => "$('rActions').hide(); $('commentAction').hide(); $('reviewForm').show();$('commentText').focus();" -%>
+    </span>
+    <% end %>
+    
   </div>
 
   <table class="reportDetails">
@@ -24,7 +43,9 @@
             Assignee:  
           </td>
           <td  class="val">
-               <%= review.assignee ? h(review.assignee.name) : '-'-%>
+            <span id="assignForm">
+                <%= review.assignee ? h(review.assignee.name) : '-'-%>
+            </span>
           </td>
           <td class="key">
                  Created by:
           </div>
         <% end %>
   </div>
+  
+  <% if current_user && review.status != "CLOSED" %>
+  <div class="discussionComment" id="reviewForm" style="display:none"></div>
+  <div style="padding: 5px" id="commentAction">
+    <%= 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()" -%>
+  </div>
+  <% end %>
+  
 </div>
\ No newline at end of file
index 109f3a292bd4f1ec685bdda4981b1b09cc905a42..f0e5574fd2227b320081e239f3c9b0aed7d40fb2 100644 (file)
@@ -13,7 +13,7 @@
     <input type="hidden" name="false_positive" value="true"/>
   <% end %>
   <h3><%= title -%></h3>
-  <textarea rows="8" name="comment" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"></textarea>
+  <textarea id="commentText<%= params[:id] -%>"  rows="8" name="comment" style="width: 100%" onkeyup="if (this.value=='') $('submit_btn').disabled='true'; else $('submit_btn').disabled='';"></textarea>
   <%= submit_to_remote "submit_btn", button, :url => { :action => 'violation_flag_as_false_positive' }, :html => { :id => "submit_btn", :disabled => "true" }, :update => 'vId'+params[:id] -%>
   <%= link_to_remote 'Cancel', :url => {:action => 'display_violation', :id => params[:id]}, :update => 'vId' + params[:id] -%>
 </form>
index 0000c7478bc153a41e1b6d0be04456c209c015af..6d4daf0d084fb8f940f00ed497c2322668819af8 100644 (file)
       <thead>
       <tr>
         <th width="1%" nowrap>St.</th>
-        <th width="1%">Project</th>
         <th>Title</th>
+        <th width="1%">Project</th>
         <th width="1%" nowrap>Se.</th>
         <th>Assignee</th>
         <th>Age</th>
+        <th width="1%" nowrap>Id</th>
 
       </tr>
       </thead>
       %>
         <tr class="<%= cycle('even', 'odd') -%>">
           <td><img src="<%= ApplicationController.root_context -%>/images/status/<%= review.status -%>.png"/></td>
-          <td><%= review.project.name -%>
-            <br/><span class="note"><%= review.resource.long_name -%></span></td>
           <td>
             <%= link_to_remote(h(review.title), :update => 'review', :url => {:action => 'show', :id => review.id}, :loading => 'onReviewLoading()', :complete => "onReviewLoaded()") -%>
           </td>
+          <td><%= review.project.name -%>
+            <br/><span class="note"><%= review.resource.long_name -%></span></td>
           <td><img src="<%= ApplicationController.root_context -%>/images/priority/<%= review.severity -%>.png"/></td>
           <td><%= review.assignee ? h(review.assignee.name) : '-' -%></td>
           <td><%= distance_of_time_in_words_to_now(review.created_at) -%></td>
+          <td style="font-weight:bold">
+            <%= link_to_remote( "#"+h(review.id), :update => 'review', :url => {:action => 'show', :id => review.id}, :loading => 'onReviewLoading()', :complete => "onReviewLoaded()") -%>
+          </td>
         </tr>
       <%
          end
diff --git a/sonar-server/src/main/webapp/images/status/CLOSED.png b/sonar-server/src/main/webapp/images/status/CLOSED.png
new file mode 100644 (file)
index 0000000..5a2fef4
Binary files /dev/null and b/sonar-server/src/main/webapp/images/status/CLOSED.png differ
diff --git a/sonar-server/src/main/webapp/images/status/OPEN.png b/sonar-server/src/main/webapp/images/status/OPEN.png
new file mode 100644 (file)
index 0000000..454ab68
Binary files /dev/null and b/sonar-server/src/main/webapp/images/status/OPEN.png differ
diff --git a/sonar-server/src/main/webapp/images/status/closed.png b/sonar-server/src/main/webapp/images/status/closed.png
deleted file mode 100644 (file)
index 5a2fef4..0000000
Binary files a/sonar-server/src/main/webapp/images/status/closed.png and /dev/null differ
diff --git a/sonar-server/src/main/webapp/images/status/open.png b/sonar-server/src/main/webapp/images/status/open.png
deleted file mode 100644 (file)
index 454ab68..0000000
Binary files a/sonar-server/src/main/webapp/images/status/open.png and /dev/null differ
index 513a1962de27145d2370ab074080097d4243057f..00e5cb59976a0a8ebd711da114e6844b3efe46bb 100644 (file)
@@ -816,7 +816,7 @@ span.rulename a:hover {
 
 
 div.reportTitle {
-       background-color: #CAE3F2;
+       background-color: #E4ECF3;
        color: #4B9FD5;
        line-height: 2.2em;
        margin: 0;
@@ -830,6 +830,9 @@ div.reportTitle h2 {
        font-size: 100%;
        text-shadow: 0 1px 0 #FFFFFF;
 }
+div.reportTitle span.actions {
+       font-size: 12px;
+}
 table.reportDetails {
        width: 100%;
        border: 0;
@@ -869,6 +872,9 @@ div.discussionComment h4 {
 div.discussionComment h4 img {
   vertical-align: sub;
 }
+div.discussionComment li {
+  list-style: square inside;
+}