2019-11-24 14:16:24 +01:00
|
|
|
<template>
|
|
|
|
<multiselect
|
|
|
|
:multiple="true"
|
|
|
|
:close-on-select="false"
|
|
|
|
:clear-on-select="true"
|
|
|
|
:options-limit="300"
|
|
|
|
:hide-selected="true"
|
|
|
|
v-model="assignees"
|
|
|
|
:options="foundUsers"
|
|
|
|
:searchable="true"
|
|
|
|
:loading="listUserService.loading"
|
|
|
|
:internal-search="true"
|
|
|
|
@search-change="findUser"
|
|
|
|
@select="addAssignee"
|
|
|
|
placeholder="Type to assign a user..."
|
|
|
|
label="username"
|
|
|
|
track-by="id"
|
|
|
|
select-label="Assign this user"
|
|
|
|
:showNoOptions="false"
|
|
|
|
>
|
2019-12-15 21:42:40 +01:00
|
|
|
<template slot="tag" slot-scope="{ option }">
|
2019-11-24 14:16:24 +01:00
|
|
|
<user :user="option" :show-username="false" :avatar-size="30"/>
|
|
|
|
<a @click="removeAssignee(option)" class="remove-assignee">
|
|
|
|
<icon icon="times"/>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
<template slot="clear" slot-scope="props">
|
|
|
|
<div class="multiselect__clear" v-if="newAssignee !== null && newAssignee.id !== 0"
|
|
|
|
@mousedown.prevent.stop="clearAllFoundUsers(props.search)"></div>
|
|
|
|
</template>
|
|
|
|
<span slot="noResult">No user found. Consider changing the search query.</span>
|
|
|
|
</multiselect>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-03-03 21:02:13 +01:00
|
|
|
import {differenceWith} from 'lodash'
|
2019-11-24 14:16:24 +01:00
|
|
|
import multiselect from 'vue-multiselect'
|
|
|
|
|
|
|
|
import UserModel from '../../../models/user'
|
|
|
|
import ListUserService from '../../../services/listUsers'
|
|
|
|
import TaskAssigneeService from '../../../services/taskAssignee'
|
|
|
|
import User from '../../global/user'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'editAssignees',
|
|
|
|
components: {
|
|
|
|
User,
|
|
|
|
multiselect,
|
|
|
|
},
|
|
|
|
props: {
|
2020-04-17 12:19:53 +02:00
|
|
|
taskId: {
|
2019-11-24 14:16:24 +01:00
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-17 12:19:53 +02:00
|
|
|
listId: {
|
2019-11-24 14:16:24 +01:00
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
initialAssignees: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
newAssignee: UserModel,
|
|
|
|
listUserService: ListUserService,
|
|
|
|
foundUsers: [],
|
|
|
|
assignees: [],
|
|
|
|
taskAssigneeService: TaskAssigneeService,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.assignees = this.initialAssignees
|
|
|
|
this.listUserService = new ListUserService()
|
|
|
|
this.newAssignee = new UserModel()
|
|
|
|
this.taskAssigneeService = new TaskAssigneeService()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
initialAssignees(newVal) {
|
|
|
|
this.assignees = newVal
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
addAssignee(user) {
|
2020-05-09 19:00:54 +02:00
|
|
|
this.$store.dispatch('tasks/addAssignee', {user: user, taskId: this.taskId})
|
2019-11-24 14:16:24 +01:00
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-11-24 14:16:24 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
removeAssignee(user) {
|
2020-05-09 19:00:54 +02:00
|
|
|
this.$store.dispatch('tasks/removeAssignee', {user: user, taskId: this.taskId})
|
2019-11-24 14:16:24 +01:00
|
|
|
.then(() => {
|
|
|
|
// Remove the assignee from the list
|
|
|
|
for (const a in this.assignees) {
|
|
|
|
if (this.assignees[a].id === user.id) {
|
|
|
|
this.assignees.splice(a, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-11-24 14:16:24 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
findUser(query) {
|
|
|
|
if (query === '') {
|
|
|
|
this.clearAllFoundUsers()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-17 12:19:53 +02:00
|
|
|
this.listUserService.getAll({listId: this.listId}, {s: query})
|
2019-11-24 14:16:24 +01:00
|
|
|
.then(response => {
|
|
|
|
// Filter the results to not include users who are already assigned
|
|
|
|
this.$set(this, 'foundUsers', differenceWith(response, this.assignees, (first, second) => {
|
|
|
|
return first.id === second.id
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-11-24 14:16:24 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
clearAllFoundUsers() {
|
|
|
|
this.$set(this, 'foundUsers', [])
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|