sim creation wired to DB with ownership
This commit is contained in:
@@ -37,6 +37,28 @@
|
|||||||
"uri": "/api/keyframes/{kfId}/agents",
|
"uri": "/api/keyframes/{kfId}/agents",
|
||||||
"method": "PUT"
|
"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
@@ -6,28 +6,41 @@ class SimsModel extends WindozModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async list() {
|
async list() {
|
||||||
// TODO: implement
|
let endpoint = {...app.config.api[this.ressource].list}
|
||||||
return([])
|
return(
|
||||||
|
this.request(endpoint.uri, endpoint.method)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(simId) {
|
async get(simId) {
|
||||||
// TODO: implement
|
let endpoint = {...app.config.api[this.ressource].get}
|
||||||
return(null)
|
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||||
|
return(
|
||||||
|
this.request(endpoint.uri, endpoint.method)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(simData) {
|
async create(simData) {
|
||||||
// TODO: implement
|
let endpoint = {...app.config.api[this.ressource].create}
|
||||||
return(null)
|
return(
|
||||||
|
this.request(endpoint.uri, endpoint.method, simData)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(simId) {
|
async start(simId) {
|
||||||
// TODO: implement
|
let endpoint = {...app.config.api[this.ressource].start}
|
||||||
return(null)
|
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||||
|
return(
|
||||||
|
this.request(endpoint.uri, endpoint.method)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async pause(simId) {
|
async pause(simId) {
|
||||||
// TODO: implement
|
let endpoint = {...app.config.api[this.ressource].pause}
|
||||||
return(null)
|
endpoint.uri = endpoint.uri.replace('{simId}', simId)
|
||||||
|
return(
|
||||||
|
this.request(endpoint.uri, endpoint.method)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class CreateSimView extends WindozDomContent {
|
|||||||
async DOMContentLoaded(options) {
|
async DOMContentLoaded(options) {
|
||||||
this.models = options.models
|
this.models = options.models
|
||||||
const components = ui.eicfy(this.el)
|
const components = ui.eicfy(this.el)
|
||||||
|
this.setupTriggers(components)
|
||||||
this.setupRefs(components)
|
this.setupRefs(components)
|
||||||
|
|
||||||
this.models.keyframes.list('', null).then(data => data.payload).then(kflist => {
|
this.models.keyframes.list('', null).then(data => data.payload).then(kflist => {
|
||||||
this.outputs.keyframesSelector.fillOptions(kflist.map(item => {
|
this.outputs.keyframesSelector.fillOptions(kflist.map(item => {
|
||||||
return({
|
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
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,3 +3,11 @@ 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.
|
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,
|
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.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user