2019-11-24 13:16:24 +00:00
|
|
|
<template>
|
2021-04-18 14:50:12 +00:00
|
|
|
<div
|
|
|
|
tabindex="-1"
|
|
|
|
@focus="focus"
|
2020-09-05 20:35:52 +00:00
|
|
|
>
|
2022-05-14 14:52:29 +00:00
|
|
|
<Multiselect
|
2021-04-18 14:50:12 +00:00
|
|
|
:loading="listUserService.loading"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('task.assignee.placeholder')"
|
2021-04-18 14:50:12 +00:00
|
|
|
:multiple="true"
|
|
|
|
@search="findUser"
|
|
|
|
:search-results="foundUsers"
|
|
|
|
@select="addAssignee"
|
|
|
|
label="username"
|
2021-06-23 23:24:57 +00:00
|
|
|
:select-placeholder="$t('task.assignee.selectPlaceholder')"
|
2021-04-18 14:50:12 +00:00
|
|
|
v-model="assignees"
|
|
|
|
ref="multiselect"
|
|
|
|
>
|
2022-05-14 14:52:29 +00:00
|
|
|
<template #tag="{item: user}">
|
2021-04-18 14:50:12 +00:00
|
|
|
<span class="assignee">
|
2022-05-14 14:52:29 +00:00
|
|
|
<user :avatar-size="32" :show-username="false" :user="user"/>
|
2022-05-10 23:14:38 +00:00
|
|
|
<BaseButton @click="removeAssignee(user)" class="remove-assignee" v-if="!disabled">
|
2021-04-18 14:50:12 +00:00
|
|
|
<icon icon="times"/>
|
2022-05-10 23:14:38 +00:00
|
|
|
</BaseButton>
|
2021-04-18 14:50:12 +00:00
|
|
|
</span>
|
|
|
|
</template>
|
2022-05-14 14:52:29 +00:00
|
|
|
</Multiselect>
|
2021-04-18 14:50:12 +00:00
|
|
|
</div>
|
2019-11-24 13:16:24 +00:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
<script setup lang="ts">
|
2022-06-23 01:08:35 +00:00
|
|
|
import {ref, shallowReactive, watch, type PropType} from 'vue'
|
2022-07-21 16:45:58 +00:00
|
|
|
import {useStore} from '@/store'
|
2022-05-14 14:52:29 +00:00
|
|
|
import {useI18n} from 'vue-i18n'
|
|
|
|
|
|
|
|
import User from '@/components/misc/user.vue'
|
2021-07-25 13:27:15 +00:00
|
|
|
import Multiselect from '@/components/input/multiselect.vue'
|
2022-05-10 23:14:38 +00:00
|
|
|
import BaseButton from '@/components/base/BaseButton.vue'
|
2019-11-24 13:16:24 +00:00
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
import {includesById} from '@/helpers/utils'
|
|
|
|
import ListUserService from '@/services/listUsers'
|
|
|
|
import {success} from '@/message'
|
2022-07-20 22:42:36 +00:00
|
|
|
import type { IUser } from '@/models/user'
|
2022-05-14 14:52:29 +00:00
|
|
|
|
|
|
|
const props = defineProps({
|
2020-09-05 20:35:52 +00:00
|
|
|
taskId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2019-11-24 13:16:24 +00:00
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
listId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2019-11-24 13:16:24 +00:00
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
disabled: {
|
|
|
|
default: false,
|
2019-11-24 13:16:24 +00:00
|
|
|
},
|
2021-08-23 19:18:12 +00:00
|
|
|
modelValue: {
|
2022-07-20 22:42:36 +00:00
|
|
|
type: Array as PropType<IUser[]>,
|
2022-05-14 14:52:29 +00:00
|
|
|
default: () => [],
|
2020-10-02 16:40:04 +00:00
|
|
|
},
|
2022-05-14 14:52:29 +00:00
|
|
|
})
|
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
|
|
|
|
|
const store = useStore()
|
2022-05-23 05:23:59 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2022-05-14 14:52:29 +00:00
|
|
|
|
|
|
|
const listUserService = shallowReactive(new ListUserService())
|
|
|
|
const foundUsers = ref([])
|
2022-07-20 22:42:36 +00:00
|
|
|
const assignees = ref<IUser[]>([])
|
2022-05-14 14:52:29 +00:00
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.modelValue,
|
|
|
|
(value) => {
|
|
|
|
assignees.value = value
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2022-05-14 14:52:29 +00:00
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
deep: true,
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2022-05-14 14:52:29 +00:00
|
|
|
)
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-07-20 22:42:36 +00:00
|
|
|
async function addAssignee(user: IUser) {
|
2022-05-14 14:52:29 +00:00
|
|
|
await store.dispatch('tasks/addAssignee', {user: user, taskId: props.taskId})
|
|
|
|
emit('update:modelValue', assignees.value)
|
|
|
|
success({message: t('task.assignee.assignSuccess')})
|
|
|
|
}
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-07-20 22:42:36 +00:00
|
|
|
async function removeAssignee(user: IUser) {
|
2022-05-14 14:52:29 +00:00
|
|
|
await store.dispatch('tasks/removeAssignee', {user: user, taskId: props.taskId})
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
// Remove the assignee from the list
|
|
|
|
for (const a in assignees.value) {
|
|
|
|
if (assignees.value[a].id === user.id) {
|
|
|
|
assignees.value.splice(a, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
success({message: t('task.assignee.unassignSuccess')})
|
|
|
|
}
|
2019-11-24 13:16:24 +00:00
|
|
|
|
2022-05-10 23:14:38 +00:00
|
|
|
async function findUser(query: string) {
|
2022-05-14 14:52:29 +00:00
|
|
|
if (query === '') {
|
|
|
|
clearAllFoundUsers()
|
|
|
|
return
|
|
|
|
}
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
const response = await listUserService.getAll({listId: props.listId}, {s: query})
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
// Filter the results to not include users who are already assigned
|
|
|
|
foundUsers.value = response.filter(({id}) => !includesById(assignees.value, id))
|
|
|
|
}
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-14 14:52:29 +00:00
|
|
|
function clearAllFoundUsers() {
|
|
|
|
foundUsers.value = []
|
|
|
|
}
|
|
|
|
|
|
|
|
const multiselect = ref()
|
|
|
|
function focus() {
|
|
|
|
multiselect.value.focus()
|
|
|
|
}
|
2019-11-24 13:16:24 +00:00
|
|
|
</script>
|
2021-10-18 12:19:24 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.assignee {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&:not(:first-child) {
|
|
|
|
margin-left: -1.5rem;
|
|
|
|
}
|
|
|
|
|
2021-10-20 12:33:36 +00:00
|
|
|
:deep(.user img) {
|
2021-11-22 21:12:54 +00:00
|
|
|
border: 2px solid var(--white);
|
2021-10-18 12:19:24 +00:00
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.remove-assignee {
|
|
|
|
position: absolute;
|
|
|
|
top: 4px;
|
|
|
|
left: 2px;
|
2021-11-22 21:12:54 +00:00
|
|
|
color: var(--danger);
|
|
|
|
background: var(--white);
|
2021-10-18 12:19:24 +00:00
|
|
|
padding: 0 4px;
|
|
|
|
display: block;
|
|
|
|
border-radius: 100%;
|
|
|
|
font-size: .75rem;
|
|
|
|
width: 18px;
|
|
|
|
height: 18px;
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|