aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-03-20 15:58:15 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-03-20 15:58:15 +0100
commitffa6a6343d6f32b47c442d58ce1572818daadb5e (patch)
tree9a684ea9d5c51ee6e804353206c2b0cdecc0f512
parente04f5f9de104566d42a3e28dbf61d0a0592f7a66 (diff)
downloadsonarqube-ffa6a6343d6f32b47c442d58ce1572818daadb5e.tar.gz
sonarqube-ffa6a6343d6f32b47c442d58ce1572818daadb5e.zip
SONAR-4116 In the Measure filters, before "new_*" measures we should not display a '+' or '-' character
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb42
2 files changed, 43 insertions, 5 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
index 7dd87280043..5c11180c912 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
@@ -427,7 +427,6 @@ module ApplicationHelper
end
end
-
#
#
# Format variation value
@@ -436,7 +435,6 @@ module ApplicationHelper
# * color: true|false. Default is true.
# * period: integer between 1 and 5. By default the index is defined by the dashboard variation select-box
# * style: light|normal|none. Default is normal (parenthesis + bold)
- # * variation: true|false. Default is true.
#
# === Examples
# format_variation('ncloc')
@@ -456,8 +454,7 @@ module ApplicationHelper
return m.format_numeric_value(val)
end
- variation = !options[:variation].nil? ? options[:variation] : true
- formatted_val= m.format_numeric_value(val, :variation => variation)
+ formatted_val= m.format_numeric_value(val, :variation => true)
css_class=''
if options[:color]||true
css_class='var'
@@ -472,6 +469,7 @@ module ApplicationHelper
end
end
end
+
if options[:style]!='light'
formatted_val=(val>=0 ? "+" : "") + formatted_val
formatted_val="<b>(#{formatted_val})</b>"
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
index 0d0b3af4d4f..e7e0062d6a5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/measures_helper.rb
@@ -38,7 +38,11 @@ module MeasuresHelper
if column.metric
measure = row.measure(column.metric)
if column.period
- format_variation(measure, :index => column.period, :style => 'light', :variation => false)
+ if measure && measure.metric.on_new_code?
+ format_new_metric_measure(measure, column.period)
+ else
+ format_variation(measure, :index => column.period, :style => 'light')
+ end
elsif column.metric.numeric?
format_measure(measure) + ' ' + trend_icon(measure, :empty => true)
else
@@ -97,4 +101,40 @@ module MeasuresHelper
[Api::Utils.period_label(1), Api::Utils.period_label(2), Api::Utils.period_label(3)]
end
+
+ private
+
+ #
+ # This method is a inspired by ApplicationHelper#format_variation for measure where metrics key begin with 'new_'
+ # It will display measure in color, without operand (+/-), and prefix with a %.
+ #
+ def format_new_metric_measure(metric_or_measure, index)
+ if metric_or_measure.is_a?(ProjectMeasure)
+ m = metric_or_measure
+ elsif @snapshot
+ m = @snapshot.measure(metric_or_measure)
+ end
+ html=nil
+ if m
+ val=variation_value(m, :index => index)
+ if val
+ formatted_val= m.format_numeric_value(val, :variation => false)
+ css_class='var'
+ if m.metric.qualitative?
+ factor=m.metric.direction * val
+ if factor>0
+ # better
+ css_class='varb'
+ elsif factor<0
+ # worst
+ css_class='varw'
+ end
+ end
+
+ html="<span class='#{css_class}'>#{formatted_val}</span>"
+ end
+ end
+ html
+ end
+
end