Merge 1fd881abc2 into 076cd214fe
This commit is contained in:
commit
93b4d79628
|
|
@ -7,11 +7,13 @@
|
||||||
:placeholder="$t('task.assignee.placeholder')"
|
:placeholder="$t('task.assignee.placeholder')"
|
||||||
:multiple="true"
|
:multiple="true"
|
||||||
:search-results="foundUsers"
|
:search-results="foundUsers"
|
||||||
|
:show-empty="true"
|
||||||
label="name"
|
label="name"
|
||||||
:select-placeholder="$t('task.assignee.selectPlaceholder')"
|
:select-placeholder="$t('task.assignee.selectPlaceholder')"
|
||||||
:autocomplete-enabled="false"
|
:autocomplete-enabled="false"
|
||||||
@search="findUser"
|
@search="findUser"
|
||||||
@select="addAssignee"
|
@select="addAssignee"
|
||||||
|
@focus="preloadUsers"
|
||||||
>
|
>
|
||||||
<template #items="{items}">
|
<template #items="{items}">
|
||||||
<AssigneeList
|
<AssigneeList
|
||||||
|
|
@ -41,6 +43,7 @@ import Multiselect from '@/components/input/Multiselect.vue'
|
||||||
import {includesById} from '@/helpers/utils'
|
import {includesById} from '@/helpers/utils'
|
||||||
import ProjectUserService from '@/services/projectUsers'
|
import ProjectUserService from '@/services/projectUsers'
|
||||||
import {success} from '@/message'
|
import {success} from '@/message'
|
||||||
|
import {useAuthStore} from '@/stores/auth'
|
||||||
import {useTaskStore} from '@/stores/tasks'
|
import {useTaskStore} from '@/stores/tasks'
|
||||||
|
|
||||||
import type {IUser} from '@/modelTypes/IUser'
|
import type {IUser} from '@/modelTypes/IUser'
|
||||||
|
|
@ -60,6 +63,7 @@ const emit = defineEmits<{
|
||||||
'update:modelValue': [value: IUser[] | undefined],
|
'update:modelValue': [value: IUser[] | undefined],
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
const taskStore = useTaskStore()
|
const taskStore = useTaskStore()
|
||||||
const {t} = useI18n({useScope: 'global'})
|
const {t} = useI18n({useScope: 'global'})
|
||||||
|
|
||||||
|
|
@ -68,6 +72,14 @@ const foundUsers = ref<IUser[]>([])
|
||||||
const assignees = ref<IUser[]>([])
|
const assignees = ref<IUser[]>([])
|
||||||
let isAdding = false
|
let isAdding = false
|
||||||
|
|
||||||
|
let hasPreloaded = false
|
||||||
|
|
||||||
|
function preloadUsers() {
|
||||||
|
if (hasPreloaded) return
|
||||||
|
hasPreloaded = true
|
||||||
|
findUser()
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(value) => {
|
(value) => {
|
||||||
|
|
@ -106,9 +118,11 @@ async function removeAssignee(user: IUser) {
|
||||||
success({message: t('task.assignee.unassignSuccess')})
|
success({message: t('task.assignee.unassignSuccess')})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findUser(query: string) {
|
async function findUser(query = '') {
|
||||||
const response = await projectUserService.getAll({projectId: props.projectId}, {s: query}) as IUser[]
|
const response = await projectUserService.getAll({projectId: props.projectId}, {s: query}) as IUser[]
|
||||||
|
|
||||||
|
const currentUserId = authStore.info?.id
|
||||||
|
|
||||||
// Filter the results to not include users who are already assigned
|
// Filter the results to not include users who are already assigned
|
||||||
foundUsers.value = response
|
foundUsers.value = response
|
||||||
.filter(({id}) => !includesById(assignees.value, id))
|
.filter(({id}) => !includesById(assignees.value, id))
|
||||||
|
|
@ -117,6 +131,11 @@ async function findUser(query: string) {
|
||||||
u.name = getDisplayName(u)
|
u.name = getDisplayName(u)
|
||||||
return u
|
return u
|
||||||
})
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a.id === currentUserId) return -1
|
||||||
|
if (b.id === currentUserId) return 1
|
||||||
|
return a.name.localeCompare(b.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue