diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-03 18:13:01 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-07-03 18:13:24 +0200 |
commit | 3641dbcc16ad55b3b234719bb4e4cc7eae722052 (patch) | |
tree | 72e1d996bcb4543ee58224fa7b622a50d008339e | |
parent | 3343d28699fc46d0e3210711dc310e2da821c9f7 (diff) | |
download | sonarqube-3641dbcc16ad55b3b234719bb4e4cc7eae722052.tar.gz sonarqube-3641dbcc16ad55b3b234719bb4e4cc7eae722052.zip |
Fix loading of project DSM in drilldown page
13 files changed, 139 insertions, 108 deletions
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java index 4929ad0e5c3..a2879d5cf8c 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java @@ -37,11 +37,11 @@ public class DesignPlugin extends SonarPlugin { public List<Class<? extends Extension>> getExtensions() { return ImmutableList.of( - // Batch - MavenDependenciesSensor.class, - ProjectDsmDecorator.class, - PackageTangleIndexDecorator.class, - FileTangleIndexDecorator.class, + // Batch + MavenDependenciesSensor.class, + ProjectDsmDecorator.class, + PackageTangleIndexDecorator.class, + FileTangleIndexDecorator.class, // UI GwtLibrariesPage.class, 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 47ede48b641..4c93d8a66cb 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 @@ -211,6 +211,10 @@ public final class JRubyFacade { return get(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures); } + public List<ViewProxy<Page>> getResourceTabs() { + return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null, null); + } + public List<ViewProxy<Page>> getResourceTabs(String scope, String qualifier, String language, Object[] availableMeasures) { return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language, (String[]) availableMeasures); } diff --git a/sonar-server/src/main/js/application.js b/sonar-server/src/main/js/application.js index 00723b0fe60..e84f1158318 100644 --- a/sonar-server/src/main/js/application.js +++ b/sonar-server/src/main/js/application.js @@ -381,44 +381,7 @@ function supportsHTML5Storage() { //******************* HANDLING OF ACCORDION NAVIGATION [BEGIN] ******************* // -function openAccordionItem(url, elt, updateCurrentElement) { - var htmlClass = 'accordion-item'; - var currentElement = $j(elt).closest('.'+ htmlClass); - - // Create loading image - var loadingImg = new Image(); - loadingImg.src = baseUrl + "/images/loading.gif"; - loadingImg.className = 'accordion-loading'; - var loading = $j(loadingImg); - var existingLoading = currentElement.find('.accordion-loading'); - if (updateCurrentElement && existingLoading.length) { - existingLoading.show(); - loading.hide(); - } - - // Remove elements under current element - if (currentElement.length) { - // Fix the height in order to not change the position on the screen when removing elements under current element - var elementToRemove = currentElement.nextAll('.'+ htmlClass); - if (elementToRemove.height()) { - $j("#accordion-panel").height($j("#accordion-panel").height() + elementToRemove.height()); - } - // Remove all accordion items after current element - elementToRemove.remove(); - // Display loading image only if not already displayed (if previous call was not finished) - if (currentElement.next('.accordion-loading').length === 0) { - loading.insertAfter(currentElement); - } - } else { - // Current element is not in a working view, remove all working views - $j('.'+ htmlClass).remove(); - // Display loading image only if not already displayed (if previous call was not finished) - if ($j("#accordion-panel").next('.accordion-loading').length === 0) { - loading.insertAfter($j("#accordion-panel")); - } - } - - // Get content from url +function openAccordionItem(url) { var ajaxRequest = $j.ajax({ url: url }).fail(function (jqXHR, textStatus) { @@ -426,58 +389,14 @@ function openAccordionItem(url, elt, updateCurrentElement) { console.log(error); $j("#accordion-panel").append($j('<div class="error">').append(error)); }).done(function (html) { - if (currentElement.length) { - var body = currentElement.find('.accordion-item-body'); - if (!updateCurrentElement && !body.hasClass('accordion-item-body-medium')) { - body.addClass("accordion-item-body-medium"); - elt.scrollIntoView(false); - } - } else { - $j("#accordion-panel").height('auto'); - - // Current element is not in a working view, remove again all working views to purge elements that could be added just before this one - $j('.'+ htmlClass).remove(); - } - - if (updateCurrentElement) { - // Fix the height in order to not change the position on the screen - var prevHeight = $j("#accordion-panel").height(); - currentElement.html(html); - $j("#accordion-panel").height('auto'); - var newHeight = $j("#accordion-panel").height(); - if (prevHeight > newHeight) { - $j("#accordion-panel").height(prevHeight); - } else { - $j("#accordion-panel").height(newHeight); - } - } else { - // Add new item add the end of the panel and restore the height param - var nbElement = $j("."+htmlClass).size(); - var newElement = $j('<div id="'+ htmlClass + nbElement +'" class="'+ htmlClass +'">'); - $j("#accordion-panel").append(newElement); - - // Add html after having adding the new element in the page in order to scripts (for instance for GWT) to be well executed - newElement.append(html); - $j("#accordion-panel").height('auto'); - - // Set the focus on the top of the current item with animation - if (currentElement.length) { - $j('html, body').animate({ - scrollTop: currentElement.offset().top}, 500 - ); - } - } - loading.remove(); + var panel = $j("#accordion-panel"); + panel.html(html); + panel.scrollIntoView(false); }); return ajaxRequest; } -function expandAccordionItem(elt) { - var currentElement = $j(elt).closest('.accordion-item'); - currentElement.find('.accordion-item-body').removeClass("accordion-item-body-medium"); -} - //******************* HANDLING OF ACCORDION NAVIGATION [END] ******************* // diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index c67ee3048ad..5f595b8daac 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -41,6 +41,20 @@ class ResourceController < ApplicationController redirect_to :controller => 'component', :action => 'index', :anchor => anchor end + # deprecated stuff for drilldown + def view + require_parameters 'id' + @resource = Project.by_key(params[:id]) + access_denied unless has_role?(:user, @resource) + @snapshot = @resource.last_snapshot + load_extensions() if @snapshot + if @extension + render :partial => 'view' + else + not_found('Extension not found') + end + end + # # Call by new component viewer to display plugin extension # 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 1f871e66399..17986d4857f 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,14 @@ <div id="resource_container"> </div> -<% if @display_viewers && @drilldown.highlighted_resource %> -<script> - d(<%= @drilldown.highlighted_resource.id -%>, true); -</script> -<% end %> +<% + if @display_viewers + resource = @drilldown.highlighted_resource || @drilldown.resource + if resource +%> + <script> + d(<%= resource.id -%>, <%= resource.source_code? -%>); + </script> +<% + end + 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 0b3a70e75bf..7049f5f5469 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 @@ -1,12 +1,13 @@ +<%= render :partial => 'gwt/base', :locals => {:resource => nil, :popup => false, :metric => (@metric ? @metric.key : nil)} -%> +<%= render :partial => 'gwt/resource_viewers' -%> + <script type="text/javascript"> /* display resource */ - function d(resourceId, display_title) { - if (display_title == undefined) { - display_title = true; - } - var url = '<%= ApplicationController.root_context -%>/resource/index/' + resourceId + '?metric=<%= @metric.id if @metric -%>' + - '&rule=<%= @rule ? @rule.id : @severity -%>&period=<%= @period -%>&project=<%= @resource.id -%>&display_title=' + display_title; - openAccordionItem(url, this); + function d(resourceId, is_file) { + var action = is_file ? 'index' : 'view'; + var url = '<%= ApplicationController.root_context -%>/resource/' + action + '/' + resourceId + '?metric=<%= @metric.id if @metric -%>' + + '&rule=<%= @rule ? @rule.id : @severity -%>&period=<%= @period -%>&project=<%= @resource.id -%>'; + openAccordionItem(url); return false; } @@ -19,4 +20,13 @@ window.location.reload(); } } + + function loadGWT(gwtId, resourceId, resourceKey, resourceName, resourceScope, resourceQualifier, resourceLanguage) { + config["resource"] = [ + {"id":resourceId, "key":resourceKey, "name":resourceName, "scope":resourceScope, "qualifier":resourceQualifier, + "lang":resourceLanguage} + ]; + config["resource_key"] = resourceId; + modules[gwtId](); + } </script> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb index 206cc9ee36e..8aef0011a5e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb @@ -213,7 +213,7 @@ }; var url = '<%= ApplicationController.root_context -%>/issues/search?' + jQuery.param(params); - openAccordionItem(url, this, false); + openAccordionItem(url); 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 8d42abe34ab..0bea2a00709 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 @@ -87,7 +87,7 @@ <a href="#" title="<%= h resource.name(true) -%>" data-key="<%= resource.key -%>" class="js-drilldown-link underlined-link"><%= h resource.name(false) %></a> <% else %> - <%= link_to(h(resource.name), {:only_path => true, :overwrite_params => {:rids => (selected ? rids-[resource.id] : rids+[resource.id])}}, :class => 'underlined-link') -%> + <%= link_to(h(resource.name), params.merge({:only_path => true, :rids => (selected ? rids-[resource.id] : rids+[resource.id])}), :class => 'underlined-link') -%> <% end %> </td> <td class="right"> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb new file mode 100644 index 00000000000..f382653f6b3 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb @@ -0,0 +1,9 @@ +<% + controller.java_facade.getResourceTabs().each do |tab| + if tab.isGwt() +%> + <script src="<%= ApplicationController.root_context -%>/deploy/gwt/<%= tab.getId() -%>/<%= tab.getId() -%>.nocache.js"></script> + <% + end + end + %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb index 817ee0c470e..e3dcb357702 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb @@ -79,9 +79,7 @@ <li> <%= qualifier_icon(resource) -%> - <%= link_to(h(resource.name), - {:overwrite_params => {:id => resource.key}.merge(resource_link)} - ) -%> + <%= link_to(h(resource.name), params.merge({:id => resource.key}.merge(resource_link))) -%> </li> <% end 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 new file mode 100644 index 00000000000..6d896b6dfbb --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb @@ -0,0 +1,54 @@ +<% + if @extensions.empty? +%> + <span class="note"><%= message('code_viewer.no_info_displayed_due_to_security') -%></span> +<% + else + display_title=(params[:display_title]=='true') +%> + + <% if display_title %> + <div class="source_title"> + <% if @resource.project %> + <div class="subtitle"> + <%= h @resource.ancestor_projects.reverse.map{|p| p.name(true)}.join(' / ') -%> + </div> + <% end %> + <% if logged_in? %><%= link_to_favourite(@resource) -%><% end %> + <span class="h1"><%= qualifier_icon(@resource) -%> <%= h @resource.name(true) -%></span> + </div> + <% end %> + + <div class="source_tabs"> + <ul class="tablinks"> + <% first=true %> + <% if @snapshot.has_source && has_role?(:codeviewer, @snapshot) %> + <li class="<%= 'first' if first -%>"> + <a href="<%= ApplicationController.root_context -%>/api/sources?resource=<%= @resource.key -%>&format=txt"><%= message('raw') -%></a> + </li> + <% first=false + end %> + <% unless @popup_mode %> + <li class="<%= 'first' if first -%>"> + <a href="<%= url_for :controller => 'resource', :action => 'index', :id => @resource.key, :period => params[:period], :metric => params[:metric], + :rule => params[:rule] ? params[:rule] : params[:rule_sev], :display_title => 'true' -%>" + onclick="window.open(this.href,'resource','height=800,width=900,scrollbars=1,resizable=1');return false;" + id="new-window-<%= @resource.key.parameterize -%>"><%= image_tag 'new-window-16.gif', :alt => message('new_window') -%></a> + </li> + <% end %> + </ul> + <ul class="tabs"> + <% @extensions.each do |extension| %> + <li> + <a href="#" onclick="return loadResourceViewer('<%= @resource.id -%>','<%= extension.getId() -%>',<%= display_title -%>,'<%= params[:period] -%>', this)" + class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= message(extension.getId() + '.page', :default => extension.getTitle()) %></a> + </li> + <% end %> + <li> + <img src="<%= ApplicationController.root_context -%>/images/loading.gif" id="resource_loading" class="accordion-loading" style="display:none"/> + </li> + </ul> + </div> + + +<% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_view.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_view.html.erb new file mode 100644 index 00000000000..1e6e4762245 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_view.html.erb @@ -0,0 +1,16 @@ +<div> + <div class="accordion-item-header"> + <%= render :partial => 'tabs' -%> + </div> + <div class="accordion-item-body"> + <% if @extension.isGwt() %> + <div id="gwtpage"> </div> + <script> + loadGWT('<%= @extension.getId() -%>', <%= @resource.id -%>,'<%= escape_javascript(@resource.key) -%>', '<%= escape_javascript(@resource.name) -%>', + '<%= @resource.scope -%>', '<%= @resource.qualifier -%>', '<%= escape_javascript(@resource.language) -%>'); + </script> + <% elsif @extension.getTarget() # ruby on rails page %> + <%= render :inline => @extension.getTarget().getTemplate() -%> + <% end %> + </div> +</div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb index d0ffca59fb2..8ba427b716e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb @@ -2,7 +2,7 @@ <td class="ind <%= statuses[:hits] -%>" title="<%= message('coverage_viewer.line_covered_by_x_tests', {:params => line.covered_lines.to_s}) if line.covered_lines > 0 -%>"> <% if line.covered_lines > 0 %> <a href="<%= ApplicationController.root_context -%>/test/testable/<%= h resource_key -%>?line=<%= index+1 -%>" - class="sources-testable-link-<%= index+1 -%>" onclick="openAccordionItem(this.href, this); return false;"><%= line.covered_lines -%></a> + class="sources-testable-link-<%= index+1 -%>" onclick="openAccordionItem(this.href); return false;"><%= line.covered_lines -%></a> <% end %> </td> <td class="ind <%= statuses[:conditions] -%>"> |