Commit c31164c3 by wajeeha-khalid

Merge pull request #11838 from edx/jia/TNL-3818

TNL-3818: fixed recent activity mapping in thread-list sort
parents a533472a 5b5fb246
......@@ -88,7 +88,7 @@ describe "DiscussionThreadListView", ->
<% } %>
<label class="forum-nav-sort">
<select class="forum-nav-sort-control">
<option value="date">by recent activity</option>
<option value="activity">by recent activity</option>
<option value="comments">by most activity</option>
<option value="votes">by most votes</option>
</select>
......@@ -232,8 +232,8 @@ describe "DiscussionThreadListView", ->
)
).toEqual(["+25 votes", "+20 votes", "+42 votes", "+12 votes"])
it "with sort preference date", ->
checkRender(@threads, "date", ["Thread1", "Thread4", "Thread2", "Thread3"])
it "with sort preference activity", ->
checkRender(@threads, "activity", ["Thread1", "Thread2", "Thread3", "Thread4"])
it "with sort preference votes", ->
checkRender(@threads, "votes", ["Thread4", "Thread1", "Thread2", "Thread3"])
......@@ -249,7 +249,7 @@ describe "DiscussionThreadListView", ->
sortControl = view.$el.find(".forum-nav-sort-control")
expect(sortControl.val()).toEqual(selected_type)
sorted_threads = []
if new_type == 'date'
if new_type == 'activity'
sorted_threads = [threads[0], threads[3], threads[1], threads[2]]
else if new_type == 'comments'
sorted_threads = [threads[0], threads[3], threads[2], threads[1]]
......@@ -265,11 +265,11 @@ describe "DiscussionThreadListView", ->
expect($.ajax).toHaveBeenCalled()
checkThreadsOrdering(view, sort_order, new_type)
it "with sort preference date", ->
changeSorting(@threads, "comments", "date", ["Thread1", "Thread4", "Thread2", "Thread3"])
it "with sort preference activity", ->
changeSorting(@threads, "comments", "activity", ["Thread1", "Thread4", "Thread3", "Thread2"])
it "with sort preference votes", ->
changeSorting(@threads, "date", "votes", ["Thread4", "Thread1", "Thread2", "Thread3"])
changeSorting(@threads, "activity", "votes", ["Thread4", "Thread1", "Thread2", "Thread3"])
it "with sort preference comments", ->
changeSorting(@threads, "votes", "comments", ["Thread1", "Thread4", "Thread3", "Thread2"])
......
......@@ -20,7 +20,7 @@ if Backbone?
setSortComparator: (sortBy) ->
switch sortBy
when 'date' then @comparator = @sortByDateRecentFirst
when 'activity' then @comparator = @sortByDateRecentFirst
when 'votes' then @comparator = @sortByVotes
when 'comments' then @comparator = @sortByComments
......@@ -49,7 +49,7 @@ if Backbone?
url = DiscussionUtil.urlFor 'followed_threads', options.user_id
if options['group_id']
data['group_id'] = options['group_id']
data['sort_key'] = sort_options.sort_key || 'date'
data['sort_key'] = sort_options.sort_key || 'activity'
data['sort_order'] = sort_options.sort_order || 'desc'
DiscussionUtil.safeAjax
$elem: @$el
......@@ -117,8 +117,9 @@ if Backbone?
pinnedThreadsSortComparatorWithDate: (thread, ascending)->
# if threads are pinned they should be displayed on top.
# Unpinned will be sorted by their date
# Unpinned will be sorted by their last activity date
threadCreatedTime = new Date(thread.get("created_at")).getTime()
threadCreatedTime = new Date(thread.get("last_activity_at")).getTime()
if thread.get('pinned')
#use tomorrow's date
today = new Date();
......
......@@ -161,7 +161,7 @@ if Backbone?
voteCounts.hide()
commentCounts.hide()
switch @$(".forum-nav-sort-control").val()
when "date", "comments"
when "activity", "comments"
commentCounts.show()
when "votes"
voteCounts.show()
......
......@@ -1121,14 +1121,14 @@ class DiscussionSortPreferenceTest(UniqueCourseTest):
Test to check the default sorting preference of user. (Default = date )
"""
selected_sort = self.sort_page.get_selected_sort_preference()
self.assertEqual(selected_sort, "date")
self.assertEqual(selected_sort, "activity")
def test_change_sort_preference(self):
"""
Test that if user sorting preference is changing properly.
"""
selected_sort = ""
for sort_type in ["votes", "comments", "date"]:
for sort_type in ["votes", "comments", "activity"]:
self.assertNotEqual(selected_sort, sort_type)
self.sort_page.change_sort_preference(sort_type)
selected_sort = self.sort_page.get_selected_sort_preference()
......@@ -1139,7 +1139,7 @@ class DiscussionSortPreferenceTest(UniqueCourseTest):
Test that user last preference is saved.
"""
selected_sort = ""
for sort_type in ["votes", "comments", "date"]:
for sort_type in ["votes", "comments", "activity"]:
self.assertNotEqual(selected_sort, sort_type)
self.sort_page.change_sort_preference(sort_type)
selected_sort = self.sort_page.get_selected_sort_preference()
......
......@@ -332,6 +332,7 @@ def make_minimal_cs_thread(overrides=None):
"anonymous_to_peers": False,
"created_at": "1970-01-01T00:00:00Z",
"updated_at": "1970-01-01T00:00:00Z",
"last_activity_at": "1970-01-01T00:00:00Z",
"thread_type": "discussion",
"title": "dummy",
"body": "dummy",
......
......@@ -94,7 +94,7 @@ def get_threads(request, course, discussion_id=None, per_page=THREADS_PER_PAGE):
default_query_params = {
'page': 1,
'per_page': per_page,
'sort_key': 'date',
'sort_key': 'activity',
'sort_order': 'desc',
'text': '',
'course_id': unicode(course.id),
......
......@@ -654,7 +654,7 @@ def prepare_content(content, course_key, is_staff=False, course_is_cohorted=None
'read', 'group_id', 'group_name', 'pinned', 'abuse_flaggers',
'stats', 'resp_skip', 'resp_limit', 'resp_total', 'thread_type',
'endorsed_responses', 'non_endorsed_responses', 'non_endorsed_resp_total',
'endorsement', 'context'
'endorsement', 'context', 'last_activity_at'
]
if (content.get('anonymous') is False) and ((content.get('anonymous_to_peers') is False) or is_staff):
......
......@@ -20,7 +20,7 @@ class Thread(models.Model):
'highlighted_body', 'endorsed', 'read', 'group_id', 'group_name', 'pinned',
'abuse_flaggers', 'resp_skip', 'resp_limit', 'resp_total', 'thread_type',
'endorsed_responses', 'non_endorsed_responses', 'non_endorsed_resp_total',
'context',
'context', 'last_activity_at',
]
# updateable_fields are sent in PUT requests
......
......@@ -54,7 +54,7 @@
<span class="sr">${_("Sort:")}</span>
<select class="forum-nav-sort-control">
## Translators: This is a menu option for sorting forum threads
<option value="date">${_("by recent activity")}</option>
<option value="activity">${_("by recent activity")}</option>
## Translators: This is a menu option for sorting forum threads
<option value="comments">${_("by most activity")}</option>
## Translators: This is a menu option for sorting forum threads
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment