Handle task relations the right way (#36)
This commit is contained in:
@ -62,17 +62,7 @@ export default class ListModel extends AbstractModel {
|
||||
* @param task
|
||||
*/
|
||||
addTaskToList(task) {
|
||||
// If it's a subtask, add it to its parent, otherwise append it to the list of tasks
|
||||
if (task.parentTaskID === 0) {
|
||||
this.tasks.push(task)
|
||||
} else {
|
||||
for (const t in this.tasks) {
|
||||
if (this.tasks[t].id === task.parentTaskID) {
|
||||
this.tasks[t].subtasks.push(task)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tasks.push(task)
|
||||
this.sortTasks()
|
||||
}
|
||||
|
||||
@ -92,7 +82,7 @@ export default class ListModel extends AbstractModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loops through all tasks and updates the one with the id it has
|
||||
* Loops through all tasks and updates the one with the id it has
|
||||
* @param task
|
||||
*/
|
||||
updateTaskByID(task) {
|
||||
@ -101,15 +91,6 @@ export default class ListModel extends AbstractModel {
|
||||
this.tasks[t] = task
|
||||
break
|
||||
}
|
||||
|
||||
if (this.tasks[t].id === task.parentTaskID) {
|
||||
for (const s in this.tasks[t].subtasks) {
|
||||
if (this.tasks[t].subtasks[s].id === task.id) {
|
||||
this.tasks[t].subtasks[s] = task
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.sortTasks()
|
||||
}
|
||||
|
13
src/models/relationKinds.json
Normal file
13
src/models/relationKinds.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"subtask": "Subtask",
|
||||
"parenttask": "Parent Task",
|
||||
"related": "Related Task",
|
||||
"duplicateof": "Duplicate Of",
|
||||
"duplicates": "Duplicates",
|
||||
"blocking": "Blocking",
|
||||
"blocked": "Blocked By",
|
||||
"precedes": "Preceds",
|
||||
"follows": "Follows",
|
||||
"copiedfrom": "Copied From",
|
||||
"copiedto": "Copied To"
|
||||
}
|
@ -37,6 +37,13 @@ export default class TaskModel extends AbstractModel {
|
||||
if (this.hexColor.substring(0, 1) !== '#') {
|
||||
this.hexColor = '#' + this.hexColor
|
||||
}
|
||||
|
||||
// Make all subtasks to task models
|
||||
Object.keys(this.related_tasks).forEach(relationKind => {
|
||||
this.related_tasks[relationKind] = this.related_tasks[relationKind].map(t => {
|
||||
return new TaskModel(t)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
defaults() {
|
||||
@ -54,10 +61,10 @@ export default class TaskModel extends AbstractModel {
|
||||
endDate: 0,
|
||||
repeatAfter: 0,
|
||||
reminderDates: [],
|
||||
subtasks: [],
|
||||
parentTaskID: 0,
|
||||
hexColor: '',
|
||||
percentDone: 0,
|
||||
related_tasks: {},
|
||||
|
||||
createdBy: UserModel,
|
||||
created: 0,
|
||||
|
21
src/models/taskRelation.js
Normal file
21
src/models/taskRelation.js
Normal file
@ -0,0 +1,21 @@
|
||||
import AbstractModel from './abstractModel'
|
||||
import UserModel from "./user";
|
||||
|
||||
export default class TaskRelationModel extends AbstractModel {
|
||||
constructor(data) {
|
||||
super(data)
|
||||
this.created_by = new UserModel(this.created_by)
|
||||
}
|
||||
|
||||
defaults() {
|
||||
return {
|
||||
id: 0,
|
||||
other_task_id: 0,
|
||||
task_id: 0,
|
||||
relation_kind: '',
|
||||
|
||||
created_by: UserModel,
|
||||
created: 0,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user