Commit 4478a65f authored by Romain DELEAU's avatar Romain DELEAU

rework move up/down tasks with possibility to put a task at the same index if there is space

parent 10f32d81
...@@ -53,7 +53,7 @@ export class Role { ...@@ -53,7 +53,7 @@ export class Role {
} }
public moveTask(i: number, j: number, direction: string): void { public moveTask(i: number, j: number, direction: string): void {
let tmp: Task | null = this.tasks[i][j]; let tmp: Task | null = this.tasks[i][j] as Task;
if (direction == 'left') { if (direction == 'left') {
this.tasks[i][j] = this.tasks[i][j - 1]; this.tasks[i][j] = this.tasks[i][j - 1];
...@@ -69,16 +69,29 @@ export class Role { ...@@ -69,16 +69,29 @@ export class Role {
if (this.tasks[i][j]?.type == 'final' || this.tasks[i][j]?.type == 'repeat') { if (this.tasks[i][j]?.type == 'final' || this.tasks[i][j]?.type == 'repeat') {
this.tasks[i][j] = this.tasks[i - 1][this.getLastTaskIndex(i - 1)]; this.tasks[i][j] = this.tasks[i - 1][this.getLastTaskIndex(i - 1)];
this.tasks[i - 1][this.getLastTaskIndex(i - 1)] = tmp; this.tasks[i - 1][this.getLastTaskIndex(i - 1)] = tmp;
} else if (this.thereIsSpace(i - 1, this.getRealIndex(i-1,j), this.tasks[i][j] as Task)) {
this.tasks[i - 1][this.getRealIndex(i-1,j)] = tmp;
this.tasks[i][j] = null;
this.tasks[i - 1].splice(this.getRealIndex(i-1,j)+1,tmp?.duration-1);
for(let index = 1; index < tmp.duration; index++) {
this.tasks[i].splice(j+index,0,null);
}
} else { } else {
let deplace = this.tasks[i - 1][this.getLastTaskIndex(i - 1)]; let deplace = this.tasks[i - 1][this.getLastTaskIndex(i - 1)];
this.tasks[i - 1][this.getLastTaskIndex(i - 1)] = tmp; this.tasks[i - 1][this.getLastTaskIndex(i - 1)] = tmp;
this.tasks[i - 1][this.getLastTaskIndex(i - 1) + 1] = deplace; this.tasks[i - 1][this.getLastTaskIndex(i - 1) + 1] = deplace;
this.tasks[i][j] = null; this.tasks[i][j] = null;
} }
} else if (this.thereIsSpace(i - 1, this.getRealIndex(i-1,j), this.tasks[i][j] as Task)) {
this.tasks[i - 1][this.getRealIndex(i-1,j)] = tmp;
this.tasks[i][j] = null;
this.tasks[i - 1].splice(this.getRealIndex(i-1,j)+1,tmp.duration-1);
for(let index = 1; index < tmp.duration; index++) {
this.tasks[i].splice(j+index,0,null);
}
} else { } else {
this.tasks[i - 1][this.getLastTaskIndex(i - 1) + 1] = tmp; this.tasks[i - 1][this.getLastTaskIndex(i - 1) + 1] = tmp;
this.tasks[i][j] = null; this.tasks[i][j] = null;
} }
if (!this.tasks[i].some(element => element instanceof Task)) { if (!this.tasks[i].some(element => element instanceof Task)) {
this.tasks.splice(i, 1); this.tasks.splice(i, 1);
...@@ -94,12 +107,26 @@ export class Role { ...@@ -94,12 +107,26 @@ export class Role {
if (this.tasks[i][j]?.type == 'final' || this.tasks[i][j]?.type == 'repeat') { if (this.tasks[i][j]?.type == 'final' || this.tasks[i][j]?.type == 'repeat') {
this.tasks[i][j] = this.tasks[i + 1][this.getLastTaskIndex(i + 1)]; this.tasks[i][j] = this.tasks[i + 1][this.getLastTaskIndex(i + 1)];
this.tasks[i + 1][this.getLastTaskIndex(i + 1)] = tmp; this.tasks[i + 1][this.getLastTaskIndex(i + 1)] = tmp;
} else if (this.thereIsSpace(i + 1, this.getRealIndex(i+1,j), this.tasks[i][j] as Task)) {
this.tasks[i + 1][this.getRealIndex(i+1,j)] = tmp;
this.tasks[i][j] = null;
this.tasks[i + 1].splice(this.getRealIndex(i+1,j)+1,tmp?.duration-1);
for(let index = 1; index < tmp.duration; index++) {
this.tasks[i].splice(j+index,0,null);
}
} else { } else {
let deplace = this.tasks[i + 1][this.getLastTaskIndex(i + 1)]; let deplace = this.tasks[i + 1][this.getLastTaskIndex(i + 1)];
this.tasks[i + 1][this.getLastTaskIndex(i + 1)] = tmp; this.tasks[i + 1][this.getLastTaskIndex(i + 1)] = tmp;
this.tasks[i + 1][this.getLastTaskIndex(i + 1) + 1] = deplace; this.tasks[i + 1][this.getLastTaskIndex(i + 1) + 1] = deplace;
this.tasks[i][j] = null; this.tasks[i][j] = null;
} }
} else if (this.thereIsSpace(i + 1, this.getRealIndex(i+1,j), this.tasks[i][j] as Task)) {
this.tasks[i + 1][this.getRealIndex(i+1,j)] = tmp;
this.tasks[i][j] = null;
this.tasks[i + 1].splice(this.getRealIndex(i+1,j)+1,tmp.duration-1);
for(let index = 1; index < tmp.duration; index++) {
this.tasks[i].splice(j+index,0,null);
}
} else { } else {
this.tasks[i + 1][this.getLastTaskIndex(i + 1) + 1] = tmp; this.tasks[i + 1][this.getLastTaskIndex(i + 1) + 1] = tmp;
this.tasks[i][j] = null; this.tasks[i][j] = null;
...@@ -107,6 +134,55 @@ export class Role { ...@@ -107,6 +134,55 @@ export class Role {
} }
} }
thereIsSpace(iDest: number, j: number, task: Task): boolean {
let res: boolean = true;
let spaceNecessary: number = 0;
if (task.durationUnit == 'UT') {
if (task.duration < 10) {
spaceNecessary = task.duration;
} else {
spaceNecessary = 10;
}
} else {
spaceNecessary = 1;
}
for(let i = 0; i < spaceNecessary; i++) {
if (this.tasks[iDest][j+i] != null) {
res = false;
}
}
return res;
}
getRealIndex(i: number, j: number): number {
let realj: number = 0;
let index: number = 0;
while (index < j) {
let task: Task|null = this.tasks[i][index];
if (task instanceof Task) {
if (task.durationUnit == 'UT') {
if (task.duration <= 10) {
index = index+task.duration;
realj++;
} else {
index = index + 10;
realj++;
}
} else {
realj++;
index++;
}
} else {
realj++;
index++;
}
}
console.log(realj);
return realj;
}
public moveStep(i: number, direction: string): void { public moveStep(i: number, direction: string): void {
let tmp: Step | null = this.chronologie[i]; let tmp: Step | null = this.chronologie[i];
if (direction == 'left') { if (direction == 'left') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment