From 2035cc0d4760b4f162b9f6af4a924977018e7dd1 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 20 May 2011 18:14:43 +0200 Subject: [PATCH] SONAR-2397 Add the ability to sort the reviews in the "Reviews" page --- .../app/controllers/reviews_controller.rb | 4 ++ .../main/webapp/WEB-INF/app/models/review.rb | 15 +++++- .../WEB-INF/app/views/reviews/index.html.erb | 50 +++++++++++++++---- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 7097953cba0..7f093468497 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index c9837436aee..c284662f3ad 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -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) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb index 1a07f21c879..b2f6762527e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb @@ -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() +}