Commit 6ee27d02 by Matthew Mongeau

Searching and fixes.

parent 3cc3876b
...@@ -20,7 +20,7 @@ import django_comment_client.utils as utils ...@@ -20,7 +20,7 @@ import django_comment_client.utils as utils
import comment_client as cc import comment_client as cc
THREADS_PER_PAGE = 5 THREADS_PER_PAGE = 50000
PAGES_NEARBY_DELTA = 2 PAGES_NEARBY_DELTA = 2
......
...@@ -427,6 +427,22 @@ if Backbone? ...@@ -427,6 +427,22 @@ if Backbone?
unfollow: -> unfollow: ->
@trigger "thread:unfollow" @trigger "thread:unfollow"
display_body: ->
if @has("highlighted_body")
@get("highlighted_body")
else
@get("body")
display_title: ->
if @has("highlighted_title")
@get("highlighted_title")
else
@get("title")
toJSON: ->
json_attributes = _.clone(@attributes)
_.extend(json_attributes, { title: @display_title(), body: @display_body() })
class @ThreadView extends @ContentView class @ThreadView extends @ContentView
class @Comment extends @Content class @Comment extends @Content
......
...@@ -5,9 +5,10 @@ class @DiscussionRouter extends Backbone.Router ...@@ -5,9 +5,10 @@ class @DiscussionRouter extends Backbone.Router
initialize: (options) -> initialize: (options) ->
@discussion = options['discussion'] @discussion = options['discussion']
@nav = new DiscussionThreadListView(collection: @discussion, el: $(".post-list")) @nav = new DiscussionThreadListView(collection: @discussion, el: $(".sidebar"))
@nav.on "thread:selected", @navigateToThread @nav.on "thread:selected", @navigateToThread
@nav.render() @nav.render()
@main = new DiscussionThreadView(el: $(".discussion-column"))
allThreads: -> allThreads: ->
true true
...@@ -15,8 +16,8 @@ class @DiscussionRouter extends Backbone.Router ...@@ -15,8 +16,8 @@ class @DiscussionRouter extends Backbone.Router
showThread: (forum_name, thread_id) -> showThread: (forum_name, thread_id) ->
@nav.setActiveThread(thread_id) @nav.setActiveThread(thread_id)
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
view = new DiscussionThreadView(el: $(".discussion-column"), model: thread) @main.model = thread
view.render() @main.render()
navigateToThread: (thread_id) => navigateToThread: (thread_id) =>
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
......
class @DiscussionThreadListView extends Backbone.View class @DiscussionThreadListView extends Backbone.View
template: _.template($("#thread-list-template").html())
events:
"click .search": "showSearch"
"keyup .post-search-field": "performSearch"
render: -> render: ->
@collection.each @renderThreadListItem @timer = 0;
@$el.html(@template())
@collection.on "reset", @renderThreads
@renderThreads()
@ @
renderThreads: =>
@$(".post-list").html("")
@collection.each @renderThreadListItem
renderThreadListItem: (thread) => renderThreadListItem: (thread) =>
view = new ThreadListItemView(model: thread) view = new ThreadListItemView(model: thread)
view.on "thread:selected", @threadSelected view.on "thread:selected", @threadSelected
view.render() view.render()
@$el.append(view.el) @$(".post-list").append(view.el)
threadSelected: (thread_id) => threadSelected: (thread_id) =>
@setActiveThread(thread_id) @setActiveThread(thread_id)
...@@ -16,3 +29,28 @@ class @DiscussionThreadListView extends Backbone.View ...@@ -16,3 +29,28 @@ class @DiscussionThreadListView extends Backbone.View
@$("a").removeClass("active") @$("a").removeClass("active")
@$("a[data-id='#{thread_id}']").addClass("active") @$("a[data-id='#{thread_id}']").addClass("active")
showSearch: ->
@$(".search").addClass('is-open');
@$(".browse").removeClass('is-open');
setTimeout (-> @$(".post-search-field").focus()), 200
delay: (callback, ms) =>
clearTimeout(@timer)
@timer = setTimeout(callback, ms)
performSearch: ->
callback = =>
url = DiscussionUtil.urlFor("search")
text = @$(".post-search-field").val()
DiscussionUtil.safeAjax
$elem: @$(".post-search-field")
data: { text: text }
url: url
type: "GET"
success: (response, textStatus) =>
console.log textStatus
if textStatus == 'success'
@collection.reset(response.discussion_data)
console.log(@collection)
@delay(callback, 300)
...@@ -5,14 +5,9 @@ class @DiscussionThreadView extends Backbone.View ...@@ -5,14 +5,9 @@ class @DiscussionThreadView extends Backbone.View
"click .discussion-submit-post": "submitComment" "click .discussion-submit-post": "submitComment"
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: (options) ->
@model.bind "change", @updateModelDetails
@$el.html(@template(@model.toJSON()))
updateModelDetails: =>
@$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"])
render: -> render: ->
@$el.html(@template(@model.toJSON()))
@model.bind "change", @updateModelDetails
if window.user.following(@model) if window.user.following(@model)
@$(".dogear").addClass("is-followed") @$(".dogear").addClass("is-followed")
...@@ -24,6 +19,9 @@ class @DiscussionThreadView extends Backbone.View ...@@ -24,6 +19,9 @@ class @DiscussionThreadView extends Backbone.View
@renderResponses() @renderResponses()
@ @
updateModelDetails: =>
@$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"])
convertMath: -> convertMath: ->
element = @$(".post-body") element = @$(".post-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html() element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html()
......
...@@ -19,8 +19,8 @@ var tooltipCoords; ...@@ -19,8 +19,8 @@ var tooltipCoords;
$(document).ready(function() { $(document).ready(function() {
$body = $('body'); $body = $('body');
$browse = $('.browse-search .browse'); $browse = $('.browse-search .browse');
$search = $('.browse-search .search'); // $search = $('.browse-search .search');
$searchField = $('.post-search-field'); // $searchField = $('.post-search-field');
$topicDrop = $('.board-drop-menu'); $topicDrop = $('.board-drop-menu');
$currentBoard = $('.current-board'); $currentBoard = $('.current-board');
$tooltip = $('<div class="tooltip"></div>'); $tooltip = $('<div class="tooltip"></div>');
...@@ -34,7 +34,7 @@ $(document).ready(function() { ...@@ -34,7 +34,7 @@ $(document).ready(function() {
sidebarWidth = $('.sidebar').width(); sidebarWidth = $('.sidebar').width();
$browse.bind('click', showTopicDrop); $browse.bind('click', showTopicDrop);
$search.bind('click', showSearch); // $search.bind('click', showSearch);
$topicDrop.bind('click', setTopic); $topicDrop.bind('click', setTopic);
$formTopicDropBtn.bind('click', showFormTopicDrop); $formTopicDropBtn.bind('click', showFormTopicDrop);
$formTopicDropMenu.bind('click', setFormTopic); $formTopicDropMenu.bind('click', setFormTopic);
...@@ -99,13 +99,13 @@ function showBrowse(e) { ...@@ -99,13 +99,13 @@ function showBrowse(e) {
$searchField.val(''); $searchField.val('');
} }
function showSearch(e) { // function showSearch(e) {
$search.addClass('is-open'); // $search.addClass('is-open');
$browse.removeClass('is-open'); // $browse.removeClass('is-open');
setTimeout(function() { // setTimeout(function() {
$searchField.focus(); // $searchField.focus();
}, 200); // }, 200);
} // }
function showTopicDrop(e) { function showTopicDrop(e) {
e.preventDefault(); e.preventDefault();
...@@ -189,4 +189,4 @@ function setFormTopic(e) { ...@@ -189,4 +189,4 @@ function setFormTopic(e) {
boardName = $(this).siblings('a').html() + ' / ' + boardName; boardName = $(this).siblings('a').html() + ' / ' + boardName;
}); });
$formTopicDropBtn.html(boardName + ' <span class="drop-arrow">▾</span>'); $formTopicDropBtn.html(boardName + ' <span class="drop-arrow">▾</span>');
} }
\ No newline at end of file
...@@ -116,56 +116,54 @@ ...@@ -116,56 +116,54 @@
<div class="discussion container"> <div class="discussion container">
<div class="discussion-body"> <div class="discussion-body">
<div class="sidebar"> <div class="sidebar"></div>
<div class="browse-search"> <div class="discussion-column"></div>
<div class="browse is-open"> </div>
<a href="#" class="board-drop-icon"></a> </div>
<a href="#" class="board-drop-btn"><span class="current-board">Homework / Week 1</span> <span class="drop-arrow"></span></a>
</div> <script type="text/template" id="thread-list-template">
<ul class="board-drop-menu"> <div class="browse-search">
<li><a href="#"><span class="board-name">All</span> <span class="unread">1,248</span></a></li> <div class="browse is-open">
<li><a href="#"><span class="board-name">Following</span></a></li> <a href="#" class="board-drop-icon"></a>
<li><a href="#"><span class="board-name">General</span> <span class="unread">124</span></a></li> <a href="#" class="board-drop-btn"><span class="current-board">Homework / Week 1</span> <span class="drop-arrow">▾</span></a>
</div>
<ul class="board-drop-menu">
<li><a href="#"><span class="board-name">All</span> <span class="unread">1,248</span></a></li>
<li><a href="#"><span class="board-name">Following</span></a></li>
<li><a href="#"><span class="board-name">General</span> <span class="unread">124</span></a></li>
<li>
<a href="#"><span class="board-name">Homework</span> <span class="unread">27</span></a>
<ul>
<li><a href="#"><span class="board-name">Week 1</span> <span class="unread">24</span></a></li>
<li> <li>
<a href="#"><span class="board-name">Homework</span> <span class="unread">27</span></a> <a href="#"><span class="board-name">Week 2</span> <span class="unread">27</span></a>
<ul> <ul>
<li><a href="#"><span class="board-name">Week 1</span> <span class="unread">24</span></a></li> <li><a href="#"><span class="board-name">Problem 1</span> <span class="unread">14</span></a></li>
<li> <li><a href="#"><span class="board-name">Problem 2</span> <span class="unread">13</span></a></li>
<a href="#"><span class="board-name">Week 2</span> <span class="unread">27</span></a>
<ul>
<li><a href="#"><span class="board-name">Problem 1</span> <span class="unread">14</span></a></li>
<li><a href="#"><span class="board-name">Problem 2</span> <span class="unread">13</span></a></li>
</ul>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
<div class="search"> </li>
<form class="post-search"> </ul>
<input type="text" placeholder="Search all discussions" class="post-search-field"> <div class="search">
</form> <form class="post-search">
</div> <input type="text" placeholder="Search all discussions" class="post-search-field">
</div> </form>
<div class="sort-bar">
<span class="sort-label">Sort by:</span>
<ul>
<li><a href="#" class="active" data-sort="date">date</a></li>
<li><a href="#" data-sort="votes">votes</a></li>
<li><a href="#" data-sort="comments">comments</a></li>
</ul>
</div>
<div class="post-list-wrapper">
<ul class="post-list">
</ul>
</div>
</div>
<div class="discussion-column">
</div> </div>
</div> </div>
</div> <div class="sort-bar">
<span class="sort-label">Sort by:</span>
<ul>
<li><a href="#" class="active" data-sort="date">date</a></li>
<li><a href="#" data-sort="votes">votes</a></li>
<li><a href="#" data-sort="comments">comments</a></li>
</ul>
</div>
<div class="post-list-wrapper">
<ul class="post-list">
</ul>
</div>
</script>
<script type="text/template" id="thread-template"> <script type="text/template" id="thread-template">
<article class="discussion-article" data-id="${'<%= id %>'}"> <article class="discussion-article" data-id="${'<%= id %>'}">
......
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