Commit b2821c53 by Rocky Duan

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into…

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into feature/tomg/new-discussions
parents d39e3de5 e8ac5860
...@@ -30,7 +30,7 @@ def _general_discussion_id(course_id): ...@@ -30,7 +30,7 @@ def _general_discussion_id(course_id):
def _should_perform_search(request): def _should_perform_search(request):
return bool(request.GET.get('text', False) or \ return bool(request.GET.get('text', False) or \
request.GET.get('tags', False)) request.GET.get('tags', False))
def render_accordion(request, course, discussion_id): def render_accordion(request, course, discussion_id):
...@@ -59,7 +59,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): ...@@ -59,7 +59,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
}[discussion_type] }[discussion_type]
base_url = { base_url = {
'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])), 'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])),
'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])), 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])),
'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])), 'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])),
}[discussion_type]() }[discussion_type]()
...@@ -123,12 +123,14 @@ def get_threads(request, course_id, discussion_id=None): ...@@ -123,12 +123,14 @@ def get_threads(request, course_id, discussion_id=None):
# discussion per page is fixed for now # discussion per page is fixed for now
def inline_discussion(request, course_id, discussion_id): def inline_discussion(request, course_id, discussion_id):
threads, query_params = get_threads(request, course_id, discussion_id) threads, query_params = get_threads(request, course_id, discussion_id)
html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \ # TODO: Remove all of this stuff or switch back to server side rendering once templates are mustache again
query_params=query_params) # html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \
# query_params=query_params)
user_info = cc.User.from_django_user(request.user).to_dict()
return utils.JsonResponse({ return utils.JsonResponse({
'html': html, # 'html': html,
'discussion_data': map(utils.safe_content, threads), 'discussion_data': map(utils.safe_content, threads),
'user_info': user_info,
}) })
def render_search_bar(request, course_id, discussion_id=None, text=''): def render_search_bar(request, course_id, discussion_id=None, text=''):
...@@ -215,6 +217,7 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -215,6 +217,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
thread = cc.Thread.find(thread_id).retrieve(recursive=True) thread = cc.Thread.find(thread_id).retrieve(recursive=True)
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info) annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
context = {'thread': thread.to_dict(), 'course_id': course_id} context = {'thread': thread.to_dict(), 'course_id': course_id}
# TODO: Remove completely or switch back to server side rendering
html = render_to_string('discussion/_ajax_single_thread.html', context) html = render_to_string('discussion/_ajax_single_thread.html', context)
return utils.JsonResponse({ return utils.JsonResponse({
...@@ -287,7 +290,7 @@ def user_profile(request, course_id, user_id): ...@@ -287,7 +290,7 @@ def user_profile(request, course_id, user_id):
}) })
else: else:
context = { context = {
'course': course, 'course': course,
'user': request.user, 'user': request.user,
'django_user': User.objects.get(id=user_id), 'django_user': User.objects.get(id=user_id),
'profiled_user': profiled_user.to_dict(), 'profiled_user': profiled_user.to_dict(),
......
...@@ -23,12 +23,17 @@ if Backbone? ...@@ -23,12 +23,17 @@ if Backbone?
type: "GET" type: "GET"
dataType: 'json' dataType: 'json'
success: (response, textStatus) => success: (response, textStatus) =>
@$el.append(response.html) #@$el.append(response.html)
$discussion = @$el.find("section.discussion") window.user = new DiscussionUser(response.user_info)
$(event.target).html("Hide Discussion") $(event.target).html("Hide Discussion")
discussion = new Discussion() discussion = new Discussion()
discussion.reset(response.discussion_data, {silent: false}) discussion.reset(response.discussion_data, {silent: false})
view = new DiscussionView(el: $discussion[0], model: discussion) $discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data})
$(".discussion-module").append($discussion)
discussion.each (thread) ->
element = $("article#thread_#{thread.id}")
dtv = new DiscussionThreadView el: element, model: thread
dtv.render()
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info) DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
@retrieved = true @retrieved = true
@showed = true @showed = true
$ -> $ ->
if !window.$$contents
window.$$contents = {}
$.fn.extend $.fn.extend
loading: -> loading: ->
@$_loading = $("<span class='discussion-loading'></span>") @$_loading = $("<span class='discussion-loading'></span>")
......
...@@ -46,7 +46,7 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -46,7 +46,7 @@ class @DiscussionThreadView extends DiscussionContentView
renderResponses: -> renderResponses: ->
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
url: @model.id url: "/courses/#{$$course_id}/discussion/forum/#{@model.get('commentable_id')}/threads/#{@model.id}"
success: (data, textStatus, xhr) => success: (data, textStatus, xhr) =>
@$(".loading").remove() @$(".loading").remove()
Content.loadContentInfos(data['annotated_content_info']) Content.loadContentInfos(data['annotated_content_info'])
......
...@@ -1393,13 +1393,6 @@ body.discussion { ...@@ -1393,13 +1393,6 @@ body.discussion {
.global-discussion-actions { .global-discussion-actions {
height: 60px; height: 60px;
@include linear-gradient(top, #ebebeb, #d9d9d9); @include linear-gradient(top, #ebebeb, #d9d9d9);
...@@ -1407,21 +1400,13 @@ body.discussion { ...@@ -1407,21 +1400,13 @@ body.discussion {
border-bottom: 1px solid #bcbcbc; border-bottom: 1px solid #bcbcbc;
} }
.discussion-module {
@extend .discussion-body
}
/* For some reason I have to do this to get the SCSS to compile, can't stick it under the above .discussion-module */
.discussion-module {
.discussion-reply-new {
display:none
}
}
<%include file="_underscore_templates.html" />
<div class="discussion-module"> <div class="discussion-module">
<a class="discussion-show control-button" href="javascript:void(0)" discussion_id="${discussion_id | h}">Show Discussion</a> <a class="discussion-show control-button" href="javascript:void(0)" discussion_id="${discussion_id | h}">Show Discussion</a>
</div> </div>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<a href="#" class="vote-btn discussion-vote discussion-vote-up"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a> <a href="#" class="vote-btn discussion-vote discussion-vote-up"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a>
<h1>${'<%- title %>'}</h1> <h1>${'<%- title %>'}</h1>
<p class="posted-details"> <p class="posted-details">
<span class="timeago" title="${'<%- created_at %>'}">sometime</span> by <span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span> by
<a href="${'<%- user_url %>'}">${'<%- username %>'}</a> <a href="${'<%- user_url %>'}">${'<%- username %>'}</a>
</p> </p>
</header> </header>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<ol class="responses"> <ol class="responses">
<li class="loading"><div class="loading-animation"></div></li> <li class="loading"><div class="loading-animation"></div></li>
</ol> </ol>
<form class="discussion-reply-new"> <form class="discussion-reply-new" data-id="${'<%- id %>'}">
<h4>Post a response:</h4> <h4>Post a response:</h4>
<ul class="discussion-errors"></ul> <ul class="discussion-errors"></ul>
<div class="reply-body"></div> <div class="reply-body"></div>
...@@ -48,14 +48,14 @@ ...@@ -48,14 +48,14 @@
<ol class="comments"> <ol class="comments">
<li> <li>
<form class="comment-form"> <form class="comment-form">
<input type="text" placeholder="Comment" class="comment-form-input"> <input type="text" placeholder="Comment..." class="comment-form-input">
</form> </form>
</li> </li>
</ol> </ol>
</script> </script>
<script type="text/template" id="response-comment-template"> <script type="text/template" id="response-comment-template">
<p><span class="response-body">${'<%- body %>'}</span><span class="posted-details">posted <span class="timeago" title="${'<%- created_at %>'}">sometime</span> by <a href="${'<%- user_url %>'}">${'<%- username %>'}</a></span></p> <p><span class="response-body">${'<%- body %>'}</span><span class="posted-details">--posted <span class="timeago" title="${'<%- created_at %>'}">sometime</span> by <a href="${'<%- user_url %>'}">${'<%- username %>'}</a></span></p>
</script> </script>
<script type="text/template" id="thread-list-item-template"> <script type="text/template" id="thread-list-item-template">
......
<section class="discussion">
{{#threads}}
<article class="discussion-article" data-id="{{id}}" id="thread_{{id}}">
</article>
{{/threads}}
</section>
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