]> cat aescling's git repositories - mastodon.git/commitdiff
Change order of announcements in admin page to sort them newest-first (#15091)
authorThibG <thib@sitedethib.com>
Wed, 4 Nov 2020 20:15:22 +0000 (21:15 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Nov 2020 20:15:22 +0000 (21:15 +0100)
* Change order of announcements in admin page to sort show newly-created first

Fixes #15090

* Use reverse-chronological rather than creation date only

app/controllers/admin/announcements_controller.rb
app/models/announcement.rb

index 494fd13d0f634b9450ff95c6bd8f63cc1df2da6e..351b9a9910709f721270e4f13ea8790e762cae02 100644 (file)
@@ -71,7 +71,7 @@ class Admin::AnnouncementsController < Admin::BaseController
   private
 
   def set_announcements
-    @announcements = AnnouncementFilter.new(filter_params).results.page(params[:page])
+    @announcements = AnnouncementFilter.new(filter_params).results.reverse_chronological.page(params[:page])
   end
 
   def set_announcement
index c493604c22bbd32a38da5fcdd013168ace681a15..f8183aabce47673597f992a1ed53e5489fe686cf 100644 (file)
@@ -22,6 +22,7 @@ class Announcement < ApplicationRecord
   scope :published, -> { where(published: true) }
   scope :without_muted, ->(account) { joins("LEFT OUTER JOIN announcement_mutes ON announcement_mutes.announcement_id = announcements.id AND announcement_mutes.account_id = #{account.id}").where('announcement_mutes.id IS NULL') }
   scope :chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) ASC')) }
+  scope :reverse_chronological, -> { order(Arel.sql('COALESCE(announcements.starts_at, announcements.scheduled_at, announcements.published_at, announcements.created_at) DESC')) }
 
   has_many :announcement_mutes, dependent: :destroy
   has_many :announcement_reactions, dependent: :destroy