diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 8050dbce7c..c71cad1583 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -224,17 +224,13 @@ def single_thread(request, course_id, discussion_id, thread_id): course_id, ) - user_info = cc.User.from_django_user(request.user).to_dict() - thread = cc.Thread.find(thread_id).retrieve(recursive=True) - annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread, user=request.user, user_info=user_info) - context = { 'discussion_id': discussion_id, 'csrf': csrf(request)['csrf_token'], 'init': '', - 'annotated_content_info': json.dumps(annotated_content_info), + 'user_info': json.dumps(user_info), 'content': render_single_thread(request, discussion_id, course_id, thread_id), 'course': course, 'recent_active_threads': recent_active_threads, diff --git a/lms/static/coffee/src/discussion/discussion_router.coffee b/lms/static/coffee/src/discussion/discussion_router.coffee new file mode 100644 index 0000000000..194e5ef2df --- /dev/null +++ b/lms/static/coffee/src/discussion/discussion_router.coffee @@ -0,0 +1,23 @@ +class @DiscussionRouter extends Backbone.Router + routes: + "": "allThreads" + ":forum_name/threads/:thread_id" : "showThread" + + initialize: (options) -> + @discussion = options['discussion'] + @nav = new DiscussionThreadListView(collection: @discussion, el: $(".post-list")) + @nav.on "thread:selected", @navigateToThread + @nav.render() + + allThreads: -> + true + + showThread: (forum_name, thread_id) -> + @nav.setActiveThread(thread_id) + thread = @discussion.get(thread_id) + view = new DiscussionThreadView(el: $(".discussion-column"), model: thread) + view.render() + + navigateToThread: (thread_id) => + thread = @discussion.get(thread_id) + @navigate("#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true) diff --git a/lms/static/coffee/src/discussion/models/discussion_user.coffee b/lms/static/coffee/src/discussion/models/discussion_user.coffee index c12006494f..1072be76be 100644 --- a/lms/static/coffee/src/discussion/models/discussion_user.coffee +++ b/lms/static/coffee/src/discussion/models/discussion_user.coffee @@ -3,8 +3,7 @@ class @DiscussionUser @content_info = content_info following: (thread) -> - @content_info[thread.id]['subscribed'] == true + _.include(@content_info['subscribed_thread_ids'], thread.id) voted: (thread) -> - @content_info[thread.id]['voted'] == 'up' - + _.include(@content_info['upvoted_ids'], thread.id) diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index c22db5bb5b..1bca105aeb 100644 --- a/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -4,5 +4,15 @@ class @DiscussionThreadListView extends Backbone.View @ renderThreadListItem: (thread) => view = new ThreadListItemView(model: thread) + view.on "thread:selected", @threadSelected view.render() @$el.append(view.el) + + threadSelected: (thread_id) => + @setActiveThread(thread_id) + @trigger("thread:selected", thread_id) + + setActiveThread: (thread_id) -> + @$("a").removeClass("active") + @$("a[data-id='#{thread_id}']").addClass("active") + diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee index 925e12ff73..b429ce3e63 100644 --- a/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee +++ b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee @@ -2,22 +2,35 @@ class @DiscussionThreadView extends Backbone.View events: "click .discussion-vote-up": "toggleVote" "click .dogear": "toggleFollowing" + template: _.template($("#thread-template").html()) + initialize: (options) -> - @user = options['user'] @model.bind "change", @updateModelDetails + @$el.html(@template(@model.toJSON())) updateModelDetails: => @$(".votes-count-number").html(@model.get("votes")["up_count"]) render: -> - if @user.following(@model) + if window.user.following(@model) @$(".dogear").addClass("is-followed") - if @user.voted(@model) + if window.user.voted(@model) @$(".vote-btn").addClass("is-cast") - + @$("span.timeago").timeago() + @renderResponses() @ + renderResponses: -> + $.ajax @model.id, success: (data, textStatus, xhr) => + comments = new Comments(data['content']['children']) + comments.each @renderResponse + + renderResponse: (response) => + view = new ThreadResponseView(model: response) + view.render() + @$(".responses").append(view.el) + toggleVote: -> @$(".vote-btn").toggleClass("is-cast") if @$(".vote-btn").hasClass("is-cast") diff --git a/lms/static/coffee/src/discussion/views/response_comment_view.coffee b/lms/static/coffee/src/discussion/views/response_comment_view.coffee new file mode 100644 index 0000000000..0dbddab7ba --- /dev/null +++ b/lms/static/coffee/src/discussion/views/response_comment_view.coffee @@ -0,0 +1,6 @@ +class @ResponseCommentView extends Backbone.View + tagName: "li" + template: _.template($("#response-comment-template").html()) + render: -> + @$el.html(@template(@model.toJSON())) + @ diff --git a/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee b/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee index 28afbdc668..0200bd4548 100644 --- a/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee +++ b/lms/static/coffee/src/discussion/views/thread_list_item_view.coffee @@ -1,8 +1,15 @@ class @ThreadListItemView extends Backbone.View tagName: "li" template: _.template($("#thread-list-item-template").html()) + events: + "click a": "threadSelected" initialize: -> @model.on "change", @render render: => @$el.html(@template(@model.toJSON())) + if window.user.following(@model) + @$("a").addClass("followed") @ + threadSelected: -> + @trigger("thread:selected", @model.id) + false diff --git a/lms/static/coffee/src/discussion/views/thread_response_view.coffee b/lms/static/coffee/src/discussion/views/thread_response_view.coffee new file mode 100644 index 0000000000..5d531a2c18 --- /dev/null +++ b/lms/static/coffee/src/discussion/views/thread_response_view.coffee @@ -0,0 +1,15 @@ +class @ThreadResponseView extends Backbone.View + tagName: "li" + template: _.template($("#thread-response-template").html()) + render: -> + @$el.html(@template(@model.toJSON())) + @renderComments() + @ + + renderComments: -> + @model.get("comments").each @renderComment + + renderComment: (comment) => + view = new ResponseCommentView(model: comment) + view.render() + @$(".comments").append(view.el) diff --git a/lms/templates/discussion/_single_thread.html b/lms/templates/discussion/_single_thread.html index 1939bfd753..bc08efb8b1 100644 --- a/lms/templates/discussion/_single_thread.html +++ b/lms/templates/discussion/_single_thread.html @@ -30,4 +30,3 @@ <%include file="_js_data.html" /> - diff --git a/lms/templates/discussion/single_thread.html b/lms/templates/discussion/single_thread.html index 79b153b4f5..0c7c557150 100644 --- a/lms/templates/discussion/single_thread.html +++ b/lms/templates/discussion/single_thread.html @@ -59,7 +59,7 @@
Homework / Week 1 -
+