]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1937 filter on new violations in violations drilldown
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Dec 2010 13:44:58 +0000 (13:44 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Dec 2010 13:44:58 +0000 (13:44 +0000)
sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb
sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb

index dcbd183408f6ffad6c793090a30f86c28797a0c4..f5fb0714d83482217bbdf32bcd060c1a9f6fadab 100644 (file)
@@ -64,12 +64,20 @@ class DrilldownController < ApplicationController
   def violations
     @rule=Rule.by_key_or_id(params[:rule])
 
-    if @rule.nil? && params[:priority]
-      @metric = Metric::by_key("#{params[:priority].downcase}_violations")
-      @priority_id=Sonar::RulePriority.id(params[:priority])
+    # variation measures
+    if params[:var].blank?
+      @variation_index=nil
+      metric_prefix = ''
     else
-      @metric = Metric::by_key('violations')
-      @priority_id=nil
+      @variation_index=params[:var].to_i
+      metric_prefix = 'new_'
+    end
+
+    @priority_id=(params[:priority].blank? ? nil : Sonar::RulePriority.id(params[:priority]))
+    if @rule.nil? && @priority_id
+      @metric = Metric::by_key("#{metric_prefix}#{params[:priority].downcase}_violations")
+    else
+      @metric = Metric::by_key("#{metric_prefix}violations")
     end
 
     # selected resources
@@ -85,12 +93,12 @@ class DrilldownController < ApplicationController
 
 
     # options for Drilldown
-    options={:exclude_zero_value => true}
+    options={:exclude_zero_value => true, :variation_index => @variation_index}
     if @rule
       params[:rule]=@rule.key  # workaround for SONAR-1767 : the javascript hash named "rp" in the HTML source must contain the rule key, but not the rule id
       options[:rule_id]=@rule.id
     end
-
+    
     # load data
     @drilldown = Drilldown.new(@project, @metric, @selected_rids, options)
     @snapshot=@drilldown.snapshot
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb
new file mode 100644 (file)
index 0000000..43576d7
--- /dev/null
@@ -0,0 +1,29 @@
+ #
+ # Sonar, entreprise quality control tool.
+ # Copyright (C) 2009 SonarSource SA
+ # mailto:contact AT sonarsource DOT com
+ #
+ # Sonar is free software; you can redistribute it and/or
+ # modify it under the terms of the GNU Lesser General Public
+ # License as published by the Free Software Foundation; either
+ # version 3 of the License, or (at your option) any later version.
+ #
+ # Sonar is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU Lesser General Public
+ # License along with Sonar; if not, write to the Free Software
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ #
+module DrilldownHelper
+
+  def measure_or_variation_value(measure)
+    if measure
+      @variation_index ? measure.variation(@variation_index) : measure.value
+    else
+      nil
+    end
+  end
+end
\ No newline at end of file
index d661c6af2b7bfb206f3bd9c910330e8ad44193cf..d424ce3ccc762d35a70d7e3af47cded87d540835 100644 (file)
@@ -68,10 +68,9 @@ class DrilldownColumn
       conditions += ' AND project_measures.rule_id=:rule'
       condition_values[:rule]=options[:rule_id]
     else
-      conditions += ' AND project_measures.rule_id IS NULL AND project_measures.rule_priority IS NULL '
+      conditions += ' AND project_measures.rule_id IS NULL '
     end
 
-
     if options[:characteristic]
       conditions += ' AND project_measures.characteristic_id=:characteristic_id'
       condition_values[:characteristic_id]=options[:characteristic].id
index 13768dcbeba57bc3897c0ff8f343030f183c54df..cd5f7c8e6189565c83e7a2c52ef024c81ecf5013 100644 (file)
@@ -62,6 +62,9 @@ class ProjectMeasure < ActiveRecord::Base
   end
 
   def formatted_value
+    if value.nil?
+      return nil
+    end
     if metric.nil?
       return value.to_s
     end
index d15af616eaa3e056f475e154d36d9b246ae72e24..c6e52fd8faa2d5d06c144f1217ac565dd54d6b88 100644 (file)
@@ -1,10 +1,11 @@
 <tr class="<%= css -%> <%= 'selected' if Sonar::RulePriority.to_s(priority_id)==params[:priority] -%>">
        <td><%= image_tag "priority/#{priority_id}.png" %></td>
-  <td><%= link_to label, {:controller => 'drilldown', :action => 'violations', :id => @project.id, :priority => Sonar::RulePriority.to_s(priority_id)} %></td>
+  <td><%= link_to label, {:controller => 'drilldown', :action => 'violations', :id => @project.id, :priority => Sonar::RulePriority.to_s(priority_id), :var => @variation_index} %></td>
   <td style="padding-left: 10px;" align="right">
-         <%= format_measure(measure) -%>
+         <%= @variation_index ? format_variation(measure, :index => @variation_index) : format_measure(measure) -%>
   </td>
   <td align="left">
-    <%= barchart(:width => 60, :percent => (measure ? (100 * measure.value / max).to_i : 0), :color => '#777') if max>0  %>
+    <% value = measure_or_variation_value(measure) %>
+    <%= barchart(:width => 60, :percent => (value ? (100 * value / max).to_i : 0), :color => '#777') if max>0  %>
   </td>
 </tr>
\ No newline at end of file
index 090af3bdb3a62f8675a7cc0e399e955686486070..2a5b503eeca40691b59341a4175df9d1bde197ec 100644 (file)
@@ -7,15 +7,25 @@
   <td align="left" width="1%" nowrap class="column first">
 
        <%
+         value_column = (@variation_index ? "variation_value_#{@variation_index}" : 'value')
                max = 0
-               blocker_violations=@snapshot.measure('blocker_violations')
-               critical_violations=@snapshot.measure('critical_violations')
-               major_violations=@snapshot.measure('major_violations')
-               minor_violations=@snapshot.measure('minor_violations')
-               info_violations=@snapshot.measure('info_violations')
+               if @variation_index
+      blocker_violations=@snapshot.measure('new_blocker_violations')
+      critical_violations=@snapshot.measure('new_critical_violations')
+      major_violations=@snapshot.measure('new_major_violations')
+      minor_violations=@snapshot.measure('new_minor_violations')
+      info_violations=@snapshot.measure('new_info_violations')
+    else
+      blocker_violations=@snapshot.measure('blocker_violations')
+      critical_violations=@snapshot.measure('critical_violations')
+      major_violations=@snapshot.measure('major_violations')
+      minor_violations=@snapshot.measure('minor_violations')
+      info_violations=@snapshot.measure('info_violations')
+    end
 
          [blocker_violations, critical_violations, major_violations, minor_violations, info_violations].each do |m|
-           max = m.value if m && m.value && m.value>max
+           value = measure_or_variation_value(m)
+           max = value if value && value>max
          end
        %>
     <h3>Severity</h3>
    <div class="scrollable">
        <table class="spacedicon" width="100%" id="col_rules">
              <%
-               rule_measures=@snapshot.rule_measures(Metric.by_key('violations'), @priority_id)
+               if @variation_index
+                 rule_measures=@snapshot.rule_measures(Metric.by_key('new_violations'), @priority_id)
+               else
+                 rule_measures=@snapshot.rule_measures(Metric.by_key('violations'), @priority_id)
+               end
                max=0
                rule_index=0
-                       rule_measures.each { |m| max=m.value if m.value>max }
+                           rule_measures.each do |m|
+                             value = m.send(value_column) if m
+                             max=value if value && value>max
+                           end
                rule_ids=rule_measures.collect{ |measure| measure.rule_id}.uniq
                rules = (rule_ids.empty? ? [] : Rule.find(rule_ids))
-                   rules_hash={}
-                   rules.each { |rule| rules_hash[rule.id]=rule }
-               rule_measures.sort do|x,y|
-                               val=y.rule_priority<=>x.rule_priority
-                               val==0 ? y.value <=> x.value : val
-                   end.each do |rule_measure|
-                     next if rule_measure.value==0
-              rule=rules_hash[rule_measure.rule_id]
-              clazz = cycle('even', 'odd', :name => 'rules')
-              clazz = clazz + ' selected' if @rule && @rule.id==rule_measure.rule_id
-              rule_index+=1
+          rules_hash={}
+          rules.each { |rule| rules_hash[rule.id]=rule }
+          rule_measures.sort do|x,y|
+            val=y.rule_priority<=>x.rule_priority
+            if val==0
+              x_value=x.send(value_column)
+              y_value=y.send(value_column)
+              y_value <=> x_value
+            else
+              val
+            end
+          end.each do |rule_measure|
+            value = rule_measure.send(value_column)
+                       next if value.nil? || value==0
+            rule=rules_hash[rule_measure.rule_id]
+            clazz = cycle('even', 'odd', :name => 'rules')
+            clazz = clazz + ' selected' if @rule && @rule.id==rule_measure.rule_id
+            rule_index+=1
                   %>
                <tr class="<%= clazz -%>">
                       <td width="1%" nowrap>
                          <%= link_to(rule.name, {:overwrite_params => {:rule => rule.key, :sid => nil, :priority => Sonar::RulePriority.to_s(@priority_id)}}, :title => "#{rule.plugin_name}: #{rule.plugin_rule_key}") %>
                    </td>
                    <td class="right" nowrap="nowrap">
-                       <span><%= rule_measure.formatted_value %></span>
+                       <span><%= @variation_index ? format_variation(rule_measure, :index => @variation_index) : rule_measure.formatted_value -%></span>
                    </td>
                    <td class="left last">
-                         <%= barchart(:width => 70, :percent => (100 * rule_measure.value / max).to_i, :color => '#777')  if max>0 %>
+                         <%= barchart(:width => 70, :percent => (100 * value / max).to_i, :color => '#777')  if max>0 %>
                          <!--[if IE]> &nbsp; &nbsp; <![endif]-->
                       </td>
                </tr>
    <% end %>
    </td>
    <td class="right last" nowrap>
-       <%= measure.formatted_value -%>
+       <%= @variation_index ? format_variation(measure, :index => @variation_index) : measure.formatted_value -%>
        <!--[if IE]> &nbsp; &nbsp; <![endif]-->
    </td>
 </tr>