working on simManage
This commit is contained in:
+57
-18
@@ -1,20 +1,36 @@
|
||||
class SimsModel extends WindozModel {
|
||||
class SimsModel extends WindozBusModel {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.ressource = '/sims'
|
||||
this.busChannels = app.Assets.Store.json.busChannels
|
||||
}
|
||||
|
||||
async list() {
|
||||
let endpoint = {...app.config.api[this.ressource].list}
|
||||
return(
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
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(simId) {
|
||||
async get(simulationUuid) {
|
||||
let endpoint = {...app.config.api[this.ressource].get}
|
||||
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||
endpoint.uri = endpoint.uri.replace('{simulationUuid}', simulationUuid)
|
||||
return(
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
)
|
||||
@@ -27,20 +43,43 @@ class SimsModel extends WindozModel {
|
||||
)
|
||||
}
|
||||
|
||||
async start(simId) {
|
||||
let endpoint = {...app.config.api[this.ressource].start}
|
||||
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||
return(
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
)
|
||||
async startSimulation(simulationUuid) {
|
||||
return(this.busActionRequest(
|
||||
this.busChannels.maestro.actionsChannel,
|
||||
'STARTSIMULATION',
|
||||
{
|
||||
simulationUuid,
|
||||
infraId: null,
|
||||
},
|
||||
60000
|
||||
))
|
||||
}
|
||||
|
||||
async pause(simId) {
|
||||
let endpoint = {...app.config.api[this.ressource].pause}
|
||||
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||
return(
|
||||
this.request(endpoint.uri, endpoint.method)
|
||||
)
|
||||
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
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user