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-11-02 21:47:31 +01:00
|
|
|
import differenceWith from 'lodash/differenceWith'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
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: {
|
|
|
|
value: {
|
|
|
|
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
|
|
|
},
|
|
|
|
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-09-08 11:59:38 +02:00
|
|
|
value: {
|
|
|
|
handler(value) {
|
|
|
|
this.labels = value
|
|
|
|
},
|
|
|
|
immediate: 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() {
|
|
|
|
const labels = (Object.values(this.$store.state.labels.labels).filter(l => {
|
|
|
|
return l.title.toLowerCase().includes(this.query.toLowerCase())
|
|
|
|
}) ?? [])
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2021-06-03 22:23:04 +02:00
|
|
|
return differenceWith(labels, this.labels, (first, second) => {
|
|
|
|
return first.id === second.id
|
|
|
|
})
|
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 = () => {
|
|
|
|
this.$emit('input', this.labels)
|
|
|
|
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
|
|
|
})
|
|
|
|
.catch(e => {
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.error(e)
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$emit('input', this.labels)
|
|
|
|
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
|
|
|
})
|
|
|
|
.catch(e => {
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.error(e)
|
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
|
|
|
})
|
|
|
|
.catch(e => {
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
</script>
|