Skip to content
Snippets Groups Projects
Commit 02309b22 authored by Bilal Hassan's avatar Bilal Hassan
Browse files

-working on implementation of station config

parent 62905b4a
No related branches found
No related tags found
4 merge requests!25Draft: Resolve #78,!7fixUrlPath,!4merge dev into main,!1after meeting with zoe
......@@ -10,7 +10,7 @@ import {
HostControllerService, SensorControllerService, Station,
StationControllerService
} from "../../../../../../projects/generated-api/src";
import {combineLatest, finalize, Observable, tap} from "rxjs";
import {combineLatest, concatMap, finalize, Observable, of, switchMap, tap} from "rxjs";
import {StationModel} from "../../admin/stationManagement/station/station.model";
import {map} from "rxjs/operators";
......@@ -183,31 +183,100 @@ export class StationConfigComponent implements OnInit{
children:[]
}
let returnNode=(name:string,type:NodeType):DateTreeNode=> {return {
let returnNode=(name:string,type:NodeType,childs:DateTreeNode[]):DateTreeNode=> {return {
name: name ? name : 'UNDEFINED',
type: type,
children: [],
children:childs,
}};
let returnMultiNode=(names:string[],type:NodeType):DateTreeNode[]=> {
return names.map(name=>returnNode(name,type))
let returnMultipleNodes=(names:string[],type:NodeType):DateTreeNode[]=> {
return names.map(name=>returnNode(name,type,[]))
}
let returnNodeMultiNode=(p_name:string,p_type:NodeType,c_names:string[],c_type:NodeType):DateTreeNode=> {return {
let returnNodeWithMultiChild=(p_name:string,p_type:NodeType,c_names:string[],c_type:NodeType):DateTreeNode=> {return {
name: p_name ? p_name : 'UNDEFINED',
type: p_type,
children: returnMultiNode(c_names,c_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(returnNodeMultiNode(client.name??"",NodeType.Client,client.sensors??[],NodeType.Sensor)))),
finalize(()=>console.log("finally got names",data))
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))
)
}
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
this.stationController.getById("ibk_s_id").pipe(
tap(s => station = s),
switchMap(() => {
// Step 2: Call saveClients function
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 staiton:Observable<Station[]>=this.stationController.getAll()
staiton.subscribe(
stations=>{
}
)
saveStation()
this.stationController.getAll().pipe().subscribe(stations=>{console.log("stations",stations)})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment