]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3893 Introduced unique partial for source display
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 22 Apr 2013 09:19:21 +0000 (11:19 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Mon, 22 Apr 2013 09:19:21 +0000 (11:19 +0200)
15 files changed:
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb [deleted file]
sonar-server/src/main/webapp/javascripts/resource.js

index 716d387f35ec30edd8968e33d35c2ef19975023d..8cce4f6448b624f75cf077afea6050aba5ccf6d2 100644 (file)
@@ -787,4 +787,56 @@ module ApplicationHelper
     html
   end
 
+
+  def prepare_colspans(display_violation_form, scm_available, display_coverage)
+
+    colspan=2
+    gray_colspan=1
+    white_colspan=0
+    if display_violation_form
+      colspan+=1
+      gray_colspan+=1
+    end
+    if scm_available
+      colspan+=1
+      gray_colspan+=1
+    end
+    if display_coverage
+      colspan+=2
+      white_colspan+=2
+    end
+
+    {:base => colspan, :gray => gray_colspan, :white => white_colspan}
+  end
+
+
+  def compute_statuses(line, display_coverage, display_violations)
+
+    status=hits_status=conditions_status=''
+
+    if line.highlighted?
+      if display_coverage && line.hits
+        hits_status=(line.hits>0 ? 'ok' : 'ko')
+        if line.conditions && line.conditions>0 && line.covered_conditions
+          if line.covered_conditions==0
+            status='ko'
+            conditions_status='ko'
+          elsif line.covered_conditions==line.conditions
+            status=''
+            conditions_status='ok'
+          else
+            conditions_status='warn'
+            status='warn'
+          end
+        elsif line.hits
+          status=(line.hits>0 ? '' : 'ko')
+        end
+      elsif display_violations && line.violations?
+        status="ko"
+      end
+    end
+
+    {:base => status, :hits => hits_status, :conditions => conditions_status}
+  end
+
 end
index bebaa63d46274a629a0fc96d951ebc0c3f2c63ac..d0b5a57c2d549cf37391aacadde346ddb0460a37 100644 (file)
@@ -59,8 +59,22 @@ module SourceHelper
     end
 
     panel.filter_min_date(options[:min_date]) if options[:min_date]
-    
-    render :partial => 'source/source', :locals => {:panel => panel}
+
+    unless panel.empty?
+
+      render :partial => "shared/source_display", :locals => { :display_manual_violation_form => false, \
+                                                               :scm_available => options[:display_scm], \
+                                                               :display_coverage => options[:display_coverage], \
+                                                               :lines => panel.html_lines, \
+                                                               :expanded => options[:expand], \
+                                                               :display_violations => options[:display_violations], \
+                                                               :resource => nil, \
+                                                               :snapshot => nil, \
+                                                               :review_screens_by_vid => false, \
+                                                               :filtered => panel.filtered }
+
+    end
+
   end
 
   def load_distribution(snapshot, metric_key)
@@ -171,5 +185,10 @@ module SourceHelper
         end
       end
     end
+
+    def highlighted?
+      # highlighted if the @highlighted has not been set or has been set to true
+      !hidden? && @highlighted!=false
+    end
   end
 end
\ No newline at end of file
index f6fd0e25332026e3f002d3728efeed1baaaf567a..2d4e1bf0aa751324379d9a9fded88b06c88b6cee 100644 (file)
     item.scrollIntoView(true);
   });
   <% end %>
-  $j("#content").on("click", "span[class|='symbol']", highlight_usages);
 </script>
 
 <div id="accordion-panel"/>
index 4ba68cf8d0a7c31ee9867cede8ce0c6a566153a9..407adaa5b67bdbadbeb3cf77a3ebcac16e706c46 100644 (file)
@@ -9,7 +9,10 @@
       <table class="global_violations" cellpadding="0" cellspacing="0" border="0">
         <% @global_violations.each do |violation| %>
           <tr>
-            <td><%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%></td>
+            <td>
+                <%= render :partial => 'violation', :locals => {:violation => violation, \
+                                                                :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%>
+            </td>
           </tr>
         <% end %>
       </table>
 
     <% if @lines && @lines.size>0 %>
 
-      <table id="sources" class="sources2 code" cellpadding="0" cellspacing="0" border="0">
-        <%
-           colspan=2
-           gray_colspan=1
-           white_colspan=0
-           if @display_manual_violation_form
-             colspan+=1
-             gray_colspan+=1
-           end
-           if @scm_available
-             colspan+=1
-             gray_colspan+=1
-           end
-           if @display_coverage
-             colspan+=2
-             white_colspan+=2
-           end
-
-           current_revision=nil
-           previous_hidden=false
-           first_section=true
-           has_displayed_lines=false
-           @lines.each_with_index do |line, index|
-             if line.hidden? && !@expanded
-               previous_hidden=true
-               next
-             end
-
-             if previous_hidden && !first_section
-               current_revision=nil
-        %>
-            <tr>
-              <td colspan="<%= colspan -%>" class="new_section"></td>
-            </tr>
-          <%
-             end
-             previous_hidden=false
-             first_section=false
-
-             status=hits_status=conditions_status=''
-             if line.highlighted?
-               has_displayed_lines=true
-               if @display_coverage && line.hits
-                 hits_status=(line.hits>0 ? 'ok' : 'ko')
-                 if line.conditions && line.conditions>0 && line.covered_conditions
-                   if line.covered_conditions==0
-                     status='ko'
-                     conditions_status='ko'
-                   elsif line.covered_conditions==line.conditions
-                     status=''
-                     conditions_status='ok'
-                   else
-                     conditions_status='warn'
-                     status='warn'
-                   end
-                 elsif line.hits
-                   status=(line.hits>0 ? '' : 'ko')
-                 end
-               elsif @display_violations && line.violations?
-                 status="ko"
-               end
-             end
-          %>
-          <tr class="row pos<%= index+1 -%>">
-            <% if @display_manual_violation_form %>
-              <td class="plus"><a onclick="return sVF(this, <%= @resource.id -%>,<%= index + 1 -%>,<%= gray_colspan -%>,<%= white_colspan -%>)"></a></td>
-            <%
-               end
-               if @scm_available
-                 if current_revision!=line.revision
-                   current_revision=line.revision
-                   title = "Revision #{h(line.revision)}"
-            %>
-                <td class="scm revision">
-                  <span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%></a></span>
-                  <span class="author"><%= h(line.author) -%></span></td>
-              <% else %>
-                <td class="scm"></td>
-              <% end
-                 end
-              %>
-            <td class="lid L<%= index+1 -%>"><a name="L<%= index+1 -%>" href="#L<%= index+1 -%>"><%= index + 1 -%></a>
-            </td>
-
-            <% if @display_coverage %>
-              <% if line.highlighted? %>
-                <td class="ind <%= hits_status -%>" 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 @snapshot.resource.key -%>?line=<%= index+1 -%>"
-                       class="sources-testable-link-<%= index+1 -%>" onclick="openAccordionItem(this.href, this); return false;"><%= line.covered_lines -%></a>
-                  <% end %>
-                </td>
-                <td class="ind <%= conditions_status -%>">
-                  <% if line.deprecated_conditions_label -%>
-                    <%= line.deprecated_conditions_label -%>
-                  <% elsif line.conditions && line.conditions>0 -%>
-                    <span title="<%= h message('coverage_viewer.x_covered_branches', {:params => line.covered_conditions.to_s})-%>"><%= line.covered_conditions -%>/<%= line.conditions -%></span>
-                  <% end %>
-                </td>
-              <% else %>
-                <td class="ind"></td>
-                <td class="ind"></td>
-              <% end %>
-            <% end %>
-            <td class="line <%= status -%>">
-              <pre><%= line.source -%></pre>
-            </td>
-          </tr>
-          <% if @display_violations && line.violations? %>
-            <tr>
-              <% if @display_manual_violation_form %>
-                <td class="gray"></td>
-              <% end
-                 if @scm_available %>
-                <td class="scm"></td>
-              <% end %>
-              <td class="lid"></td>
-              <td class="violations">
-                <% line.violations.each_with_index do |violation, index| %>
-                  <%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%>
-                  <% if index < line.violations.size-1 %>
-                    &nbsp;
-                  <% end %>
-                <% end %>
-              </td>
-            </tr>
-          <% end %>
-        <% end %>
-      </table>
-
-      <% if @filtered && !has_displayed_lines %>
-        <p style="padding: 10px"><%= message('no_lines_match_your_filter_criteria') -%></p>
-      <% end %>
+      <%= render :partial => "shared/source_display", :locals => { :display_manual_violation_form => @display_manual_violation_form, \
+                                                                   :scm_available => @scm_available, \
+                                                                   :display_coverage => @display_coverage, \
+                                                                   :lines => @lines, \
+                                                                   :expanded => @expanded, \
+                                                                   :display_violations => @display_violations, \
+                                                                   :resource => @resource, \
+                                                                   :snapshot => @snapshot, \
+                                                                   :review_screens_by_vid => @review_screens_by_vid, \
+                                                                   :filtered => @filtered}
+      %>
 
     <% end %>
 
index 752923d18c40e2b23b2a4b9fe0410a450c3a3aae..f1ba5bc0a8c397afcc23fb02ec56afda81e6f71b 100644 (file)
@@ -6,5 +6,4 @@
 <script type="text/javascript">
   // Always display title in popup mode
   openAccordionItem('<%= url_for(params.merge({:display_title => 'true', :popup => 'true'})) -%>', this);
-  $j("#accordion-panel").on("click", "span[class|='symbol']", highlight_usages);
 </script>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_code.html.erb
new file mode 100644 (file)
index 0000000..76ffc41
--- /dev/null
@@ -0,0 +1,3 @@
+<td class="line <%= status -%>">
+    <pre><%= code -%></pre>
+</td>
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..c17d488
--- /dev/null
@@ -0,0 +1,19 @@
+<% if line.highlighted? %>
+  <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>
+      <% end %>
+  </td>
+  <td class="ind <%= statuses[:conditions] -%>">
+      <% if line.deprecated_conditions_label -%>
+        <%= line.deprecated_conditions_label -%>
+      <% elsif line.conditions && line.conditions>0 -%>
+                    <span title="<%= h message('coverage_viewer.x_covered_branches', {:params => line.covered_conditions.to_s}) -%>"><%= line.covered_conditions -%>
+                        /<%= line.conditions -%></span>
+      <% end %>
+  </td>
+<% else %>
+  <td class="ind"></td>
+  <td class="ind"></td>
+<% end %>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb
new file mode 100644 (file)
index 0000000..b672b1b
--- /dev/null
@@ -0,0 +1,72 @@
+
+<%= current_display_id = "sources_#{rand(100)}" %>
+
+<table id="<%= current_display_id %>" class="sources2 code" cellpadding="0" cellspacing="0" border="0">
+
+    <script>
+      $j("#<%= current_display_id %>").on("click", "span[class|='symbol']", {id : "<%= current_display_id.to_s() %>"}, highlight_usages);
+    </script>
+
+    <%
+       colspans = prepare_colspans(display_manual_violation_form, scm_available, display_coverage)
+       first_section = true
+    %>
+
+    <%
+       lines.each_with_index do |line, index|
+         if line.hidden? && !expanded
+           previous_hidden = true
+           next
+         end
+         if previous_hidden && !first_section
+           current_revision = nil
+    %>
+        <%= render :partial => "shared/source_new_section", :locals => {:colspan => colspans[:base]} %>
+      <%
+         end
+
+         previous_hidden=false
+         first_section=false
+         statuses = compute_statuses(line, display_coverage, display_violations)
+         has_displayed_lines = line.highlighted?
+      %>
+
+      <tr class="row pos<%= index+1 -%>">
+
+          <% if display_manual_violation_form %>
+            <%= render :partial => "shared/source_violation_form", :locals => {:resource_id => resource.id, :index => index, :colspans => colspans} %>
+          <% end %>
+
+          <% if scm_available %>
+                render :partial => "shared/source_scm", :locals => {:line => line, :current_revision => current_revision}
+          <% end %>
+
+          <%= render :partial => "shared/source_line_numbers", :locals => {:index => index} %>
+
+          <% if display_coverage %>
+            <%= render :partial => "shared/source_coverage", :locals => {:line => line, \
+                                                                          :statuses => statuses, \
+                                                                          :index => index, \
+                                                                          :resource_key => snapshot.resource.key} %>
+          <% end %>
+
+          <%= render :partial => "shared/source_code", :locals => {:code => line.source, :status => statuses[:base]} %>
+
+      </tr>
+
+      <% if display_violations && line.violations? %>
+        <%= render :partial => "shared/source_violations", :locals => {:line => line, \
+                                                                        :display_violation_form => display_manual_violation_form, \
+                                                                        :scm_available => scm_available, \
+                                                                        :review_screens_by_vid => review_screens_by_vid} %>
+      <% end %>
+
+    <% end %>
+</table>
+
+<% if filtered && !has_displayed_lines %>
+  <p style="padding: 10px"><%= message('no_lines_match_your_filter_criteria') -%></p>
+<% end %>
+
+
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_line_numbers.erb
new file mode 100644 (file)
index 0000000..0847124
--- /dev/null
@@ -0,0 +1 @@
+<td class="lid L<%= index+1 -%>"><a name="L<%= index+1 -%>" href="#L<%= index+1 -%>"><%= index + 1 -%></a></td>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_new_section.html.erb
new file mode 100644 (file)
index 0000000..21a7dfb
--- /dev/null
@@ -0,0 +1,4 @@
+<tr>
+    <td colspan="<%= colspan %>" class="new_section"></td>
+</tr>
+
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_scm.html.erb
new file mode 100644 (file)
index 0000000..90f0a4a
--- /dev/null
@@ -0,0 +1,11 @@
+<%
+   if current_revision!=line.revision
+    current_revision=line.revision
+    title = "Revision #{h(line.revision)}"
+  %>
+  <td class="scm revision">
+    <span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%></a></span>
+    <span class="author"><%= h(line.author) -%></span></td>
+  <% else %>
+  <td class="scm"></td>
+<% end %>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violation_form.html.erb
new file mode 100644 (file)
index 0000000..e0a0996
--- /dev/null
@@ -0,0 +1,3 @@
+<td class="plus">
+    <a onclick="return sVF(this, <%= resource_id -%>,<%= index + 1 -%>,<%= colspans[:gray] -%>,<%= colspans[:white] -%>)"></a>
+</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_violations.html.erb
new file mode 100644 (file)
index 0000000..b71e514
--- /dev/null
@@ -0,0 +1,17 @@
+<tr>
+    <% if @display_manual_violation_form %>
+      <td class="gray"></td>
+    <% end
+       if @scm_available %>
+      <td class="scm"></td>
+    <% end %>
+    <td class="lid"></td>
+    <td class="violations">
+        <% line.violations.each_with_index do |violation, index| %>
+          <%= render :partial => 'violation', :locals => {:violation => violation, :review_screens => @review_screens_by_vid ? @review_screens_by_vid.get(violation.id) : []} -%>
+          <% if index < line.violations.size-1 %>
+            &nbsp;
+          <% end %>
+        <% end %>
+    </td>
+</tr>
\ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/source/_source.html.erb
deleted file mode 100644 (file)
index 6905137..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<% if !panel.empty? %>
-<table id="sources" class="sources2 code" cellpadding="0" cellspacing="0" border="0">
-  <%
-    current_revision=nil
-    colspan=2
-    colspan+=1 if panel.display_scm
-#    colspan+=2 if @display_coverage
-    previous_hidden=false
-    first_section=true
-    has_displayed_lines=false
-    panel.html_lines.each do |line|
-      if line.hidden? && panel.expanded
-        previous_hidden=true
-        next
-      end
-
-      if previous_hidden && !first_section
-       current_revision=nil
-%>
-  <tr>
-    <td colspan="<%= colspan -%>" class="new_section"> </td>
-  </tr>
-<%
-      end
-      previous_hidden=false
-      first_section=false
-
-      status=hits_status=conditions_status=''
-      if line.selected?
-        has_displayed_lines=true
-        if line.highlighted
-          status='ko'
-        end
-      end
-  %>
-  <tr>
-    <%
-      if panel.display_scm
-         if current_revision!=line.revision
-           current_revision=line.revision
-           title = "Revision #{h(line.revision)}"
-    %>
-            <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
-    <%   else %>
-            <td class="scm"></td>
-    <%   end
-       end
-    %>
-    <td class="lid" id="L<%= line.id -%>"><a name="L<%= line.id -%>" href="#L<%= line.id -%>"><%= line.id -%></a></td>
-
-
-    <td class="line <%= status -%>">
-      <pre><%= line.source -%></pre>
-    </td>
-  </tr>
-
-  <% end %>
-</table>
-
-  <% if panel.filtered && !has_displayed_lines %>
-    <p style="padding: 10px"><%= message('no_lines_match_your_filter_criteria') -%></p>
-  <% end %>
-<% end %>
\ No newline at end of file
index 33adf56b94afebd7b2413358da194eeb1ec11b9f..8c1dcc8179bffab081866add10dfb618eca6ffd1 100644 (file)
@@ -203,8 +203,8 @@ function collapseTests(index, elt){
 }
 
 /* Source decoration functions */
-function highlight_usages(){
+function highlight_usages(event){
   var selectedClass = $j(this).attr("class").split(" ")[0];
-  $j(".highlighted").removeClass("highlighted");
-  $j("." + selectedClass).toggleClass("highlighted");
+  $j("#" + event.data.id + " span.highlighted").removeClass("highlighted");
+  $j("#" + event.data.id + " span." + selectedClass).toggleClass("highlighted");
 }
\ No newline at end of file