From 3ed6a62ad9e0fa21c108ab1e13724c90269ad2ca Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 3 Dec 2010 00:09:06 +0000 Subject: [PATCH] SONAR-249 do not hide widgets which are changed in variation view + improve ruby api to display trend icons and measure variations + support variations in the widgets rules/size --- .../sonar/plugins/core/widgets/rules.html.erb | 124 +++++++++++----- .../sonar/plugins/core/widgets/size.html.erb | 51 ++++--- .../org/sonar/api/measures/CoreMetrics.java | 14 +- .../java/org/sonar/server/ui/JRubyFacade.java | 4 +- .../java/org/sonar/server/ui/ViewProxy.java | 9 -- .../main/java/org/sonar/server/ui/Views.java | 4 +- .../app/controllers/dashboard_controller.rb | 2 +- .../WEB-INF/app/helpers/application_helper.rb | 140 +++++++++++++----- .../WEB-INF/app/models/project_measure.rb | 58 ++++---- ..._plugins_child_first_classloader_column.rb | 4 + .../db/migrate/151_create_dashboards.rb | 3 + .../152_delete_duplicated_lib_snapshots.rb | 4 + ...160_add_rule_failures_created_at_column.rb | 4 + .../migrate/161_add_snapshots_var_columns.rb | 4 + .../migrate/162_delete_iso_rule_categories.rb | 5 + .../src/main/webapp/stylesheets/style.css | 17 ++- .../java/org/sonar/server/ui/ViewsTest.java | 6 +- 17 files changed, 299 insertions(+), 154 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/rules.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/rules.html.erb index c62d9c4c78e..8875bed9ffd 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/rules.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/rules.html.erb @@ -1,88 +1,134 @@ -<% if measure(Metric::LINES) %> +<% + violations=@snapshot.measure('violations') + density=@snapshot.measure('violations_density') + 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') +%> - - -
+

Violations

-
- <%= format_measure(Metric::VIOLATIONS, :url => url_for(:controller => 'drilldown', :action => 'violations', :id => @project.key)) -%> <%= trend_icon(Metric::VIOLATIONS) -%> +
+ + <%= format_measure(violations, :url => url_for(:controller => 'drilldown', :action => 'violations', :id => @project.key)) -%> + + <%= dashboard_configuration.variation? ? format_variation(violations) : trend_icon(violations) -%>

Rules compliance

-
- <%= format_measure(Metric::VIOLATIONS_DENSITY, :url => url_for_drilldown(Metric::WEIGHTED_VIOLATIONS, {:highlight => Metric::WEIGHTED_VIOLATIONS})) -%> <%= trend_icon(Metric::VIOLATIONS_DENSITY) -%> +
+ + <%= format_measure(density, :url => url_for_drilldown(Metric::WEIGHTED_VIOLATIONS, {:highlight => Metric::WEIGHTED_VIOLATIONS})) -%> + + <%= dashboard_configuration.variation? ? format_variation(density) : trend_icon(density) -%>
+ <% - blocker_violations = @snapshot.measure(Metric::BLOCKER_VIOLATIONS) - critical_violations = @snapshot.measure(Metric::CRITICAL_VIOLATIONS) - major_violations = @snapshot.measure(Metric::MAJOR_VIOLATIONS) - minor_violations = @snapshot.measure(Metric::MINOR_VIOLATIONS) - info_violations = @snapshot.measure(Metric::INFO_VIOLATIONS) - max = 0 - [blocker_violations,critical_violations,major_violations,minor_violations,info_violations].each do |m| - max = m.value if m and m.value and m.value>max - end + values=[blocker_violations,critical_violations,major_violations,minor_violations,info_violations] + if dashboard_configuration.variation? + values=values.map{|m| m ? (m.variation(dashboard_configuration.variation_index)||0) : 0} + else + values=values.map{|m| m ? (m.value||0) : 0} + end + max=values.map{|val| val.abs}.max %> - - + - + - - - + + - - + + - - + +
<%= image_tag 'priority/BLOCKER.png'%>  <%= link_to 'Blocker', {:controller => 'drilldown', :action => 'violations', :id => @project.key, :priority => 'BLOCKER'} %> + <%= format_measure(blocker_violations) -%> <%= trend_icon(blocker_violations) -%> + <%= dashboard_configuration.variation? ? format_variation(blocker_violations) : trend_icon(blocker_violations, :empty => true) -%> + - <%= barchart(:width => 60, :percent => (blocker_violations ? (100 * blocker_violations.value / max).to_i : 0), :color => '#777777') if max>0 %> + <% if dashboard_configuration.variation? %> + <%= barchart(:width => 35, :percent => (values[0]<0 ? (100 * values[0] / max).to_i : 0), :color => '#078C00') %> + <%= barchart(:width => 35, :percent => (values[0]>0 ? (100 * values[0] / max).to_i : 0), :color => '#cc0000') %> + <% else %> + <%= barchart(:width => 70, :percent => (100 * values[0] / max).to_i) %> + <% end %>
<%= image_tag 'priority/CRITICAL.png' %>  <%= link_to 'Critical', {:controller => 'drilldown', :action => 'violations', :id => @project.key, :priority => 'CRITICAL'} %> - <%= format_measure(critical_violations) -%> + + <%= format_measure(critical_violations) -%> + + <%= dashboard_configuration.variation? ? format_variation(critical_violations) : trend_icon(critical_violations, :empty => true) -%> <%= trend_icon(critical_violations) -%> - <%= barchart(:width => 60, :percent => (critical_violations ? (100 * critical_violations.value / max).to_i : 0), :color => '#777777') if max>0 %> + <% if dashboard_configuration.variation? %> + <%= barchart(:width => 35, :percent => (values[1]<0 ? (100 * values[1] / max).to_i : 0), :color => '#078C00') %> + <%= barchart(:width => 35, :percent => (values[1]>0 ? (100 * values[1] / max).to_i : 0), :color => '#cc0000') %> + <% else %> + <%= barchart(:width => 70, :percent => (100 * values[1] / max).to_i) %> + <% end %>
<%= image_tag 'priority/MAJOR.png' %>  <%= link_to 'Major', {:controller => 'drilldown', :action => 'violations', :id => @project.key, :priority => 'MAJOR'} %> + <%= format_measure(major_violations) -%> - <%= trend_icon(major_violations) -%> + <%= dashboard_configuration.variation? ? format_variation(major_violations) : trend_icon(major_violations, :empty => true) -%> + - <%= barchart(:width => 60, :percent => (major_violations ? (100 * major_violations.value / max).to_i : 0), :color => '#777777') if max>0 %> + <% if dashboard_configuration.variation? %> + <%= barchart(:width => 35, :percent => (values[2]<0 ? (100 * values[2] / max).to_i : 0), :color => '#078C00') %> + <%= barchart(:width => 35, :percent => (values[2]>0 ? (100 * values[2] / max).to_i : 0), :color => '#cc0000') %> + <% else %> + <%= barchart(:width => 70, :percent => (100 * values[2] / max).to_i) %> + <% end %>
<%= image_tag 'priority/MINOR.png' %>  <%= link_to 'Minor', {:controller => 'drilldown', :action => 'violations', :id => @project.key, :priority => 'MINOR'} %> - <%= format_measure(minor_violations) -%> - <%= trend_icon(minor_violations) -%> + <%= format_measure(minor_violations) -%> + + <%= dashboard_configuration.variation? ? format_variation(minor_violations) : trend_icon(minor_violations, :empty => true) -%> + - <%= barchart(:width => 60, :percent => (minor_violations ? (100 * minor_violations.value / max).to_i : 0), :color => '#777777') if max>0 %> + <% if dashboard_configuration.variation? %> + <%= barchart(:width => 35, :percent => (values[3]<0 ? (100 * values[3] / max).to_i : 0), :color => '#078C00') %> + <%= barchart(:width => 35, :percent => (values[3]>0 ? (100 * values[3] / max).to_i : 0), :color => '#cc0000') %> + <% else %> + <%= barchart(:width => 70, :percent => (100 * values[3] / max).to_i) %> + <% end %>
<%= image_tag 'priority/INFO.png' %>  <%= link_to 'Info', {:controller => 'drilldown', :action => 'violations', :id => @project.key, :priority => 'INFO'} %> - <%= format_measure(info_violations) -%> - <%= trend_icon(info_violations) -%> + <%= format_measure(info_violations) -%> + + <%= dashboard_configuration.variation? ? format_variation(info_violations) : trend_icon(info_violations, :empty => true) -%> + - <%= barchart(:width => 60, :percent => (info_violations ? (100 * info_violations.value / max).to_i : 0), :color => '#777777') if max>0 %> + <% if dashboard_configuration.variation? %> + <%= barchart(:width => 35, :percent => (values[4]<0 ? (100 * values[4] / max).to_i : 0), :color => '#078C00') %> + <%= barchart(:width => 35, :percent => (values[4]>0 ? (100 * values[4] / max).to_i : 0), :color => '#cc0000') %> + <% else %> + <%= barchart(:width => 70, :percent => (100 * values[4] / max).to_i) %> + <% end %>
-<% end %> \ No newline at end of file + diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb index bf89a8e1903..1e8e44cf792 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/size.html.erb @@ -1,63 +1,76 @@ <% -if measure('lines') || measure('ncloc') + lines=measure('lines') + ncloc=measure('ncloc') + classes=measure('classes') files=measure('files') - statements=measure('statements') + packages=measure('packages') + functions=measure('functions') + if measure('lines') || ncloc + files=measure('files') + statements=measure('statements') %> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index 0954951f490..b51e25ac688 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -351,31 +351,31 @@ public final class CoreMetrics { public static final String VIOLATIONS_KEY = "violations"; public static final Metric VIOLATIONS = new Metric(VIOLATIONS_KEY, "Violations", "Violations", Metric.ValueType.INT, - Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); public static final String NEW_VIOLATIONS_KEY = "new_violations"; public static final Metric NEW_VIOLATIONS = new Metric(NEW_VIOLATIONS_KEY, "New Violations", "New Violations", Metric.ValueType.INT, - Metric.DIRECTION_WORST, false, DOMAIN_RULES); + Metric.DIRECTION_WORST, true, DOMAIN_RULES); public static final String BLOCKER_VIOLATIONS_KEY = "blocker_violations"; public static final Metric BLOCKER_VIOLATIONS = new Metric(BLOCKER_VIOLATIONS_KEY, "Blocker violations", "Blocker violations", - Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); public static final String CRITICAL_VIOLATIONS_KEY = "critical_violations"; public static final Metric CRITICAL_VIOLATIONS = new Metric(CRITICAL_VIOLATIONS_KEY, "Critical violations", "Critical violations", - Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); public static final String MAJOR_VIOLATIONS_KEY = "major_violations"; public static final Metric MAJOR_VIOLATIONS = new Metric(MAJOR_VIOLATIONS_KEY, "Major violations", "Major violations", - Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); public static final String MINOR_VIOLATIONS_KEY = "minor_violations"; public static final Metric MINOR_VIOLATIONS = new Metric(MINOR_VIOLATIONS_KEY, "Minor violations", "Minor violations", - Metric.ValueType.INT, Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); public static final String INFO_VIOLATIONS_KEY = "info_violations"; public static final Metric INFO_VIOLATIONS = new Metric(INFO_VIOLATIONS_KEY, "Info violations", "Info violations", Metric.ValueType.INT, - Metric.DIRECTION_WORST, false, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); + Metric.DIRECTION_WORST, true, DOMAIN_RULES).setBestValue(0.0).setOptimizedBestValue(true); /* Design */ diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 259fcb9f06a..d6681e35148 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -111,8 +111,8 @@ public final class JRubyFacade implements ServerComponent { } } - public List> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage, boolean differentialDashboard) { - return getContainer().getComponent(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage, differentialDashboard); + public List> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage) { + return getContainer().getComponent(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage); } public List> getWidgets() { diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java index 791d1c17ff8..59fae3ac6a5 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java @@ -42,7 +42,6 @@ public class ViewProxy implements Comparable { private WidgetLayoutType widgetLayout = WidgetLayoutType.DEFAULT; private boolean isDefaultTab = false; private boolean isWidget = false; - private boolean supportsVariationDashboard = false; public ViewProxy(final V view) { this.view = view; @@ -104,10 +103,6 @@ public class ViewProxy implements Comparable { widgetLayout = layoutAnnotation.value(); } - if (AnnotationUtils.getClassAnnotation(view, SupportVariationDashboard.class)!=null) { - supportsVariationDashboard = true; - } - isWidget = (view instanceof Widget); } @@ -179,10 +174,6 @@ public class ViewProxy implements Comparable { return !ArrayUtils.isEmpty(widgetProperties); } - public boolean supportsVariationDashboard() { - return supportsVariationDashboard; - } - public boolean hasRequiredProperties() { boolean requires = false; for (WidgetProperty property : widgetProperties) { diff --git a/sonar-server/src/main/java/org/sonar/server/ui/Views.java b/sonar-server/src/main/java/org/sonar/server/ui/Views.java index 2f0ccfba48a..69e4c8ee643 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/Views.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/Views.java @@ -76,10 +76,10 @@ public class Views implements ServerComponent { return widgetsPerId.get(id); } - public List> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage, boolean variationDashboard) { + public List> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage) { List> result = Lists.newArrayList(); for (ViewProxy proxy : widgets) { - if (accept(proxy, null, resourceScope, resourceQualifier, resourceLanguage) && (!variationDashboard || proxy.supportsVariationDashboard())) { + if (accept(proxy, null, resourceScope, resourceQualifier, resourceLanguage)) { result.add(proxy); } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 02baac0c617..2ac65f9e3ba 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -185,7 +185,7 @@ class DashboardController < ApplicationController end def load_authorized_widget_definitions() - @widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language, @dashboard_configuration.variation?) + @widget_definitions = java_facade.getWidgets(@resource.scope, @resource.qualifier, @resource.language) @widget_definitions=@widget_definitions.select do |widget| authorized=widget.getUserRoles().size==0 unless authorized 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 12ae02f6c87..191370f66ac 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 @@ -211,8 +211,6 @@ module ApplicationHelper # * :prefix - add a prefix. Default is ''. # * :suffix - add a suffix. Default is ''. # * :default - text to return if metric or measure not found. Default is blank string. - # * :mode - display the measure value (:value) or the variation (:variation). The default mode is :auto, according to the mode selected in the dashboard - # * :variation - the configuration index between 1 and 3. Only when :mode => :variation # # === Examples # @@ -236,39 +234,23 @@ module ApplicationHelper link_rel='' show_link= !options[:url].blank? - variation_mode = false if m.metric.val_type==Metric::VALUE_TYPE_LEVEL html=image_tag("levels/#{m.data.downcase}.png") unless m.data.blank? else - mode=options[:mode]||:auto - if mode==:value - html=m.formatted_value - elsif mode==:variation - html=m.formatted_var_value(options[:variation_index]||1) - variation_mode = true - else - if @dashboard_configuration && @dashboard_configuration.variation? - html=m.formatted_variation_value(@dashboard_configuration.variation_index) - variation_mode = true - else - html=m.formatted_value - end - end + html=m.formatted_value end alert_class='' alert_link = false style = '' - if !variation_mode - if !(m.alert_status.blank?) - alert_class="class='alert_#{m.alert_status}'" unless m.metric.val_type==Metric::VALUE_TYPE_LEVEL - link_rel=h(m.alert_text) - show_link=true - alert_link = true - - elsif m.metric.val_type==Metric::VALUE_TYPE_RATING && m.color - style = "style='background-color: #{m.color.html};padding: 2px 5px'" - end + if !(m.alert_status.blank?) + alert_class="class='alert_#{m.alert_status}'" unless m.metric.val_type==Metric::VALUE_TYPE_LEVEL + link_rel=h(m.alert_text) + show_link=true + alert_link = true + + elsif m.metric.val_type==Metric::VALUE_TYPE_RATING && m.color + style = "style='background-color: #{m.color.html};padding: 2px 5px'" end span_id='' @@ -359,13 +341,28 @@ module ApplicationHelper chart end + # + # + # Draw a HTML/CSS bar + # + # === Optional parameters + # * width: container width in pixels. Default is 150. + # * percent: integer between -100 and 100. Size of the bar inside the container. Default is 100. Bar is aligned to right if the value is negative. + # * color: the bar HTML color. Default value is '#777' + # def barchart(options) percent = (options[:percent] || 100).to_i - return '' if percent<=0 + width=(options[:width] || 150).to_i + if options[:positive_color] && percent>0 + color = options[:positive_color] + elsif options[:negative_color] && percent<0 + color = options[:negative_color] + else + color = options[:color]||'#777' + end - width = (options[:width] || 150).to_i - color = (options[:color] ? "background-color: #{options[:color]};" : '') - "
" + align=(percent<0 ? 'float: right;' : nil) + "
" end def chart(parameters, options={}) @@ -394,12 +391,12 @@ module ApplicationHelper # # === Optional parameters # * big: true|false. Default is false. - # * force: true|false. By default trend icons are hidden when the dashboard variation mode is selected. + # * empty: true|false. Show an empty transparent image when no trend or no measure. Default is false. # # === Examples # trend_icon('ncloc') # trend_icon(measure('ncloc')) - # trend_icon('ncloc', :big => true) + # trend_icon('ncloc', :big => true, :empty => true) # def trend_icon(metric_or_measure, options={}) if metric_or_measure.is_a? ProjectMeasure @@ -408,13 +405,9 @@ module ApplicationHelper m = @snapshot.measure(metric_or_measure) end - if defined?(@dashboard_configuration) && @dashboard_configuration.variation? - return nil unless options[:force] - end - big=options[:big]||false if m.nil? || m.tendency.nil? || m.tendency==0 - return image_tag("transparent.gif", :width => big ? "18" : "16", :alt => "") + return options[:empty] ? image_tag("transparent.gif", :width => big ? "18" : "16", :alt => "") : nil end filename = m.tendency.to_s @@ -429,4 +422,75 @@ module ApplicationHelper suffix = (big ? '' : '-small') image_tag("tendency/#{filename}#{suffix}.png") end + + # + # + # Numeric value of variation + # + # === Optional parameters + # * index: integer between 1 and 3. By default the index is defined by the dashboard variation select-box + # + # === Examples + # variation_value('ncloc') + # variation_value(measure('ncloc')) + # variation_value('ncloc', :index => 3) + # + def variation_value(metric_or_measure, options={}) + if metric_or_measure.is_a?(ProjectMeasure) + m = metric_or_measure + elsif @snapshot + m = @snapshot.measure(metric_or_measure) + end + + index=options[:index] + if index.nil? && defined?(@dashboard_configuration) && @dashboard_configuration.variation? + index = @dashboard_configuration.variation_index + end + + m.variation(index) + end + + + # + # + # Format variation value + # + # === Optional parameters + # * color: true|false. Default is true. + # * index: integer between 1 and 3. By default the index is defined by the dashboard variation select-box + # + # === Examples + # format_variation('ncloc') + # format_variation(measure('ncloc'), :index => 3, :color => true) + # + def format_variation(metric_or_measure, options={}) + 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, options) + if val + formatted_val=(val>=0 ? "+#{m.format_numeric_value(val)}" : m.format_numeric_value(val)) + css_class='' + if options[:color]||true + 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 + end + html="(#{formatted_val})" + end + end + html + end end 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 42f4cccc19f..e249ed87b6c 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 @@ -88,22 +88,36 @@ class ProjectMeasure < ActiveRecord::Base end end - def formatted_variation_value(variation_index) - variation=nil + def format_numeric_value(val) + if metric.nil? + return val.to_s + end + + case metric().val_type + when Metric::VALUE_TYPE_INT + number_with_precision(val, :precision => 0) + when Metric::VALUE_TYPE_FLOAT + number_with_precision(val, :precision => 1) + when Metric::VALUE_TYPE_PERCENT + number_to_percentage(val, {:precision => 1}) + when Metric::VALUE_TYPE_MILLISEC + millisecs_formatted_value( val ) + else + val.to_s + end + end + + def variation(variation_index) + result = nil case variation_index when 1 - variation=diff_value_1 + result=diff_value_1 when 2 - variation=diff_value_2 + result=diff_value_2 when 3 - variation=diff_value_3 - end - if variation - label=format_numeric_value(variation) - variation<0 ? label : "+#{label}" - else - nil + result=diff_value_3 end + result end def millisecs_formatted_value( value ) @@ -277,8 +291,6 @@ class ProjectMeasure < ActiveRecord::Base end end - - def <=>(other) return value<=>other.value end @@ -289,26 +301,6 @@ class ProjectMeasure < ActiveRecord::Base [Metric::VALUE_TYPE_INT, Metric::VALUE_TYPE_FLOAT, Metric::VALUE_TYPE_PERCENT, Metric::VALUE_TYPE_MILLISEC].include?(metric.val_type) end - - def format_numeric_value(val) - if metric.nil? - return val.to_s - end - - case metric().val_type - when Metric::VALUE_TYPE_INT - number_with_precision(val, :precision => 0) - when Metric::VALUE_TYPE_FLOAT - number_with_precision(val, :precision => 1) - when Metric::VALUE_TYPE_PERCENT - number_to_percentage(val, {:precision => 1}) - when Metric::VALUE_TYPE_MILLISEC - millisecs_formatted_value( val ) - else - val.to_s - end - end - def validate_date if not measure_date errors.add_to_base('A valid date must be provided') diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb index 14842ab96a6..e16f0c6a6a9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb @@ -17,6 +17,10 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # + +# +# Sonar 2.4 +# class AddPluginsChildFirstClassloaderColumn < ActiveRecord::Migration def self.up diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb index f1c3fcbe8f6..4ee855ea473 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb @@ -18,6 +18,9 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # +# +# Sonar 2.4 +# class CreateDashboards < ActiveRecord::Migration def self.up diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/152_delete_duplicated_lib_snapshots.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/152_delete_duplicated_lib_snapshots.rb index d7b317bd3e1..f9906e36a8f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/152_delete_duplicated_lib_snapshots.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/152_delete_duplicated_lib_snapshots.rb @@ -17,6 +17,10 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # + +# +# Sonar 2.4 +# class DeleteDuplicatedLibSnapshots < ActiveRecord::Migration def self.up metric=Metric.find(:first, :conditions => ['name=?','lines']) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb index cf9d3189187..f5e0aea9860 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb @@ -17,6 +17,10 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # + +# +# Sonar 2.5 +# class AddRuleFailuresCreatedAtColumn < ActiveRecord::Migration def self.up diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/161_add_snapshots_var_columns.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/161_add_snapshots_var_columns.rb index 8beb83d0cfb..7c18dd8ad0f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/161_add_snapshots_var_columns.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/161_add_snapshots_var_columns.rb @@ -17,6 +17,10 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # + +# +# Sonar 2.5 +# class AddSnapshotsVarColumns < ActiveRecord::Migration def self.up diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb index 8f1cf9c62a2..413b26a437d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb @@ -17,8 +17,13 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # + +# +# Sonar 2.5 +# class DeleteIsoRuleCategories < ActiveRecord::Migration + def self.up remove_rule_categories delete_measures_on_iso_category diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 53562ec76a9..2893e22bba3 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -881,6 +881,21 @@ ul.operations li a { padding: 10px; } + +/* ------------------- VARIATIONS ------------------- */ +.var { + font-weight: bold; + color: #005C9C !important; +} +.varb {/* better */ + font-weight: bold; + color: #078C00 !important; +} +.varw {/* worst */ + font-weight: bold; + color: #cc0000 !important; +} + /* ------------------- HELP ------------------- */ .help { border: 1px solid #ccc; @@ -1303,7 +1318,7 @@ ul.bullet li { div.barchart { border: 0; margin: 0; - padding: 0 5px; + padding: 0; float: left; } diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java index e1ae897c007..69584d249f0 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java @@ -71,7 +71,7 @@ public class ViewsTest { @Test public void getWidgets() { final Views views = new Views(VIEWS); - List> widgets = views.getWidgets(null, null, null, false); + List> widgets = views.getWidgets(null, null, null); assertThat(widgets.size(), is(1)); assertThat(widgets.get(0).getTarget(), is(FakeWidget.class)); } @@ -79,7 +79,7 @@ public class ViewsTest { @Test public void sortViewsByTitle() { final Views views = new Views(new View[]{new FakeWidget("ccc", "ccc"), new FakeWidget("aaa", "aaa"), new FakeWidget("bbb", "bbb")}); - List> widgets = views.getWidgets(null, null, null, false); + List> widgets = views.getWidgets(null, null, null); assertThat(widgets.size(), is(3)); assertThat(widgets.get(0).getId(), is("aaa")); assertThat(widgets.get(1).getId(), is("bbb")); @@ -89,7 +89,7 @@ public class ViewsTest { @Test public void prefixTitleByNumberToDisplayFirst() { final Views views = new Views(new View[]{new FakeWidget("other", "Other"), new FakeWidget("1id", "1widget"), new FakeWidget("2id", "2widget")}); - List> widgets = views.getWidgets(null, null, null, false); + List> widgets = views.getWidgets(null, null, null); assertThat(widgets.size(), is(3)); assertThat(widgets.get(0).getId(), is("1id")); assertThat(widgets.get(1).getId(), is("2id")); -- 2.39.5

Lines of code

- <% if measure('ncloc') %> -

- <%= format_measure('ncloc', :suffix => '', :url => url_for_drilldown('ncloc')) -%> <%= trend_icon('ncloc', :big => true) -%>

+ <% if ncloc %> +

+ <%= format_measure(ncloc, :suffix => '', :url => url_for_drilldown(ncloc)) -%> + <%= dashboard_configuration.variation? ? format_variation(ncloc) : trend_icon(ncloc, :big => true) -%> +

<% generated_ncloc=measure('generated_ncloc') if generated_ncloc && generated_ncloc.value>0 %> -

+<%= format_measure(generated_ncloc, :suffix => ' generated', :url => url_for_drilldown(generated_ncloc)) -%> <%= trend_icon(generated_ncloc) -%>

+

+<%= format_measure(generated_ncloc, :suffix => ' generated', :url => url_for_drilldown(generated_ncloc)) -%> <%= dashboard_configuration.variation? ? format_variation(generated_ncloc) : trend_icon(generated_ncloc) -%>

<% end %> -

<%= format_measure('lines', :suffix => ' lines', :url => url_for_drilldown('lines')) -%> <%= trend_icon('lines') -%>

+

<%= format_measure(lines, :suffix => ' lines', :url => url_for_drilldown(lines)) -%> <%= dashboard_configuration.variation? ? format_variation(lines) : trend_icon(lines) -%>

<% else%> -

<%= format_measure('lines', :suffix => '', :url => url_for_drilldown('lines')) -%> <%= trend_icon('lines', :big => true) -%>

+

<%= format_measure(lines, :suffix => '', :url => url_for_drilldown(lines)) -%> <%= trend_icon(lines, :big => true) -%>

<% end %> <% generated_lines=measure('generated_lines') if generated_lines && generated_lines.value>0 %> -

incl. <%= format_measure(generated_lines, :suffix => ' generated', :url => url_for_drilldown(generated_lines)) -%> <%= trend_icon(generated_lines) -%>

+

incl. <%= format_measure(generated_lines, :suffix => ' generated', :url => url_for_drilldown(generated_lines)) -%> <%= dashboard_configuration.variation? ? format_variation(generated_lines) : trend_icon(generated_lines) -%>

<% end %> <% if statements %>

- <%= format_measure(statements, :suffix => ' statements', :url => url_for_drilldown(statements)) -%> <%= trend_icon(statements) -%> + <%= format_measure(statements, :suffix => ' statements', :url => url_for_drilldown(statements)) -%> <%= dashboard_configuration.variation? ? format_variation(statements) : trend_icon(statements) -%>

<% end %> <% if files && measure('classes') %> -

<%= format_measure(files, :suffix => ' files', :url => url_for_drilldown(files)) -%> <%= trend_icon(files) -%>

+

<%= format_measure(files, :suffix => ' files', :url => url_for_drilldown(files)) -%> <%= dashboard_configuration.variation? ? format_variation(files) : trend_icon(files) -%>

<% end %>
- <% if measure('classes') %> + <% if classes %>

Classes

-

<%= format_measure('classes', :url => url_for_drilldown('classes')) -%> <%= trend_icon('classes') -%>

-

<%= format_measure('packages', :suffix => ' packages', :url => url_for_drilldown('packages')) -%> <%= trend_icon('packages') -%>

+

+ <%= format_measure(classes, :url => url_for_drilldown(classes)) -%> + <%= dashboard_configuration.variation? ? format_variation(classes) : trend_icon(classes, :big => true) -%> +

+

<%= format_measure(packages, :suffix => ' packages', :url => url_for_drilldown(packages)) -%> <%= dashboard_configuration.variation? ? format_variation(packages) : trend_icon(packages) -%>

<% else %>

Files

-

<%= format_measure('files', :url => url_for_drilldown('files')) -%> <%= trend_icon('files') -%>

-

<%= format_measure('directories', :suffix => ' directories', :url => url_for_drilldown('directories')) -%> <%= trend_icon('directories') -%>

+

<%= format_measure(files, :url => url_for_drilldown(files)) -%> + <%= dashboard_configuration.variation? ? format_variation(files) : trend_icon(files, :big => true) -%> +

+

<%= format_measure('directories', :suffix => ' directories', :url => url_for_drilldown('directories')) -%> <%= dashboard_configuration.variation? ? format_variation('directories') : trend_icon('directories') -%>

<% end %> -

<%= format_measure('functions', :suffix => ' methods', :url => url_for_drilldown('functions')) -%> <%= trend_icon('functions') -%>

+

<%= format_measure(functions, :suffix => ' methods', :url => url_for_drilldown(functions)) -%> <%= dashboard_configuration.variation? ? format_variation(functions) : trend_icon(functions) -%>

<% if (measure('accessors')) prefix=(dashboard_configuration.variation? ? '' : '+') %> -

<%= format_measure('accessors', :prefix => prefix, :suffix => ' accessors', :url => url_for_drilldown('accessors')) -%> <%= trend_icon('accessors') -%>

+

<%= format_measure('accessors', :prefix => prefix, :suffix => ' accessors', :url => url_for_drilldown('accessors')) -%> <%= dashboard_configuration.variation? ? format_variation('accessors') : trend_icon('accessors') -%>

<% end %> <% if measure('paragraphs') %> -

<%= format_measure('paragraphs', :suffix => ' paragraphs', :url => url_for_drilldown('paragraphs')) -%> <%= trend_icon('paragraphs') -%>

+

<%= format_measure('paragraphs', :suffix => ' paragraphs', :url => url_for_drilldown('paragraphs')) -%> <%= dashboard_configuration.variation? ? format_variation('paragraphs') : trend_icon('paragraphs') -%>

<% end %>