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
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)
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
item.scrollIntoView(true);
});
<% end %>
- $j("#content").on("click", "span[class|='symbol']", highlight_usages);
</script>
<div id="accordion-panel"/>
<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 %>
-
- <% 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 %>
<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
--- /dev/null
+<td class="line <%= status -%>">
+ <pre><%= code -%></pre>
+</td>
\ No newline at end of file
--- /dev/null
+<% 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
--- /dev/null
+
+<%= 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 %>
+
+
+
--- /dev/null
+<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
--- /dev/null
+<tr>
+ <td colspan="<%= colspan %>" class="new_section"></td>
+</tr>
+
--- /dev/null
+<%
+ 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
--- /dev/null
+<td class="plus">
+ <a onclick="return sVF(this, <%= resource_id -%>,<%= index + 1 -%>,<%= colspans[:gray] -%>,<%= colspans[:white] -%>)"></a>
+</td>
--- /dev/null
+<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 %>
+
+ <% end %>
+ <% end %>
+ </td>
+</tr>
\ No newline at end of file
+++ /dev/null
-<% 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
}
/* 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