Files
2026-06-21 21:09:21 +00:00

87 lines
2.3 KiB
JavaScript

class SimsModel extends WindozBusModel {
constructor() {
super()
this.ressource = '/sims'
this.busChannels = app.Assets.Store.json.busChannels
}
async list() {
const endpoint = {...app.config.api[this.ressource].list}
const [listResponse, statusList] = await Promise.all([
this.request(endpoint.uri, endpoint.method),
this.getSimulationsStatus(),
])
const sims = listResponse?.payload ?? []
const statuses = Array.isArray(statusList) ? statusList : (statusList?.simulations ?? [])
const stateBySimulationId = new Map(
statuses.map(item => [item.simulationId, item.state])
)
return({
...listResponse,
payload: sims.map(sim => ({
...sim,
state: stateBySimulationId.get(sim.simulationUuid) ?? 'idle',
})),
})
}
async get(simulationUuid) {
let endpoint = {...app.config.api[this.ressource].get}
endpoint.uri = endpoint.uri.replace('{simulationUuid}', simulationUuid)
return(
this.request(endpoint.uri, endpoint.method)
)
}
async create(simData) {
let endpoint = {...app.config.api[this.ressource].create}
return(
this.request(endpoint.uri, endpoint.method, simData)
)
}
async startSimulation(simulationUuid) {
return(this.busActionRequest(
this.busChannels.maestro.actionsChannel,
'STARTSIMULATION',
{
simulationUuid,
infraId: null,
},
60000
))
}
async stopSimulation(simulationUuid) {
return(this.busActionRequest(
this.busChannels.maestro.actionsChannel,
'STOPSIMULATION',
{ simulationUuid },
30000
))
}
async pauseSimulation(simulationUuid) {
return(this.busActionRequest(
this.busChannels.maestro.actionsChannel,
'PAUSESIMULATION',
{ simulationUuid },
30000
))
}
async getSimulationsStatus() {
return(this.busActionRequest(
this.busChannels.maestro.actionsChannel,
'GETSIMULATIONSSTATUS',
{},
15000
))
}
}
app.registerClass('SimsModel', SimsModel)