|
@@ -182,7 +182,8 @@ class Timeline extends LitElement {
|
|
|
* @param ressource
|
|
* @param ressource
|
|
|
* @returns The Ressource object registered to in the timeline
|
|
* @returns The Ressource object registered to in the timeline
|
|
|
*/
|
|
*/
|
|
|
- addRessource(ressource: IRessource): Ressource {
|
|
|
|
|
|
|
+ //TODO add posibbility to add resource at a given rows
|
|
|
|
|
+ addRessource(ressource: IRessource, pos = 0): Ressource {
|
|
|
const existingRessource = this.getRessourceFromId(ressource.id);
|
|
const existingRessource = this.getRessourceFromId(ressource.id);
|
|
|
if (existingRessource) {
|
|
if (existingRessource) {
|
|
|
return existingRessource;
|
|
return existingRessource;
|
|
@@ -193,13 +194,33 @@ class Timeline extends LitElement {
|
|
|
r.parent = this.getRessourceFromId(r.parent.id) ?? this.addRessource(r.parent);
|
|
r.parent = this.getRessourceFromId(r.parent.id) ?? this.addRessource(r.parent);
|
|
|
const idx = this.rows.indexOf(r.parent as Ressource);
|
|
const idx = this.rows.indexOf(r.parent as Ressource);
|
|
|
if (idx > -1) {
|
|
if (idx > -1) {
|
|
|
- this.rows[idx].children.push(r);
|
|
|
|
|
- this.rows.splice(idx + 1, 0, r);
|
|
|
|
|
|
|
+ r.parent.children = [r, ...r.parent.children];
|
|
|
|
|
+ if (pos <= idx) {
|
|
|
|
|
+ this.rows.splice(idx + 1, 0, r);
|
|
|
|
|
+ } else if (pos > idx + r.parent.children.length) {
|
|
|
|
|
+ this.rows.splice(idx + r.parent.children.length, 0, r);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.rows.splice(pos, 0, r);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
throw new Error("Not able to create ressource parent.\n" + r.id);
|
|
throw new Error("Not able to create ressource parent.\n" + r.id);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- this.rows = [...this.rows, r];
|
|
|
|
|
|
|
+ if (pos < 0) {
|
|
|
|
|
+ this.rows = [r, ...this.rows];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let idx = pos;
|
|
|
|
|
+ while (idx < this.rows.length) {
|
|
|
|
|
+ if (this.rows[idx].parent == undefined) {
|
|
|
|
|
+ this.rows.splice(idx, 0, r);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ idx++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (idx >= this.rows.length) {
|
|
|
|
|
+ this.rows = [...this.rows, r];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.addRessources(r.children);
|
|
this.addRessources(r.children);
|