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">
|
2022-09-21 08:08:25 +00:00
|
|
|
import contact, { Employee } from '@hcengineering/contact'
|
|
|
|
import { Class, Doc, Ref } from '@hcengineering/core'
|
2022-10-05 06:41:02 +00:00
|
|
|
import { Issue, IssueTemplate } from '@hcengineering/tracker'
|
2022-09-21 08:08:25 +00:00
|
|
|
import { UsersPopup, getClient } from '@hcengineering/presentation'
|
|
|
|
import { AttributeModel } from '@hcengineering/view'
|
|
|
|
import { eventToHTMLElement, showPopup } from '@hcengineering/ui'
|
|
|
|
import { getObjectPresenter } from '@hcengineering/view-resources'
|
|
|
|
import { IntlString } from '@hcengineering/platform'
|
2022-04-12 18:12:59 +00:00
|
|
|
import tracker from '../../plugin'
|
|
|
|
|
2022-06-07 08:57:05 +00:00
|
|
|
export let value: Employee | null | undefined
|
2022-04-28 12:03:10 +00:00
|
|
|
export let issueId: Ref<Issue>
|
2022-10-05 06:41:02 +00:00
|
|
|
export let issueClass: Ref<Class<Issue | IssueTemplate>> = tracker.class.Issue
|
2022-04-28 12:03:10 +00:00
|
|
|
export let defaultClass: Ref<Class<Doc>> | 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()
|
|
|
|
|
2022-04-28 12:03:10 +00:00
|
|
|
let presenter: AttributeModel | undefined
|
|
|
|
|
|
|
|
$: if (value || defaultClass) {
|
|
|
|
if (value) {
|
|
|
|
getObjectPresenter(client, value._class, { key: '' }).then((p) => {
|
|
|
|
presenter = p
|
|
|
|
})
|
|
|
|
} else if (defaultClass) {
|
|
|
|
getObjectPresenter(client, defaultClass, { key: '' }).then((p) => {
|
|
|
|
presenter = p
|
|
|
|
})
|
2022-04-20 06:06:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-10-05 06:41:02 +00:00
|
|
|
const currentIssue = await client.findOne(issueClass, { _id: issueId })
|
2022-04-12 18:12:59 +00:00
|
|
|
|
|
|
|
if (currentIssue === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const newAssignee = result === null ? null : result._id
|
|
|
|
|
2022-10-05 06:41:02 +00:00
|
|
|
await client.update(currentIssue, { assignee: newAssignee })
|
2022-04-12 18:12:59 +00:00
|
|
|
}
|
|
|
|
|
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-06-16 04:24:17 +00:00
|
|
|
event?.preventDefault()
|
|
|
|
event?.stopPropagation()
|
2022-05-18 05:35:34 +00:00
|
|
|
|
2022-04-12 18:12:59 +00:00
|
|
|
showPopup(
|
|
|
|
UsersPopup,
|
|
|
|
{
|
|
|
|
_class: contact.class.Employee,
|
2022-04-28 12:03:10 +00:00
|
|
|
selected: value?._id,
|
2022-06-29 05:51:29 +00:00
|
|
|
docQuery: {
|
|
|
|
active: true
|
|
|
|
},
|
2022-04-12 18:12:59 +00:00
|
|
|
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-28 12:03:10 +00:00
|
|
|
{#if presenter}
|
|
|
|
<svelte:component
|
|
|
|
this={presenter.presenter}
|
|
|
|
{value}
|
|
|
|
{defaultName}
|
2022-06-21 03:53:48 +00:00
|
|
|
avatarSize={'x-small'}
|
2022-04-28 12:03:10 +00:00
|
|
|
isInteractive={true}
|
|
|
|
shouldShowPlaceholder={true}
|
|
|
|
shouldShowName={shouldShowLabel}
|
2022-05-18 05:35:34 +00:00
|
|
|
onEmployeeEdit={handleAssigneeEditorOpened}
|
2022-06-07 11:29:35 +00:00
|
|
|
tooltipLabels={{ personLabel: tracker.string.AssignedTo, placeholderLabel: tracker.string.Unassigned }}
|
2022-04-28 12:03:10 +00:00
|
|
|
/>
|
2022-04-20 06:06:05 +00:00
|
|
|
{/if}
|