Skip to content

Commit

Permalink
Sortable columns. Closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Parrish committed Mar 11, 2015
1 parent 5ee6fd3 commit 71f52ba
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/concerns/action_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module ActionRendering
def index
authorize model_class
scoped = policy_scope model_class
params[:sort] ||= serializer_class.default_sort if serializer_class.default_sort
render json: serializer_class.page(params, scoped)
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def index
authorize model_class
scoped = policy_scope model_class
scoped = scoped.unread if params.delete(:unread)
params[:sort] ||= serializer_class.default_sort if serializer_class.default_sort
render json: serializer_class.page(params, scoped)
end

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/board_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ class BoardSerializer
include TalkSerializer
all_attributes except: :permissions
can_include :discussions, :parent, :sub_boards
can_sort_by :created_at
self.default_sort = 'created_at'
end
2 changes: 2 additions & 0 deletions app/serializers/comment_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class CommentSerializer
include TalkSerializer
all_attributes
can_sort_by :created_at
self.default_sort = 'created_at'

def custom_attributes
{
Expand Down
4 changes: 4 additions & 0 deletions app/serializers/concerns/talk_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module TalkSerializer
attr_reader :model
attributes :href, :links

class << self
attr_accessor :default_sort
end

is_sectioned = model_class.columns_hash.has_key?('section') rescue false
can_filter_by(:section) if is_sectioned
end
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/conversation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ class ConversationSerializer
include TalkSerializer
all_attributes
can_include :messages
can_sort_by :updated_at
self.default_sort = 'updated_at'
end
3 changes: 3 additions & 0 deletions app/serializers/discussion_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ class DiscussionSerializer
include TalkSerializer
all_attributes
can_include :comments, :board, :user
can_filter_by :sticky
can_sort_by :updated_at, :sticky_position
self.default_sort = '-updated_at,sticky_position'
end

0 comments on commit 71f52ba

Please sign in to comment.