From f38c7a39915fb4290369b18804c8c952bfad3bbb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 7 Mar 2017 23:33:10 +0000 Subject: [PATCH 1/2] Initial work on getting answer quoted under question --- .../extend-for-solved-button.js.es6 | 23 +++++++++++++++++-- plugin.rb | 10 ++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 index ed068d7..296052b 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 @@ -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'); @@ -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", { @@ -153,7 +155,24 @@ function initializeWithApi(api) { if (postModel) { const topic = postModel.get('topic'); if (topic.get('accepted_answer')) { - return dec.rawHtml(`

${topic.get('acceptedAnswerHtml')}

`); + var rawhtml = ` + ` + + 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; } } } diff --git a/plugin.rb b/plugin.rb index b8c4915..bf2b04d 100644 --- a/plugin.rb +++ b/plugin.rb @@ -224,17 +224,19 @@ SQL { 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 From 4aaeee8aec23c22afa0c9fe4767ecd75ab55c4ac Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 8 Mar 2017 00:38:15 +0000 Subject: [PATCH 2/2] Remove excerpt stuff, only show quote once clicked --- .../extend-for-solved-button.js.es6 | 17 ++++++----------- plugin.rb | 10 ++++------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 index 296052b..300482a 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js.es6 @@ -47,8 +47,7 @@ function acceptPost(post) { topic.set('accepted_answer', { username: post.get('username'), - post_number: post.get('post_number'), - excerpt: post.get('cooked') + post_number: post.get('post_number') }); ajax("/solution/accept", { @@ -155,24 +154,20 @@ function initializeWithApi(api) { if (postModel) { const topic = postModel.get('topic'); if (topic.get('accepted_answer')) { + var rawhtml = ` -