]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1973 Improve Resource Viewer
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 21 Apr 2011 08:18:23 +0000 (10:18 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 21 Apr 2011 08:18:23 +0000 (10:18 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_rules_filter.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb

index ad8dfbed1baa7d94304fed1f19b026b5efd646fc..4c2f796a5dd7e635ad6f1760103e36042fbfb60f 100644 (file)
@@ -173,15 +173,25 @@ class ResourceController < ApplicationController
 
     conditions='snapshot_id=?'
     values=[@snapshot.id]
-    unless params[:rule].blank?
-      severity=Sonar::RulePriority.id(params[:rule])
-      if severity
-        conditions += ' AND failure_level=?'
-        values<<severity
+    if params[:rule].blank?
+      conditions+='AND (switched_off IS NULL OR switched_off=?)'
+      values<<false
+    else
+      if params[:rule] == "f-positive"
+        conditions+='AND switched_off=?'
+        values<<true
       else
-        rule=Rule.by_key_or_id(params[:rule])
-        conditions += ' AND rule_id=?'
-        values<<(rule ? rule.id : -1)
+        conditions+='AND (switched_off IS NULL OR switched_off=?)'
+        values<<false
+        severity=Sonar::RulePriority.id(params[:rule])
+        if severity
+          conditions += ' AND failure_level=?'
+          values<<severity
+        else
+          rule=Rule.by_key_or_id(params[:rule])
+          conditions += ' AND rule_id=?'
+          values<<(rule ? rule.id : -1)
+        end
       end
     end
 
@@ -194,15 +204,6 @@ class ResourceController < ApplicationController
         conditions+=' AND id=-1'
       end
     end
-    
-    if params[:switchedOff]
-      @switchedOff=true
-      conditions+='AND switched_off=?'
-      values<<true
-    else
-      conditions+='AND (switched_off IS NULL OR switched_off=?)'
-      values<<false
-    end
 
     RuleFailure.find(:all, :include => ['rule', 'reviews' ], :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
       # sorted by severity => from blocker to info
index a0efbef164588b4713ee3e020aaaf719022136ef..dd98d5a3ecc486cbf5c12aba238bef94f397346c 100644 (file)
@@ -59,7 +59,7 @@ class ReviewsController < ApplicationController
 
   def create
     rule_failure = find_last_rule_failure_with_permanent_id params[:review][:rule_failure_permanent_id]
-    unless has_rights_to_create? rule_failure
+    unless has_rights_to_modify? rule_failure
       render :text => "<b>Cannot create the review</b> : access denied."
       return
     end
@@ -107,7 +107,7 @@ class ReviewsController < ApplicationController
 
   def create_comment
     rule_failure = find_last_rule_failure_with_permanent_id params[:rule_failure_permanent_id]
-    unless has_rights_to_create? rule_failure
+    unless has_rights_to_modify? rule_failure
       render :text => "<b>Cannot create the comment</b> : access denied."
       return
     end
@@ -179,6 +179,23 @@ class ReviewsController < ApplicationController
     violation = find_last_rule_failure_with_permanent_id review.rule_failure_permanent_id
     render :partial => "resource/violation", :locals => { :violation => violation }
   end
+  
+  def switch_on_violation
+    rule_failure = RuleFailure.find params[:rule_failure_id]
+    unless has_rights_to_modify? rule_failure
+      render :text => "<b>Cannot switch on the violation</b> : access denied."
+      return
+    end
+    
+    rule_failure.switched_off = false
+    rule_failure.save
+    
+    review = rule_failure.get_open_review
+    review.status = "closed"
+    review.save
+    
+    render :partial => "resource/violation", :locals => { :violation => rule_failure }
+  end
 
   ## -------------- PRIVATE -------------- ##
   private
@@ -246,7 +263,7 @@ class ReviewsController < ApplicationController
     return RuleFailure.last( :all, :conditions => [ "permanent_id = ?", rule_failure_permanent_id ], :include => ['snapshot'] )
   end
 
-  def has_rights_to_create? ( rule_failure )
+  def has_rights_to_modify? ( rule_failure )
     return false unless current_user
     
     project = rule_failure.snapshot.root_project
index e1594d7d44105fd6c031585f9c1bea8274789ca9..7e76510220662e227bdc2f467cbd9100ba86abf8 100644 (file)
          end %>
 
       <% if @display_violations %>
-        <td class="<%= 'first' if first -%>">
-          <input type="checkbox" value="true" name="switchedOff" id="switchedOff" <%= 'checked' if @switchedOff -%> onclick="applyOptions()"/>
-          <label for="expand">Show only switched-off violations</label>
-        </td>
         <td class="<%= 'first' if first -%>">
           <select id="period" name="period" onchange="applyOptions()">
             <option value="">Time changes...</option>
index 0bd942683bd474beaf0d3db63274d1337ed11889..06d89dc541453245edf0b7d75caf1897b7844f76 100644 (file)
@@ -32,7 +32,8 @@
    end
 %>
 <select id="rule" name="rule" onchange="applyOptions()">
-  <option value="">No filters</option>
+  <option value="">All violations</option>
+  <option value="f-positive" <%= 'selected' if params[:rule]=="f-positive" -%>>False-Positives only</option>
   <optgroup label="Severity">
     <% if blocker_violations
          value=(@period ? blocker_violations.variation(@period) : blocker_violations.value)
index 880786791c8e90934351724c713970b579c8619a..1fec9f4e7bc2c22e1621d3ebd38136a2d12db28d 100644 (file)
       <%= image_tag("sep12.png") -%>
       &nbsp;&nbsp;
       False-Positive
+      &nbsp;&nbsp;
     <% end %>
     <% if current_open_review && current_open_review.assignee %>
       <%= image_tag("sep12.png") -%>
       &nbsp;&nbsp;
       <%= h(current_open_review.assignee.name) -%>
+      &nbsp;&nbsp;
     <% end %>
     
     
                        :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>
         &nbsp;&nbsp;
       <% end %>
-      <%= link_to_remote "Switch-off",  
+      <% if violation.switched_off %>
+        <%= link_to_remote "Switch-on",  
+                       :url => { :controller => "reviews", :action => "switch_on_violation", :rule_failure_id => violation.id },
+                       :update => "vId" + violation.permanent_id.to_s -%>
+      <% else %>
+        <%= link_to_remote "Switch-off",  
                        :url => { :controller => "reviews", :action => "form", :rule_failure_permanent_id => violation.permanent_id, :switch_off => true },
                        :update => "reviewForm" + violation.permanent_id.to_s,
                        :complete => "$('reviewForm" + violation.permanent_id.to_s + "').style.display='';$('reviewText').focus();" -%>
+      <% end %>
       &nbsp;&nbsp;
     </span>
     <% end %>