From 4fe456fb3bfa1baa156d719e31033304fc10b755 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 2 Mar 2011 15:19:32 +0100 Subject: [PATCH] SONAR-2218 fix rule filter in violations tab --- .../app/controllers/browse_controller.rb | 31 +++++++++++++++++-- .../app/views/browse/_rules_filter.html.erb | 10 +++--- .../WEB-INF/app/views/browse/index.html.erb | 8 ++++- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb index bacf6c73325..4a1642a57ea 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb @@ -125,6 +125,16 @@ class BrowseController < ApplicationController end end + if @snapshot.measure('conditions_by_line').nil? + deprecated_branches_by_line=load_distribution('branch_coverage_hits_data') + deprecated_branches_by_line.each_pair do |line_id,label| + line=@lines[line_id-1] + if line + line.deprecated_conditions_label=label + end + end + end + filter_lines_by_date() render :action => 'index' end @@ -161,8 +171,7 @@ class BrowseController < ApplicationController end end - @violations=RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC') - @violations.each do |violation| + RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation| # sorted by severity => from blocker to info if violation.line && violation.line>0 @lines[violation.line-1].add_violation(violation) @@ -207,7 +216,7 @@ class BrowseController < ApplicationController end class Line - attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden + attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :deprecated_conditions_label def initialize(source) @source=source @@ -234,6 +243,22 @@ class BrowseController < ApplicationController def date @datetime ? @datetime.to_date : nil end + + def deprecated_conditions_label=(label) + if label + @deprecated_conditions_label=label + if label=='0%' + @conditions=2 + @covered_conditions=0 + elsif label=='100%' + @conditions=2 + @covered_conditions=2 + else + @conditions=2 + @covered_conditions=1 + end + end + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_rules_filter.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_rules_filter.html.erb index cd37ea4255e..ea36a4da8d1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_rules_filter.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_rules_filter.html.erb @@ -7,14 +7,12 @@ rule_counts={} rules=[] - - @violations.each do |violation| - count=(rule_counts[violation.rule_id]||0) +1 - rule_counts[violation.rule_id]=count - rules< 'rule', :conditions => ['metric_id=? AND snapshot_id=? AND rule_id IS NOT NULL AND characteristic_id IS NULL', Metric.by_key('violations').id, @snapshot.id]) + rule_measures.each do |rule_measure| + rule_counts[rule_measure.rule_id]=rule_measure.value.to_i + rules< <%= line.hits -%> - <% if line.conditions && line.conditions>0 %><%= line.covered_conditions -%>/<%= line.conditions -%><% end %> + + <% if line.deprecated_conditions_label -%> + <%= line.deprecated_conditions_label -%> + <% elsif line.conditions && line.conditions>0 -%> + <%= line.covered_conditions -%>/<%= line.conditions -%> + <% end %> + <% end %> <%= line.source -%> -- 2.39.5