FEATURE: display icon on front page

This commit is contained in:
Sam 2015-06-15 16:26:40 +10:00
parent 76e3b44cf5
commit 57b4cb853f
3 changed files with 60 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import PostView from 'discourse/views/post';
import { Button } from 'discourse/views/post-menu'; import { Button } from 'discourse/views/post-menu';
import Topic from 'discourse/models/topic'; import Topic from 'discourse/models/topic';
import User from 'discourse/models/user'; import User from 'discourse/models/user';
import TopicStatus from 'discourse/views/topic-status'
export default { export default {
name: 'extend-for-solved-button', name: 'extend-for-solved-button',
@ -39,6 +40,21 @@ export default {
}.property('accepted_answer', 'id') }.property('accepted_answer', 'id')
}); });
TopicStatus.reopen({
statuses: function(){
var results = this._super();
if (this.topic.has_accepted_answer) {
results.push({
openTag: 'span',
closeTag: 'span',
title: I18n.t('solved.has_accepted_answer'),
icon: 'check-square'
});
}
return results;
}.property()
});
PostView.reopen({ PostView.reopen({
classNameBindings: ['post.accepted_answer:accepted-answer'] classNameBindings: ['post.accepted_answer:accepted-answer']
}); });

View File

@ -3,6 +3,7 @@ en:
solved: solved:
allow_accepted_answers: "Allow users to accept answers" allow_accepted_answers: "Allow users to accept answers"
accept_answer: "Accept answer" accept_answer: "Accept answer"
has_accepted_answer: "This topic has an accepted answer"
unaccept_answer: "Unaccept answer" unaccept_answer: "Unaccept answer"
accepted_answer: "Accepted answer" accepted_answer: "Accepted answer"
accepted_html: "<i class='fa-check-square fa accepted'></i> Solved by <a href data-user-card='{{username_lower}}'>{{username}}</a> in <a href='{{post_path}}'>post #{{post_number}}</a>" accepted_html: "<i class='fa-check-square fa accepted'></i> Solved by <a href data-user-card='{{username_lower}}'>{{username}}</a> in <a href='{{post_path}}'>post #{{post_number}}</a>"

View File

@ -173,6 +173,48 @@ after_initialize do
def accepted_answer def accepted_answer
post_custom_fields["is_accepted_answer"] post_custom_fields["is_accepted_answer"]
end end
end end
require_dependency 'topic_list_item_serializer'
class ::TopicListItemSerializer
attributes :has_accepted_answer
def include_has_accepted_answer?
object.has_accepted_answer
end
def has_accepted_answer
true
end
end
class ::Topic
attr_accessor :has_accepted_answer
end
module ::DiscourseSolved::ExtendTopics
def load_topics
topics = super
if topics.present?
# super efficient for front page
with_accepted = Set.new(Topic.exec_sql(
'SELECT topic_id FROM topic_custom_fields
WHERE topic_id in (:topic_ids) AND
value IS NOT NULL AND
name = \'accepted_answer_post_id\'',
topic_ids: topics.map(&:id)
).values.flatten.map(&:to_i))
topics.each do |topic|
topic.has_accepted_answer = true if with_accepted.include? topic.id
end
end
topics
end
end
class ::TopicList
prepend ::DiscourseSolved::ExtendTopics
end
end end