2022-03-14 09:05:02 +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-04-09 16:00:48 +00:00
|
|
|
import { Person } from '@anticrm/contact'
|
2022-03-14 09:05:02 +00:00
|
|
|
import type { Class, Doc, Ref } from '@anticrm/core'
|
2022-04-14 11:04:24 +00:00
|
|
|
import type { IntlString } from '@anticrm/platform'
|
|
|
|
import { translate } from '@anticrm/platform'
|
|
|
|
import type { ButtonKind, ButtonSize, TooltipAlignment } from '@anticrm/ui'
|
|
|
|
import { Tooltip, showPopup, Button } from '@anticrm/ui'
|
2022-03-14 09:05:02 +00:00
|
|
|
import { createEventDispatcher } from 'svelte'
|
2022-04-14 11:04:24 +00:00
|
|
|
import presentation, { CombineAvatars, UsersPopup } from '..'
|
2022-03-14 09:05:02 +00:00
|
|
|
import { createQuery } from '../utils'
|
2022-04-14 11:04:24 +00:00
|
|
|
import Members from './icons/Members.svelte'
|
2022-03-14 09:05:02 +00:00
|
|
|
|
|
|
|
export let items: Ref<Person>[] = []
|
|
|
|
export let _class: Ref<Class<Doc>>
|
2022-04-14 11:04:24 +00:00
|
|
|
export let label: IntlString
|
2022-03-14 09:05:02 +00:00
|
|
|
export let noItems: IntlString
|
|
|
|
|
2022-04-14 11:04:24 +00:00
|
|
|
export let kind: ButtonKind = 'no-border'
|
|
|
|
export let size: ButtonSize = 'small'
|
|
|
|
export let justify: 'left' | 'center' = 'center'
|
|
|
|
export let width: string | undefined = undefined
|
|
|
|
export let labelDirection: TooltipAlignment | undefined = undefined
|
|
|
|
|
2022-03-14 09:05:02 +00:00
|
|
|
let persons: Person[] = []
|
|
|
|
|
|
|
|
const query = createQuery()
|
|
|
|
|
|
|
|
$: query.query<Person>(_class, { _id: { $in: items } }, (result) => {
|
|
|
|
persons = result
|
|
|
|
})
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
|
|
|
async function addPerson (evt: Event): Promise<void> {
|
|
|
|
showPopup(
|
|
|
|
UsersPopup,
|
|
|
|
{
|
|
|
|
_class,
|
2022-04-14 11:04:24 +00:00
|
|
|
label,
|
|
|
|
multiSelect: true,
|
2022-03-14 09:05:02 +00:00
|
|
|
allowDeselect: false,
|
2022-04-14 11:04:24 +00:00
|
|
|
selectedUsers: items
|
2022-03-14 09:05:02 +00:00
|
|
|
},
|
|
|
|
evt.target as HTMLElement,
|
2022-04-14 11:04:24 +00:00
|
|
|
() => { },
|
2022-03-14 09:05:02 +00:00
|
|
|
(result) => {
|
|
|
|
if (result !== undefined) {
|
2022-04-14 11:04:24 +00:00
|
|
|
items = result
|
|
|
|
dispatch('update', items)
|
2022-03-14 09:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-04-14 11:04:24 +00:00
|
|
|
<Tooltip {label} fill={width === '100%'} direction={labelDirection}>
|
|
|
|
<Button
|
|
|
|
icon={persons.length === 0 ? Members : undefined}
|
|
|
|
label={persons.length === 0 ? presentation.string.Members : undefined}
|
|
|
|
width={width ?? 'min-content'}
|
|
|
|
{kind} {size} {justify}
|
|
|
|
on:click={addPerson}
|
|
|
|
>
|
|
|
|
<svelte:fragment slot="content">
|
|
|
|
{#if persons.length > 0}
|
|
|
|
<div class="flex-row-center flex-nowrap">
|
|
|
|
<CombineAvatars {_class} bind:items size={'inline'} />
|
2022-04-16 03:06:32 +00:00
|
|
|
{#await translate(presentation.string.NumberMembers, { count: persons.length }) then text}
|
2022-04-14 11:04:24 +00:00
|
|
|
<span class="ml-1-5">{text}</span>
|
|
|
|
{/await}
|
2022-03-14 09:05:02 +00:00
|
|
|
</div>
|
2022-04-14 11:04:24 +00:00
|
|
|
{/if}
|
|
|
|
</svelte:fragment>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|