Commit ad2a2f29 by alisan617

discussion thread post preview in DiscussionThreadListView

parent 14c01e3a
...@@ -107,6 +107,7 @@ ...@@ -107,6 +107,7 @@
this.boardName = null; this.boardName = null;
this.current_search = ''; this.current_search = '';
this.mode = 'all'; this.mode = 'all';
this.showThreadPreview = options.showThreadPreview;
this.searchAlertCollection = new Backbone.Collection([], { this.searchAlertCollection = new Backbone.Collection([], {
model: Backbone.Model model: Backbone.Model
}); });
...@@ -316,14 +317,26 @@ ...@@ -316,14 +317,26 @@
}, error); }, error);
}; };
DiscussionThreadListView.prototype.containsMarkup = function(threadBody) {
var imagePostSearchString = '![',
mathJaxSearchString = /\$/g,
containsImages = threadBody.indexOf(imagePostSearchString) !== -1,
// mathJax has to have at least 2 dollar signs
containsMathJax = (threadBody.match(mathJaxSearchString) || []).length > 1;
return containsImages || containsMathJax;
};
DiscussionThreadListView.prototype.renderThread = function(thread) { DiscussionThreadListView.prototype.renderThread = function(thread) {
var threadCommentCount = thread.get('comments_count'), var threadCommentCount = thread.get('comments_count'),
threadUnreadCommentCount = thread.get('unread_comments_count'), threadUnreadCommentCount = thread.get('unread_comments_count'),
neverRead = !thread.get('read') && threadUnreadCommentCount === threadCommentCount, neverRead = !thread.get('read') && threadUnreadCommentCount === threadCommentCount,
threadPreview = this.containsMarkup(thread.get('body')) ? '' : thread.get('body'),
context = _.extend( context = _.extend(
{ {
neverRead: neverRead, neverRead: neverRead,
threadUrl: thread.urlFor('retrieve') threadUrl: thread.urlFor('retrieve'),
threadPreview: threadPreview,
showThreadPreview: this.showThreadPreview
}, },
thread.toJSON() thread.toJSON()
); );
......
...@@ -83,10 +83,12 @@ ...@@ -83,10 +83,12 @@
renderSingleThreadWithProps = function(props) { renderSingleThreadWithProps = function(props) {
return makeView(new Discussion([new Thread(DiscussionViewSpecHelper.makeThreadWithProps(props))])).render(); return makeView(new Discussion([new Thread(DiscussionViewSpecHelper.makeThreadWithProps(props))])).render();
}; };
makeView = function(discussion) { makeView = function(discussion, options) {
var opts = options || {};
return new DiscussionThreadListView({ return new DiscussionThreadListView({
el: $('#fixture-element'), el: $('#fixture-element'),
collection: discussion, collection: discussion,
showThreadPreview: opts.showThreadPreview || true,
courseSettings: new DiscussionCourseSettings({ courseSettings: new DiscussionCourseSettings({
is_cohorted: true is_cohorted: true
}) })
...@@ -542,5 +544,40 @@ ...@@ -542,5 +544,40 @@
}); });
}); });
describe('thread preview body', function() {
it('should be shown when showThreadPreview is true', function() {
renderSingleThreadWithProps({
thread_type: 'discussion'
});
expect($('.thread-preview-body').length).toEqual(1);
});
it('should not show image when showThreadPreview is true', function() {
renderSingleThreadWithProps({
thread_type: 'discussion',
body: '![customizedImageAltTitle].png'
});
expect($('.thread-preview-body').text()).toEqual('');
});
it('should not show MathJax when showThreadPreview is true', function() {
renderSingleThreadWithProps({
thread_type: 'discussion',
body: '$$x^2 + sqrt(y)$$'
});
expect($('.thread-preview-body').text()).toEqual('');
});
it('should not be shown when showThreadPreview is false', function() {
var view,
discussion = new Discussion([]),
options = {
showThreadPreview: false
};
view = makeView(discussion, options);
view.render();
expect(view.$el.find('.thread-preview-body').length).toEqual(0);
});
});
}); });
}).call(this); }).call(this);
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
<span class="icon fa <%= icon_class %>" aria-hidden="true"></span> <span class="icon fa <%= icon_class %>" aria-hidden="true"></span>
</div><div class="forum-nav-thread-wrapper-1"> </div><div class="forum-nav-thread-wrapper-1">
<span class="forum-nav-thread-title"><%- title %></span> <span class="forum-nav-thread-title"><%- title %></span>
<% if (showThreadPreview){ %>
<div class="thread-preview-body"><%- threadPreview %></div>
<% } %>
<% if(typeof(subscribed) === "undefined") { var subscribed = null; } %> <% if(typeof(subscribed) === "undefined") { var subscribed = null; } %>
<% if(pinned || subscribed || staff_authored || community_ta_authored) { %> <% if(pinned || subscribed || staff_authored || community_ta_authored) { %>
<ul class="forum-nav-thread-labels"> <ul class="forum-nav-thread-labels">
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
initialize: function(options) { initialize: function(options) {
this.courseSettings = options.courseSettings; this.courseSettings = options.courseSettings;
this.showThreadPreview = true;
this.sidebar_padding = 10; this.sidebar_padding = 10;
this.current_search = ''; this.current_search = '';
this.mode = 'all'; this.mode = 'all';
...@@ -45,7 +46,8 @@ ...@@ -45,7 +46,8 @@
this.discussionThreadListView = new DiscussionThreadListView({ this.discussionThreadListView = new DiscussionThreadListView({
collection: this.discussion, collection: this.discussion,
el: this.$('.discussion-thread-list-container'), el: this.$('.discussion-thread-list-container'),
courseSettings: this.courseSettings courseSettings: this.courseSettings,
showThreadPreview: this.showThreadPreview
}).render(); }).render();
this.searchView = new DiscussionSearchView({ this.searchView = new DiscussionSearchView({
el: this.$('.forum-search') el: this.$('.forum-search')
......
...@@ -176,6 +176,15 @@ ...@@ -176,6 +176,15 @@
.forum-nav-thread-labels { .forum-nav-thread-labels {
margin: 5px 0 0; margin: 5px 0 0;
} }
.thread-preview-body {
margin-top: $baseline / 4;
color: $forum-color-response-count;
font-size: $forum-small-font-size;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
} }
.forum-nav-thread { .forum-nav-thread {
...@@ -191,7 +200,7 @@ ...@@ -191,7 +200,7 @@
.forum-nav-thread-link { .forum-nav-thread-link {
@include border-left(3px solid transparent); @include border-left(3px solid transparent);
display: flex; display: flex;
padding: ($baseline/4) ($baseline/2); padding: $baseline / 2;
transition: none; transition: none;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
...@@ -231,6 +240,10 @@ ...@@ -231,6 +240,10 @@
span.icon { span.icon {
color: $forum-color-background; color: $forum-color-background;
} }
.thread-preview-body {
color: $forum-color-background;
}
} }
.forum-nav-thread-unread-comments-count { .forum-nav-thread-unread-comments-count {
...@@ -273,7 +286,8 @@ ...@@ -273,7 +286,8 @@
.forum-nav-thread-wrapper-1 { .forum-nav-thread-wrapper-1 {
@extend %forum-nav-thread-wrapper; @extend %forum-nav-thread-wrapper;
margin: 0 ($baseline/2); margin: 0 ($baseline / 4);
width: 80%;
flex-grow: 1; // This column should consume all the available space flex-grow: 1; // This column should consume all the available space
} }
......
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