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;
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);
}
return defaultForMetrics;
}
+ public boolean supportsMetric(String metricKey) {
+ return ArrayUtils.contains(defaultForMetrics, metricKey);
+ }
+
public boolean isWidget() {
return isWidget;
}
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);
}
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
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]
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
#
module DrilldownHelper
-
end
\ No newline at end of file
# 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=[]
<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 %>
<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;
}
<%= render :partial => 'header' -%>
-
-
<% if params[:period] && @snapshot.project_snapshot.periods? %>
<div id="snapshot_title" class="page_title">
<h4>
</div>
<% end %>
-
-
-
<div class="dashbox">
<% if @characteristic %>
<h3><%= @highlighted_metric.short_name -%> / <%= h(@characteristic.name(true)) -%></h3>
-<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">
<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>