Add panel that shows who topic is assigned to
This commit is contained in:
parent
0205a12956
commit
c7253f1d38
|
@ -2,6 +2,20 @@ import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
|
|
||||||
function initialize(api) {
|
function initialize(api) {
|
||||||
api.addPostSmallActionIcon('assigned','user-plus');
|
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 {
|
export default {
|
||||||
|
|
|
@ -3,6 +3,7 @@ en:
|
||||||
action_codes:
|
action_codes:
|
||||||
assigned: "assigned"
|
assigned: "assigned"
|
||||||
discourse_assign:
|
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_notification: "<i title='assigned' class='fa fa-user-plus'></i><p><span>{{username}}</span> {{description}}</p>"
|
||||||
assign:
|
assign:
|
||||||
title: "Assign"
|
title: "Assign"
|
||||||
|
|
32
plugin.rb
32
plugin.rb
|
@ -66,6 +66,38 @@ after_initialize do
|
||||||
render json: success_json
|
render json: success_json
|
||||||
end
|
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
|
DiscourseAssign::Engine.routes.draw do
|
||||||
put "/assign" => "assign#assign"
|
put "/assign" => "assign#assign"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue