Commit 6105f892 by Arjun Singh Committed by Matthew Mongeau

Top level discussions

parent b1136b0e
......@@ -68,6 +68,15 @@ def get_discussion_category_map(course):
initialize_discussion_info(course)
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):
global _DISCUSSIONINFO
......@@ -80,7 +89,9 @@ def initialize_discussion_info(course):
all_modules = get_full_modules()[course_id]
discussion_id_map = {}
unexpanded_category_map = defaultdict(list)
for location, module in all_modules.items():
if location.category == 'discussion':
id = module.metadata['id']
......@@ -112,40 +123,17 @@ def initialize_discussion_info(course):
node[level]["entries"][entry["title"]] = {"id": entry["id"],
"sort_key": entry["sort_key"]}
<<<<<<< HEAD
sort_map_entries(category_map)
=======
def sort_map_entries(map):
things = []
for title, entry in map["entries"].items():
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"])]
for topic, entry in course.metadata['discussion_topics'].items():
category_map['entries'][topic] = {"id": entry["id"],
"sort_key": entry.get("sort_key", topic)}
sort_map_entries(category_map)
#for level in category_map["subcategories"].values():
# sort_map_entries(level)
>>>>>>> populate dropdown
_DISCUSSIONINFO = {}
_DISCUSSIONINFO['id_map'] = discussion_id_map
<<<<<<< HEAD
_DISCUSSIONINFO['category_map'] = category_map
=======
_DISCUSSIONINFO['category_map'] = category_map
# TODO delete me when you've used me
#_DISCUSSIONINFO['categorized']['General'] = [{
# 'title': 'General',
# 'discussion_id': url_course_id,
# 'category': 'General',
#}]
>>>>>>> populate dropdown
class JsonResponse(HttpResponse):
def __init__(self, data=None):
......
......@@ -9,6 +9,7 @@ class @NewPostView extends Backbone.View
@topicId = @$(".topic").first().data("discussion_id")
@topicText = @getFullTopicName(@$(".topic").first())
@maxNameWidth = 100
@setSelectedTopic()
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body"
......@@ -34,7 +35,6 @@ class @NewPostView extends Backbone.View
@showTopicDropdown()
showTopicDropdown: () ->
console.log "showing"
@menuOpen = true
@dropdownButton.addClass('dropped')
@topicMenu.show()
......@@ -61,12 +61,8 @@ class @NewPostView extends Backbone.View
@topicText = @getFullTopicName($target)
@topicId = $target.data('discussion_id')
@setSelectedTopic()
else
console.log "NOTHING IN "
console.log $target
setSelectedTopic: ->
if @topicText
@dropdownButton.html(@fitName(@topicText) + ' <span class="drop-arrow">▾</span>')
getFullTopicName: (topicElement) ->
......@@ -90,7 +86,6 @@ class @NewPostView extends Backbone.View
return width
fitName: (name) ->
console.log name
width = @getNameWidth(name)
if width < @maxNameWidth
return name
......@@ -141,7 +136,6 @@ class @NewPostView extends Backbone.View
auto_subscribe: follow
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
success: (response, textStatus) =>
console.log response
thread = new Thread response['content']
DiscussionUtil.clearFormErrors(@$(".new-post-form-errors"))
@$el.hide()
......
......@@ -42,7 +42,7 @@
<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>
<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 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