sim creation wired to DB with ownership

This commit is contained in:
STEINNI
2026-06-05 20:27:57 +00:00
parent b122cf153e
commit d172e06611
4 changed files with 62 additions and 15 deletions
+22
View File
@@ -37,6 +37,28 @@
"uri": "/api/keyframes/{kfId}/agents",
"method": "PUT"
}
},
"/sims": {
"list": {
"uri": "/api/sims",
"method": "POST"
},
"get": {
"uri": "/api/sims/{simId}",
"method": "GET"
},
"create": {
"uri": "/api/sims",
"method": "PUT"
},
"start": {
"uri": "/api/sims/{simId}/start",
"method": "PUT"
},
"pause": {
"uri": "/api/sims/{simId}/pause",
"method": "PUT"
}
}
}
}
+23 -10
View File
@@ -6,28 +6,41 @@ class SimsModel extends WindozModel {
}
async list() {
// TODO: implement
return([])
let endpoint = {...app.config.api[this.ressource].list}
return(
this.request(endpoint.uri, endpoint.method)
)
}
async get(simId) {
// TODO: implement
return(null)
let endpoint = {...app.config.api[this.ressource].get}
endpoint.uri = endpoint.uri.replace('{simId}', simId)
return(
this.request(endpoint.uri, endpoint.method)
)
}
async create(simData) {
// TODO: implement
return(null)
let endpoint = {...app.config.api[this.ressource].create}
return(
this.request(endpoint.uri, endpoint.method, simData)
)
}
async start(simId) {
// TODO: implement
return(null)
let endpoint = {...app.config.api[this.ressource].start}
endpoint.uri = endpoint.uri.replace('{simId}', simId)
return(
this.request(endpoint.uri, endpoint.method)
)
}
async pause(simId) {
// TODO: implement
return(null)
let endpoint = {...app.config.api[this.ressource].pause}
endpoint.uri = endpoint.uri.replace('{simId}', simId)
return(
this.request(endpoint.uri, endpoint.method)
)
}
}
+8 -4
View File
@@ -8,8 +8,8 @@ class CreateSimView extends WindozDomContent {
async DOMContentLoaded(options) {
this.models = options.models
const components = ui.eicfy(this.el)
this.setupTriggers(components)
this.setupRefs(components)
this.models.keyframes.list('', null).then(data => data.payload).then(kflist => {
this.outputs.keyframesSelector.fillOptions(kflist.map(item => {
return({
@@ -18,12 +18,16 @@ class CreateSimView extends WindozDomContent {
})
}))
})
this.outputs.keyframesSelector.addEventListener('change', this.onChangeKeyframe.bind(this))
}
onChangeKeyframe(event) {
onCreateSim(comp, event) {
if(!this.outputs.keyframesSelector.value) return
// TODO: use selected keyframe for simulation creation
if(!this.outputs.simName.value) return
this.models.sims.create({
kfId: this.outputs.keyframesSelector.value,
simName: this.outputs.simName.value
}).then(data => ui.growl.append('Simulation created!','success',3000))
this.unload()
}
}
+9 -1
View File
@@ -2,4 +2,12 @@ In SPARC, the app menu is created from app/assets/json/global/app-menu-map.json
Each entry defines a route.
A "high level" route is then configured in app/config/baseRoutes.json that delegates a group of URLs to a controller.
Then, a controller, in its associated .json file defines in its "routes" section the sub-route managed by the controller,
and the method to be called inside that controller.
and the method to be called inside that controller.
In SPARC, models inherit from the core and from WindozModel a mecanism that gets the URL from app/assets/json/global/services.json
That configuration file associates actions grouped in sections to API urls and http method.
Sections are identified by an URL-prefix (only used as label), and correspond to API "services".
The server-side of this API is served by the node daemon in p42api.
p42api has a folder 'api' with one file / module per API service, they are all declared in and imported by api/index.js.
Each module defines a mapping object, that contains all the complete urls served, http-method, and local handling method.