FEATURE: displays assignee avatar in button and dropdown (#66)

This commit is contained in:
Joffrey JAFFEUX 2020-05-11 19:02:22 +02:00 committed by GitHub
parent b7acd12244
commit af11fdca47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 3 deletions

View File

@ -1,3 +1,4 @@
import { renderAvatar } from "discourse/helpers/user-avatar";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import { default as computed } from "discourse-common/utils/decorators"; import { default as computed } from "discourse-common/utils/decorators";
import { iconNode } from "discourse-common/lib/icon-library"; import { iconNode } from "discourse-common/lib/icon-library";
@ -5,22 +6,38 @@ import { h } from "virtual-dom";
import { iconHTML } from "discourse-common/lib/icon-library"; import { iconHTML } from "discourse-common/lib/icon-library";
import { queryRegistry } from "discourse/widgets/widget"; import { queryRegistry } from "discourse/widgets/widget";
import { getOwner } from "discourse-common/lib/get-owner"; import { getOwner } from "discourse-common/lib/get-owner";
import { htmlSafe } from "@ember/template";
function registerTopicFooterButtons(api) { function registerTopicFooterButtons(api) {
api.registerTopicFooterButton({ api.registerTopicFooterButton({
id: "assign", id: "assign",
icon() { icon() {
const hasAssignement = this.get("topic.assigned_to_user"); const hasAssignement = this.get("topic.assigned_to_user");
return hasAssignement ? "user-times" : "user-plus"; return hasAssignement ? null : "user-plus";
}, },
priority: 250, priority: 250,
title() { title() {
const hasAssignement = this.get("topic.assigned_to_user"); const hasAssignement = this.get("topic.assigned_to_user");
return `discourse_assign.${hasAssignement ? "unassign" : "assign"}.help`; return `discourse_assign.${hasAssignement ? "unassign" : "assign"}.help`;
}, },
label() { ariaLabel() {
const hasAssignement = this.get("topic.assigned_to_user"); const hasAssignement = this.get("topic.assigned_to_user");
return `discourse_assign.${hasAssignement ? "unassign" : "assign"}.title`; return `discourse_assign.${hasAssignement ? "unassign" : "assign"}.help`;
},
translatedLabel() {
const user = this.get("topic.assigned_to_user");
if (user) {
const label = I18n.t("discourse_assign.unassign.title");
return htmlSafe(
`${renderAvatar(user, {
imageSize: "tiny",
ignoreTitle: true
})} <span class="unassign-label">${label}</span>`
);
} else {
return I18n.t("discourse_assign.assign.title");
}
}, },
action() { action() {
if (!this.get("currentUser.can_assign")) { if (!this.get("currentUser.can_assign")) {

View File

@ -80,3 +80,19 @@
margin-right: 5px; margin-right: 5px;
} }
} }
.topic-footer-button {
.d-button-label {
position: relative;
.avatar {
position: absolute;
top: -2px;
left: -2px;
}
.avatar + .unassign-label {
margin-left: 25px;
}
}
}

View File

@ -4,3 +4,20 @@
margin-top: 1em; margin-top: 1em;
} }
} }
.select-kit-row.assign {
.name {
position: relative;
overflow: visible;
.avatar {
position: absolute;
top: -1px;
left: -2px;
}
.avatar + .unassign-label {
margin-left: 25px;
}
}
}