From 0966e8bdef403501c335b5c11d1f6cb4d401c145 Mon Sep 17 00:00:00 2001 From: Ibrahim Awwal Date: Tue, 18 Sep 2012 15:06:05 -0700 Subject: [PATCH] Keep thread sorting order stable when sorting by comments or votes by using created_at time as a tiebreaker. This is a stopgap though; the service should handle this. But it looks silly with things shuffling around right now. --- lms/static/coffee/src/discussion/content.coffee | 6 ++++++ lms/static/coffee/src/discussion/discussion.coffee | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index d489782571..4e612dfc40 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -129,6 +129,12 @@ if Backbone? json_attributes = _.clone(@attributes) _.extend(json_attributes, { title: @display_title(), body: @display_body() }) + created_at_date: -> + new Date(@get("created_at")) + + created_at_time: -> + new Date(@get("created_at")).getTime() + class @Comment extends @Content urlMappers: 'reply': -> DiscussionUtil.urlFor('create_sub_comment', @id) diff --git a/lms/static/coffee/src/discussion/discussion.coffee b/lms/static/coffee/src/discussion/discussion.coffee index 2b4339015f..af74afc6e9 100644 --- a/lms/static/coffee/src/discussion/discussion.coffee +++ b/lms/static/coffee/src/discussion/discussion.coffee @@ -66,9 +66,15 @@ if Backbone? sortByVotes: (thread1, thread2) -> thread1_count = parseInt(thread1.get("votes")['up_count']) thread2_count = parseInt(thread2.get("votes")['up_count']) - thread2_count - thread1_count + if thread2_count != thread1_count + thread2_count - thread1_count + else + thread2.created_at_time() - thread1.created_at_time() sortByComments: (thread1, thread2) -> thread1_count = parseInt(thread1.get("comments_count")) thread2_count = parseInt(thread2.get("comments_count")) - thread2_count - thread1_count + if thread2_count != thread1_count + thread2_count - thread1_count + else + thread2.created_at_time() - thread1.created_at_time()