aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-07 13:44:58 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-07 13:44:58 +0000
commit2f65b14c5b45bf513cfb0a56d1087c4a49299744 (patch)
tree1f6de14945c870f67e4ba57cbff625d7870381a6 /sonar-server
parentb0aaefba85e9b8fe61d34c202ded62d7269fc034 (diff)
downloadsonarqube-2f65b14c5b45bf513cfb0a56d1087c4a49299744.tar.gz
sonarqube-2f65b14c5b45bf513cfb0a56d1087c4a49299744.zip
SONAR-1937 filter on new violations in violations drilldown
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb29
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb68
6 files changed, 98 insertions, 34 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
index dcbd183408f..f5fb0714d83 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
@@ -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
index 00000000000..43576d79496
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb
index d661c6af2b7..d424ce3ccc7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
index 13768dcbeba..cd5f7c8e618 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb
index d15af616eaa..c6e52fd8faa 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_rule_priority.erb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
index 090af3bdb3a..2a5b503eeca 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
@@ -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>
@@ -32,23 +42,37 @@
<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>
@@ -58,10 +82,10 @@
<%= 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>
@@ -113,7 +137,7 @@
<% 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>