Skip to content

Commit 923171e

Browse files
committed
Functions store
1 parent de43e87 commit 923171e

File tree

2 files changed

+120
-68
lines changed

2 files changed

+120
-68
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2025 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.Functions", {
19+
type: "static",
20+
21+
statics: {
22+
__functions: null,
23+
__functionsPromiseCached: null,
24+
25+
__createFunctionData: function(templateData, name, description, defaultInputs = {}, exposedInputs = {}, exposedOutputs = {}) {
26+
const functionData = {
27+
"projectId": templateData["uuid"],
28+
"title": name,
29+
"description": description,
30+
"function_class": "PROJECT",
31+
"inputSchema": {
32+
"schema_class": "application/schema+json",
33+
"schema_content": {
34+
"type": "object",
35+
"properties": {},
36+
"required": []
37+
}
38+
},
39+
"outputSchema": {
40+
"schema_class": "application/schema+json",
41+
"schema_content": {
42+
"type": "object",
43+
"properties": {},
44+
"required": []
45+
}
46+
},
47+
"defaultInputs": {},
48+
};
49+
50+
const parameters = osparc.study.Utils.extractFunctionableParameters(templateData["workbench"]);
51+
parameters.forEach(parameter => {
52+
const parameterKey = parameter["label"];
53+
if (exposedInputs[parameterKey]) {
54+
const parameterMetadata = osparc.store.Services.getMetadata(parameter["key"], parameter["version"]);
55+
if (parameterMetadata) {
56+
const type = osparc.service.Utils.getParameterType(parameterMetadata);
57+
functionData["inputSchema"]["schema_content"]["properties"][parameterKey] = {
58+
"type": type,
59+
};
60+
functionData["inputSchema"]["schema_content"]["required"].push(parameterKey);
61+
}
62+
}
63+
if (parameterKey in defaultInputs) {
64+
functionData["defaultInputs"][parameterKey] = defaultInputs[parameterKey];
65+
}
66+
});
67+
68+
const probes = osparc.study.Utils.extractFunctionableProbes(templateData["workbench"]);
69+
probes.forEach(probe => {
70+
const probeLabel = probe["label"];
71+
if (exposedOutputs[probeLabel]) {
72+
const probeMetadata = osparc.store.Services.getMetadata(probe["key"], probe["version"]);
73+
if (probeMetadata) {
74+
const type = osparc.service.Utils.getProbeType(probeMetadata);
75+
functionData["outputSchema"]["schema_content"]["properties"][probeLabel] = {
76+
"type": type,
77+
};
78+
functionData["outputSchema"]["schema_content"]["required"].push(probeLabel);
79+
}
80+
}
81+
});
82+
83+
return functionData;
84+
},
85+
86+
registerFunction: function(templateData, name, description, defaultInputs, exposedInputs, exposedOutputs) {
87+
const functionData = this.self().__createFunctionData(templateData, name, description, defaultInputs, exposedInputs, exposedOutputs);
88+
const params = {
89+
data: functionData,
90+
};
91+
return osparc.data.Resources.fetch("functions", "create", params);
92+
},
93+
94+
fetchFunctionsPaginated: function(params, options) {
95+
return osparc.data.Resources.fetch("functions", "getPage", params, options)
96+
.then(response => {
97+
const functions = response["data"];
98+
functions.forEach(func => func["resourceType"] = "function");
99+
return response;
100+
})
101+
.catch(err => osparc.FlashMessenger.logError(err));
102+
},
103+
104+
fetchFunction: function(functionId) {
105+
return osparc.store.Study.getInstance().getOne(functionId)
106+
.catch(err => console.error(err));
107+
},
108+
109+
getFunction: function(functionId) {
110+
if (this.__functions) {
111+
const func = this.__functions.find(t => t["functionId"] === functionId);
112+
if (func) {
113+
return new osparc.data.model.Function(func);
114+
}
115+
}
116+
return null;
117+
},
118+
}
119+
});

services/static-webserver/client/source/class/osparc/study/CreateFunction.js

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -32,69 +32,6 @@ qx.Class.define("osparc.study.CreateFunction", {
3232
this.__buildLayout();
3333
},
3434

35-
statics: {
36-
createFunctionData: function(projectData, name, description, defaultInputs = {}, exposedInputs = {}, exposedOutputs = {}) {
37-
const functionData = {
38-
"projectId": projectData["uuid"],
39-
"title": name,
40-
"description": description,
41-
"function_class": "PROJECT",
42-
"inputSchema": {
43-
"schema_class": "application/schema+json",
44-
"schema_content": {
45-
"type": "object",
46-
"properties": {},
47-
"required": []
48-
}
49-
},
50-
"outputSchema": {
51-
"schema_class": "application/schema+json",
52-
"schema_content": {
53-
"type": "object",
54-
"properties": {},
55-
"required": []
56-
}
57-
},
58-
"defaultInputs": {},
59-
};
60-
61-
const parameters = osparc.study.Utils.extractFunctionableParameters(projectData["workbench"]);
62-
parameters.forEach(parameter => {
63-
const parameterKey = parameter["label"];
64-
if (exposedInputs[parameterKey]) {
65-
const parameterMetadata = osparc.store.Services.getMetadata(parameter["key"], parameter["version"]);
66-
if (parameterMetadata) {
67-
const type = osparc.service.Utils.getParameterType(parameterMetadata);
68-
functionData["inputSchema"]["schema_content"]["properties"][parameterKey] = {
69-
"type": type,
70-
};
71-
functionData["inputSchema"]["schema_content"]["required"].push(parameterKey);
72-
}
73-
}
74-
if (parameterKey in defaultInputs) {
75-
functionData["defaultInputs"][parameterKey] = defaultInputs[parameterKey];
76-
}
77-
});
78-
79-
const probes = osparc.study.Utils.extractFunctionableProbes(projectData["workbench"]);
80-
probes.forEach(probe => {
81-
const probeLabel = probe["label"];
82-
if (exposedOutputs[probeLabel]) {
83-
const probeMetadata = osparc.store.Services.getMetadata(probe["key"], probe["version"]);
84-
if (probeMetadata) {
85-
const type = osparc.service.Utils.getProbeType(probeMetadata);
86-
functionData["outputSchema"]["schema_content"]["properties"][probeLabel] = {
87-
"type": type,
88-
};
89-
functionData["outputSchema"]["schema_content"]["required"].push(probeLabel);
90-
}
91-
}
92-
});
93-
94-
return functionData;
95-
}
96-
},
97-
9835
members: {
9936
__studyData: null,
10037
__form: null,
@@ -335,11 +272,7 @@ qx.Class.define("osparc.study.CreateFunction", {
335272
const nameField = this.__form.getItem("name");
336273
const descriptionField = this.__form.getItem("description");
337274

338-
const functionData = this.self().createFunctionData(templateData, nameField.getValue(), descriptionField.getValue(), defaultInputs, exposedInputs, exposedOutputs);
339-
const params = {
340-
data: functionData,
341-
};
342-
osparc.data.Resources.fetch("functions", "create", params)
275+
osparc.store.Functions.registerFunction(templateData, nameField.getValue(), descriptionField.getValue(), defaultInputs, exposedInputs, exposedOutputs)
343276
.then(() => osparc.FlashMessenger.logAs(this.tr("Function created"), "INFO"))
344277
.catch(err => osparc.FlashMessenger.logError(err))
345278
.finally(() => this.__createFunctionBtn.setFetching(false));

0 commit comments

Comments
 (0)