diff --git a/assets/javascripts/discourse/connectors/topic-list-custom-tags/assign-to.raw.hbs b/assets/javascripts/discourse/connectors/topic-list-custom-tags/assign-to.raw.hbs new file mode 100644 index 0000000..8b46635 --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-list-custom-tags/assign-to.raw.hbs @@ -0,0 +1,3 @@ +{{#if context.topic.owner}} + @{{context.topic.owner.username}} +{{/if}} diff --git a/assets/javascripts/discourse/connectors/topic-list-tags/assigned-to.raw.hbs b/assets/javascripts/discourse/connectors/topic-list-tags/assigned-to.raw.hbs new file mode 100644 index 0000000..1d4836c --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-list-tags/assigned-to.raw.hbs @@ -0,0 +1,7 @@ +{{#unless context.topic.tags}} +{{#if context.topic.owner}} +
+{{/if}} +{{/unless}} diff --git a/plugin.rb b/plugin.rb index e0937ed..455c9c8 100644 --- a/plugin.rb +++ b/plugin.rb @@ -66,6 +66,46 @@ after_initialize do render json: success_json end + class ::Topic + def owner + @owner || + if user_id = custom_fields["assigned_to_id"] + @owner = User.find_by(id: user_id) + end + end + + def preload_owner(owner) + @owner = owner + end + end + + TopicList.preloaded_custom_fields << "assigned_to_id" + + TopicList.on_preload do |topics| + if topics.length > 0 + users = User.where("id in ( + SELECT value::int + FROM topic_custom_fields + WHERE name = 'assigned_to_id' AND topic_id IN (?) + )", topics.map(&:id)) + .select(:id, :email, :username, :uploaded_avatar_id) + + map = {} + users.each{|u| map[u.id] = u} + + topics.each do |t| + if id = t.custom_fields['assigned_to_id'] + t.preload_owner(map[id.to_i]) + end + end + end + end + + require_dependency 'listable_topic_serializer' + class ::ListableTopicSerializer + has_one :owner, serializer: BasicUserSerializer, embed: :objects + end + require_dependency 'topic_view_serializer' class ::TopicViewSerializer attributes :assigned_to_user