Fix tasks moving infinitely in gantt chart (#493)

Fixes https://kolaente.dev/vikunja/frontend/issues/489

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/493
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2021-04-25 16:01:17 +00:00
parent 4d998d891e
commit 85e55d1300
4 changed files with 76 additions and 72 deletions

View file

@ -85,7 +85,7 @@ export default {
if (typeof this.$route.query.code !== 'undefined' || location.hash.startsWith('#token=')) { if (typeof this.$route.query.code !== 'undefined' || location.hash.startsWith('#token=')) {
if (location.hash.startsWith('#token=')) { if (location.hash.startsWith('#token=')) {
this.migratorAuthCode = location.hash.substring(7) this.migratorAuthCode = location.hash.substring(7)
console.log(location.hash.substring(7)) console.debug(location.hash.substring(7))
} else { } else {
this.migratorAuthCode = this.$route.query.code this.migratorAuthCode = this.$route.query.code
} }

View file

@ -59,7 +59,8 @@
</div> </div>
<div :style="{ width: fullWidth + 'px' }" class="tasks"> <div :style="{ width: fullWidth + 'px' }" class="tasks">
<div <div
:key="t.id" v-for="(t, k) in theTasks"
:key="t ? t.id : 0"
:style="{ :style="{
background: background:
'repeating-linear-gradient(90deg, #ededed, #ededed 1px, ' + 'repeating-linear-gradient(90deg, #ededed, #ededed 1px, ' +
@ -70,13 +71,11 @@
'px)', 'px)',
}" }"
class="row" class="row"
v-for="(t, k) in theTasks"
> >
<VueDragResize <VueDragResize
:class="{ :class="{
done: t.done, done: t ? t.done : false,
'is-current-edit': 'is-current-edit': taskToEdit !== null && taskToEdit.id === t.id,
taskToEdit !== null && taskToEdit.id === t.id,
'has-light-text': !colorIsDark(t.getHexColor()), 'has-light-text': !colorIsDark(t.getHexColor()),
'has-dark-text': colorIsDark(t.getHexColor()), 'has-dark-text': colorIsDark(t.getHexColor()),
}" }"
@ -367,27 +366,24 @@ export default {
}) })
}, },
addGantAttributes(t) { addGantAttributes(t) {
if (typeof t.durationDays !== 'undefined' && typeof t.offsetDays !== 'undefined') {
return t
}
t.endDate === null ? this.endDate : t.endDate t.endDate === null ? this.endDate : t.endDate
t.durationDays = t.durationDays = Math.floor((t.endDate - t.startDate) / 1000 / 60 / 60 / 24)
Math.floor((t.endDate - t.startDate) / 1000 / 60 / 60 / 24) + 1 t.offsetDays = Math.floor((t.startDate - this.startDate) / 1000 / 60 / 60 / 24)
t.offsetDays =
Math.floor(
(t.startDate - this.startDate) / 1000 / 60 / 60 / 24
) + 1
return t return t
}, },
setTaskDragged(t) { setTaskDragged(t) {
this.taskDragged = t this.taskDragged = t
}, },
resizeTask(newRect) { resizeTask(newRect) {
// Timeout to definitly catch if the user clicked on taskedit
setTimeout(() => {
if (this.isTaskEdit) { if (this.isTaskEdit) {
return return
} }
let didntHaveDates = const didntHaveDates = this.taskDragged.startDate === null ? true : false
this.taskDragged.startDate === null ? true : false
let startDate = new Date(this.startDate) let startDate = new Date(this.startDate)
startDate.setDate( startDate.setDate(
@ -415,9 +411,19 @@ export default {
} }
} }
const ganttData = {
endDate: this.taskDragged.endDate,
durationDays: this.taskDragged.durationDays,
offsetDays: this.taskDragged.offsetDays,
}
this.taskService this.taskService
.update(this.taskDragged) .update(this.taskDragged)
.then((r) => { .then(r => {
r.endDate = ganttData.endDate
r.durationDays = ganttData.durationDays
r.offsetDays = ganttData.offsetDays
// If the task didn't have dates before, we'll update the list // If the task didn't have dates before, we'll update the list
if (didntHaveDates) { if (didntHaveDates) {
for (const t in this.tasksWithoutDates) { for (const t in this.tasksWithoutDates) {
@ -443,7 +449,6 @@ export default {
.catch((e) => { .catch((e) => {
this.error(e, this) this.error(e, this)
}) })
}, 100)
}, },
editTask(task) { editTask(task) {
this.taskToEdit = task this.taskToEdit = task

View file

@ -72,6 +72,7 @@ $gantt-vertical-border-color: $grey-100;
padding: 0.25rem 0.5rem; padding: 0.25rem 0.5rem;
cursor: grab; cursor: grab;
position: relative; position: relative;
height: 31px !important;
-webkit-touch-callout: none; // iOS Safari -webkit-touch-callout: none; // iOS Safari
-webkit-user-select: none; // Safari -webkit-user-select: none; // Safari

View file

@ -505,8 +505,6 @@ export default {
this.listViewName = `list.${parts[1]}` this.listViewName = `list.${parts[1]}`
} }
console.log(this.task)
this.loadTask() this.loadTask()
}, },
computed: { computed: {