mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-02-16 16:45:02 +00:00
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:
parent
b20ff337f7
commit
76e3b44cf5
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## Discourse Solved
|
||||||
|
|
||||||
|
Provides a solved button on designated categories
|
@ -2,7 +2,7 @@
|
|||||||
<div class="enable-accepted-answer">
|
<div class="enable-accepted-answer">
|
||||||
<label class="checkbox-label">
|
<label class="checkbox-label">
|
||||||
{{input type="checkbox" checked=model.enable_accepted_answers}}
|
{{input type="checkbox" checked=model.enable_accepted_answers}}
|
||||||
{{i18n 'accepted_answer.allow_accepted_answers'}}
|
{{i18n 'solved.allow_accepted_answers'}}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -29,7 +29,7 @@ export default {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return I18n.t("accepted_answer.accepted_html", {
|
return I18n.t("solved.accepted_html", {
|
||||||
username_lower: username.toLowerCase(),
|
username_lower: username.toLowerCase(),
|
||||||
username: username,
|
username: username,
|
||||||
post_path: this.get('url') + "/" + postNumber,
|
post_path: this.get('url') + "/" + postNumber,
|
||||||
|
@ -7,10 +7,17 @@
|
|||||||
// background-color: #E9FFE0;
|
// background-color: #E9FFE0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cooked .solved {
|
.mobile-view .cooked .solved {
|
||||||
margin-top: 20px;
|
position: static;
|
||||||
margin-bottom: 0px;
|
}
|
||||||
padding: 4px 10px;
|
|
||||||
border: 1px solid #ddd;
|
.cooked .solved {
|
||||||
background-color: #E9FFE0;
|
position: absolute;
|
||||||
|
bottom: -10px;
|
||||||
|
z-index: 1000;
|
||||||
|
// margin-top: 20px;
|
||||||
|
// margin-bottom: 0px;
|
||||||
|
// padding: 4px 0px;
|
||||||
|
//border-top: 1px solid #ddd;
|
||||||
|
//background-color: #E9FFE0;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
en:
|
en:
|
||||||
js:
|
js:
|
||||||
accepted_answer:
|
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"
|
||||||
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>"
|
||||||
|
accepted_notification: "<i title='accepted' class='fa fa-check-square'></i><p><span>{{username}}</span> {{description}}</p>"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
zh_CN:
|
zh_CN:
|
||||||
js:
|
js:
|
||||||
accepted_answer:
|
solved:
|
||||||
allow_accepted_answers: "允许用户认可答案"
|
allow_accepted_answers: "允许用户认可答案"
|
||||||
accept_answer: "认可答案"
|
accept_answer: "认可答案"
|
||||||
unaccept_answer: "取消认可答案"
|
unaccept_answer: "取消认可答案"
|
||||||
|
28
plugin.rb
28
plugin.rb
@ -1,23 +1,23 @@
|
|||||||
# name: discourse-solved-button
|
# name: discourse-solved
|
||||||
# about: Add a solved button to answers on Discourse
|
# about: Add a solved button to answers on Discourse
|
||||||
# version: 0.1
|
# version: 0.1
|
||||||
# authors: Sam Saffron
|
# authors: Sam Saffron
|
||||||
|
|
||||||
PLUGIN_NAME = "discourse_solved_button".freeze
|
PLUGIN_NAME = "discourse_solved".freeze
|
||||||
|
|
||||||
register_asset 'stylesheets/solutions.scss'
|
register_asset 'stylesheets/solutions.scss'
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
module ::DiscourseSolvedButton
|
module ::DiscourseSolved
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
engine_name PLUGIN_NAME
|
engine_name PLUGIN_NAME
|
||||||
isolate_namespace DiscourseSolvedButton
|
isolate_namespace DiscourseSolved
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency "application_controller"
|
require_dependency "application_controller"
|
||||||
class DiscourseSolvedButton::AnswerController < ::ApplicationController
|
class DiscourseSolved::AnswerController < ::ApplicationController
|
||||||
def accept
|
def accept
|
||||||
post = Post.find(params[:id].to_i)
|
post = Post.find(params[:id].to_i)
|
||||||
|
|
||||||
@ -36,6 +36,20 @@ after_initialize do
|
|||||||
post.topic.save!
|
post.topic.save!
|
||||||
post.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
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -53,13 +67,13 @@ after_initialize do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DiscourseSolvedButton::Engine.routes.draw do
|
DiscourseSolved::Engine.routes.draw do
|
||||||
post "/accept" => "answer#accept"
|
post "/accept" => "answer#accept"
|
||||||
post "/unaccept" => "answer#unaccept"
|
post "/unaccept" => "answer#unaccept"
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
mount ::DiscourseSolvedButton::Engine, at: "solution"
|
mount ::DiscourseSolved::Engine, at: "solution"
|
||||||
end
|
end
|
||||||
|
|
||||||
TopicView.add_post_custom_fields_whitelister do |user|
|
TopicView.add_post_custom_fields_whitelister do |user|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user