FEATURE: add notification when an answer is accepted

Cleanup terminology (use solved vs accepted-answer)
Cleanup styling, get rid of green box
This commit is contained in:
Sam 2015-06-15 14:24:49 +10:00
parent b20ff337f7
commit 76e3b44cf5
7 changed files with 42 additions and 17 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
## Discourse Solved
Provides a solved button on designated categories

View File

@ -2,7 +2,7 @@
<div class="enable-accepted-answer">
<label class="checkbox-label">
{{input type="checkbox" checked=model.enable_accepted_answers}}
{{i18n 'accepted_answer.allow_accepted_answers'}}
{{i18n 'solved.allow_accepted_answers'}}
</label>
</div>
</section>

View File

@ -29,7 +29,7 @@ export default {
return "";
}
return I18n.t("accepted_answer.accepted_html", {
return I18n.t("solved.accepted_html", {
username_lower: username.toLowerCase(),
username: username,
post_path: this.get('url') + "/" + postNumber,

View File

@ -7,10 +7,17 @@
// background-color: #E9FFE0;
}
.cooked .solved {
margin-top: 20px;
margin-bottom: 0px;
padding: 4px 10px;
border: 1px solid #ddd;
background-color: #E9FFE0;
.mobile-view .cooked .solved {
position: static;
}
.cooked .solved {
position: absolute;
bottom: -10px;
z-index: 1000;
// margin-top: 20px;
// margin-bottom: 0px;
// padding: 4px 0px;
//border-top: 1px solid #ddd;
//background-color: #E9FFE0;
}

View File

@ -1,8 +1,9 @@
en:
js:
accepted_answer:
solved:
allow_accepted_answers: "Allow users to accept answers"
accept_answer: "Accept answer"
unaccept_answer: "Unaccept 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_notification: "<i title='accepted' class='fa fa-check-square'></i><p><span>{{username}}</span> {{description}}</p>"

View File

@ -1,6 +1,6 @@
zh_CN:
js:
accepted_answer:
solved:
allow_accepted_answers: "允许用户认可答案"
accept_answer: "认可答案"
unaccept_answer: "取消认可答案"

View File

@ -1,23 +1,23 @@
# name: discourse-solved-button
# name: discourse-solved
# about: Add a solved button to answers on Discourse
# version: 0.1
# authors: Sam Saffron
PLUGIN_NAME = "discourse_solved_button".freeze
PLUGIN_NAME = "discourse_solved".freeze
register_asset 'stylesheets/solutions.scss'
after_initialize do
module ::DiscourseSolvedButton
module ::DiscourseSolved
class Engine < ::Rails::Engine
engine_name PLUGIN_NAME
isolate_namespace DiscourseSolvedButton
isolate_namespace DiscourseSolved
end
end
require_dependency "application_controller"
class DiscourseSolvedButton::AnswerController < ::ApplicationController
class DiscourseSolved::AnswerController < ::ApplicationController
def accept
post = Post.find(params[:id].to_i)
@ -36,6 +36,20 @@ after_initialize do
post.topic.save!
post.save!
unless current_user.id == post.user_id
Notification.create!(notification_type: Notification.types[:custom],
user_id: post.user_id,
topic_id: post.topic_id,
post_number: post.post_number,
data: {
message: 'solved.accepted_notification',
display_username: current_user.username,
topic_title: post.topic.title
}.to_json
)
end
render json: success_json
end
@ -53,13 +67,13 @@ after_initialize do
end
end
DiscourseSolvedButton::Engine.routes.draw do
DiscourseSolved::Engine.routes.draw do
post "/accept" => "answer#accept"
post "/unaccept" => "answer#unaccept"
end
Discourse::Application.routes.append do
mount ::DiscourseSolvedButton::Engine, at: "solution"
mount ::DiscourseSolved::Engine, at: "solution"
end
TopicView.add_post_custom_fields_whitelister do |user|