-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathAssignmentSelector.vue
More file actions
128 lines (122 loc) · 2.97 KB
/
Copy pathAssignmentSelector.vue
File metadata and controls
128 lines (122 loc) · 2.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!--
- SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="selector-wrapper" :aria-label="t('deck', 'Assign to users/groups/team')" data-test="assignment-selector">
<div class="selector-wrapper--icon">
<AccountMultiple :size="20" />
</div>
<NcSelect v-if="canEdit"
v-model="assignedUsers"
class="selector-wrapper--selector"
:disabled="assignables.length === 0"
:multiple="true"
:options="formatedAssignables"
:user-select="true"
:aria-label-combobox="t('deck', 'Assign a user to this card…')"
:placeholder="t('deck', 'Select a user to assign to this card…')"
label="displayname"
track-by="multiselectKey"
@option:selected="onSelect"
@option:deselected="onRemove" />
<div v-else class="avatar-list--readonly">
<NcUserBubble v-for="option in assignedUsers"
:key="option.primaryKey"
:user="option.uid"
:display-name="option.displayname"
:is-no-user="option.isNoUser"
:size="32" />
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue'
import { NcSelect, NcUserBubble } from '@nextcloud/vue'
import AccountMultiple from 'vue-material-design-icons/AccountMultipleOutline.vue'
export default defineComponent({
name: 'AssignmentSelector',
components: {
AccountMultiple,
NcSelect,
NcUserBubble,
},
props: {
card: {
type: Object,
default: null,
},
canEdit: {
type: Boolean,
default: true,
},
assignables: {
type: Array,
default: () => [],
},
},
data() {
return {
assignedUsers: [],
}
},
computed: {
formatedAssignables() {
return this.assignables.map(item => {
const assignable = {
...item,
user: item.primaryKey,
displayName: item.displayname,
icon: 'icon-user',
isNoUser: false,
multiselectKey: item.type + ':' + item.uid,
}
if (item.type === 1) {
assignable.icon = 'icon-group'
assignable.isNoUser = true
}
if (item.type === 7) {
assignable.icon = 'icon-circles'
assignable.isNoUser = true
}
return assignable
})
},
},
watch: {
card() {
this.initialize()
},
},
mounted() {
this.initialize()
},
methods: {
async initialize() {
if (!this.card) {
return
}
if (this.card.assignedUsers && this.card.assignedUsers.length > 0) {
this.assignedUsers = this.card.assignedUsers.map((item) => ({
...item.participant,
isNoUser: item.participant.type !== 0,
multiselectKey: item.participant.type + ':' + item.participant.primaryKey,
user: item.participant.uid,
}))
} else {
this.assignedUsers = []
}
},
onSelect(options) {
const addition = options.filter((item) => !this.card.assignedUsers.find((user) => user.participant.primaryKey === item.primaryKey))
this.$emit('select', addition[0])
},
onRemove(removed) {
this.$emit('remove', removed)
},
},
})
</script>
<style lang="scss" scoped>
@import '../../css/selector.scss';
</style>