Commit 1a06efc5 by arjun810

Merge pull request #716 from MITx/feature/ibrahim/followed-threads

Feature/ibrahim/followed threads
parents 40d25acf 57d5ba07
...@@ -2,6 +2,7 @@ from django.conf.urls.defaults import url, patterns ...@@ -2,6 +2,7 @@ from django.conf.urls.defaults import url, patterns
import django_comment_client.forum.views import django_comment_client.forum.views
urlpatterns = patterns('django_comment_client.forum.views', urlpatterns = patterns('django_comment_client.forum.views',
url(r'users/(?P<user_id>\w+)/followed$', 'followed_threads', name='followed_threads'),
url(r'users/(?P<user_id>\w+)$', 'user_profile', name='user_profile'), url(r'users/(?P<user_id>\w+)$', 'user_profile', name='user_profile'),
url(r'(?P<discussion_id>[\w\-]+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'), url(r'(?P<discussion_id>[\w\-]+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'),
url(r'(?P<discussion_id>[\w\-]+)/inline$', 'inline_discussion', name='inline_discussion'), url(r'(?P<discussion_id>[\w\-]+)/inline$', 'inline_discussion', name='inline_discussion'),
......
...@@ -85,10 +85,7 @@ def inline_discussion(request, course_id, discussion_id): ...@@ -85,10 +85,7 @@ def inline_discussion(request, course_id, discussion_id):
log.error("Error loading inline discussion threads.") log.error("Error loading inline discussion threads.")
raise Http404 raise Http404
def infogetter(thread): annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
allow_anonymous = course.metadata.get("allow_anonymous", True) allow_anonymous = course.metadata.get("allow_anonymous", True)
allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False) allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False)
...@@ -121,10 +118,8 @@ def forum_form_discussion(request, course_id): ...@@ -121,10 +118,8 @@ def forum_form_discussion(request, course_id):
user_info = cc.User.from_django_user(request.user).to_dict() user_info = cc.User.from_django_user(request.user).to_dict()
def infogetter(thread): annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
for thread in threads: for thread in threads:
courseware_context = get_courseware_context(thread, course) courseware_context = get_courseware_context(thread, course)
if courseware_context: if courseware_context:
...@@ -224,10 +219,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -224,10 +219,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
#) #)
def infogetter(thread): annotated_content_info = utils.get_metadata_for_threads(course_id, threads, request.user, user_info)
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
context = { context = {
'discussion_id': discussion_id, 'discussion_id': discussion_id,
...@@ -250,7 +242,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -250,7 +242,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
@login_required @login_required
def user_profile(request, course_id, user_id): def user_profile(request, course_id, user_id):
#TODO: Allow sorting?
course = get_course_with_access(request.user, course_id, 'load') course = get_course_with_access(request.user, course_id, 'load')
try: try:
profiled_user = cc.User(id=user_id, course_id=course_id) profiled_user = cc.User(id=user_id, course_id=course_id)
...@@ -263,19 +255,20 @@ def user_profile(request, course_id, user_id): ...@@ -263,19 +255,20 @@ 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({
'html': content,
'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()
def infogetter(thread):
return utils.get_annotated_content_infos(course_id, thread, request.user, user_info)
annotated_content_info = reduce(merge_dict, map(infogetter, threads), {})
context = { context = {
'course': course, 'course': course,
'user': request.user, 'user': request.user,
...@@ -290,3 +283,46 @@ def user_profile(request, course_id, user_id): ...@@ -290,3 +283,46 @@ def user_profile(request, course_id, user_id):
return render_to_response('discussion/user_profile.html', context) return render_to_response('discussion/user_profile.html', context)
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err: except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
raise Http404 raise Http404
def followed_threads(request, course_id, user_id):
course = get_course_with_access(request.user, course_id, 'load')
try:
profiled_user = cc.User(id=user_id, course_id=course_id)
query_params = {
'page': request.GET.get('page', 1),
'per_page': THREADS_PER_PAGE, # more than threads_per_page to show more activities
'sort_key': request.GET.get('sort_key', 'date'),
'sort_order': request.GET.get('sort_order', 'desc'),
}
threads, page, num_pages = profiled_user.subscribed_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({
'annotated_content_info': annotated_content_info,
'discussion_data': map(utils.safe_content, threads),
'page': query_params['page'],
'num_pages': query_params['num_pages'],
})
else:
context = {
'course': course,
'user': request.user,
'django_user': User.objects.get(id=user_id),
'profiled_user': profiled_user.to_dict(),
'threads': saxutils.escape(json.dumps(threads), escapedict),
'user_info': saxutils.escape(json.dumps(user_info),escapedict),
'annotated_content_info': saxutils.escape(json.dumps(annotated_content_info),escapedict),
# 'content': content,
}
return render_to_response('discussion/user_profile.html', context)
except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError) as err:
raise Http404
...@@ -259,7 +259,11 @@ def get_ability(course_id, content, user): ...@@ -259,7 +259,11 @@ def get_ability(course_id, content, user):
'can_vote': check_permissions_by_view(user, course_id, content, "vote_for_thread" if content['type'] == 'thread' else "vote_for_comment"), 'can_vote': check_permissions_by_view(user, course_id, content, "vote_for_thread" if content['type'] == 'thread' else "vote_for_comment"),
} }
#TODO: RENAME
def get_annotated_content_info(course_id, content, user, user_info): def get_annotated_content_info(course_id, content, user, user_info):
"""
Get metadata for an individual content (thread or comment)
"""
voted = '' voted = ''
if content['id'] in user_info['upvoted_ids']: if content['id'] in user_info['upvoted_ids']:
voted = 'up' voted = 'up'
...@@ -271,7 +275,11 @@ def get_annotated_content_info(course_id, content, user, user_info): ...@@ -271,7 +275,11 @@ def get_annotated_content_info(course_id, content, user, user_info):
'ability': get_ability(course_id, content, user), 'ability': get_ability(course_id, content, user),
} }
#TODO: RENAME
def get_annotated_content_infos(course_id, thread, user, user_info): def get_annotated_content_infos(course_id, thread, user, user_info):
"""
Get metadata for a thread and its children
"""
infos = {} infos = {}
def annotate(content): def annotate(content):
infos[str(content['id'])] = get_annotated_content_info(course_id, content, user, user_info) infos[str(content['id'])] = get_annotated_content_info(course_id, content, user, user_info)
...@@ -280,6 +288,13 @@ def get_annotated_content_infos(course_id, thread, user, user_info): ...@@ -280,6 +288,13 @@ def get_annotated_content_infos(course_id, thread, user, user_info):
annotate(thread) annotate(thread)
return infos return infos
def get_metadata_for_threads(course_id, threads, user, user_info):
def infogetter(thread):
return get_annotated_content_infos(course_id, thread, user, user_info)
metadata = reduce(merge_dict, map(infogetter, threads), {})
return metadata
# put this method in utils.py to avoid circular import dependency between helpers and mustache_helpers # put this method in utils.py to avoid circular import dependency between helpers and mustache_helpers
def url_for_tags(course_id, tags): def url_for_tags(course_id, tags):
return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': tags}) return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': tags})
...@@ -304,7 +319,7 @@ def extend_content(content): ...@@ -304,7 +319,7 @@ def extend_content(content):
roles = dict(('name', role.name.lower()) for role in user.roles.filter(course_id=content['course_id'])) roles = dict(('name', role.name.lower()) for role in user.roles.filter(course_id=content['course_id']))
except user.DoesNotExist: except user.DoesNotExist:
logging.error('User ID {0} in comment content {1} but not in our DB.'.format(content.get('user_id'), content.get('id'))) logging.error('User ID {0} in comment content {1} but not in our DB.'.format(content.get('user_id'), content.get('id')))
content_info = { content_info = {
'displayed_title': content.get('highlighted_title') or content.get('title', ''), 'displayed_title': content.get('highlighted_title') or content.get('title', ''),
'displayed_body': content.get('highlighted_body') or content.get('body', ''), 'displayed_body': content.get('highlighted_body') or content.get('body', ''),
...@@ -323,9 +338,9 @@ def get_courseware_context(content, course): ...@@ -323,9 +338,9 @@ def get_courseware_context(content, course):
location = id_map[id]["location"].url() location = id_map[id]["location"].url()
title = id_map[id]["title"] title = id_map[id]["title"]
(course_id, chapter, section, position) = path_to_location(modulestore(), course.id, location) (course_id, chapter, section, position) = path_to_location(modulestore(), course.id, location)
url = reverse('courseware_position', kwargs={"course_id":course_id, url = reverse('courseware_position', kwargs={"course_id":course_id,
"chapter":chapter, "chapter":chapter,
"section":section, "section":section,
"position":position}) "position":position})
content_info = {"courseware_url": url, "courseware_title": title} content_info = {"courseware_url": url, "courseware_title": title}
return content_info return content_info
......
...@@ -156,6 +156,9 @@ DEBUG_TOOLBAR_PANELS = ( ...@@ -156,6 +156,9 @@ DEBUG_TOOLBAR_PANELS = (
# 'debug_toolbar.panels.profiling.ProfilingDebugPanel', # 'debug_toolbar.panels.profiling.ProfilingDebugPanel',
) )
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False
}
############################ FILE UPLOADS (ASKBOT) ############################# ############################ FILE UPLOADS (ASKBOT) #############################
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
MEDIA_ROOT = ENV_ROOT / "uploads" MEDIA_ROOT = ENV_ROOT / "uploads"
......
...@@ -8,7 +8,7 @@ class User(models.Model): ...@@ -8,7 +8,7 @@ class User(models.Model):
accessible_fields = ['username', 'email', 'follower_ids', 'upvoted_ids', 'downvoted_ids', accessible_fields = ['username', 'email', 'follower_ids', 'upvoted_ids', 'downvoted_ids',
'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id', 'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id',
'subscribed_thread_ids', 'subscribed_commentable_ids', 'subscribed_thread_ids', 'subscribed_commentable_ids',
'subscribed_course_ids', 'threads_count', 'comments_count', 'subscribed_course_ids', 'threads_count', 'comments_count',
'default_sort_key' 'default_sort_key'
] ]
...@@ -65,6 +65,15 @@ class User(models.Model): ...@@ -65,6 +65,15 @@ class User(models.Model):
response = perform_request('get', url, params) response = perform_request('get', url, params)
return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
def subscribed_threads(self, query_params={}):
if not self.course_id:
raise CommentClientError("Must provide course_id when retrieving subscribed threads for the user")
url = _url_for_user_subscribed_threads(self.id)
params = {'course_id': self.course_id}
params = merge_dict(params, query_params)
response = perform_request('get', url, params)
return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1)
def _retrieve(self, *args, **kwargs): def _retrieve(self, *args, **kwargs):
url = self.url(action='get', params=self.attributes) url = self.url(action='get', params=self.attributes)
retrieve_params = self.default_retrieve_params retrieve_params = self.default_retrieve_params
...@@ -84,3 +93,6 @@ def _url_for_subscription(user_id): ...@@ -84,3 +93,6 @@ def _url_for_subscription(user_id):
def _url_for_user_active_threads(user_id): def _url_for_user_active_threads(user_id):
return "{prefix}/users/{user_id}/active_threads".format(prefix=settings.PREFIX, user_id=user_id) return "{prefix}/users/{user_id}/active_threads".format(prefix=settings.PREFIX, user_id=user_id)
def _url_for_user_subscribed_threads(user_id):
return "{prefix}/users/{user_id}/subscribed_threads".format(prefix=settings.PREFIX, user_id=user_id)
...@@ -129,6 +129,12 @@ if Backbone? ...@@ -129,6 +129,12 @@ if Backbone?
json_attributes = _.clone(@attributes) json_attributes = _.clone(@attributes)
_.extend(json_attributes, { title: @display_title(), body: @display_body() }) _.extend(json_attributes, { title: @display_title(), body: @display_body() })
created_at_date: ->
new Date(@get("created_at"))
created_at_time: ->
new Date(@get("created_at")).getTime()
class @Comment extends @Content class @Comment extends @Content
urlMappers: urlMappers:
'reply': -> DiscussionUtil.urlFor('create_sub_comment', @id) 'reply': -> DiscussionUtil.urlFor('create_sub_comment', @id)
......
...@@ -25,17 +25,22 @@ if Backbone? ...@@ -25,17 +25,22 @@ if Backbone?
@add model @add model
model model
retrieveAnotherPage: (search_text="", commentable_ids="", sort_key="")-> retrieveAnotherPage: (mode, options={}, sort_options={})->
# TODO: I really feel that this belongs in DiscussionThreadListView
@current_page += 1 @current_page += 1
url = DiscussionUtil.urlFor 'threads'
data = { page: @current_page } data = { page: @current_page }
if search_text switch mode
data['text'] = search_text when 'search'
if sort_key url = DiscussionUtil.urlFor 'search'
data['sort_key'] = sort_key data['text'] = options.search_text
if commentable_ids when 'commentables'
data['commentable_ids'] = commentable_ids url = DiscussionUtil.urlFor 'search'
data['commentable_ids'] = options.commentable_ids
when 'all'
url = DiscussionUtil.urlFor 'threads'
when 'followed'
url = DiscussionUtil.urlFor 'followed_threads', options.user_id
data['sort_key'] = sort_options.sort_key || 'date'
data['sort_order'] = sort_options.sort_order || 'desc'
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$el $elem: @$el
url: url url: url
...@@ -45,7 +50,10 @@ if Backbone? ...@@ -45,7 +50,10 @@ if Backbone?
models = @models models = @models
new_threads = [new Thread(data) for data in response.discussion_data][0] new_threads = [new Thread(data) for data in response.discussion_data][0]
new_collection = _.union(models, new_threads) new_collection = _.union(models, new_threads)
Content.loadContentInfos(response.annotated_content_info)
@reset new_collection @reset new_collection
@pages = response.num_pages
@current_page = response.page
sortByDate: (thread) -> sortByDate: (thread) ->
thread.get("created_at") thread.get("created_at")
...@@ -60,9 +68,15 @@ if Backbone? ...@@ -60,9 +68,15 @@ if Backbone?
sortByVotes: (thread1, thread2) -> sortByVotes: (thread1, thread2) ->
thread1_count = parseInt(thread1.get("votes")['up_count']) thread1_count = parseInt(thread1.get("votes")['up_count'])
thread2_count = parseInt(thread2.get("votes")['up_count']) thread2_count = parseInt(thread2.get("votes")['up_count'])
thread2_count - thread1_count if thread2_count != thread1_count
thread2_count - thread1_count
else
thread2.created_at_time() - thread1.created_at_time()
sortByComments: (thread1, thread2) -> sortByComments: (thread1, thread2) ->
thread1_count = parseInt(thread1.get("comments_count")) thread1_count = parseInt(thread1.get("comments_count"))
thread2_count = parseInt(thread2.get("comments_count")) thread2_count = parseInt(thread2.get("comments_count"))
thread2_count - thread1_count if thread2_count != thread1_count
thread2_count - thread1_count
else
thread2.created_at_time() - thread1.created_at_time()
...@@ -66,6 +66,7 @@ class @DiscussionUtil ...@@ -66,6 +66,7 @@ class @DiscussionUtil
permanent_link_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" permanent_link_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}"
permanent_link_comment : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}##{param2}" permanent_link_comment : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}##{param2}"
user_profile : "/courses/#{$$course_id}/discussion/forum/users/#{param}" user_profile : "/courses/#{$$course_id}/discussion/forum/users/#{param}"
followed_threads : "/courses/#{$$course_id}/discussion/forum/users/#{param}/followed"
threads : "/courses/#{$$course_id}/discussion/forum" threads : "/courses/#{$$course_id}/discussion/forum"
}[name] }[name]
......
...@@ -31,6 +31,7 @@ if Backbone? ...@@ -31,6 +31,7 @@ if Backbone?
@boardName @boardName
@template = _.template($("#thread-list-template").html()) @template = _.template($("#thread-list-template").html())
@current_search = "" @current_search = ""
@mode = 'all'
reloadDisplayedCollection: (thread) => reloadDisplayedCollection: (thread) =>
thread_id = thread.get('id') thread_id = thread.get('id')
...@@ -119,10 +120,19 @@ if Backbone? ...@@ -119,10 +120,19 @@ 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: (event) -> loadMorePages: (event) ->
event.preventDefault() if event
event.preventDefault()
@$(".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, @discussionIds, @sortBy) options = {}
switch @mode
when 'search'
options.search_text = @current_search
when 'followed'
options.user_id = window.user.id
when 'commentables'
options.commentable_ids = @discussionIds
@collection.retrieveAnotherPage(@mode, options, {sort_key: @sortBy})
renderThread: (thread) => renderThread: (thread) =>
content = $(_.template($("#thread-list-item-template").html())(thread.toJSON())) content = $(_.template($("#thread-list-item-template").html())(thread.toJSON()))
...@@ -148,7 +158,7 @@ if Backbone? ...@@ -148,7 +158,7 @@ if Backbone?
threadSelected: (e) => threadSelected: (e) =>
thread_id = $(e.target).closest("a").data("id") thread_id = $(e.target).closest("a").data("id")
@setActiveThread(thread_id) @setActiveThread(thread_id)
@trigger("thread:selected", thread_id) @trigger("thread:selected", thread_id) # This triggers a callback in the DiscussionRouter which calls the line above...
false false
threadRemoved: (thread_id) => threadRemoved: (thread_id) =>
...@@ -245,10 +255,13 @@ if Backbone? ...@@ -245,10 +255,13 @@ if Backbone?
else else
@setTopic(event) # just sets the title for the dropdown @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" discussionId = item.find("span.board-name").data("discussion_id")
if discussionId == "#all"
@discussionIds = "" @discussionIds = ""
@$(".post-search-field").val("") @$(".post-search-field").val("")
@retrieveAllThreads() @retrieveAllThreads()
else if discussionId == "#following"
@retrieveFollowed(event)
else else
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
@retrieveDiscussions(discussionIds) @retrieveDiscussions(discussionIds)
...@@ -262,48 +275,35 @@ if Backbone? ...@@ -262,48 +275,35 @@ if Backbone?
@collection.current_page = response.page @collection.current_page = response.page
@collection.pages = response.num_pages @collection.pages = response.num_pages
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info) Content.loadContentInfos(response.annotated_content_info)
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models)# Don't think this is necessary because it's called on collection.reset
if callback? if callback?
callback() callback()
retrieveDiscussions: (discussion_ids) -> retrieveDiscussions: (discussion_ids) ->
@discussionIds = discussion_ids.join(',') @discussionIds = discussion_ids.join(',')
url = DiscussionUtil.urlFor("search") @mode = 'commentables'
DiscussionUtil.safeAjax @retrieveFirstPage()
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)
retrieveAllThreads: () -> retrieveAllThreads: () ->
url = DiscussionUtil.urlFor("threads") @mode = 'all'
DiscussionUtil.safeAjax @retrieveFirstPage()
url: url
type: "GET" retrieveFirstPage: (event)->
success: (response, textStatus) => @collection.current_page = 0
@collection.current_page = response.page @collection.reset()
@collection.pages = response.num_pages @loadMorePages(event)
@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")
$(event.target).addClass("active") $(event.target).addClass("active")
@sortBy = $(event.target).data("sort") @sortBy = $(event.target).data("sort")
if @sortBy == "date"
@displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst @displayedCollection.comparator = switch @sortBy
else if @sortBy == "votes" when 'date' then @displayedCollection.sortByDateRecentFirst
@displayedCollection.comparator = @displayedCollection.sortByVotes when 'votes' then @displayedCollection.sortByVotes
else if @sortBy == "comments" when 'comments' then @displayedCollection.sortByComments
@displayedCollection.comparator = @displayedCollection.sortByComments @retrieveFirstPage(event)
@displayedCollection.sort()
performSearch: (event) -> performSearch: (event) ->
if event.which == 13 if event.which == 13
...@@ -317,8 +317,12 @@ if Backbone? ...@@ -317,8 +317,12 @@ if Backbone?
@searchFor(text) @searchFor(text)
searchFor: (text, callback, value) -> searchFor: (text, callback, value) ->
@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 }
...@@ -334,13 +338,13 @@ if Backbone? ...@@ -334,13 +338,13 @@ if Backbone?
if textStatus == 'success' if textStatus == 'success'
# 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.annotated_content_info)
@collection.current_page = response.page @collection.current_page = response.page
@collection.pages = response.num_pages @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
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models) # Don't think this is necessary
clearSearch: (callback, value) -> clearSearch: (callback, value) ->
@$(".post-search-field").val("") @$(".post-search-field").val("")
...@@ -372,3 +376,7 @@ if Backbone? ...@@ -372,3 +376,7 @@ if Backbone?
scrollTarget = Math.min(scrollTop - itemFromTop, scrollTop) scrollTarget = Math.min(scrollTop - itemFromTop, scrollTop)
scrollTarget = Math.max(scrollTop - itemFromTop - $(".browse-topic-drop-menu").height() + $(items[index]).height(), scrollTarget) scrollTarget = Math.max(scrollTop - itemFromTop - $(".browse-topic-drop-menu").height() + $(items[index]).height(), scrollTarget)
$(".browse-topic-drop-menu").scrollTop(scrollTarget) $(".browse-topic-drop-menu").scrollTop(scrollTarget)
retrieveFollowed: (event)=>
@mode = 'followed'
@retrieveFirstPage(event)
...@@ -84,7 +84,6 @@ if Backbone? ...@@ -84,7 +84,6 @@ if Backbone?
toggleFollowing: (event) -> toggleFollowing: (event) ->
$elem = $(event.target) $elem = $(event.target)
url = null url = null
console.log "follow"
if not @model.get('subscribed') if not @model.get('subscribed')
@model.follow() @model.follow()
url = @model.urlFor("follow") url = @model.urlFor("follow")
......
...@@ -6,15 +6,12 @@ if Backbone? ...@@ -6,15 +6,12 @@ if Backbone?
@renderThreads @$el, @collection @renderThreads @$el, @collection
renderThreads: ($elem, threads) => renderThreads: ($elem, threads) =>
#Content.loadContentInfos(response.annotated_content_info) #Content.loadContentInfos(response.annotated_content_info)
console.log threads
@discussion = new Discussion() @discussion = new Discussion()
@discussion.reset(threads, {silent: false}) @discussion.reset(threads, {silent: false})
$discussion = $(Mustache.render $("script#_user_profile").html(), {'threads':threads}) $discussion = $(Mustache.render $("script#_user_profile").html(), {'threads':threads})
console.log $discussion
$elem.append($discussion) $elem.append($discussion)
@threadviews = @discussion.map (thread) -> @threadviews = @discussion.map (thread) ->
new DiscussionThreadProfileView el: @$("article#thread_#{thread.id}"), model: thread new DiscussionThreadProfileView el: @$("article#thread_#{thread.id}"), model: thread
console.log @threadviews
_.each @threadviews, (dtv) -> dtv.render() _.each @threadviews, (dtv) -> dtv.render()
addThread: (thread, collection, options) => addThread: (thread, collection, options) =>
......
...@@ -27,12 +27,17 @@ ...@@ -27,12 +27,17 @@
<div class="browse-topic-drop-search"> <div class="browse-topic-drop-search">
<input type="text" class="browse-topic-drop-search-input" placeholder="filter topics"> <input type="text" class="browse-topic-drop-search-input" placeholder="filter topics">
</div> </div>
<ul class="browse-topic-drop-menu"> <ul class="browse-topic-drop-menu">
<li> <li>
<a href="#"> <a href="#">
<span class="board-name" data-discussion_id='#all'>All</span> <span class="board-name" data-discussion_id='#all'>All</span>
</a> </a>
</li> </li>
<li>
<a href="#">
<span class="board-name" data-discussion_id='#following'>Following</span>
</a>
</li>
${render_dropdown(category_map)} ${render_dropdown(category_map)}
</ul> </ul>
</div> </div>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<%include file="_new_post.html" /> <%include file="_new_post.html" />
<section class="discussion container" id="discussion-container" data-roles="${roles}" data-course-id="${course_id}" data-user-info="${user_info}" data-threads="${threads}" data-thread-pages="${thread_pages}"> <section class="discussion container" id="discussion-container" data-roles="${roles}" data-course-id="${course_id}" data-user-info="${user_info}" data-threads="${threads}" data-thread-pages="${thread_pages}" data-content-info="${annotated_content_info}">
<div class="discussion-body"> <div class="discussion-body">
<div class="sidebar"></div> <div class="sidebar"></div>
<div class="discussion-column"> <div class="discussion-column">
......
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