2022-04-29 08:22:47 +00:00
|
|
|
<script lang="ts">
|
2023-03-22 02:48:57 +00:00
|
|
|
import { Employee, EmployeeAccount, getName } from '@hcengineering/contact'
|
2023-03-17 16:05:22 +00:00
|
|
|
import core, { IdMap, Ref, Space } from '@hcengineering/core'
|
2023-03-22 02:48:57 +00:00
|
|
|
import presentation, { getClient } from '@hcengineering/presentation'
|
2023-03-09 09:05:42 +00:00
|
|
|
import { ActionIcon, Button, IconClose, Label } from '@hcengineering/ui'
|
2022-04-29 08:22:47 +00:00
|
|
|
import { createEventDispatcher } from 'svelte'
|
2023-03-22 02:48:57 +00:00
|
|
|
import contact from '../plugin'
|
2023-02-28 18:36:00 +00:00
|
|
|
import UsersPopup from './UsersPopup.svelte'
|
2022-04-29 08:22:47 +00:00
|
|
|
|
2023-02-28 18:36:00 +00:00
|
|
|
export let value: Space
|
2022-04-29 08:22:47 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
2023-03-09 09:05:42 +00:00
|
|
|
|
2023-03-17 16:05:22 +00:00
|
|
|
const employees: IdMap<Employee> = new Map()
|
2022-04-29 08:22:47 +00:00
|
|
|
|
|
|
|
let membersToAdd: EmployeeAccount[] = []
|
|
|
|
let channelMembers: Ref<Employee>[] = []
|
2023-02-28 18:36:00 +00:00
|
|
|
client.findAll(core.class.Account, { _id: { $in: value.members } }).then((res) => {
|
2022-04-29 08:22:47 +00:00
|
|
|
channelMembers = res
|
|
|
|
.filter((e) => e._class === contact.class.EmployeeAccount)
|
|
|
|
.map((e) => (e as EmployeeAccount).employee)
|
|
|
|
})
|
|
|
|
|
|
|
|
async function changeMembersToAdd (employees: Ref<Employee>[]) {
|
|
|
|
if (employees) {
|
|
|
|
await client.findAll(contact.class.EmployeeAccount, { employee: { $in: employees } }).then((res) => {
|
|
|
|
if (res) {
|
|
|
|
membersToAdd = res
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$: selectedEmployees = membersToAdd.map((e) => e.employee)
|
|
|
|
|
|
|
|
function removeMember (_id: Ref<EmployeeAccount>) {
|
|
|
|
membersToAdd = membersToAdd.filter((m) => m._id !== _id)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="antiPopup antiPopup-withHeader">
|
|
|
|
<div class="ap-header flex-between header">
|
|
|
|
<div class="ap-caption">
|
2023-03-22 02:48:57 +00:00
|
|
|
<Label label={contact.string.AddMembersHeader} params={{ value: value.name }} />
|
2022-04-29 08:22:47 +00:00
|
|
|
</div>
|
|
|
|
<div class="tool">
|
|
|
|
<ActionIcon
|
|
|
|
icon={IconClose}
|
|
|
|
size={'small'}
|
|
|
|
action={() => {
|
|
|
|
dispatch('close')
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{#if membersToAdd.length}
|
|
|
|
<div class="flex-row-top flex-wrap ml-6 mr-6 mt-4">
|
|
|
|
{#each membersToAdd as m}
|
2023-03-09 09:05:42 +00:00
|
|
|
{@const employee = employees.get(m.employee)}
|
2023-02-28 18:36:00 +00:00
|
|
|
<div class="mr-2 p-1 item">
|
2023-03-09 09:05:42 +00:00
|
|
|
{employee ? getName(employee) : ''}
|
2022-04-29 08:22:47 +00:00
|
|
|
<div class="tool">
|
|
|
|
<ActionIcon
|
|
|
|
icon={IconClose}
|
|
|
|
size={'small'}
|
|
|
|
action={() => {
|
|
|
|
removeMember(m._id)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
<div class="ml-8 mr-8 mb-6 mt-4">
|
|
|
|
<UsersPopup
|
|
|
|
selected={undefined}
|
|
|
|
_class={contact.class.Employee}
|
2022-06-29 05:51:29 +00:00
|
|
|
docQuery={{
|
|
|
|
active: true
|
|
|
|
}}
|
2022-04-29 08:22:47 +00:00
|
|
|
multiSelect={true}
|
|
|
|
allowDeselect={true}
|
|
|
|
selectedUsers={selectedEmployees}
|
|
|
|
ignoreUsers={channelMembers}
|
|
|
|
shadows={false}
|
|
|
|
on:update={(ev) => changeMembersToAdd(ev.detail)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
on:click={() => {
|
|
|
|
dispatch(
|
2023-02-28 18:36:00 +00:00
|
|
|
'close',
|
2022-04-29 08:22:47 +00:00
|
|
|
membersToAdd.map((m) => m._id)
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
label={presentation.string.Add}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.header {
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
|
|
|
|
|
|
|
.item {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
width: fit-content;
|
|
|
|
background-color: var(--popup-bg-hover);
|
|
|
|
}
|
|
|
|
</style>
|