From: simonbrandhof Date: Thu, 28 Apr 2011 14:09:26 +0000 (+0200) Subject: Improve display of resource viewers on projects and directories. X-Git-Tag: 2.8~83 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1f586999329fba3ee0bdd75774b1a542f312768e;p=sonarqube.git Improve display of resource viewers on projects and directories. SONAR-2338 Unable to drilldown by dependency metrics from sub-project SONAR-2201 Display project violations --- 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 972017928b3..7fae7b28124 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 @@ -24,7 +24,6 @@ import org.picocontainer.PicoContainer; import org.slf4j.LoggerFactory; import org.sonar.api.Plugins; import org.sonar.api.Property; -import org.sonar.api.ServerComponent; import org.sonar.api.profiles.ProfileExporter; import org.sonar.api.profiles.ProfileImporter; import org.sonar.api.resources.Language; @@ -155,6 +154,10 @@ public final class JRubyFacade { return getContainer().getComponent(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language); } + public List> getResourceTabsForMetric(String scope, String qualifier, String language, String metric) { + return getContainer().getComponent(Views.class).getPagesForMetric(NavigationSection.RESOURCE_TAB, scope, qualifier, language, metric); + } + public ViewProxy getPage(String id) { return getContainer().getComponent(Views.class).getPage(id); } 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 c00437ac9dc..badeb5f78ec 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 @@ -158,6 +158,10 @@ public class ViewProxy implements Comparable { return defaultForMetrics; } + public boolean supportsMetric(String metricKey) { + return ArrayUtils.contains(defaultForMetrics, metricKey); + } + public boolean isWidget() { return isWidget; } 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 d1bf0e9c80d..dc776684a14 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 @@ -79,6 +79,16 @@ public class Views implements ServerComponent { return result; } + public List> getPagesForMetric(String section, String resourceScope, String resourceQualifier, String resourceLanguage, String metric) { + List> result = Lists.newArrayList(); + for (ViewProxy proxy : pages) { + if (accept(proxy, section, resourceScope, resourceQualifier, resourceLanguage) && proxy.supportsMetric(metric)) { + result.add(proxy); + } + } + return result; + } + public ViewProxy getWidget(String id) { return widgetsPerId.get(id); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb index 90a2cce018b..a64ef97622f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb @@ -62,6 +62,8 @@ class DrilldownController < ApplicationController if @highlighted_resource.nil? && @drilldown.columns.empty? @highlighted_resource=@project end + + @display_viewers=display_metric_viewers?(@highlighted_resource||@project, @highlighted_metric.key) end def violations @@ -111,9 +113,11 @@ class DrilldownController < ApplicationController if @highlighted_resource.nil? && @drilldown.columns.empty? @highlighted_resource=@project end + + @display_viewers=display_violation_viewers?(@snapshot) end - protected + private def init_project project_key = params[:id] @@ -151,4 +155,20 @@ class DrilldownController < ApplicationController hash end + def display_metric_viewers?(resource,metric_key) + return true if resource.file? + java_facade.getResourceTabsForMetric(resource.scope, resource.qualifier, resource.language, metric_key).each do |tab| + tab.getUserRoles().each do |role| + if has_role?(role, resource) + return true + end + end + end + false + end + + def display_violation_viewers?(snapshot) + return true if snapshot.file? + snapshot.violations.size>0 + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb index 400d4af0886..103934e9e49 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb @@ -19,5 +19,4 @@ # module DrilldownHelper - end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb index 33108f61b8c..62148d4e8bd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb @@ -18,9 +18,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class Drilldown - attr_reader :snapshot, :columns, :metric + attr_reader :snapshot, :columns, :metric, :resource def initialize(resource, metric, selected_resource_ids, options={}) + @resource=resource @snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => resource.id}, :include => [:project]) @metric=metric @columns=[] diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb index 435c2c67952..a2e095d5078 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb @@ -1,7 +1,11 @@
-<% if @drilldown.highlighted_resource %> +<% if @display_viewers %> -<% end %> \ No newline at end of file +<% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb index f8556da3636..f9b93245679 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb @@ -3,17 +3,23 @@