Commit de92fffe by Ibrahim Awwal

Make pagination respect any filters or searches or sort keys. Searches and filters will

query the comment service to get their results rather than filtering threads that have
already been loaded.
parent 05bac031
...@@ -22,7 +22,7 @@ import django_comment_client.utils as utils ...@@ -22,7 +22,7 @@ import django_comment_client.utils as utils
import comment_client as cc import comment_client as cc
import xml.sax.saxutils as saxutils import xml.sax.saxutils as saxutils
THREADS_PER_PAGE = 2 THREADS_PER_PAGE = 5
INLINE_THREADS_PER_PAGE = 5 INLINE_THREADS_PER_PAGE = 5
PAGES_NEARBY_DELTA = 2 PAGES_NEARBY_DELTA = 2
escapedict = {'"': '"'} escapedict = {'"': '"'}
...@@ -78,7 +78,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG ...@@ -78,7 +78,7 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
user.save() user.save()
query_params = merge_dict(default_query_params, query_params = merge_dict(default_query_params,
strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags']))) strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags', 'commentable_ids'])))
threads, page, num_pages = cc.Thread.search(query_params) threads, page, num_pages = cc.Thread.search(query_params)
...@@ -143,6 +143,8 @@ def forum_form_discussion(request, course_id): ...@@ -143,6 +143,8 @@ def forum_form_discussion(request, course_id):
return utils.JsonResponse({ return utils.JsonResponse({
'discussion_data': threads, # TODO: Standardize on 'discussion_data' vs 'threads' 'discussion_data': threads, # TODO: Standardize on 'discussion_data' vs 'threads'
'annotated_content_info': annotated_content_info, 'annotated_content_info': annotated_content_info,
'num_pages': query_params['num_pages'],
'page': query_params['page'],
}) })
else: else:
#recent_active_threads = cc.search_recent_active_threads( #recent_active_threads = cc.search_recent_active_threads(
......
...@@ -33,7 +33,7 @@ class Thread(models.Model): ...@@ -33,7 +33,7 @@ class Thread(models.Model):
'course_id': query_params['course_id'], 'course_id': query_params['course_id'],
'recursive': False} 'recursive': False}
params = merge_dict(default_params, strip_blank(strip_none(query_params))) params = merge_dict(default_params, strip_blank(strip_none(query_params)))
if query_params.get('text') or query_params.get('tags'): if query_params.get('text') or query_params.get('tags') or query_params.get('commentable_ids'):
url = cls.url(action='search') url = cls.url(action='search')
else: else:
url = cls.url(action='get_all', params=extract(params, 'commentable_id')) url = cls.url(action='get_all', params=extract(params, 'commentable_id'))
......
...@@ -18,18 +18,23 @@ if Backbone? ...@@ -18,18 +18,23 @@ if Backbone?
@current_page < @pages @current_page < @pages
addThread: (thread, options) -> addThread: (thread, options) ->
# TODO: Check for existing thread with same ID?
options ||= {} options ||= {}
model = new Thread thread model = new Thread thread
@add model @add model
model model
retrieveAnotherPage: (search_text="", commentable_id="", sort_key="")-> retrieveAnotherPage: (search_text="", commentable_ids="", sort_key="")->
# TODO: Obey dropdown filter (commentable_id) # TODO: I really feel that this belongs in DiscussionThreadListView
@current_page += 1 @current_page += 1
url = DiscussionUtil.urlFor 'threads' url = DiscussionUtil.urlFor 'threads'
data = { page: @current_page, text: search_text } data = { page: @current_page }
if search_text
data['text'] = search_text
if sort_key if sort_key
data['sort_key'] = sort_key data['sort_key'] = sort_key
if commentable_ids
data['commentable_ids'] = commentable_ids
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$el $elem: @$el
url: url url: url
......
...@@ -14,6 +14,7 @@ if Backbone? ...@@ -14,6 +14,7 @@ if Backbone?
@displayedCollection = new Discussion(@collection.models, pages: @collection.pages) @displayedCollection = new Discussion(@collection.models, pages: @collection.pages)
@collection.on "change", @reloadDisplayedCollection @collection.on "change", @reloadDisplayedCollection
@sortBy = "date" @sortBy = "date"
@discussionIds=""
@collection.on "reset", (discussion) => @collection.on "reset", (discussion) =>
board = $(".current-board").html() board = $(".current-board").html()
@displayedCollection.current_page = discussion.current_page @displayedCollection.current_page = discussion.current_page
...@@ -117,10 +118,12 @@ if Backbone? ...@@ -117,10 +118,12 @@ if Backbone?
@$(".post-list").append("<li class='more-pages'><a href='#'>Load more</a></li>") @$(".post-list").append("<li class='more-pages'><a href='#'>Load more</a></li>")
loadMorePages: -> loadMorePages: ->
# TODO: Obey dropdown filter
@$(".more-pages").html('<div class="loading-animation"></div>') @$(".more-pages").html('<div class="loading-animation"></div>')
@$(".more-pages").addClass("loading") @$(".more-pages").addClass("loading")
@collection.retrieveAnotherPage(@current_search, "", @sortBy) @collection.retrieveAnotherPage(@current_search, @discussionIds, @sortBy)
if not @collection.hasMorePages()
$(".more-pages").hide()
renderThread: (thread) => renderThread: (thread) =>
content = $(_.template($("#thread-list-item-template").html())(thread.toJSON())) content = $(_.template($("#thread-list-item-template").html())(thread.toJSON()))
...@@ -232,14 +235,27 @@ if Backbone? ...@@ -232,14 +235,27 @@ if Backbone?
@setTopic(event) @setTopic(event)
@clearSearch @filterTopic, event @clearSearch @filterTopic, event
else else
@setTopic(event) @setTopic(event) # just sets the title for the dropdown
item = $(event.target).closest('li') item = $(event.target).closest('li')
if item.find("span.board-name").data("discussion_id") == "#all" if item.find("span.board-name").data("discussion_id") == "#all"
item = item.parent() item = item.parent()
@discussionIds = ""
discussionIds = _.map item.find(".board-name[data-discussion_id]"), (board) -> $(board).data("discussion_id").id discussionIds = _.map item.find(".board-name[data-discussion_id]"), (board) -> $(board).data("discussion_id").id
filtered = @collection.filter (thread) => @retrieveDiscussions(discussionIds)
_.include(discussionIds, thread.get('commentable_id'))
@displayedCollection.reset filtered retrieveDiscussions: (discussion_ids) ->
@discussionIds = discussion_ids.join(',')
url = DiscussionUtil.urlFor("search")
DiscussionUtil.safeAjax
data: { 'commentable_ids': @discussionIds }
url: url
type: "GET"
success: (response, textStatus) =>
@collection.current_page = response.page
@collection.pages = response.num_pages
@collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info)
@displayedCollection.reset(@collection.models)
sortThreads: (event) -> sortThreads: (event) ->
@$(".sort-bar a").removeClass("active") @$(".sort-bar a").removeClass("active")
...@@ -283,6 +299,8 @@ if Backbone? ...@@ -283,6 +299,8 @@ if Backbone?
# TODO: Augment existing collection? # TODO: Augment existing collection?
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info) Content.loadContentInfos(response.content_info)
@collection.current_page = response.page
@collection.pages = response.num_pages
# TODO: Perhaps reload user info so that votes can be updated. # TODO: Perhaps reload user info so that votes can be updated.
# In the future we might not load all of a user's votes at once # In the future we might not load all of a user's votes at once
# so this would probably be necessary anyway # so this would probably be necessary anyway
......
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
$('<span>').text(value).append('&nbsp;&nbsp;'), $('<span>').text(value).append('&nbsp;&nbsp;'),
$('<a>', { $('<a>', {
href : '#', href : '#',
title : 'Removing tag', title : 'Remove tag',
text : 'x' text : 'x'
}).click(function () { }).click(function () {
return $('#' + id).removeTag(escape(value)); return $('#' + id).removeTag(escape(value));
......
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