diff --git a/src/app/module/pages/home/station-config/station-config.component.ts b/src/app/module/pages/home/station-config/station-config.component.ts index e45a122a275662ced141acc445412e1be2158485..599ba97fa504c68be1a7a28c2d925303c5660280 100644 --- a/src/app/module/pages/home/station-config/station-config.component.ts +++ b/src/app/module/pages/home/station-config/station-config.component.ts @@ -139,6 +139,9 @@ interface ExampleFlatNode { }) export class StationConfigComponent implements OnInit{ + + private dataSate=false; + private treeStation?:DateTreeNode private _transformer = (node: TreeNode, level: number) => { return { expandable: !!node.children && node.children.length > 0, @@ -146,6 +149,7 @@ export class StationConfigComponent implements OnInit{ level: level, }; }; + hasChild = (_: number, node: ExampleFlatNode) => node.expandable; treeControl = new FlatTreeControl<ExampleFlatNode>( node => node.level, @@ -170,19 +174,13 @@ export class StationConfigComponent implements OnInit{ this.dataSource.data = TREE_DATA; } + ngOnInit(): void { // this.fetchData(); - this.test() + this.fetchData(); } - test(){ - - let treeNode:DateTreeNode={ - name:"root", - type:NodeType.Station, - children:[] - } - + fetchData(){ let returnNode=(name:string,type:NodeType,childs:DateTreeNode[]):DateTreeNode=> {return { name: name ? name : 'UNDEFINED', type: type, @@ -197,51 +195,20 @@ export class StationConfigComponent implements OnInit{ type: p_type, children: returnMultipleNodes(c_names,c_type), }}; - let saveClients=(client_names:string[],treeNode:DateTreeNode)=>{ - let data:DateTreeNode[]=[] - let clients:Observable<Client>[]= client_names.map(name=> this.clientController.getClientById(name)) - combineLatest(clients).pipe( - tap(clients=>clients.forEach(client=>data.push(returnNodeWithMultiChild(client.name??"",NodeType.Client,client.sensors??[],NodeType.Sensor)))), - finalize(()=>console.log("TreeData of Clients",data)) - ).subscribe() - } - let saveClients2=(client_names:string[],treeNode:DateTreeNode[])=>{ - let clients:Observable<Client>[]= client_names.map(name=> this.clientController.getClientById(name)) - combineLatest(clients).pipe( - tap(clients=>clients.forEach(client=>treeNode.push(returnNodeWithMultiChild(client.name??"",NodeType.Client,client.sensors??[],NodeType.Sensor)))), - finalize(()=>console.log("TreeData of Clients",treeNode)) - ).subscribe() - } let saveClients3=(client_names:string[],treeNode:DateTreeNode[]):Observable<Client[]>=>{ let clients:Observable<Client>[]= client_names.map(name=> this.clientController.getClientById(name)) return combineLatest(clients).pipe( - tap(clients=>clients.forEach(client=>treeNode.push(returnNodeWithMultiChild(client.name??"",NodeType.Client,client.sensors??[],NodeType.Sensor)))), - finalize(()=>console.log("TreeData of Clients",treeNode)) + tap(clients=>{ + clients.forEach(client=>treeNode.push(returnNodeWithMultiChild(client.name??"",NodeType.Client,client.sensors??[],NodeType.Sensor))) + }) ) } - - - - - saveClients(["ibk_c_id_1","ibk_c_id_2","ibk_c_id_3"],treeNode) - - let saveStation=()=> { - - let clientsDataTree: DateTreeNode[] = [] let station:Station={} - //1 step - this.stationController.getById("ibk_s_id_1").pipe(tap(s=>station=s)).subscribe() - //2 steo - saveClients(station.clients??[],treeNode) - //3 step - let staionNodes:DateTreeNode= returnNodeWithMultiChild(station.name??"",NodeType.Station,station.clients??[],NodeType.Client); - - - let treNodeFinal:DateTreeNode + // Step 1: Call getById function this.stationController.getById("ibk_s_id").pipe( tap(s => station = s), switchMap(() => { @@ -249,85 +216,14 @@ export class StationConfigComponent implements OnInit{ console.log("fiiiiiiiiiiiiiiiiirs"); return saveClients3(station.clients ?? [], clientsDataTree); }), - switchMap(data => { - console.log("seeeeeecond"); - console.log("data", clientsDataTree) - // Step 3: Create station nodes - let sN: DateTreeNode = returnNode(station.name ?? "", NodeType.Station, clientsDataTree); - - // Do something with stationNodes or return it as needed - return of(sN); - }) ).subscribe(sNN => { // Handle the final result of stationNodes - console.log('final result:', sNN); + let sN: DateTreeNode = returnNode(station.name ?? "", NodeType.Station, clientsDataTree); + this.treeStation=sN; + this.dataSate=true; + console.log('final result:', sN); }); - - } - - - let staiton:Observable<Station[]>=this.stationController.getAll() - - staiton.subscribe( - stations=>{ - - } - ) - - saveStation() - this.stationController.getAll().pipe().subscribe(stations=>{console.log("stations",stations)}) } - - fetchData(){ - console.log("fetching data") - let station:Station[] - - let stationTree:DateTreeNode[]=[] - - let returnNode=(name:string,type:NodeType):DateTreeNode=> {return { - name: name ? name : 'UNDEFINED', - type: type, - children: [], - }}; - - let callClients=(station_index:number,clients:string[])=>{ - clients.forEach((client,client_index)=>this.clientController.getClientById(client).pipe(tap( - x=>{console.log("station ibk_c_id_1",x) - stationTree.push(returnNode(x.name??"",NodeType.Client)) - stationTree.at(station_index)?.children?.at(client_index)?.children?.push(returnNode(x.name??"",NodeType.Sensor)) - } - )).subscribe()) - } - - - - this.stationController.getAll().pipe( - tap(stations=> - stations.forEach(item=>stationTree.push({ - name:''+item.name, - type:NodeType.Station, - children:item.clients?.map(x=>returnNode(x,NodeType.Client))}))), - finalize( - ()=>{ - console.log("stationTree",stationTree) - stationTree.forEach((station,staion_index)=>callClients(staion_index,station.children?.map(x=>x.name??"")??[])) - }) - ).subscribe() - - - this.hostController.getAll1().pipe(tap(x=>console.log(x))).subscribe() - let clienName:string; - //clienName=stationTree.at(0)?.name??"" - clienName=stationTree.at(0)?.children?.at(0)?.name??"" - console.log("clienName",clienName) - - this.clientController.getClientById("ibk_c_id_1").pipe(tap(x=>console.log("station ibk_c_id_1",x))).subscribe(); - - this.clientController.getAllClients().pipe(tap(x=>console.log("all clients",x))).subscribe(); - this.sensorController.getAllSensors().pipe(tap(x=>console.log(x))).subscribe(); - } - - hasChild = (_: number, node: ExampleFlatNode) => node.expandable; }