From 9c1c70b598066c1cd5e6c05c463abcd82bf2b6ed Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 2 Apr 2012 02:46:48 +0800 Subject: [PATCH] Fix sorting in annoucement --- .../announcement/back_end/bulletins_controller.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 3642fe4f..47c97b29 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -314,8 +314,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController nil end when 'title' - h = Hash.new - bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin } + h = Array.new + bulletins.each { |bulletin| h << [bulletin.title[I18n.locale].downcase, bulletin] } sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! sorted_titles = sorted.collect {|a| a[1] } Kaminari.paginate_array(sorted_titles).page(params[:page]).per(10) @@ -325,8 +325,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController user_ids = bulletins.distinct(:update_user_id) users = User.find(user_ids) rescue nil if users - h = Hash.new - users.each { |user| h[user.name] = user.id } + h = Array.new + users.each { |user| h << [user.name, user.id] } sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! sorted_users = sorted.collect {|a| bulletins.where(:update_user_id => a[1]).entries } sorted_users.flatten! @@ -339,6 +339,12 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins } a.flatten! a.uniq! + tmp = Array.new + bulletins.where(:tag_ids => []).each { |bulletin| tmp << [bulletin.title[I18n.locale].downcase, bulletin] } + sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse! + sorted_titles = sorted.collect {|a| a[1] } + a = params[:direction].eql?('asc') ? (sorted_titles + a) : (a + sorted_titles) + a.flatten! Kaminari.paginate_array(a).page(params[:page]).per(10) end end