Fix gantt chart (#79)
Fix moving tasks in Gantt Start fixing gantt Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/79
This commit is contained in:
parent
27e2839f4c
commit
8480bf334f
3 changed files with 72 additions and 28 deletions
|
@ -44,7 +44,7 @@
|
||||||
:parentW="fullWidth"
|
:parentW="fullWidth"
|
||||||
@resizestop="resizeTask"
|
@resizestop="resizeTask"
|
||||||
@dragstop="resizeTask"
|
@dragstop="resizeTask"
|
||||||
@clicked="taskDragged = t"
|
@clicked="setTaskDragged(t)"
|
||||||
>
|
>
|
||||||
<span :class="{
|
<span :class="{
|
||||||
'has-high-priority': t.priority >= priorities.HIGH,
|
'has-high-priority': t.priority >= priorities.HIGH,
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
:parentW="fullWidth"
|
:parentW="fullWidth"
|
||||||
@resizestop="resizeTask"
|
@resizestop="resizeTask"
|
||||||
@dragstop="resizeTask"
|
@dragstop="resizeTask"
|
||||||
@clicked="taskDragged = t"
|
@clicked="setTaskDragged(t)"
|
||||||
v-tooltip="'This task has no dates set.'"
|
v-tooltip="'This task has no dates set.'"
|
||||||
>
|
>
|
||||||
<span>{{t.text}}</span>
|
<span>{{t.text}}</span>
|
||||||
|
@ -132,7 +132,8 @@
|
||||||
import TaskModel from '../../models/task'
|
import TaskModel from '../../models/task'
|
||||||
import ListModel from '../../models/list'
|
import ListModel from '../../models/list'
|
||||||
import priorities from '../../models/priorities'
|
import priorities from '../../models/priorities'
|
||||||
import PriorityLabel from "./reusable/priorityLabel";
|
import PriorityLabel from './reusable/priorityLabel'
|
||||||
|
import TaskCollectionService from '../../services/taskCollection'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'GanttChart',
|
name: 'GanttChart',
|
||||||
|
@ -179,12 +180,10 @@
|
||||||
newTaskTitle: '',
|
newTaskTitle: '',
|
||||||
newTaskFieldActive: false,
|
newTaskFieldActive: false,
|
||||||
priorities: {},
|
priorities: {},
|
||||||
|
taskCollectionService: TaskCollectionService,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
list() {
|
|
||||||
this.parseTasks()
|
|
||||||
},
|
|
||||||
dateFrom() {
|
dateFrom() {
|
||||||
this.buildTheGanttChart()
|
this.buildTheGanttChart()
|
||||||
},
|
},
|
||||||
|
@ -192,10 +191,13 @@
|
||||||
this.buildTheGanttChart()
|
this.buildTheGanttChart()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
beforeMount() {
|
created() {
|
||||||
this.now = new Date()
|
this.now = new Date()
|
||||||
|
this.taskCollectionService = new TaskCollectionService()
|
||||||
this.taskService = new TaskService()
|
this.taskService = new TaskService()
|
||||||
this.priorities = priorities
|
this.priorities = priorities
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
this.buildTheGanttChart()
|
this.buildTheGanttChart()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -231,22 +233,46 @@
|
||||||
this.prepareTasks()
|
this.prepareTasks()
|
||||||
},
|
},
|
||||||
prepareTasks() {
|
prepareTasks() {
|
||||||
this.theTasks = this.list.tasks
|
|
||||||
.filter(t => {
|
const getAllTasks = (page = 1) => {
|
||||||
if(t.startDate === null && !t.done) {
|
return this.taskCollectionService.getAll({listID: this.$route.params.id}, {}, page)
|
||||||
this.tasksWithoutDates.push(t)
|
.then(tasks => {
|
||||||
}
|
if(page < this.taskCollectionService.totalPages) {
|
||||||
return t.startDate >= this.startDate && t.endDate <= this.endDate
|
return getAllTasks(page + 1)
|
||||||
|
.then(nextTasks => {
|
||||||
|
return tasks.concat(nextTasks)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return tasks
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
return Promise.reject(e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllTasks()
|
||||||
|
.then(tasks => {
|
||||||
|
this.theTasks = tasks
|
||||||
|
.filter(t => {
|
||||||
|
if(t.startDate === null && !t.done) {
|
||||||
|
this.tasksWithoutDates.push(t)
|
||||||
|
}
|
||||||
|
return t.startDate >= this.startDate && t.endDate <= this.endDate
|
||||||
|
})
|
||||||
|
.map(t => {
|
||||||
|
return this.addGantAttributes(t)
|
||||||
|
})
|
||||||
|
.sort(function(a,b) {
|
||||||
|
if (a.startDate < b.startDate)
|
||||||
|
return -1
|
||||||
|
if (a.startDate > b.startDate)
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.map(t => {
|
.catch(e => {
|
||||||
return this.addGantAttributes(t)
|
this.error(e, this)
|
||||||
})
|
|
||||||
.sort(function(a,b) {
|
|
||||||
if (a.startDate < b.startDate)
|
|
||||||
return -1
|
|
||||||
if (a.startDate > b.startDate)
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addGantAttributes(t) {
|
addGantAttributes(t) {
|
||||||
|
@ -255,6 +281,9 @@
|
||||||
t.offsetDays = Math.floor((t.startDate - this.startDate) / 1000 / 60 / 60 / 24) + 1
|
t.offsetDays = Math.floor((t.startDate - this.startDate) / 1000 / 60 / 60 / 24) + 1
|
||||||
return t
|
return t
|
||||||
},
|
},
|
||||||
|
setTaskDragged(t) {
|
||||||
|
this.taskDragged = t
|
||||||
|
},
|
||||||
resizeTask(newRect) {
|
resizeTask(newRect) {
|
||||||
|
|
||||||
// Timeout to definitly catch if the user clicked on taskedit
|
// Timeout to definitly catch if the user clicked on taskedit
|
||||||
|
@ -278,6 +307,17 @@
|
||||||
this.taskDragged.startDate = startDate
|
this.taskDragged.startDate = startDate
|
||||||
this.taskDragged.endDate = endDate
|
this.taskDragged.endDate = endDate
|
||||||
|
|
||||||
|
|
||||||
|
// We take the task from the overall tasks array because the one in it has bad data after it was updated once.
|
||||||
|
// FIXME: This is a workaround. We should use a better mechanism to get the task or, even better,
|
||||||
|
// prevent it from containing outdated Data in the first place.
|
||||||
|
for (const tt in this.theTasks) {
|
||||||
|
if (this.theTasks[tt].id === this.taskDragged.id) {
|
||||||
|
this.$set(this, 'taskDragged', this.theTasks[tt])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.taskService.update(this.taskDragged)
|
this.taskService.update(this.taskDragged)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
// 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
|
||||||
|
@ -285,13 +325,15 @@
|
||||||
for (const t in this.tasksWithoutDates) {
|
for (const t in this.tasksWithoutDates) {
|
||||||
if (this.tasksWithoutDates[t].id === r.id) {
|
if (this.tasksWithoutDates[t].id === r.id) {
|
||||||
this.tasksWithoutDates.splice(t, 1)
|
this.tasksWithoutDates.splice(t, 1)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.theTasks.push(this.addGantAttributes(r))
|
this.theTasks.push(this.addGantAttributes(r))
|
||||||
} else {
|
} else {
|
||||||
for (const tt in this.theTasks) {
|
for (const tt in this.theTasks) {
|
||||||
if (this.theTasks[tt].id === r.id) {
|
if (this.theTasks[tt].id === r.id) {
|
||||||
this.theTasks[tt] = this.addGantAttributes(r)
|
this.$set(this.theTasks, tt, this.addGantAttributes(r))
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ export default class TaskModel extends AbstractModel {
|
||||||
this.listID = Number(this.listID)
|
this.listID = Number(this.listID)
|
||||||
|
|
||||||
// Make date objects from timestamps
|
// Make date objects from timestamps
|
||||||
this.dueDate = new Date(this.dueDate)
|
this.dueDate = this.dueDate ? new Date(this.dueDate) : null
|
||||||
this.startDate = new Date(this.startDate)
|
this.startDate = this.startDate ? new Date(this.startDate) : null
|
||||||
this.endDate = new Date(this.endDate)
|
this.endDate = this.endDate ? new Date(this.endDate) : null
|
||||||
|
|
||||||
// Cancel all scheduled notifications for this task to be sure to only have available notifications
|
// Cancel all scheduled notifications for this task to be sure to only have available notifications
|
||||||
this.cancelScheduledNotifications()
|
this.cancelScheduledNotifications()
|
||||||
|
@ -215,4 +215,5 @@ export default class TaskModel extends AbstractModel {
|
||||||
console.debug('Error scheduling notification', e)
|
console.debug('Error scheduling notification', e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,4 +95,5 @@ export default class TaskService extends AbstractService {
|
||||||
|
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue