Initial work on getting answer quoted under question
This commit is contained in:
parent
c5bd8d5861
commit
f38c7a3991
|
@ -4,6 +4,7 @@ import TopicStatus from 'discourse/views/topic-status';
|
||||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
import PostCooked from 'discourse/widgets/post-cooked'
|
||||||
|
|
||||||
function clearAccepted(topic) {
|
function clearAccepted(topic) {
|
||||||
const posts = topic.get('postStream.posts');
|
const posts = topic.get('postStream.posts');
|
||||||
|
@ -46,7 +47,8 @@ function acceptPost(post) {
|
||||||
|
|
||||||
topic.set('accepted_answer', {
|
topic.set('accepted_answer', {
|
||||||
username: post.get('username'),
|
username: post.get('username'),
|
||||||
post_number: post.get('post_number')
|
post_number: post.get('post_number'),
|
||||||
|
excerpt: post.get('cooked')
|
||||||
});
|
});
|
||||||
|
|
||||||
ajax("/solution/accept", {
|
ajax("/solution/accept", {
|
||||||
|
@ -153,7 +155,24 @@ function initializeWithApi(api) {
|
||||||
if (postModel) {
|
if (postModel) {
|
||||||
const topic = postModel.get('topic');
|
const topic = postModel.get('topic');
|
||||||
if (topic.get('accepted_answer')) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
plugin.rb
10
plugin.rb
|
@ -224,17 +224,19 @@ SQL
|
||||||
{
|
{
|
||||||
post_number: info[0],
|
post_number: info[0],
|
||||||
username: info[1],
|
username: info[1],
|
||||||
|
excerpt: info[2]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepted_answer_post_info
|
def accepted_answer_post_info
|
||||||
# TODO: we may already have it in the stream ... so bypass query here
|
# 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
|
end
|
||||||
|
|
||||||
def accepted_answer_post_id
|
def accepted_answer_post_id
|
||||||
|
|
Loading…
Reference in New Issue