Add panel that shows who topic is assigned to

This commit is contained in:
Sam Saffron 2017-02-10 17:45:22 -05:00
parent 0205a12956
commit c7253f1d38
6 changed files with 47 additions and 0 deletions

View File

@ -2,6 +2,20 @@ import { withPluginApi } from 'discourse/lib/plugin-api';
function initialize(api) {
api.addPostSmallActionIcon('assigned','user-plus');
api.decorateWidget('post-contents:after-cooked', dec => {
if (dec.attrs.post_number === 1) {
const postModel = dec.getModel();
if (postModel) {
const assignedToUser = postModel.get('topic.assigned_to_user');
if (assignedToUser) {
const html = I18n.t('discourse_assign.assign_html', assignedToUser);
//const topic = postModel.get('topic');
return dec.rawHtml(html);
}
}
}
});
};
export default {

View File

@ -3,6 +3,7 @@ en:
action_codes:
assigned: "assigned"
discourse_assign:
assign_html: "<p class='assigned-to'>Assigned to: @{{username}}</p>"
assign_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"
assign:
title: "Assign"

View File

@ -66,6 +66,38 @@ after_initialize do
render json: success_json
end
require_dependency 'topic_view_serializer'
class ::TopicViewSerializer
attributes :assigned_to_user
def assigned_to_user
if user = User.find_by(id: assigned_to_user_id)
assigned_at = TopicCustomField.where(
topic_id: object.topic.id,
name: "assigned_to_id"
).pluck(:created_at).first
{
username: user.username,
name: user.name,
avatar_template: user.avatar_template,
assigned_at: assigned_at
}
end
end
def include_assigned_to_user?
assigned_to_user_id
end
def assigned_to_user_id
id = object.topic.custom_fields["assigned_to_id"]
# a bit messy but race conditions can give us an array here, avoid
id && id.to_i rescue nil
end
end
DiscourseAssign::Engine.routes.draw do
put "/assign" => "assign#assign"
end