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
# 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
--- /dev/null
+ #
+ # 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
<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
<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]> <![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]> <![endif]-->
</td>
</tr>