|
| 1 | +import Component from "@glimmer/component"; |
| 2 | +import { service } from "@ember/service"; |
| 3 | +import { htmlSafe } from "@ember/template"; |
| 4 | +import icon from "discourse/helpers/d-icon"; |
| 5 | +import { bind } from "discourse/lib/decorators"; |
| 6 | +import { i18n } from "discourse-i18n"; |
| 7 | +import { assignedToGroupPath, assignedToUserPath } from "../lib/url"; |
| 8 | + |
| 9 | +export default class AssignedToFirstPost extends Component { |
| 10 | + @service siteSettings; |
| 11 | + |
| 12 | + get assignedToUser() { |
| 13 | + return this.args.post?.topic?.assigned_to_user; |
| 14 | + } |
| 15 | + |
| 16 | + get assignedToGroup() { |
| 17 | + return this.args.post?.topic?.assigned_to_group; |
| 18 | + } |
| 19 | + |
| 20 | + get icon() { |
| 21 | + return this.assignedToUser ? "user-plus" : "group-plus"; |
| 22 | + } |
| 23 | + |
| 24 | + get indirectlyAssignedTo() { |
| 25 | + return this.args.post?.topic?.indirectly_assigned_to; |
| 26 | + } |
| 27 | + |
| 28 | + get indirectAssignments() { |
| 29 | + if (!this.indirectlyAssignedTo) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + return Object.keys(this.indirectlyAssignedTo).map((postId) => { |
| 34 | + const postNumber = this.indirectlyAssignedTo[postId].post_number; |
| 35 | + |
| 36 | + return { |
| 37 | + postId, |
| 38 | + assignee: this.indirectlyAssignedTo[postId].assigned_to, |
| 39 | + postNumber, |
| 40 | + url: `${this.args.post.topic.url}/${postNumber}`, |
| 41 | + }; |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | + get isAssigned() { |
| 46 | + return !!( |
| 47 | + this.assignedToUser || |
| 48 | + this.assignedToGroup || |
| 49 | + this.args.post?.topic?.indirectly_assigned_to |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + get hasOnlyIndirectAssignments() { |
| 54 | + return !this.assignedToUser && !this.assignedToGroup; |
| 55 | + } |
| 56 | + |
| 57 | + @bind |
| 58 | + prioritizedAssigneeName(assignee) { |
| 59 | + // if this code is ever replaced to use `prioritize_username_in_ux`, remove this function and use the helper |
| 60 | + // userPrioritizedName instead |
| 61 | + return this.siteSettings.prioritize_full_name_in_ux || !assignee.username |
| 62 | + ? assignee.name || assignee.username |
| 63 | + : assignee.username; |
| 64 | + } |
| 65 | + |
| 66 | + <template> |
| 67 | + {{#if this.isAssigned}} |
| 68 | + <p class="assigned-to"> |
| 69 | + {{icon this.icon}} |
| 70 | + {{#if this.assignedToUser}} |
| 71 | + <span class="assignee"> |
| 72 | + <span class="assigned-to--user"> |
| 73 | + {{htmlSafe |
| 74 | + (i18n |
| 75 | + "discourse_assign.assigned_topic_to" |
| 76 | + username=(this.prioritizedAssigneeName this.assignedToUser) |
| 77 | + path=(assignedToUserPath this.assignedToUser) |
| 78 | + ) |
| 79 | + }} |
| 80 | + </span> |
| 81 | + </span> |
| 82 | + {{/if}} |
| 83 | + |
| 84 | + {{#if this.assignedToGroup}} |
| 85 | + <span class="assignee"> |
| 86 | + <span class="assigned-to--group"> |
| 87 | + {{htmlSafe |
| 88 | + (i18n |
| 89 | + "discourse_assign.assigned_topic_to" |
| 90 | + username=this.assignedToGroup.name |
| 91 | + path=(assignedToGroupPath this.assignedToGroup) |
| 92 | + ) |
| 93 | + }} |
| 94 | + </span> |
| 95 | + </span> |
| 96 | + {{/if}} |
| 97 | + |
| 98 | + {{#if this.hasOnlyIndirectAssignments}} |
| 99 | + <span class="assign-text"> |
| 100 | + {{i18n "discourse_assign.assigned"}} |
| 101 | + </span> |
| 102 | + {{/if}} |
| 103 | + {{#if this.indirectlyAssignedTo}} |
| 104 | + {{#each |
| 105 | + this.indirectAssignments key="postId" |
| 106 | + as |indirectAssignment| |
| 107 | + }} |
| 108 | + <span class="assignee"> |
| 109 | + <a href={{indirectAssignment.url}} class="assigned-indirectly"> |
| 110 | + {{i18n |
| 111 | + "discourse_assign.assign_post_to_multiple" |
| 112 | + post_number=indirectAssignment.postNumber |
| 113 | + username=(this.prioritizedAssigneeName |
| 114 | + indirectAssignment.assignee |
| 115 | + ) |
| 116 | + }} |
| 117 | + </a> |
| 118 | + </span> |
| 119 | + {{/each}} |
| 120 | + {{/if}} |
| 121 | + </p> |
| 122 | + {{/if}} |
| 123 | + </template> |
| 124 | +} |
0 commit comments