2021-12-06 10:07:08 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// 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
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// 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.
|
2021-12-15 09:15:43 +00:00
|
|
|
//
|
2021-12-06 10:07:08 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-01-12 09:52:22 +00:00
|
|
|
import attachment from '@anticrm/attachment'
|
2022-04-28 09:53:35 +00:00
|
|
|
import { combineName, getFirstName, getLastName, Person } from '@anticrm/contact'
|
|
|
|
import { getCurrentAccount, Ref, Space } from '@anticrm/core'
|
2022-02-25 15:32:23 +00:00
|
|
|
import { getResource } from '@anticrm/platform'
|
2022-04-28 09:53:35 +00:00
|
|
|
import { AttributeEditor, Avatar, createQuery, EditableAvatar, getClient } from '@anticrm/presentation'
|
|
|
|
import setting, { IntegrationType } from '@anticrm/setting'
|
|
|
|
import { CircleButton, EditBox, IconActivity, Label } from '@anticrm/ui'
|
|
|
|
import { afterUpdate, createEventDispatcher, onMount } from 'svelte'
|
2021-12-06 10:07:08 +00:00
|
|
|
import contact from '../plugin'
|
2022-01-31 09:06:30 +00:00
|
|
|
import ChannelsEditor from './ChannelsEditor.svelte'
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2021-12-15 09:15:43 +00:00
|
|
|
export let object: Person
|
2022-02-25 15:32:23 +00:00
|
|
|
const client = getClient()
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2022-02-25 15:32:23 +00:00
|
|
|
const hierarchy = client.getHierarchy()
|
|
|
|
|
|
|
|
$: editable = !hierarchy.isDerived(object._class, contact.class.Employee)
|
2022-02-25 09:03:12 +00:00
|
|
|
let firstName = getFirstName(object.name)
|
|
|
|
let lastName = getLastName(object.name)
|
|
|
|
|
|
|
|
$: setName(object)
|
|
|
|
|
|
|
|
function setName (object: Person) {
|
|
|
|
firstName = getFirstName(object.name)
|
|
|
|
lastName = getLastName(object.name)
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
function firstNameChange () {
|
|
|
|
client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
name: combineName(firstName, getLastName(object.name))
|
|
|
|
})
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
function lastNameChange () {
|
|
|
|
client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
name: combineName(getFirstName(object.name), lastName)
|
|
|
|
})
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
2021-12-10 09:46:08 +00:00
|
|
|
|
|
|
|
const accountId = getCurrentAccount()._id
|
|
|
|
let integrations: Set<Ref<IntegrationType>> = new Set<Ref<IntegrationType>>()
|
|
|
|
const settingsQuery = createQuery()
|
2022-03-16 09:02:57 +00:00
|
|
|
$: settingsQuery.query(setting.class.Integration, { space: accountId as string as Ref<Space>, disabled: false }, (res) => {
|
2021-12-10 09:46:08 +00:00
|
|
|
integrations = new Set(res.map((p) => p.type))
|
|
|
|
})
|
2021-12-15 09:15:43 +00:00
|
|
|
|
2022-01-11 09:05:53 +00:00
|
|
|
const sendOpen = () => dispatch('open', { ignoreKeys: ['comments', 'name', 'channels', 'city'] })
|
2021-12-30 09:04:32 +00:00
|
|
|
onMount(sendOpen)
|
|
|
|
afterUpdate(sendOpen)
|
2022-01-12 09:52:22 +00:00
|
|
|
|
|
|
|
async function onAvatarDone (e: any) {
|
|
|
|
const uploadFile = await getResource(attachment.helper.UploadFile)
|
2022-01-14 09:09:01 +00:00
|
|
|
const deleteFile = await getResource(attachment.helper.DeleteFile)
|
2022-01-12 09:52:22 +00:00
|
|
|
const { file: avatar } = e.detail
|
|
|
|
|
2022-01-14 09:09:01 +00:00
|
|
|
if (object.avatar != null) {
|
|
|
|
await deleteFile(object.avatar)
|
|
|
|
}
|
2022-01-12 09:52:22 +00:00
|
|
|
const uuid = await uploadFile(avatar)
|
|
|
|
await client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
avatar: uuid
|
|
|
|
})
|
|
|
|
}
|
2022-03-28 15:25:39 +00:00
|
|
|
|
|
|
|
async function removeAvatar (): Promise<void> {
|
|
|
|
const deleteFile = await getResource(attachment.helper.DeleteFile)
|
|
|
|
if (object.avatar != null) {
|
|
|
|
await client.updateDoc(object._class, object.space, object._id, {
|
|
|
|
avatar: null
|
|
|
|
})
|
|
|
|
await deleteFile(object.avatar)
|
|
|
|
}
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if object !== undefined}
|
2022-04-18 10:27:29 +00:00
|
|
|
<div class="flex-row-stretch flex-grow">
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="mr-8">
|
2022-02-25 15:32:23 +00:00
|
|
|
{#if editable}
|
2022-03-28 15:25:39 +00:00
|
|
|
<EditableAvatar avatar={object.avatar} size={'x-large'} on:done={onAvatarDone} on:remove={removeAvatar} />
|
2022-02-25 15:32:23 +00:00
|
|
|
{:else}
|
|
|
|
<Avatar avatar={object.avatar} size={'x-large'} />
|
|
|
|
{/if}
|
2021-12-15 09:15:43 +00:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow flex-col">
|
2022-01-06 11:38:40 +00:00
|
|
|
<div class="flex-grow flex-col">
|
|
|
|
<div class="name">
|
2022-02-25 15:32:23 +00:00
|
|
|
{#if editable}
|
|
|
|
<EditBox placeholder={contact.string.PersonFirstNamePlaceholder} maxWidth="20rem" bind:value={firstName} on:change={firstNameChange} />
|
|
|
|
{:else}
|
|
|
|
{firstName}
|
|
|
|
{/if}
|
2022-01-06 11:38:40 +00:00
|
|
|
</div>
|
|
|
|
<div class="name">
|
2022-02-25 15:32:23 +00:00
|
|
|
{#if editable}
|
|
|
|
<EditBox placeholder={contact.string.PersonLastNamePlaceholder} maxWidth="20rem" bind:value={lastName} on:change={lastNameChange} />
|
|
|
|
{:else}
|
|
|
|
{lastName}
|
|
|
|
{/if}
|
2022-01-06 11:38:40 +00:00
|
|
|
</div>
|
2022-01-11 09:05:53 +00:00
|
|
|
<div class="location">
|
2022-02-25 15:32:23 +00:00
|
|
|
<AttributeEditor maxWidth="20rem" _class={contact.class.Person} {editable} {object} key="city" />
|
2022-01-11 09:05:53 +00:00
|
|
|
</div>
|
2021-12-15 09:15:43 +00:00
|
|
|
</div>
|
2022-01-06 11:38:40 +00:00
|
|
|
|
|
|
|
<div class="separator" />
|
|
|
|
|
2022-03-03 09:26:00 +00:00
|
|
|
<div class="flex-between">
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="flex-row-center">
|
2022-04-21 09:38:09 +00:00
|
|
|
<ChannelsEditor
|
|
|
|
attachedTo={object._id}
|
|
|
|
attachedClass={object._class}
|
|
|
|
{editable}
|
|
|
|
{integrations}
|
|
|
|
shape={'circle'}
|
|
|
|
on:click
|
|
|
|
/>
|
2021-12-07 09:05:52 +00:00
|
|
|
</div>
|
2021-12-06 10:07:08 +00:00
|
|
|
|
2021-12-15 09:15:43 +00:00
|
|
|
<div class="flex-row-center">
|
2022-02-08 09:03:27 +00:00
|
|
|
<div class="over-underline flex-row-center" on:click>
|
2021-12-15 09:15:43 +00:00
|
|
|
<CircleButton icon={IconActivity} size={'small'} primary on:click />
|
2022-02-23 16:10:11 +00:00
|
|
|
<span class="ml-2 text-sm"><Label label={contact.string.ViewActivity} /></span>
|
2022-02-08 09:03:27 +00:00
|
|
|
</div>
|
2021-12-15 09:15:43 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-07 09:05:52 +00:00
|
|
|
</div>
|
2021-12-15 09:15:43 +00:00
|
|
|
</div>
|
2021-12-06 10:07:08 +00:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.name {
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 1.25rem;
|
|
|
|
color: var(--theme-caption-color);
|
|
|
|
}
|
2022-01-11 09:05:53 +00:00
|
|
|
.location {
|
|
|
|
margin-top: 0.25rem;
|
|
|
|
font-size: 0.75rem;
|
|
|
|
}
|
2022-01-06 11:38:40 +00:00
|
|
|
|
|
|
|
.separator {
|
|
|
|
margin: 1rem 0;
|
|
|
|
height: 1px;
|
|
|
|
background-color: var(--theme-card-divider);
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
</style>
|