Przeglądaj źródła

implement add ressource at pgiven position

tripeur 4 lat temu
rodzic
commit
b1368e842c
4 zmienionych plików z 53 dodań i 9 usunięć
  1. 1 1
      lib/Timeline.d.ts
  2. 27 4
      lib/Timeline.js
  3. 0 0
      lib/Timeline.js.map
  4. 25 4
      src/Timeline.ts

+ 1 - 1
lib/Timeline.d.ts

@@ -45,7 +45,7 @@ declare class Timeline extends LitElement {
     setLegendUnitFormatAll(legend: Partial<UnitLegend>): void;
     setLegendUnitFormat(unit: dayjsUnit, format: string): void;
     addRessources(list: Array<IRessource>): Array<Ressource>;
-    addRessource(ressource: IRessource): Ressource;
+    addRessource(ressource: IRessource, pos?: number): Ressource;
     removeRessourceById(id: string): TimelineContent;
     _removeRessourceById(id: string, depth?: number): TimelineContent;
     getRessources(): Array<Ressource>;

+ 27 - 4
lib/Timeline.js

@@ -126,7 +126,7 @@ let Timeline = class Timeline extends lit_element_1.LitElement {
     addRessources(list) {
         return list.map((r) => this.addRessource(r));
     }
-    addRessource(ressource) {
+    addRessource(ressource, pos = 0) {
         var _a;
         const existingRessource = this.getRessourceFromId(ressource.id);
         if (existingRessource) {
@@ -137,15 +137,38 @@ let Timeline = class Timeline extends lit_element_1.LitElement {
             r.parent = (_a = this.getRessourceFromId(r.parent.id)) !== null && _a !== void 0 ? _a : this.addRessource(r.parent);
             const idx = this.rows.indexOf(r.parent);
             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 {
                 throw new Error("Not able to create ressource parent.\n" + r.id);
             }
         }
         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._updateEventPosition(r);

Plik diff jest za duży
+ 0 - 0
lib/Timeline.js.map


+ 25 - 4
src/Timeline.ts

@@ -182,7 +182,8 @@ class Timeline extends LitElement {
    * @param ressource
    * @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);
     if (existingRessource) {
       return existingRessource;
@@ -193,13 +194,33 @@ class Timeline extends LitElement {
       r.parent = this.getRessourceFromId(r.parent.id) ?? this.addRessource(r.parent);
       const idx = this.rows.indexOf(r.parent as Ressource);
       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 {
         throw new Error("Not able to create ressource parent.\n" + r.id);
       }
     } 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);

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików