Jelajahi Sumber

Custom dashboard prototype

A-Konig 1 Minggu lalu
induk
melakukan
e726078024

+ 3 - 20
src/app/dashboard/components/custom-dashboard/custom-dashboard.component.ts

@@ -95,14 +95,10 @@ export class CustomDashboardComponent implements OnChanges {
    */
   private fetchDataAndDraw(graph: any, range: Date[], containerId: string) {
     const groupId = graph.graphId;
-    const sensorIds = [];
-    const sensors = [];
-    const requests = []; // Array to hold all observable requests
 
     this.graphViews[groupId] = null;
     console.log(groupId);
 
-    for (const source of graph.sources) {
       // 1. Find the sensor metadata
       const unit = this.units.find(u => u.unit.unitId === graph.sources[0].unitId);
       const sensor = unit?.sensors?.find(s => s.sensorId === graph.sources[0].sensorIds[0]);
@@ -115,9 +111,6 @@ export class CustomDashboardComponent implements OnChanges {
       const unitId = unit.unit.unitId;
       const sensorId = sensor.sensorId;
 
-      sensorIds.push(sensorId);
-      sensors.push(sensor);
-
       // 4. Create the request for this specific source/sensor
       const request = this.observationService.getObservation$Response({
           unit_id: unitId,
@@ -136,27 +129,17 @@ export class CustomDashboardComponent implements OnChanges {
             })
       );
 
-      requests.push(request);
-    }
 
     // Execute all requests and render
-    if (requests.length > 0) {
-      forkJoin(requests).subscribe(async (results: any[][]) => {
-        const allObservations = results.map(res => res ? res : []);
-
-        // TODO here i want to load a custom graph with multiple datasets
-        //  - each dataset could have different type (line or bar)
-        //  - sensorIds, sensors - information about sensors
-        //  - allObservations - the recieved data that will be displayed
-
+      forkJoin(request).subscribe(async (results: any[][]) => {
+        const allObservations = [].concat(...results).filter(obs => obs !== null);
         if (allObservations.length > 0) {
-          this.graphViews[groupId] = await GraphLoader.getGraph(sensorIds, allObservations, sensors, containerId, false);
+          this.graphViews[groupId] = await GraphLoader.getGraph(sensorId, allObservations, sensor, containerId, false);
         } else {
           this.graphViews[groupId] = await GraphLoader.getGraph(null, null, null, containerId, null);
         }
       });
     }
-  }
 
   /**
    * Get all units and theirs sensors from backend