From 1a0d00659736c083afa6eae1f08c6ee3ea6f6752 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 4 Oct 2012 18:54:51 +0200 Subject: SONAR-3819 Use the "options" parameter on @Property to filter metrics --- .../webapp/WEB-INF/app/helpers/settings_helper.rb | 19 +++++++++++ .../app/views/settings/_type_METRIC.html.erb | 38 +++++++++------------- 2 files changed, 35 insertions(+), 22 deletions(-) (limited to 'sonar-server') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb index 13603e2af35..0272059d815 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb @@ -86,4 +86,23 @@ module SettingsHelper end name end + + def metrics_for_property(property) + Metric.all.select(&:display?).sort_by(&:short_name).select do |metric| + property.options.blank? || property.options.any? { |option| metric_matches(metric, option) } + end + end + + def metric_matches(metric, option) + if /key:(.*)/.match(option) + Regexp.new(Regexp.last_match(1).strip).match(metric.key) + elsif /domain:(.*)/.match(option) + Regexp.new(Regexp.last_match(1)).match(metric.domain) + elsif /type:(.*)/.match(option) + false + Regexp.last_match(1).split(',').any? { |type| (type == metric.value_type) || ((type == 'NUMERIC') && metric.numeric?) } + else + false + end + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb index c4329684079..61840cb7fa4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb @@ -1,27 +1,21 @@ \ No newline at end of file -- cgit v1.2.3