Commit 9a7afb58 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 d9e7c5d9 098b90eb
...@@ -65,6 +65,15 @@ def get_discussion_category_map(course): ...@@ -65,6 +65,15 @@ def get_discussion_category_map(course):
initialize_discussion_info(course) initialize_discussion_info(course)
return _DISCUSSIONINFO['category_map'] return _DISCUSSIONINFO['category_map']
def sort_map_entries(category_map):
things = []
for title, entry in category_map["entries"].items():
things.append((title, entry))
for title, category in category_map["subcategories"].items():
things.append((title, category))
sort_map_entries(category_map["subcategories"][title])
category_map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
def initialize_discussion_info(course): def initialize_discussion_info(course):
global _DISCUSSIONINFO global _DISCUSSIONINFO
...@@ -77,7 +86,9 @@ def initialize_discussion_info(course): ...@@ -77,7 +86,9 @@ def initialize_discussion_info(course):
all_modules = get_full_modules()[course_id] all_modules = get_full_modules()[course_id]
discussion_id_map = {} discussion_id_map = {}
unexpanded_category_map = defaultdict(list) unexpanded_category_map = defaultdict(list)
for location, module in all_modules.items(): for location, module in all_modules.items():
if location.category == 'discussion': if location.category == 'discussion':
id = module.metadata['id'] id = module.metadata['id']
...@@ -109,14 +120,10 @@ def initialize_discussion_info(course): ...@@ -109,14 +120,10 @@ def initialize_discussion_info(course):
node[level]["entries"][entry["title"]] = {"id": entry["id"], node[level]["entries"][entry["title"]] = {"id": entry["id"],
"sort_key": entry["sort_key"]} "sort_key": entry["sort_key"]}
def sort_map_entries(map): for topic, entry in course.metadata['discussion_topics'].items():
things = [] category_map['entries'][topic] = {"id": entry["id"],
for title, entry in map["entries"].items(): "sort_key": entry.get("sort_key", topic)}
things.append((title, entry))
for title, category in map["subcategories"].items():
things.append((title, category))
sort_map_entries(map["subcategories"][title])
map["children"] = [x[0] for x in sorted(things, key=lambda x: x[1]["sort_key"])]
sort_map_entries(category_map) sort_map_entries(category_map)
#for level in category_map["subcategories"].values(): #for level in category_map["subcategories"].values():
......
...@@ -9,6 +9,7 @@ class @NewPostView extends Backbone.View ...@@ -9,6 +9,7 @@ class @NewPostView extends Backbone.View
@topicId = @$(".topic").first().data("discussion_id") @topicId = @$(".topic").first().data("discussion_id")
@topicText = @getFullTopicName(@$(".topic").first()) @topicText = @getFullTopicName(@$(".topic").first())
@maxNameWidth = 100
@setSelectedTopic() @setSelectedTopic()
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body" DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body"
...@@ -34,7 +35,6 @@ class @NewPostView extends Backbone.View ...@@ -34,7 +35,6 @@ class @NewPostView extends Backbone.View
@showTopicDropdown() @showTopicDropdown()
showTopicDropdown: () -> showTopicDropdown: () ->
console.log "showing"
@menuOpen = true @menuOpen = true
@dropdownButton.addClass('dropped') @dropdownButton.addClass('dropped')
@topicMenu.show() @topicMenu.show()
...@@ -61,13 +61,9 @@ class @NewPostView extends Backbone.View ...@@ -61,13 +61,9 @@ class @NewPostView extends Backbone.View
@topicText = @getFullTopicName($target) @topicText = @getFullTopicName($target)
@topicId = $target.data('discussion_id') @topicId = $target.data('discussion_id')
@setSelectedTopic() @setSelectedTopic()
else
console.log "NOTHING IN "
console.log $target
setSelectedTopic: -> setSelectedTopic: ->
if @topicText @dropdownButton.html(@fitName(@topicText) + ' <span class="drop-arrow">▾</span>')
@dropdownButton.html(@fitName(@topicText) + ' <span class="drop-arrow">▾</span>')
getFullTopicName: (topicElement) -> getFullTopicName: (topicElement) ->
name = topicElement.html() name = topicElement.html()
...@@ -90,7 +86,6 @@ class @NewPostView extends Backbone.View ...@@ -90,7 +86,6 @@ class @NewPostView extends Backbone.View
return width return width
fitName: (name) -> fitName: (name) ->
console.log name
width = @getNameWidth(name) width = @getNameWidth(name)
if width < @maxNameWidth if width < @maxNameWidth
return name return name
...@@ -141,7 +136,6 @@ class @NewPostView extends Backbone.View ...@@ -141,7 +136,6 @@ class @NewPostView extends Backbone.View
auto_subscribe: follow auto_subscribe: follow
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors")) error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
success: (response, textStatus) => success: (response, textStatus) =>
console.log response
thread = new Thread response['content'] thread = new Thread response['content']
DiscussionUtil.clearFormErrors(@$(".new-post-form-errors")) DiscussionUtil.clearFormErrors(@$(".new-post-form-errors"))
@$el.hide() @$el.hide()
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<div class="options"> <div class="options">
<input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label> <input type="checkbox" name="follow" class="discussion-follow" class="discussion-follow" id="new-post-follow" checked><label for="new-post-follow">follow this post</label>
<br> <br>
<input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous" checked><label for="new-post-anonymous">post anonymously</label> <input type="checkbox" name="anonymous" class="discussion-anonymous" id="new-post-anonymous"><label for="new-post-anonymous">post anonymously</label>
</div> </div>
</div> </div>
<div class="right-column"> <div class="right-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