From a6559a22df82a1686de32e1dc34e5075e8b78cd3 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 18 Jun 2014 18:20:21 +0200 Subject: [PATCH] SONAR-5007 Fix display of active rules in Profile inheritance page --- .../server/qualityprofile/QProfiles.java | 14 +-------- .../app/controllers/profiles_controller.rb | 2 ++ .../WEB-INF/app/helpers/profiles_helper.rb | 20 +++++++++---- .../app/views/profiles/inheritance.html.erb | 30 +++++++++---------- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java index cd688a37511..b6baa8f657f 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java @@ -28,6 +28,7 @@ import org.sonar.server.user.UserSession; import org.sonar.server.util.Validation; import javax.annotation.CheckForNull; + import java.util.List; import java.util.Map; @@ -132,19 +133,6 @@ public class QProfiles implements ServerComponent { projectOperations.removeAllProjects(profileId, UserSession.get()); } - - // PROFILE RULES - public long countProfileRules(QProfile profile) { - // TODO - return -1; - } - - public long countOverridingProfileRules(QProfile profile) { - // TODO - return -1; - //return rules.countProfileRules(ProfileRuleQuery.create(profile.id()).setInheritance(QProfileRule.OVERRIDES)); - } - private void checkProfileNameParam(String name) { if (Strings.isNullOrEmpty(name)) { throw new BadRequestException("quality_profiles.please_type_profile_name"); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index 0be0572ec01..d309b105358 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -222,6 +222,8 @@ class ProfilesController < ApplicationController profiles = Internal.quality_profiles.profilesByLanguage(@profile.language()).to_a.reject { |p| p.id == @profile.id() || p.parent() == @profile.name() } profiles = Api::Utils.insensitive_sort(profiles) { |p| p.name() } @select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name(), profile.id()] } + + @all_profile_stats = Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).getAllProfileStats() end set_profile_breadcrumbs diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb index 156f9648351..280eaf1331d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb @@ -23,12 +23,13 @@ module ProfilesHelper controller.java_facade.getLanguages() end - def label_for_rules_count(qProfile) - profile_rules_count = profile_rules_count(qProfile) + def label_for_rules_count(qProfile, all_profile_stats) + profile_stat = all_profile_stats[qProfile.key()] + profile_rules_count = profile_rules_count(qProfile, profile_stat) label = "#{profile_rules_count} #{message('rules').downcase}" - count_overriding = Internal.quality_profiles.countOverridingProfileRules(qProfile).to_i - if count_overriding>0 + count_overriding = overriding_rules_count(profile_stat) + if count_overriding && count_overriding>0 label += message('quality_profiles.including_x_overriding.suffix', :params => count_overriding) label += image_tag('overrides.png') end @@ -55,7 +56,14 @@ module ProfilesHelper Internal.quality_profiles.countProjects(qProfile).to_i end - def profile_rules_count(qProfile) - Internal.quality_profiles.countProfileRules(qProfile).to_i + def profile_rules_count(qProfile, profile_stat) + count = 0 + count = profile_stat.get('countActiveRules').get(0).getValue() if profile_stat && profile_stat.get('countActiveRules') + count + end + + def overriding_rules_count(profile_stat) + inheritance_stats = Hash[ *profile_stat.get('inheritance').collect { |v| [ v.getKey(), v ] }.flatten ] if profile_stat + inheritance_stats['OVERRIDES'].getValue().to_i if inheritance_stats['OVERRIDES'] end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb index 8ec69c3fe3a..eb6831e481b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb @@ -7,24 +7,24 @@
- <% @ancestors.reverse.each do |parent| %> - <%= parent.name() -%> - (<%= label_for_rules_count(parent) -%>)
- <%= image_tag 'blue-up.png' -%>
- <% end %> + <% @ancestors.reverse.each do |parent| %> + <%= parent.name() -%> + (<%= label_for_rules_count(parent, @all_profile_stats) -%>)
+ <%= image_tag 'blue-up.png' -%>
+ <% end %> - <%= @profile.name -%> (<%= label_for_rules_count(@profile) -%>)
+ <%= @profile.name -%> (<%= label_for_rules_count(@profile, @all_profile_stats) -%>)
- <% if @children.size>0 %> - <%= image_tag 'blue-up.png' -%>
- <% @children.each_with_index do |child,index| %> - <%= ', ' if index>0 -%> - <%= child.name() -%> - (<%= label_for_rules_count(child) -%>) - <% end %> -
<%= image_tag 'blue-up.png' -%>
- ... + <% if @children.size>0 %> + <%= image_tag 'blue-up.png' -%>
+ <% @children.each_with_index do |child,index| %> + <%= ', ' if index>0 -%> + <%= child.name() -%> + (<%= label_for_rules_count(child, @all_profile_stats) -%>) <% end %> +
<%= image_tag 'blue-up.png' -%>
+ ... + <% end %>
<% if profiles_administrator? %> -- 2.39.5