Fix sorting in annoucement
This commit is contained in:
parent
503f71e554
commit
9c1c70b598
|
@ -314,8 +314,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
when 'title'
|
when 'title'
|
||||||
h = Hash.new
|
h = Array.new
|
||||||
bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin }
|
bulletins.each { |bulletin| h << [bulletin.title[I18n.locale].downcase, bulletin] }
|
||||||
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
||||||
sorted_titles = sorted.collect {|a| a[1] }
|
sorted_titles = sorted.collect {|a| a[1] }
|
||||||
Kaminari.paginate_array(sorted_titles).page(params[:page]).per(10)
|
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)
|
user_ids = bulletins.distinct(:update_user_id)
|
||||||
users = User.find(user_ids) rescue nil
|
users = User.find(user_ids) rescue nil
|
||||||
if users
|
if users
|
||||||
h = Hash.new
|
h = Array.new
|
||||||
users.each { |user| h[user.name] = user.id }
|
users.each { |user| h << [user.name, user.id] }
|
||||||
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
|
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 = sorted.collect {|a| bulletins.where(:update_user_id => a[1]).entries }
|
||||||
sorted_users.flatten!
|
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 }
|
AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins }
|
||||||
a.flatten!
|
a.flatten!
|
||||||
a.uniq!
|
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)
|
Kaminari.paginate_array(a).page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue