Skip to content

Commit

Permalink
Initial work on getting answer quoted under question
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Mar 7, 2017
1 parent c5bd8d5 commit f38c7a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Expand Up @@ -4,6 +4,7 @@ import TopicStatus from 'discourse/views/topic-status';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { withPluginApi } from 'discourse/lib/plugin-api';
import { ajax } from 'discourse/lib/ajax';
import PostCooked from 'discourse/widgets/post-cooked'

function clearAccepted(topic) {
const posts = topic.get('postStream.posts');
Expand Down Expand Up @@ -46,7 +47,8 @@ function acceptPost(post) {

topic.set('accepted_answer', {
username: post.get('username'),
post_number: post.get('post_number')
post_number: post.get('post_number'),
excerpt: post.get('cooked')
});

ajax("/solution/accept", {
Expand Down Expand Up @@ -153,7 +155,24 @@ function initializeWithApi(api) {
if (postModel) {
const topic = postModel.get('topic');
if (topic.get('accepted_answer')) {
return dec.rawHtml(`<p class="solved">${topic.get('acceptedAnswerHtml')}</p>`);
var rawhtml = `
<aside class='quote' data-post="${topic.get('accepted_answer').post_number}" data-topic="${topic.id}"><div class='title'>
${topic.get('acceptedAnswerHtml')} <div class="quote-controls"><\/div>
</div>
<blockquote>
${topic.get('accepted_answer').excerpt}
</blockquote>
</aside>`

console.log(topic.id);
var cooked = new PostCooked({cooked:rawhtml, topicId: topic.id});

var html = cooked.init();

return dec.rawHtml(html);

// html = postModel._insertQuoteControls(html);
// return html;
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions plugin.rb
Expand Up @@ -224,17 +224,19 @@ def accepted_answer
{
post_number: info[0],
username: info[1],
excerpt: info[2]
}
end
end

def accepted_answer_post_info
# TODO: we may already have it in the stream ... so bypass query here
post = Post.where(id: accepted_answer_post_id, topic_id: object.topic.id).joins(:user).first
excerpt = post.excerpt

return [post.post_number, post.username, post.excerpt(100)]


Post.where(id: accepted_answer_post_id, topic_id: object.topic.id)
.joins(:user)
.pluck('post_number, username')
.first
end

def accepted_answer_post_id
Expand Down

0 comments on commit f38c7a3

Please sign in to comment.