]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2218 improve experimental resource viewer - support period filtering on all...
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 1 Mar 2011 16:31:21 +0000 (17:31 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 1 Mar 2011 18:07:11 +0000 (19:07 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/browse/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb

index 5ae0ae64c12bb7801921bb21ee9941e4d83948c0..5021fe3eefc701fd5383855acfed7ce6bc916fb5 100644 (file)
@@ -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
index fe1c0da82f044a59363e76df3b30a1a6a650c9e2..53023f55127aa1b1bf491d7210ec7064b826ad75 100644 (file)
@@ -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={})
index e0803a8ec423d44983ad3ec997f7e5c6a0655bce..c3feeb1f0b4af54eb8122da6c4a2b6cac4f250a5 100644 (file)
@@ -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
index d05ecd6f3c68c11323493df64fbc5c5c1b7a5ec9..a5ae5545a925baa77ae060f503b5a5ad49955315 100644 (file)
@@ -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