2019-11-24 14:16:24 +01:00
|
|
|
<template>
|
|
|
|
<multiselect
|
2021-06-03 22:23:04 +02:00
|
|
|
:loading="loading"
|
2021-06-24 01:24:57 +02:00
|
|
|
:placeholder="$t('task.label.placeholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
:multiple="true"
|
2021-01-06 23:36:31 +01:00
|
|
|
@search="findLabel"
|
|
|
|
:search-results="foundLabels"
|
|
|
|
@select="addLabel"
|
2020-09-05 22:35:52 +02:00
|
|
|
label="title"
|
2021-01-06 23:36:31 +01:00
|
|
|
:creatable="true"
|
|
|
|
@create="createAndAddLabel"
|
2021-06-24 01:24:57 +02:00
|
|
|
:create-placeholder="$t('task.label.createPlaceholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
v-model="labels"
|
2021-06-03 22:58:47 +02:00
|
|
|
:search-delay="10"
|
2019-11-24 14:16:24 +01:00
|
|
|
>
|
2021-08-19 19:55:13 +02:00
|
|
|
<template #tag="props">
|
2020-09-05 22:35:52 +02:00
|
|
|
<span
|
2021-01-06 23:36:31 +01:00
|
|
|
:style="{'background': props.item.hexColor, 'color': props.item.textColor}"
|
2021-01-17 10:55:04 +01:00
|
|
|
class="tag">
|
2021-01-06 23:36:31 +01:00
|
|
|
<span>{{ props.item.title }}</span>
|
|
|
|
<a @click="removeLabel(props.item)" class="delete is-small"></a>
|
2020-09-05 22:35:52 +02:00
|
|
|
</span>
|
2019-11-24 14:16:24 +01:00
|
|
|
</template>
|
2021-08-19 19:55:13 +02:00
|
|
|
<template #searchResult="props">
|
2021-01-14 22:06:22 +01:00
|
|
|
<span
|
|
|
|
v-if="typeof props.option === 'string'"
|
2021-01-17 10:55:04 +01:00
|
|
|
class="tag">
|
2021-01-14 22:06:22 +01:00
|
|
|
<span>{{ props.option }}</span>
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
v-else
|
|
|
|
:style="{'background': props.option.hexColor, 'color': props.option.textColor}"
|
2021-01-17 10:55:04 +01:00
|
|
|
class="tag">
|
2021-01-14 22:06:22 +01:00
|
|
|
<span>{{ props.option.title }}</span>
|
|
|
|
</span>
|
|
|
|
</template>
|
2019-11-24 14:16:24 +01:00
|
|
|
</multiselect>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import LabelModel from '../../../models/label'
|
|
|
|
import LabelTaskService from '../../../services/labelTask'
|
2021-01-06 23:36:31 +01:00
|
|
|
|
2021-07-25 15:27:15 +02:00
|
|
|
import Multiselect from '@/components/input/multiselect.vue'
|
2021-06-03 22:23:04 +02:00
|
|
|
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'edit-labels',
|
|
|
|
props: {
|
2021-08-23 21:18:12 +02:00
|
|
|
modelValue: {
|
2020-09-05 22:35:52 +02:00
|
|
|
default: () => [],
|
|
|
|
type: Array,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
taskId: {
|
|
|
|
type: Number,
|
2021-07-20 22:42:34 +02:00
|
|
|
required: false,
|
|
|
|
default: () => 0,
|
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-09-05 22:35:52 +02:00
|
|
|
},
|
2021-08-23 21:18:12 +02:00
|
|
|
emits: ['update:modelValue', 'change'],
|
2020-09-05 22:35:52 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2021-09-08 11:59:38 +02:00
|
|
|
labelTaskService: new LabelTaskService(),
|
2020-09-05 22:35:52 +02:00
|
|
|
labelTimeout: null,
|
|
|
|
labels: [],
|
2021-06-03 22:23:04 +02:00
|
|
|
query: '',
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2021-01-06 23:36:31 +01:00
|
|
|
Multiselect,
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
watch: {
|
2021-08-23 21:18:12 +02:00
|
|
|
modelValue: {
|
2021-09-08 11:59:38 +02:00
|
|
|
handler(value) {
|
|
|
|
this.labels = value
|
|
|
|
},
|
|
|
|
immediate: true,
|
2021-10-07 17:51:27 +02:00
|
|
|
deep: true,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-06-03 22:23:04 +02:00
|
|
|
computed: {
|
|
|
|
foundLabels() {
|
2021-10-06 22:25:06 +02:00
|
|
|
return this.$store.getters['labels/filterLabelsByQuery'](this.labels, this.query)
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-06-03 22:23:04 +02:00
|
|
|
loading() {
|
|
|
|
return this.labelTaskService.loading || (this.$store.state[LOADING] && this.$store.state[LOADING_MODULE] === 'labels')
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
findLabel(query) {
|
|
|
|
this.query = query
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2020-11-22 17:32:35 +01:00
|
|
|
addLabel(label, showNotification = true) {
|
2021-07-20 22:42:34 +02:00
|
|
|
const bubble = () => {
|
2021-08-23 21:18:12 +02:00
|
|
|
this.$emit('update:modelValue', this.labels)
|
2021-07-20 22:42:34 +02:00
|
|
|
this.$emit('change', this.labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.taskId === 0) {
|
|
|
|
bubble()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.$store.dispatch('tasks/addLabel', {label: label, taskId: this.taskId})
|
|
|
|
.then(() => {
|
2021-07-20 22:42:34 +02:00
|
|
|
bubble()
|
2020-11-22 17:32:35 +01:00
|
|
|
if (showNotification) {
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.success({message: this.$t('task.label.addSuccess')})
|
2020-11-22 17:32:35 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
removeLabel(label) {
|
2021-07-20 22:42:34 +02:00
|
|
|
const removeFromState = () => {
|
|
|
|
for (const l in this.labels) {
|
|
|
|
if (this.labels[l].id === label.id) {
|
|
|
|
this.labels.splice(l, 1)
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 21:18:12 +02:00
|
|
|
this.$emit('update:modelValue', this.labels)
|
2021-07-20 22:42:34 +02:00
|
|
|
this.$emit('change', this.labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.taskId === 0) {
|
|
|
|
removeFromState()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.$store.dispatch('tasks/removeLabel', {label: label, taskId: this.taskId})
|
|
|
|
.then(() => {
|
2021-07-20 22:42:34 +02:00
|
|
|
removeFromState()
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.success({message: this.$t('task.label.removeSuccess')})
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
createAndAddLabel(title) {
|
2021-07-20 22:42:34 +02:00
|
|
|
if (this.taskId === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-03 22:23:04 +02:00
|
|
|
const newLabel = new LabelModel({title: title})
|
|
|
|
this.$store.dispatch('labels/createLabel', newLabel)
|
2020-09-05 22:35:52 +02:00
|
|
|
.then(r => {
|
2020-11-22 17:32:35 +01:00
|
|
|
this.addLabel(r, false)
|
2020-09-05 22:35:52 +02:00
|
|
|
this.labels.push(r)
|
2021-10-04 21:14:39 +02:00
|
|
|
this.$message.success({message: this.$t('task.label.addCreateSuccess')})
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
</script>
|