Commit 5b5fb246 by wajeeha-khalid

TNL-3818: fixed recent activity mapping in thread-list sort for Forums Web

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