Commit ef8ca23d by Ibrahim Awwal

Fix pagination and sorting for followed threads. Also fixed sorting so that it…

Fix pagination and sorting for followed threads. Also fixed sorting so that it always retrieves a new set of threads from the server for the initial set.
parent a444166d
......@@ -249,15 +249,19 @@ def user_profile(request, course_id, user_id):
threads, page, num_pages = profiled_user.active_threads(query_params)
query_params['page'] = page
query_params['num_pages'] = num_pages
user_info = cc.User.from_django_user(request.user).to_dict()
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
if request.is_ajax():
return utils.JsonResponse({
'discussion_data': map(utils.safe_content, threads),
'page': query_params['page'],
'num_pages': query_params['num_pages'],
'annotated_content_info': saxutils.escape(json.dumps(annotated_content_info),escapedict),
})
else:
user_info = cc.User.from_django_user(request.user).to_dict()
annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
context = {
'course': course,
......@@ -286,7 +290,7 @@ def following_threads(request, course_id, user_id):
'sort_key': 'date',#TODO: Allow custom sorting?
'sort_order': 'desc',
}
print user_id
threads, page, num_pages = profiled_user.subscribed_threads(query_params)
query_params['page'] = page
query_params['num_pages'] = num_pages
......@@ -297,6 +301,8 @@ def following_threads(request, course_id, user_id):
return utils.JsonResponse({
'annotated_content_info': annotated_content_info,
'discussion_data': map(utils.safe_content, threads),
'page': query_params['page'],
'num_pages': query_params['num_pages'],
})
else:
......
......@@ -52,6 +52,7 @@ if Backbone?
new_collection = _.union(models, new_threads)
Content.loadContentInfos(response.annotated_content_info)
@reset new_collection
@pages = response.num_pages
sortByDate: (thread) ->
thread.get("created_at")
......
......@@ -307,12 +307,13 @@ if Backbone?
@$(".sort-bar a").removeClass("active")
$(event.target).addClass("active")
@sortBy = $(event.target).data("sort")
if @sortBy == "date"
@displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst
else if @sortBy == "votes"
@displayedCollection.comparator = @displayedCollection.sortByVotes
else if @sortBy == "comments"
@displayedCollection.comparator = @displayedCollection.sortByComments
@collection.reset()
@collection.current_page = 0
@loadMorePages(event)
@displayedCollection.comparator = switch @sortBy
when 'date' then @displayedCollection.sortByDateRecentFirst
when 'votes' then @displayedCollection.sortByVotes
when 'comments' then @displayedCollection.sortByComments
@displayedCollection.sort()
performSearch: (event) ->
......@@ -330,6 +331,9 @@ if Backbone?
@mode = 'search'
@current_search = text
url = DiscussionUtil.urlFor("search")
#TODO: This might be better done by setting discussion.current_page=0 and calling discussion.loadMorePages
# Mainly because this currently does not reset any pagination variables which could cause problems.
# This doesn't use pagination either.
DiscussionUtil.safeAjax
$elem: @$(".post-search-field")
data: { text: text }
......
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