From d172e06611affab7eb1a17c3767bb057f97887f9 Mon Sep 17 00:00:00 2001 From: STEINNI Date: Fri, 5 Jun 2026 20:27:57 +0000 Subject: [PATCH] sim creation wired to DB with ownership --- app/assets/json/global/services.json | 22 +++++++++++++++++++ app/models/SimsModel.js | 33 +++++++++++++++++++--------- app/views/sims/CreateSimView.js | 12 ++++++---- doc/prompts_blobs.txt | 10 ++++++++- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/app/assets/json/global/services.json b/app/assets/json/global/services.json index c19be5a..5afd364 100644 --- a/app/assets/json/global/services.json +++ b/app/assets/json/global/services.json @@ -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" + } } } } diff --git a/app/models/SimsModel.js b/app/models/SimsModel.js index c568196..abd5066 100644 --- a/app/models/SimsModel.js +++ b/app/models/SimsModel.js @@ -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) + ) } } diff --git a/app/views/sims/CreateSimView.js b/app/views/sims/CreateSimView.js index de6a621..5ed44c3 100644 --- a/app/views/sims/CreateSimView.js +++ b/app/views/sims/CreateSimView.js @@ -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() } } diff --git a/doc/prompts_blobs.txt b/doc/prompts_blobs.txt index 5ce199c..8922ade 100644 --- a/doc/prompts_blobs.txt +++ b/doc/prompts_blobs.txt @@ -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. \ No newline at end of file +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. +