-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathApplicableEntities.vue
More file actions
67 lines (57 loc) · 2.04 KB
/
Copy pathApplicableEntities.vue
File metadata and controls
67 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script setup lang="ts">
import axios from '@nextcloud/axios'
import { t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { useDebounceFn } from '@vueuse/core'
import { computed, ref } from 'vue'
import NcSelectUsers from '@nextcloud/vue/components/NcSelectUsers'
import { mapGroupToUserData, useGroups, useUsers } from '../../composables/useEntities.ts'
type IUserData = InstanceType<typeof NcSelectUsers>['$props']['options'][number]
const groups = defineModel<string[]>('groups', { default: () => [] })
const users = defineModel<string[]>('users', { default: () => [] })
const entities = ref<IUserData[]>([])
const selectedUsers = useUsers(users)
const selectedGroups = useGroups(groups)
const model = computed({
get() {
return [...selectedGroups.value, ...selectedUsers.value]
},
set(value: IUserData[]) {
users.value = value.filter((u) => u.user).map((u) => u.user!)
groups.value = value.filter((g) => g.isNoUser).map((g) => g.id)
},
})
const debouncedSearch = useDebounceFn(onSearch, 500)
/**
* Handle searching for users and groups
*
* @param pattern - The pattern to search
*/
async function onSearch(pattern: string) {
const { data } = await axios.get<{ groups: Record<string, string>, users: Record<string, string> }>(
generateUrl('apps/files_external/ajax/applicable'),
{ params: { pattern, limit: 20 } },
)
const newEntries = [
...entities.value.map((e) => [e.id, e]),
...Object.entries(data.groups)
.map(([id, displayName]) => [id, { ...mapGroupToUserData(id), displayName }]),
...Object.entries(data.users)
.map(([id, displayName]) => [`user:${id}`, { id: `user:${id}`, user: id, displayName }]),
] as [string, IUserData][]
entities.value = [...new Map(newEntries).values()]
}
</script>
<template>
<NcSelectUsers
v-model="model"
keepOpen
multiple
:options="entities"
:inputLabel="t('files_external', 'Restrict to')"
@search="debouncedSearch" />
</template>