2020-08-01 15:17:10 +02:00
|
|
|
<template>
|
2021-01-17 18:57:57 +01:00
|
|
|
<div
|
|
|
|
:class="{ 'is-loading': taskService.loading }"
|
|
|
|
class="defer-task loading-container"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
<label class="label">{{ $t('task.deferDueDate.title') }}</label>
|
2020-08-01 15:17:10 +02:00
|
|
|
<div class="defer-days">
|
2021-01-17 18:57:57 +01:00
|
|
|
<x-button
|
|
|
|
@click.prevent.stop="() => deferDays(1)"
|
|
|
|
:shadow="false"
|
|
|
|
type="secondary"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.deferDueDate.1day') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
|
|
|
<x-button
|
|
|
|
@click.prevent.stop="() => deferDays(3)"
|
|
|
|
:shadow="false"
|
|
|
|
type="secondary"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.deferDueDate.3days') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
|
|
|
<x-button
|
|
|
|
@click.prevent.stop="() => deferDays(7)"
|
|
|
|
:shadow="false"
|
|
|
|
type="secondary"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.deferDueDate.1week') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
2020-08-01 15:17:10 +02:00
|
|
|
</div>
|
|
|
|
<flat-pickr
|
2021-01-17 18:57:57 +01:00
|
|
|
:class="{ disabled: taskService.loading }"
|
2020-09-05 22:35:52 +02:00
|
|
|
:config="flatPickerConfig"
|
|
|
|
:disabled="taskService.loading"
|
|
|
|
class="input"
|
|
|
|
v-model="dueDate"
|
2020-08-01 15:17:10 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import TaskService from '../../../services/task'
|
|
|
|
import flatPickr from 'vue-flatpickr-component'
|
2020-08-01 15:17:10 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'defer-task',
|
|
|
|
data() {
|
|
|
|
return {
|
2021-09-08 11:59:38 +02:00
|
|
|
taskService: new TaskService(),
|
2020-09-05 22:35:52 +02:00
|
|
|
task: null,
|
|
|
|
// We're saving the due date seperately to prevent null errors in very short periods where the task is null.
|
|
|
|
dueDate: null,
|
|
|
|
lastValue: null,
|
|
|
|
changeInterval: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
flatPickr,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
required: true,
|
2020-08-01 15:17:10 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-09-08 11:59:38 +02:00
|
|
|
watch: {
|
|
|
|
value: {
|
|
|
|
handler(value) {
|
|
|
|
this.task = value
|
|
|
|
this.dueDate = value.dueDate
|
|
|
|
this.lastValue = value.dueDate
|
|
|
|
},
|
|
|
|
immediate: true,
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// Because we don't really have other ways of handling change since if we let flatpickr
|
|
|
|
// change events trigger updates, it would trigger a flatpickr change event which would trigger
|
|
|
|
// an update which would trigger a change event and so on...
|
|
|
|
// This is either a bug in flatpickr or in the vue component of it.
|
|
|
|
// To work around that, we're only updating if something changed and check each second and when closing the popup.
|
|
|
|
if (this.changeInterval) {
|
|
|
|
clearInterval(this.changeInterval)
|
|
|
|
}
|
2020-08-01 15:17:10 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.changeInterval = setInterval(this.updateDueDate, 1000)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (this.changeInterval) {
|
|
|
|
clearInterval(this.changeInterval)
|
|
|
|
}
|
|
|
|
this.updateDueDate()
|
|
|
|
},
|
2021-06-24 01:24:57 +02:00
|
|
|
computed: {
|
|
|
|
flatPickerConfig() {
|
|
|
|
return {
|
|
|
|
altFormat: this.$t('date.altFormatLong'),
|
|
|
|
altInput: true,
|
|
|
|
dateFormat: 'Y-m-d H:i',
|
|
|
|
enableTime: true,
|
|
|
|
time_24hr: true,
|
|
|
|
inline: true,
|
|
|
|
locale: {
|
|
|
|
firstDayOfWeek: this.$store.state.auth.settings.weekStart,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
methods: {
|
|
|
|
deferDays(days) {
|
|
|
|
this.dueDate = new Date(this.dueDate)
|
|
|
|
this.dueDate = this.dueDate.setDate(this.dueDate.getDate() + days)
|
2020-08-01 15:17:10 +02:00
|
|
|
this.updateDueDate()
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
updateDueDate() {
|
|
|
|
if (!this.dueDate) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-01 15:17:10 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (+new Date(this.dueDate) === +this.lastValue) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-01 15:17:10 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.task.dueDate = new Date(this.dueDate)
|
2021-01-17 18:57:57 +01:00
|
|
|
this.taskService
|
|
|
|
.update(this.task)
|
|
|
|
.then((r) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
this.lastValue = r.dueDate
|
|
|
|
this.task = r
|
|
|
|
this.$emit('input', r)
|
|
|
|
})
|
2021-01-17 18:57:57 +01:00
|
|
|
.catch((e) => {
|
2021-08-25 12:28:29 +02:00
|
|
|
this.$message.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2020-08-01 15:17:10 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2020-08-01 15:17:10 +02:00
|
|
|
</script>
|