2019-11-24 14:16:24 +01:00
|
|
|
<template>
|
|
|
|
<multiselect
|
2020-09-05 22:35:52 +02:00
|
|
|
:clear-on-select="true"
|
|
|
|
:close-on-select="false"
|
|
|
|
:disabled="disabled"
|
|
|
|
:hide-selected="true"
|
|
|
|
:internal-search="true"
|
|
|
|
:loading="listUserService.loading"
|
|
|
|
:multiple="true"
|
|
|
|
:options="foundUsers"
|
|
|
|
:options-limit="300"
|
|
|
|
:searchable="true"
|
|
|
|
:showNoOptions="false"
|
|
|
|
@search-change="findUser"
|
|
|
|
@select="addAssignee"
|
|
|
|
label="username"
|
|
|
|
placeholder="Type to assign a user..."
|
|
|
|
select-label="Assign this user"
|
|
|
|
track-by="id"
|
|
|
|
v-model="assignees"
|
|
|
|
>
|
2019-12-15 21:42:40 +01:00
|
|
|
<template slot="tag" slot-scope="{ option }">
|
2020-09-05 22:35:52 +02:00
|
|
|
<user :avatar-size="30" :show-username="false" :user="option"/>
|
2020-08-11 20:18:59 +02:00
|
|
|
<a @click="removeAssignee(option)" class="remove-assignee" v-if="!disabled">
|
2019-11-24 14:16:24 +01:00
|
|
|
<icon icon="times"/>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
<template slot="clear" slot-scope="props">
|
2020-09-05 22:35:52 +02:00
|
|
|
<div
|
|
|
|
@mousedown.prevent.stop="clearAllFoundUsers(props.search)"
|
|
|
|
class="multiselect__clear"
|
|
|
|
v-if="newAssignee !== null && newAssignee.id !== 0"></div>
|
2019-11-24 14:16:24 +01:00
|
|
|
</template>
|
|
|
|
<span slot="noResult">No user found. Consider changing the search query.</span>
|
|
|
|
</multiselect>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import {differenceWith} from 'lodash'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
import UserModel from '../../../models/user'
|
|
|
|
import ListUserService from '../../../services/listUsers'
|
|
|
|
import TaskAssigneeService from '../../../services/taskAssignee'
|
|
|
|
import User from '../../misc/user'
|
|
|
|
import LoadingComponent from '../../misc/loading'
|
|
|
|
import ErrorComponent from '../../misc/error'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'editAssignees',
|
|
|
|
components: {
|
|
|
|
User,
|
|
|
|
multiselect: () => ({
|
|
|
|
component: import(/* webpackPrefetch: true *//* webpackChunkName: "multiselect" */ 'vue-multiselect'),
|
|
|
|
loading: LoadingComponent,
|
|
|
|
error: ErrorComponent,
|
|
|
|
timeout: 60000,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
taskId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
listId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
disabled: {
|
|
|
|
default: false,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-10-02 18:40:04 +02:00
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
newAssignee: UserModel,
|
|
|
|
listUserService: ListUserService,
|
|
|
|
foundUsers: [],
|
|
|
|
assignees: [],
|
|
|
|
taskAssigneeService: TaskAssigneeService,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2020-10-02 18:40:04 +02:00
|
|
|
this.assignees = this.value
|
2020-09-05 22:35:52 +02:00
|
|
|
this.listUserService = new ListUserService()
|
|
|
|
this.newAssignee = new UserModel()
|
|
|
|
this.taskAssigneeService = new TaskAssigneeService()
|
|
|
|
},
|
|
|
|
watch: {
|
2020-10-02 18:40:04 +02:00
|
|
|
value(newVal) {
|
2020-09-05 22:35:52 +02:00
|
|
|
this.assignees = newVal
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
addAssignee(user) {
|
|
|
|
this.$store.dispatch('tasks/addAssignee', {user: user, taskId: this.taskId})
|
2020-10-02 18:40:04 +02:00
|
|
|
.then(() => {
|
|
|
|
this.$emit('input', this.assignees)
|
|
|
|
})
|
2020-09-05 22:35:52 +02:00
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
removeAssignee(user) {
|
|
|
|
this.$store.dispatch('tasks/removeAssignee', {user: user, taskId: this.taskId})
|
|
|
|
.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)
|
2019-11-24 14:16:24 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
findUser(query) {
|
|
|
|
if (query === '') {
|
|
|
|
this.clearAllFoundUsers()
|
|
|
|
return
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.listUserService.getAll({listId: this.listId}, {s: query})
|
|
|
|
.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 => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
clearAllFoundUsers() {
|
|
|
|
this.$set(this, 'foundUsers', [])
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
</script>
|