FEATURE: support listing user solutions in user page
This commit is contained in:
parent
426480064d
commit
026f7a3ab0
|
@ -0,0 +1,3 @@
|
||||||
|
{{#link-to 'userActivity.solved'}}
|
||||||
|
<i class="glyph fa fa-check-square"></i>{{i18n 'solved.title'}}
|
||||||
|
{{/link-to}}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{{#link-to 'userActivity.solved'}}
|
||||||
|
{{user-stat value=model.solved_count label="solved.solution_summary"}}
|
||||||
|
{{/link-to}}
|
|
@ -0,0 +1,6 @@
|
||||||
|
import UserActivityStreamRoute from "discourse/routes/user-activity-stream";
|
||||||
|
|
||||||
|
export default UserActivityStreamRoute.extend({
|
||||||
|
userActionType: 15,
|
||||||
|
noContentHelpKey: "solved.no_solutions"
|
||||||
|
});
|
|
@ -0,0 +1,6 @@
|
||||||
|
export default {
|
||||||
|
resource: 'user.userActivity',
|
||||||
|
map() {
|
||||||
|
this.route('solved');
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,11 +1,15 @@
|
||||||
en:
|
en:
|
||||||
js:
|
js:
|
||||||
solved:
|
solved:
|
||||||
|
title: "Solved"
|
||||||
allow_accepted_answers: "Allow topic owner and staff to mark a reply as the solution"
|
allow_accepted_answers: "Allow topic owner and staff to mark a reply as the solution"
|
||||||
accept_answer: "This reply solves the problem"
|
accept_answer: "This reply solves the problem"
|
||||||
has_accepted_answer: "This topic has a solution"
|
has_accepted_answer: "This topic has a solution"
|
||||||
unaccept_answer: "This reply no longer solves the problem"
|
unaccept_answer: "This reply no longer solves the problem"
|
||||||
accepted_answer: "Solution"
|
accepted_answer: "Solution"
|
||||||
solution: "Solution"
|
solution: "Solution"
|
||||||
|
solution_summary:
|
||||||
|
one: "solution <i class='fa fa-check-square'></i>"
|
||||||
|
other: "solutions <i class='fa fa-check-square'></i>"
|
||||||
accepted_html: "<i class='fa-check-square fa accepted'></i> Solved <span class='by'>by <a href data-user-card='{{username_lower}}'>{{username}}</a></span> in <a href='{{post_path}}'>post #{{post_number}}</a>"
|
accepted_html: "<i class='fa-check-square fa accepted'></i> Solved <span class='by'>by <a href data-user-card='{{username_lower}}'>{{username}}</a></span> 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>"
|
accepted_notification: "<i title='accepted' class='fa fa-check-square'></i><p><span>{{username}}</span> {{description}}</p>"
|
||||||
|
|
|
@ -7,3 +7,7 @@ en:
|
||||||
title: "Accepted solutions"
|
title: "Accepted solutions"
|
||||||
xaxis: "Day"
|
xaxis: "Day"
|
||||||
yaxis: "Total"
|
yaxis: "Total"
|
||||||
|
solved:
|
||||||
|
no_solutions:
|
||||||
|
self: "You have no accepted solutions yet."
|
||||||
|
others: "No accepted solutions."
|
||||||
|
|
80
plugin.rb
80
plugin.rb
|
@ -9,6 +9,44 @@ register_asset 'stylesheets/solutions.scss'
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
|
# we got to do a one time upgrade
|
||||||
|
if defined?(UserAction::SOLVED)
|
||||||
|
unless $redis.get('solved_already_upgraded')
|
||||||
|
unless UserAction.where(action_type: UserAction::SOLVED).exists?
|
||||||
|
Rails.logger.info("Upgrading storage for solved")
|
||||||
|
sql =<<SQL
|
||||||
|
INSERT INTO user_actions(action_type,
|
||||||
|
user_id,
|
||||||
|
target_topic_id,
|
||||||
|
target_post_id,
|
||||||
|
acting_user_id,
|
||||||
|
created_at,
|
||||||
|
updated_at)
|
||||||
|
SELECT :solved,
|
||||||
|
p.user_id,
|
||||||
|
p.topic_id,
|
||||||
|
p.id,
|
||||||
|
t.user_id,
|
||||||
|
pc.created_at,
|
||||||
|
pc.updated_at
|
||||||
|
FROM
|
||||||
|
post_custom_fields pc
|
||||||
|
JOIN
|
||||||
|
posts p ON p.id = pc.post_id
|
||||||
|
JOIN
|
||||||
|
topics t ON t.id = p.topic_id
|
||||||
|
WHERE
|
||||||
|
pc.name = 'is_accepted_answer' AND
|
||||||
|
pc.value = 'true' AND
|
||||||
|
p.user_id IS NOT NULL
|
||||||
|
SQL
|
||||||
|
|
||||||
|
UserAction.exec_sql(sql, solved: UserAction::SOLVED)
|
||||||
|
end
|
||||||
|
$redis.set("solved_already_upgraded", "true")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module ::DiscourseSolved
|
module ::DiscourseSolved
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
engine_name PLUGIN_NAME
|
engine_name PLUGIN_NAME
|
||||||
|
@ -18,6 +56,7 @@ after_initialize do
|
||||||
|
|
||||||
require_dependency "application_controller"
|
require_dependency "application_controller"
|
||||||
class DiscourseSolved::AnswerController < ::ApplicationController
|
class DiscourseSolved::AnswerController < ::ApplicationController
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
|
|
||||||
limit_accepts
|
limit_accepts
|
||||||
|
@ -31,6 +70,10 @@ after_initialize do
|
||||||
if p2 = Post.find_by(id: accepted_id)
|
if p2 = Post.find_by(id: accepted_id)
|
||||||
p2.custom_fields["is_accepted_answer"] = nil
|
p2.custom_fields["is_accepted_answer"] = nil
|
||||||
p2.save!
|
p2.save!
|
||||||
|
|
||||||
|
if defined?(UserAction::SOLVED)
|
||||||
|
UserAction.where(action_type: UserAction::SOLVED, target_post_id: p2.id).destroy_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,6 +82,14 @@ after_initialize do
|
||||||
post.topic.save!
|
post.topic.save!
|
||||||
post.save!
|
post.save!
|
||||||
|
|
||||||
|
if defined?(UserAction::SOLVED)
|
||||||
|
UserAction.log_action!(action_type: UserAction::SOLVED,
|
||||||
|
user_id: post.user_id,
|
||||||
|
acting_user_id: guardian.user.id,
|
||||||
|
target_post_id: post.id,
|
||||||
|
target_topic_id: post.topic_id)
|
||||||
|
end
|
||||||
|
|
||||||
unless current_user.id == post.user_id
|
unless current_user.id == post.user_id
|
||||||
|
|
||||||
Notification.create!(notification_type: Notification.types[:custom],
|
Notification.create!(notification_type: Notification.types[:custom],
|
||||||
|
@ -71,6 +122,14 @@ after_initialize do
|
||||||
post.topic.save!
|
post.topic.save!
|
||||||
post.save!
|
post.save!
|
||||||
|
|
||||||
|
# TODO remove_action! does not allow for this type of interface
|
||||||
|
if defined? UserAction::SOLVED
|
||||||
|
UserAction.where(
|
||||||
|
action_type: UserAction::SOLVED,
|
||||||
|
target_post_id: post.id
|
||||||
|
).destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
# yank notification
|
# yank notification
|
||||||
notification = Notification.find_by(
|
notification = Notification.find_by(
|
||||||
notification_type: Notification.types[:custom],
|
notification_type: Notification.types[:custom],
|
||||||
|
@ -129,6 +188,27 @@ after_initialize do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if defined?(UserAction::SOLVED)
|
||||||
|
require_dependency 'user_summary'
|
||||||
|
class ::UserSummary
|
||||||
|
def solved_count
|
||||||
|
UserAction
|
||||||
|
.where(user: @user)
|
||||||
|
.where(action_type: UserAction::SOLVED)
|
||||||
|
.count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
require_dependency 'user_summary_serializer'
|
||||||
|
class ::UserSummarySerializer
|
||||||
|
attributes :solved_count
|
||||||
|
|
||||||
|
def solved_count
|
||||||
|
object.solved_count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require_dependency 'topic_view_serializer'
|
require_dependency 'topic_view_serializer'
|
||||||
class ::TopicViewSerializer
|
class ::TopicViewSerializer
|
||||||
attributes :accepted_answer
|
attributes :accepted_answer
|
||||||
|
|
Loading…
Reference in New Issue