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): ...@@ -249,15 +249,19 @@ def user_profile(request, course_id, user_id):
threads, page, num_pages = profiled_user.active_threads(query_params) threads, page, num_pages = profiled_user.active_threads(query_params)
query_params['page'] = page query_params['page'] = page
query_params['num_pages'] = num_pages 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(): if request.is_ajax():
return utils.JsonResponse({ return utils.JsonResponse({
'discussion_data': map(utils.safe_content, threads), '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: 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 = { context = {
'course': course, 'course': course,
...@@ -286,7 +290,7 @@ def following_threads(request, course_id, user_id): ...@@ -286,7 +290,7 @@ def following_threads(request, course_id, user_id):
'sort_key': 'date',#TODO: Allow custom sorting? 'sort_key': 'date',#TODO: Allow custom sorting?
'sort_order': 'desc', 'sort_order': 'desc',
} }
print user_id
threads, page, num_pages = profiled_user.subscribed_threads(query_params) threads, page, num_pages = profiled_user.subscribed_threads(query_params)
query_params['page'] = page query_params['page'] = page
query_params['num_pages'] = num_pages query_params['num_pages'] = num_pages
...@@ -297,6 +301,8 @@ def following_threads(request, course_id, user_id): ...@@ -297,6 +301,8 @@ def following_threads(request, course_id, user_id):
return utils.JsonResponse({ return utils.JsonResponse({
'annotated_content_info': annotated_content_info, 'annotated_content_info': annotated_content_info,
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
'page': query_params['page'],
'num_pages': query_params['num_pages'],
}) })
else: else:
......
...@@ -52,6 +52,7 @@ if Backbone? ...@@ -52,6 +52,7 @@ if Backbone?
new_collection = _.union(models, new_threads) new_collection = _.union(models, new_threads)
Content.loadContentInfos(response.annotated_content_info) Content.loadContentInfos(response.annotated_content_info)
@reset new_collection @reset new_collection
@pages = response.num_pages
sortByDate: (thread) -> sortByDate: (thread) ->
thread.get("created_at") thread.get("created_at")
......
...@@ -307,12 +307,13 @@ if Backbone? ...@@ -307,12 +307,13 @@ if Backbone?
@$(".sort-bar a").removeClass("active") @$(".sort-bar a").removeClass("active")
$(event.target).addClass("active") $(event.target).addClass("active")
@sortBy = $(event.target).data("sort") @sortBy = $(event.target).data("sort")
if @sortBy == "date" @collection.reset()
@displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst @collection.current_page = 0
else if @sortBy == "votes" @loadMorePages(event)
@displayedCollection.comparator = @displayedCollection.sortByVotes @displayedCollection.comparator = switch @sortBy
else if @sortBy == "comments" when 'date' then @displayedCollection.sortByDateRecentFirst
@displayedCollection.comparator = @displayedCollection.sortByComments when 'votes' then @displayedCollection.sortByVotes
when 'comments' then @displayedCollection.sortByComments
@displayedCollection.sort() @displayedCollection.sort()
performSearch: (event) -> performSearch: (event) ->
...@@ -330,6 +331,9 @@ if Backbone? ...@@ -330,6 +331,9 @@ if Backbone?
@mode = 'search' @mode = 'search'
@current_search = text @current_search = text
url = DiscussionUtil.urlFor("search") 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 DiscussionUtil.safeAjax
$elem: @$(".post-search-field") $elem: @$(".post-search-field")
data: { text: text } 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