File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,10 +3,12 @@ class NotificationsController < ApplicationController
33 include CommentsHelper
44
55 before_action :authenticate_user! , only : [ :index ]
6+ before_action :set_sorting , only : [ :index ]
67
78 def index
89 @notifications = Notification . unscoped
910 . where ( user : current_user )
11+ . order ( :is_read => :asc , @sort_type => @sort_order )
1012 . paginate ( page : params [ :page ] , per_page : 100 )
1113 . order ( Arel . sql ( 'is_read ASC, created_at DESC' ) )
1214
@@ -78,4 +80,17 @@ def read_all
7880 end
7981 end
8082 end
83+
84+ private
85+
86+ def set_sorting
87+ sort_orders = { asc : :asc , desc : :desc }
88+ sort_types = { age : :created_at }
89+
90+ @default_sort_type = :age
91+ @default_sort_order = :desc
92+
93+ @sort_order = sort_orders [ params [ :order ] &.to_sym ] || sort_orders [ @default_sort_order ]
94+ @sort_type = sort_types [ params [ :sort ] &.to_sym ] || sort_types [ @default_sort_type ]
95+ end
8196end
Original file line number Diff line number Diff line change 1616 <%= link_to 'Unread' , query_url ( status : 'unread' ) ,
1717 class : "button is-muted is-outlined #{ 'is-active' if status == 'unread' } " %>
1818 </ div >
19+
20+ <%= render 'shared/sorting' , default_order : @default_sort_order ,
21+ default_type : @default_sort_type ,
22+ types : %w[ age ] %>
1923</ div >
2024
2125<% @notifications . each do |notif | %>
You can’t perform that action at this time.
0 commit comments