]> source.dussan.org Git - sonarqube.git/commitdiff
Fix loading of project DSM in drilldown page
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 3 Jul 2014 16:13:01 +0000 (18:13 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 3 Jul 2014 16:13:24 +0000 (18:13 +0200)
13 files changed:
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
sonar-server/src/main/js/application.js
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_footer.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_resource_viewers.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_breadcrumb.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_view.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb

index 4929ad0e5c391353288bbd1743f69efe00acd768..a2879d5cf8c8690c0ee9f1022c3732d3c1933884 100644 (file)
@@ -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,
index 47ede48b64178592bbdd82c8f17cbd1b6155550b..4c93d8a66cb93c09e098dd899d2cc4542c39a560 100644 (file)
@@ -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);
   }
index 00723b0fe60d3b34254659af71b0d9737fb3c336..e84f1158318bbb533061642936ae5024c8b60593 100644 (file)
@@ -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] ******************* //
 
 
index c67ee3048add15d1978d3e46f032a601af28937a..5f595b8daac882ecabc0c4a89512e2a256e5c611 100644 (file)
@@ -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
   #
index 1f871e6639916946151186c3bd36aac2f1a72e12..17986d4857f837f4febd7164fc2ad35176eb3506 100644 (file)
@@ -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
+%>
index 0b3a70e75bf040638caf2698c1cb6e55a571f7e5..7049f5f5469f6496a96c3f0ac5b28cd13ec76d83 100644 (file)
@@ -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;
   }
 
       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>
index 206cc9ee36e5afb00a52ad15ec5e28eea3f9492f..8aef0011a5e795dbe44bb43dfa59841d4332e050 100644 (file)
     };
 
     var url = '<%= ApplicationController.root_context -%>/issues/search?' + jQuery.param(params);
-    openAccordionItem(url, this, false);
+    openAccordionItem(url);
     return false;
   }
 
index 8d42abe34ab14cd661897775c5a30537858e32c0..0bea2a00709f5fcfc5a2d99447fa21684fde8c56 100644 (file)
@@ -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 (file)
index 0000000..f382653
--- /dev/null
@@ -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
+  %>
index 817ee0c470ed98b14778adc11aa7ba78e8dab09e..e3dcb357702b2e6b33515a0579ce82aecce44c44 100644 (file)
@@ -79,9 +79,7 @@
           <li>
             <%= qualifier_icon(resource) -%>
             &nbsp;
-            <%= 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 (file)
index 0000000..6d896b6
--- /dev/null
@@ -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 -%>&amp;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 (file)
index 0000000..1e6e476
--- /dev/null
@@ -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>
index d0ffca59fb278f01ab0fd79f4e9dd5e227e060f9..8ba427b716e3d4c093417fee7e5023c7b0a5bfd0 100644 (file)
@@ -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] -%>">