aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-28 16:09:26 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-28 16:10:39 +0200
commit1f586999329fba3ee0bdd75774b1a542f312768e (patch)
treed8a7b00f4c0ee5d3f2ba405947f9c03a3d8aef2b /sonar-server
parente4f93c4e8959352487f4c4105f158023fd4558be (diff)
downloadsonarqube-1f586999329fba3ee0bdd75774b1a542f312768e.tar.gz
sonarqube-1f586999329fba3ee0bdd75774b1a542f312768e.zip
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
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java5
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/Views.java10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb11
10 files changed, 64 insertions, 21 deletions
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<ViewProxy<Page>> getResourceTabsForMetric(String scope, String qualifier, String language, String metric) {
+ return getContainer().getComponent(Views.class).getPagesForMetric(NavigationSection.RESOURCE_TAB, scope, qualifier, language, metric);
+ }
+
public ViewProxy<Page> 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<V extends View> implements Comparable<ViewProxy> {
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<ViewProxy<Page>> getPagesForMetric(String section, String resourceScope, String resourceQualifier, String resourceLanguage, String metric) {
+ List<ViewProxy<Page>> result = Lists.newArrayList();
+ for (ViewProxy<Page> proxy : pages) {
+ if (accept(proxy, section, resourceScope, resourceQualifier, resourceLanguage) && proxy.supportsMetric(metric)) {
+ result.add(proxy);
+ }
+ }
+ return result;
+ }
+
public ViewProxy<Widget> 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 @@
<div id="resource_container"> </div>
-<% if @drilldown.highlighted_resource %>
+<% if @display_viewers %>
<script>
- d(<%= @drilldown.highlighted_resource.id -%>);
+ <% if @drilldown.highlighted_resource %>
+ d(<%= @drilldown.highlighted_resource.id -%>, true);
+ <% else %>
+ d(<%= @drilldown.resource.id -%>, false);
+ <% end %>
</script>
-<% 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 @@
<script>
/* display resource */
- function d(resourceId) {
+ function d(resourceId, display_title) {
var loading = new Image();
loading.src = "<%= ApplicationController.root_context-%>/images/loading.gif";
$('resource_container').update(loading);
- new Ajax.Updater('resource_container', '<%= ApplicationController.root_context-%>/resource/index/' + resourceId + '?metric=<%= @metric.id if @metric -%>&rule=<%= @rule ? @rule.id : params[:priority] -%>&period=<%= @period -%>', {asynchronous:true, evalScripts:true});
+ if (display_title==undefined) {
+ display_title=true;
+ }
+ new Ajax.Updater('resource_container', '<%= ApplicationController.root_context-%>/resource/index/' + resourceId + '?metric=<%= @metric.id if @metric -%>&rule=<%= @rule ? @rule.id : params[:priority] -%>&period=<%= @period -%>&display_title=' + display_title, {asynchronous:true, evalScripts:true});
return false;
}
- function loadAjaxTab(resourceId, tab) {
+ function loadAjaxTab(resourceId, tab, display_title) {
$('resource-loading').show();
- new Ajax.Updater('resource_container', '<%= ApplicationController.root_context-%>/resource/index/' + resourceId + '?tab=' + tab, {asynchronous:true, evalScripts:true});
+ if (display_title==undefined) {
+ display_title=true;
+ }
+ new Ajax.Updater('resource_container', '<%= ApplicationController.root_context-%>/resource/index/' + resourceId + '?tab=' + tab + '&display_title=' + display_title, {asynchronous:true, evalScripts:true});
return false;
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
index dccb0e81d9d..e6f5d625eb5 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
@@ -1,7 +1,5 @@
<%= render :partial => 'header' -%>
-
-
<% if params[:period] && @snapshot.project_snapshot.periods? %>
<div id="snapshot_title" class="page_title">
<h4>
@@ -21,9 +19,6 @@
</div>
<% end %>
-
-
-
<div class="dashbox">
<% if @characteristic %>
<h3><%= @highlighted_metric.short_name -%> / <%= h(@characteristic.name(true)) -%></h3>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb
index 37b30e047e5..3374fc037fc 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb
@@ -1,10 +1,11 @@
-<style>
-
-</style>
-
+<%
+ display_title=(params[:display_title]!='false')
+ if display_title
+%>
<div id="source_title">
<span class="h1"><%= qualifier_icon(@resource) -%> <%= @resource.long_name -%></span>
</div>
+<% end %>
<div id="source_tabs">
<ul class="tablinks">
@@ -22,7 +23,7 @@
<ul class="tabs" >
<% if request.xhr? %>
<% @extensions.each do |extension| %>
- <li><a href="#" onclick="loadAjaxTab('<%= @resource.id -%>','<%= extension.getId() -%>')" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
+ <li><a href="#" onclick="loadAjaxTab('<%= @resource.id -%>','<%= extension.getId() -%>',<%= display_title -%>)" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
<% end %>
<% else %>
<script>function loadTab(url) {$('resource-loading').show();document.location.href=url;return false;}</script>