2022-04-12 18:12:59 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import contact, { Employee, formatName } from '@anticrm/contact'
|
|
|
|
import { Ref, WithLookup } from '@anticrm/core'
|
|
|
|
import { Issue, Team } from '@anticrm/tracker'
|
|
|
|
import { Avatar, UsersPopup, getClient } from '@anticrm/presentation'
|
2022-04-19 09:38:31 +00:00
|
|
|
import { eventToHTMLElement, showPopup, Tooltip } from '@anticrm/ui'
|
2022-04-12 18:12:59 +00:00
|
|
|
|
|
|
|
import tracker from '../../plugin'
|
2022-04-20 06:06:05 +00:00
|
|
|
import { IntlString, translate } from '@anticrm/platform'
|
|
|
|
import { onMount } from 'svelte'
|
2022-04-12 18:12:59 +00:00
|
|
|
|
|
|
|
export let value: WithLookup<Issue>
|
|
|
|
export let currentSpace: Ref<Team> | undefined = undefined
|
2022-04-20 06:06:05 +00:00
|
|
|
export let isEditable: boolean = true
|
|
|
|
export let shouldShowLabel: boolean = false
|
|
|
|
export let defaultName: IntlString | undefined = undefined
|
2022-04-12 18:12:59 +00:00
|
|
|
|
2022-04-20 06:06:05 +00:00
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
let defaultNameString: string = ''
|
|
|
|
let assignee: Employee | undefined = undefined
|
|
|
|
|
|
|
|
$: employee = (value?.$lookup?.assignee ?? assignee) as Employee | undefined
|
2022-04-12 18:12:59 +00:00
|
|
|
$: avatar = employee?.avatar
|
2022-04-20 06:06:05 +00:00
|
|
|
$: formattedName = employee?.name ? formatName(employee.name) : defaultNameString
|
|
|
|
$: label = employee ? tracker.string.AssignedTo : tracker.string.AssignTo
|
2022-04-12 18:12:59 +00:00
|
|
|
|
2022-04-20 06:06:05 +00:00
|
|
|
$: findEmployeeById(value.assignee)
|
|
|
|
$: getDefaultNameString = async () => {
|
|
|
|
if (!defaultName) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = await translate(defaultName, {})
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultNameString = result
|
|
|
|
}
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
getDefaultNameString()
|
|
|
|
})
|
|
|
|
|
|
|
|
const findEmployeeById = async (id: Ref<Employee> | null) => {
|
|
|
|
if (!id) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
const current = await client.findOne(contact.class.Employee, { _id: id })
|
|
|
|
|
|
|
|
if (current === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assignee = current
|
|
|
|
}
|
2022-04-12 18:12:59 +00:00
|
|
|
|
|
|
|
const handleAssigneeChanged = async (result: Employee | null | undefined) => {
|
2022-04-20 06:06:05 +00:00
|
|
|
if (!isEditable || result === undefined) {
|
2022-04-12 18:12:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentIssue = await client.findOne(tracker.class.Issue, { space: currentSpace, _id: value._id })
|
|
|
|
|
|
|
|
if (currentIssue === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const newAssignee = result === null ? null : result._id
|
|
|
|
|
|
|
|
await client.update(currentIssue, { assignee: newAssignee })
|
|
|
|
}
|
|
|
|
|
2022-04-19 09:38:31 +00:00
|
|
|
const handleAssigneeEditorOpened = async (event: MouseEvent) => {
|
2022-04-20 06:06:05 +00:00
|
|
|
if (!isEditable) {
|
|
|
|
return
|
|
|
|
}
|
2022-04-12 18:12:59 +00:00
|
|
|
showPopup(
|
|
|
|
UsersPopup,
|
|
|
|
{
|
|
|
|
_class: contact.class.Employee,
|
|
|
|
selected: employee?._id,
|
|
|
|
allowDeselect: true,
|
|
|
|
placeholder: tracker.string.AssignTo
|
|
|
|
},
|
2022-04-19 09:38:31 +00:00
|
|
|
eventToHTMLElement(event),
|
2022-04-12 18:12:59 +00:00
|
|
|
handleAssigneeChanged
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-04-20 06:06:05 +00:00
|
|
|
{#if isEditable}
|
|
|
|
<Tooltip {label} props={{ value: formattedName }}>
|
|
|
|
<div class="flex-presenter" on:click={handleAssigneeEditorOpened}>
|
|
|
|
<div class="icon">
|
2022-04-26 07:12:58 +00:00
|
|
|
<Avatar size={'tiny'} {avatar} />
|
2022-04-20 06:06:05 +00:00
|
|
|
</div>
|
|
|
|
{#if shouldShowLabel}
|
|
|
|
<div class="label nowrap ml-2">
|
|
|
|
{formattedName}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
{:else}
|
|
|
|
<div class="presenter">
|
2022-04-12 18:12:59 +00:00
|
|
|
<div class="icon">
|
2022-04-26 07:12:58 +00:00
|
|
|
<Avatar size={'tiny'} {avatar} />
|
2022-04-12 18:12:59 +00:00
|
|
|
</div>
|
2022-04-20 06:06:05 +00:00
|
|
|
{#if shouldShowLabel}
|
|
|
|
<div class="label nowrap ml-2">
|
|
|
|
{formattedName}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-04-12 18:12:59 +00:00
|
|
|
</div>
|
2022-04-20 06:06:05 +00:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.presenter {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
}
|
|
|
|
</style>
|