class BrowseController < ApplicationController
SECTION=Navigation::SECTION_RESOURCE
-
+ helper DashboardHelper
+
def index
@resource = Project.by_key(params[:id])
def render_resource
+ @period = params[:period].to_i unless params[:period].blank?
+ @expanded=(params[:expand]=='true')
+
@source = @snapshot.source
if @source
source_lines=Java::OrgSonarServerUi::JRubyFacade.new.colorizeCode(@source.data, @snapshot.project.language).split("\n")
load_scm()
@lines=[]
- current_revision=nil
source_lines.each_with_index do |source, index|
line=Line.new(source)
@lines<<line
line.revision=@revisions_by_line[index+1]
line.author=@authors_by_line[index+1]
- line.date=@dates_by_line[index+1]
- if line.revision
- if current_revision!=line.revision
- current_revision=line.revision
- line.display_scm=true
- end
- end
+ date_string=@dates_by_line[index+1]
+ line.datetime=(date_string ? DateTime::strptime(date_string): nil)
end
end
line.covered_conditions=@covered_conditions_by_line[line_id].to_i
end
end
+
+ filter_lines_by_date()
end
def load_violations_tab
@display_violations=true
@global_violations=[]
+ @expandable=true
conditions='snapshot_id=?'
values=[@snapshot.id]
end
end
- unless params[:date].blank?
- conditions+=' AND created_at>=?'
- values<<Date::strptime(params[:date])
+ if @period
+ date=@snapshot.period_datetime(@period)
+ if date
+ conditions+=' AND created_at>=?'
+ values<<date
+ else
+ conditions+=' AND id=-1'
+ end
end
RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
@global_violations<<violation
end
end
+
+ unless @expanded
+ @lines.each_with_index do |line,index|
+ if line.violations?
+ for i in index-4..index+4
+ @lines[i].hidden=false if i>=0 && i<@lines.size
+ end
+ elsif line.hidden==nil
+ line.hidden=true
+ end
+ end
+ end
end
def load_source_tab
+ filter_lines_by_date()
+ end
+ def filter_lines_by_date
+ if @period
+ date=@snapshot.period_datetime(@period)
+ if date
+ @lines.each do |line|
+ line.hidden=true if line.datetime==nil || line.datetime<date
+ end
+ end
+ end
end
class Line
- attr_accessor :source, :revision, :author, :date, :display_scm, :violations, :hits, :conditions, :covered_conditions
+ attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden
def initialize(source)
@source=source
- @display_scm=false
end
def add_violation(violation)
nil
end
end
+
+ def date
+ @datetime ? @datetime.to_date : nil
+ end
end
end
\ No newline at end of file
# deprecated since 2.5. Use trend_icon() instead
def tendency_icon(metric_or_measure, small=true, no_tendency_img=true)
- return trend_icon(metric_or_measure, {:big => !small, :empty => !no_tendency_img})
+ trend_icon(metric_or_measure, {:big => !small, :empty => !no_tendency_img})
end
def boolean_icon(boolean_value, options={})
<span class="rulename"><a onclick="window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;" href="<%= url_for :controller => 'rules', :action => 'show', :id => violation.rule.key, :layout => 'false' -%>"><%= h(violation.rule.name) -%></a></span>
ยป
-<%= h(violation.message) -%>
\ No newline at end of file
+<%= h(violation.message) -%>
+<%
+ if violation.created_at
+ duration=Date.today - violation.created_at.to_date
+
+%>
+ <span class="violation_date"><%= duration==0 ? 'today' : "#{duration} days ago" -%></span>
+<% end %>
\ No newline at end of file
color: #4183C4;
text-decoration: none;
}
+span.violation_date {
+ color: #AAA;
+ font-size: 11px;
+}
span.rulename a:hover {
text-decoration: underline;
}
<div id="source_title">
<span class="h1"><%= qualifier_icon(@resource) -%> <%= @resource.long_name -%></span>
<% if @lines %>
- | <span class="source_link"><a href="<%= ApplicationController.root_context -%>/api/sources?resource=<%= @resource.key -%>&format=txt" target="raw">raw</a></span>
+ | <span class="source_link"><a href="<%= ApplicationController.root_context -%>/api/sources?resource=<%= @resource.key -%>&format=txt">raw</a></span>
<% end %>
</div>
-<table id="source_metrics" cellpadding="0" cellspacing="0" border="0">
-</table>
+<ul id="source_tabs" class="tabs">
+ <li><a href="<%= url_for(:overwrite_params => {:tab => 'source'}) -%>" class="<%= 'selected' if params[:tab]=='source' || params[:tab].blank? -%>">source</a></li>
+ <li><a href="<%= url_for(:overwrite_params => {:tab => 'coverage'}) -%>" class="<%= 'selected' if params[:tab]=='coverage' -%>">coverage</a></li>
+ <li><a href="<%= url_for(:overwrite_params => {:tab => 'violations'}) -%>" class="<%= 'selected' if params[:tab]=='violations' -%>">violations</a></li>
+</ul>
+
+<div id="source_header">
+ <form method="GET" action="<%= url_for :controller => 'browse', :id => @resource.key -%>">
+ <input type="hidden" name="tab" value="<%= params[:tab] -%>"/>
+ <% if @scm_available %>
+ <input type="checkbox" value="true" name="scm" id="scm" <%= 'checked' if @display_scm -%> onclick="submit()"/>
+ <label for="scm">Authors</label>
+ <% end %>
+
+ <% if @snapshot.project_snapshot.periods? %>
+ <select id="period" name="period" class="small" onchange="submit()">
+ <option value="">Time changes...</option>
+ <%= period_select_options(@snapshot, 1) -%>
+ <%= period_select_options(@snapshot, 2) -%>
+ <%= period_select_options(@snapshot, 3) -%>
+ <%= period_select_options(@snapshot, 4) -%>
+ <%= period_select_options(@snapshot, 5) -%>
+ </select>
+ <% end %>
+
+ <% if @expandable %>
+ <input type="checkbox" value="true" name="expand" id="expand" <%= 'checked' if @expanded -%> onclick="submit()"/>
+ <label for="expand">Expand</label>
+ <% end %>
+ </form>
+</div>
<% if @display_violations && @global_violations && @global_violations.size>0 -%>
<table id="global_violations" cellpadding="0" cellspacing="0" border="0">
<% if @lines && @lines.size>0 %>
<table id="sources" class="sources2 code" cellpadding="0" cellspacing="0" border="0">
<%
+ current_revision=nil
@lines.each_with_index do |line, index|
+ next if line.hidden
+
status=hits_status=conditions_status=''
if @display_coverage && line.hits
hits_status=(line.hits>0 ? 'ok' : 'ko')
%>
<tr>
<% if @display_scm
- if line.display_scm
- title = "Revision #{h(line.revision)} (#{line.date})"
+ if current_revision!=line.revision
+ current_revision=line.revision
+ title = "Revision #{h(line.revision)} (#{l(line.datetime)})"
%>
- <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= line.date[0..9] -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
+ <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= l(line.date) -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
<% else %>
<td class="scm"></td>
<% end