diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-01 17:31:21 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-01 19:07:11 +0100 |
commit | 4464c719e065e714fc2726b1d04a86b85c6a0222 (patch) | |
tree | 433340613cd848535278211473734f44ea8d6478 | |
parent | 87f77507a1ea50767c5d818beb85434df80d9bbe (diff) | |
download | sonarqube-4464c719e065e714fc2726b1d04a86b85c6a0222.tar.gz sonarqube-4464c719e065e714fc2726b1d04a86b85c6a0222.zip |
SONAR-2218 improve experimental resource viewer - support period filtering on all tabs
4 files changed, 98 insertions, 22 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb index 5ae0ae64c12..5021fe3eefc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb @@ -20,7 +20,8 @@ class BrowseController < ApplicationController SECTION=Navigation::SECTION_RESOURCE - + helper DashboardHelper + def index @resource = Project.by_key(params[:id]) @@ -36,27 +37,24 @@ class BrowseController < ApplicationController 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 @@ -104,11 +102,14 @@ class BrowseController < ApplicationController 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] @@ -124,9 +125,14 @@ class BrowseController < ApplicationController 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| @@ -137,18 +143,40 @@ class BrowseController < ApplicationController @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) @@ -168,5 +196,9 @@ class BrowseController < ApplicationController nil end end + + def date + @datetime ? @datetime.to_date : nil + end end end
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index fe1c0da82f0..53023f55127 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -58,7 +58,7 @@ module ApplicationHelper # 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={}) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_violation.html.erb index e0803a8ec42..c3feeb1f0b4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/_violation.html.erb @@ -2,4 +2,11 @@ <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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb index d05ecd6f3c6..a5ae5545a92 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb @@ -52,6 +52,10 @@ span.rulename, span.rulename a { color: #4183C4; text-decoration: none; } +span.violation_date { + color: #AAA; + font-size: 11px; +} span.rulename a:hover { text-decoration: underline; } @@ -121,12 +125,41 @@ span.rulename a:hover { <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"> @@ -141,7 +174,10 @@ span.rulename a:hover { <% 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') @@ -165,10 +201,11 @@ span.rulename a:hover { %> <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 |