]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2397 Add the ability to sort the reviews in the "Reviews" page
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 20 May 2011 16:14:43 +0000 (18:14 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 20 May 2011 16:14:43 +0000 (18:14 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb

index 7097953cba0cf92de2e9965f2e7e29947bec0685..7f0934684972ef63cbd8179cc26f9992064d38d1 100644 (file)
@@ -276,6 +276,8 @@ class ReviewsController < ApplicationController
     @statuses = filter_any(params[:statuses]) || [Review::STATUS_OPEN]
     @projects = filter_any(params[:projects]) || ['']
     @id = params[:review_id] || ""
+    @sort = params[:sort]
+    @asc = params[:asc] == "true"
   end
 
   def options_for_users
@@ -321,6 +323,8 @@ class ReviewsController < ApplicationController
         options['id'] = -1
       end
     end
+    options['sort'] = @sort unless @sort.blank?
+    options['asc'] = @asc
     
     found_reviews = Review.search(options)
     @reviews = select_authorized(:user, found_reviews, :project)
index c9837436aeed6458eca7837bee6876ebbd58909d..c284662f3ad91ce27a7d7399704855981cc1b3d6 100644 (file)
@@ -144,7 +144,20 @@ class Review < ActiveRecord::Base
       end
     end
 
-    Review.find(:all, :include => [ 'review_comments', 'project', 'user', 'assignee', 'resource' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200)
+    sort=options['sort']
+    asc=options['asc']
+    if sort 
+      if asc
+        sort += ' ASC, reviews.updated_at DESC'
+      else
+        sort += ' DESC, reviews.updated_at DESC'
+      end
+    else
+      sort = 'reviews.updated_at DESC'
+    end
+    
+    # We define 'assignee' before 'user' in the ':include' so that it is possible to sort on the assignee.name
+    Review.find(:all, :include => [ 'review_comments', 'project', 'assignee', 'resource', 'user' ], :conditions => [conditions.join(' AND '), values], :order => sort, :limit => 200)
   end
 
   def self.reviews_to_xml(reviews, convert_markdown=false)
index 1a07f21c8793661f7633bc10a6f86695a6c84c30..b2f6762527e8f6b7d5afeff238d2a4678cf2014d 100644 (file)
@@ -8,6 +8,15 @@ function reviewIdFieldModified(field) {
     $('assignees').value = ''
   }
 }
+function launchSearch(columnName, link) {
+  $('sort').value = columnName
+  if ($('asc').value == "true") {
+    $('asc').value = "false";
+  } else {
+    $('asc').value = "true";
+  }
+  document.forms[0].submit()
+}
 </script>
 <div id="reviews-search">
   <h1>Reviews</h1>
@@ -68,6 +77,8 @@ function reviewIdFieldModified(field) {
           <br/>
           <br/>
           <div style="width:100%; text-align: right">
+          <input type="hidden" name="sort" id="sort" value="<%= @sort -%>"/>
+          <input type="hidden" name="asc" id="asc" value="<%= @asc -%>"/>
           <%= submit_tag "Search", :id => 'submit_search' %>
           </div>
         </td>
@@ -85,13 +96,34 @@ function reviewIdFieldModified(field) {
     <table id="reviews-list" class="data width100">
       <thead>
       <tr>
-        <th width="1%" nowrap></th>
-        <th width="1%" nowrap>Id</th>
-        <th width="1%" nowrap></th>
-        <th>Title</th>
-        <th width="1%">Project</th>
-        <th>Assignee</th>
-        <th>Age</th>
+        <th width="1%" nowrap>
+          <a href="#" onClick="launchSearch('status', this)">St.</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'status' -%>
+        </th>
+        <th width="1%" nowrap>
+          <a href="#" onClick="launchSearch('id', this)">Id</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'id' -%>
+        </th>
+        <th width="1%" nowrap>
+          <a href="#" onClick="launchSearch('severity', this)">Se.</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'severity' -%>
+        </th>
+        <th>
+          <a href="#" onClick="launchSearch('title', this)">Title</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'title' -%>
+        </th>
+        <th width="1%">
+          <a href="#" onClick="launchSearch('projects.name', this)">Project</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'projects.name' -%>
+        </th>
+        <th>
+          <a href="#" onClick="launchSearch('users.name', this)">Assignee</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'users.name' -%>
+        </th>
+        <th>
+          <a href="#" onClick="launchSearch('updated_at', this)">Age</a>
+          <%= image_tag(@asc ? "asc12.png" : "desc12.png") if @sort == 'updated_at' -%>
+        </th>
 
       </tr>
       </thead>
@@ -103,7 +135,7 @@ function reviewIdFieldModified(field) {
       <tbody>
       <%
          @reviews.each do |review|
-           comment = review.comments.first
+           comment = review.comments.last
       %>
         <tr class="<%= cycle('even', 'odd') -%>">
           <td><img src="<%= ApplicationController.root_context -%>/images/status/<%= review.status -%>.png" title="<%= review.status.capitalize -%>"/></td>
@@ -123,7 +155,7 @@ function reviewIdFieldModified(field) {
           <td><%= review.project.name -%>
             <br/><span class="note"><%= review.resource.long_name -%></span></td>
           <td><%= review.assignee ? h(review.assignee.name) : '-' -%></td>
-          <td><%= distance_of_time_in_words_to_now(review.created_at) -%></td>
+          <td><%= distance_of_time_in_words_to_now(review.updated_at) -%></td>
         </tr>
       <%
          end