2019-03-07 20:48:40 +01:00
|
|
|
<template>
|
|
|
|
<div class="loader-container content" :class="{ 'is-loading': labelService.loading}">
|
|
|
|
<h1>Manage labels</h1>
|
|
|
|
<p>
|
|
|
|
Click on a label to edit it.
|
2020-05-04 10:14:17 +02:00
|
|
|
You can edit all labels you created, you can use all labels which are associated with a task to whose list
|
|
|
|
you have access.
|
2019-03-07 20:48:40 +01:00
|
|
|
</p>
|
|
|
|
<div class="columns">
|
|
|
|
<div class="labels-list column">
|
2019-10-26 14:39:27 +02:00
|
|
|
<span
|
2020-05-04 10:14:17 +02:00
|
|
|
v-for="l in labels" :key="l.id"
|
|
|
|
class="tag"
|
2020-05-08 20:43:51 +02:00
|
|
|
:class="{'disabled': userInfo.id !== l.createdBy.id}"
|
2020-05-04 10:14:17 +02:00
|
|
|
:style="{'background': l.hexColor, 'color': l.textColor}"
|
2019-03-07 20:48:40 +01:00
|
|
|
>
|
|
|
|
<span
|
2020-05-08 20:43:51 +02:00
|
|
|
v-if="userInfo.id !== l.createdBy.id"
|
2020-05-04 10:14:17 +02:00
|
|
|
v-tooltip.bottom="'You are not allowed to edit this label because you dont own it.'">
|
2019-03-07 20:48:40 +01:00
|
|
|
{{ l.title }}
|
|
|
|
</span>
|
2019-10-26 14:39:27 +02:00
|
|
|
<a
|
2020-05-04 10:14:17 +02:00
|
|
|
@click="editLabel(l)"
|
|
|
|
:style="{'color': l.textColor}"
|
|
|
|
v-else>
|
2019-10-26 14:39:27 +02:00
|
|
|
{{ l.title }}
|
|
|
|
</a>
|
2020-05-08 20:43:51 +02:00
|
|
|
<a class="delete is-small" @click="deleteLabel(l)" v-if="userInfo.id === l.createdBy.id"></a>
|
2019-10-26 14:39:27 +02:00
|
|
|
</span>
|
2019-03-07 20:48:40 +01:00
|
|
|
</div>
|
|
|
|
<div class="column is-4" v-if="isLabelEdit">
|
|
|
|
<div class="card">
|
|
|
|
<header class="card-header">
|
|
|
|
<span class="card-header-title">
|
|
|
|
Edit Label
|
|
|
|
</span>
|
2019-11-02 20:00:10 +01:00
|
|
|
<a class="card-header-icon" @click="isLabelEdit = false">
|
2019-03-07 20:48:40 +01:00
|
|
|
<span class="icon">
|
2019-11-02 20:00:10 +01:00
|
|
|
<icon icon="times"/>
|
2019-03-07 20:48:40 +01:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</header>
|
|
|
|
<div class="card-content">
|
|
|
|
<form @submit.prevent="editLabelSubmit()">
|
|
|
|
<div class="field">
|
|
|
|
<label class="label">Title</label>
|
|
|
|
<div class="control">
|
2020-05-04 10:14:17 +02:00
|
|
|
<input
|
|
|
|
class="input"
|
|
|
|
type="text"
|
|
|
|
placeholder="Label title"
|
|
|
|
v-model="labelEditLabel.title"/>
|
2019-03-07 20:48:40 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label">Description</label>
|
|
|
|
<div class="control">
|
2020-05-04 10:14:17 +02:00
|
|
|
<textarea
|
|
|
|
class="textarea"
|
|
|
|
placeholder="Label description"
|
|
|
|
v-model="labelEditLabel.description"></textarea>
|
2019-03-07 20:48:40 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label">Color</label>
|
|
|
|
<div class="control">
|
2020-06-15 11:46:52 +02:00
|
|
|
<color-picker v-model="labelEditLabel.hexColor"/>
|
2019-03-07 20:48:40 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field has-addons">
|
|
|
|
<div class="control is-expanded">
|
2020-05-04 10:14:17 +02:00
|
|
|
<button type="submit" class="button is-fullwidth is-success"
|
|
|
|
:class="{ 'is-loading': labelService.loading}">
|
2019-03-07 20:48:40 +01:00
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
2020-05-04 10:14:17 +02:00
|
|
|
<a
|
|
|
|
class="button has-icon is-danger"
|
|
|
|
@click="() => {deleteLabel(labelEditLabel);isLabelEdit = false}">
|
2019-03-07 20:48:40 +01:00
|
|
|
<span class="icon">
|
|
|
|
<icon icon="trash-alt"/>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-05-08 20:43:51 +02:00
|
|
|
import {mapState} from 'vuex'
|
2019-03-07 20:48:40 +01:00
|
|
|
|
|
|
|
import LabelService from '../../services/label'
|
|
|
|
import LabelModel from '../../models/label'
|
2020-06-17 22:15:59 +02:00
|
|
|
import ColorPicker from '../../components/input/colorPicker'
|
2019-03-07 20:48:40 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ListLabels',
|
|
|
|
components: {
|
2020-06-15 11:46:52 +02:00
|
|
|
ColorPicker,
|
2019-03-07 20:48:40 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
labelService: LabelService,
|
|
|
|
labels: [],
|
|
|
|
labelEditLabel: LabelModel,
|
|
|
|
isLabelEdit: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.labelService = new LabelService()
|
|
|
|
this.labelEditLabel = new LabelModel()
|
|
|
|
this.loadLabels()
|
|
|
|
},
|
2020-07-07 22:07:13 +02:00
|
|
|
mounted() {
|
|
|
|
this.setTitle('Labels')
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
computed: mapState({
|
|
|
|
userInfo: state => state.auth.info
|
|
|
|
}),
|
2019-03-07 20:48:40 +01:00
|
|
|
methods: {
|
|
|
|
loadLabels() {
|
2020-05-04 10:14:17 +02:00
|
|
|
const getAllLabels = (page = 1) => {
|
|
|
|
return this.labelService.getAll({}, {}, page)
|
|
|
|
.then(labels => {
|
|
|
|
if(page < this.labelService.totalPages) {
|
|
|
|
return getAllLabels(page + 1)
|
|
|
|
.then(nextLabels => {
|
|
|
|
return labels.concat(nextLabels)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
return Promise.reject(e)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllLabels()
|
2019-03-07 20:48:40 +01:00
|
|
|
.then(r => {
|
|
|
|
this.$set(this, 'labels', r)
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-07 20:48:40 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteLabel(label) {
|
|
|
|
this.labelService.delete(label)
|
|
|
|
.then(() => {
|
|
|
|
// Remove the label from the list
|
|
|
|
for (const l in this.labels) {
|
|
|
|
if (this.labels[l].id === label.id) {
|
|
|
|
this.labels.splice(l, 1)
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 22:47:08 +01:00
|
|
|
this.success({message: 'The label was successfully deleted.'}, this)
|
2019-03-07 20:48:40 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-07 20:48:40 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
editLabelSubmit() {
|
|
|
|
this.labelService.update(this.labelEditLabel)
|
|
|
|
.then(r => {
|
|
|
|
for (const l in this.labels) {
|
|
|
|
if (this.labels[l].id === r.id) {
|
|
|
|
this.$set(this.labels, l, r)
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 22:47:08 +01:00
|
|
|
this.success({message: 'The label was successfully updated.'}, this)
|
2019-03-07 20:48:40 +01:00
|
|
|
})
|
|
|
|
.catch(e => {
|
2020-01-30 22:47:08 +01:00
|
|
|
this.error(e, this)
|
2019-03-07 20:48:40 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
editLabel(label) {
|
2020-05-08 20:43:51 +02:00
|
|
|
if (label.createdBy.id !== this.userInfo.id) {
|
2019-03-07 20:48:40 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
this.labelEditLabel = label
|
|
|
|
this.isLabelEdit = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 07:49:20 +01:00
|
|
|
</script>
|