Skip to content

Commit 03bc710

Browse files
authored
🎨 [Frontend] Create Functions: Make default input values editable (#7951)
1 parent 4bf443b commit 03bc710

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ qx.Class.define("osparc.study.CreateFunction", {
3333
},
3434

3535
statics: {
36-
createFunctionData: function(projectData, name, description, exposedInputs, exposedOutputs) {
36+
createFunctionData: function(projectData, name, description, defaultInputs = {}, exposedInputs = {}, exposedOutputs = {}) {
3737
const functionData = {
3838
"projectId": projectData["uuid"],
3939
"title": name,
@@ -60,18 +60,19 @@ qx.Class.define("osparc.study.CreateFunction", {
6060

6161
const parameters = osparc.study.Utils.extractFunctionableParameters(projectData["workbench"]);
6262
parameters.forEach(parameter => {
63-
const parameterLabel = parameter["label"];
64-
if (exposedInputs[parameterLabel]) {
63+
const parameterKey = parameter["label"];
64+
if (exposedInputs[parameterKey]) {
6565
const parameterMetadata = osparc.store.Services.getMetadata(parameter["key"], parameter["version"]);
6666
if (parameterMetadata) {
6767
const type = osparc.service.Utils.getParameterType(parameterMetadata);
68-
functionData["inputSchema"]["schema_content"]["properties"][parameterLabel] = {
68+
functionData["inputSchema"]["schema_content"]["properties"][parameterKey] = {
6969
"type": type,
7070
};
71-
functionData["inputSchema"]["schema_content"]["required"].push(parameterLabel);
71+
functionData["inputSchema"]["schema_content"]["required"].push(parameterKey);
7272
}
73-
} else {
74-
functionData["defaultInputs"][parameterLabel] = osparc.service.Utils.getParameterValue(parameter);
73+
}
74+
if (parameterKey in defaultInputs) {
75+
functionData["defaultInputs"][parameterKey] = defaultInputs[parameterKey];
7576
}
7677
});
7778

@@ -120,11 +121,12 @@ qx.Class.define("osparc.study.CreateFunction", {
120121
form.add(description, this.tr("Description"), null, "description");
121122

122123

124+
const defaultInputs = {};
123125
const exposedInputs = {};
124126
const exposedOutputs = {};
125127

126128
// INPUTS
127-
const inGrid = new qx.ui.layout.Grid(10, 6);
129+
const inGrid = new qx.ui.layout.Grid(12, 6);
128130
const inputsLayout = new qx.ui.container.Composite(inGrid).set({
129131
allowGrowX: false,
130132
alignX: "left",
@@ -163,7 +165,8 @@ qx.Class.define("osparc.study.CreateFunction", {
163165

164166
const parameters = osparc.study.Utils.extractFunctionableParameters(this.__studyData["workbench"]);
165167
parameters.forEach(parameter => {
166-
const parameterLabel = new qx.ui.basic.Label(parameter["label"]);
168+
const parameterKey = parameter["label"];
169+
const parameterLabel = new qx.ui.basic.Label(parameterKey);
167170
inputsLayout.add(parameterLabel, {
168171
row,
169172
column,
@@ -185,11 +188,28 @@ qx.Class.define("osparc.study.CreateFunction", {
185188
row,
186189
column,
187190
});
188-
exposedInputs[parameter["label"]] = true;
189-
parameterExposed.addListener("changeValue", e => exposedInputs[parameter["label"]] = e.getData());
191+
exposedInputs[parameterKey] = true;
192+
parameterExposed.addListener("changeValue", e => exposedInputs[parameterKey] = e.getData());
190193
column++;
191194

192-
const parameterDefaultValue = new qx.ui.basic.Label(String(osparc.service.Utils.getParameterValue(parameter)));
195+
const paramValue = osparc.service.Utils.getParameterValue(parameter);
196+
defaultInputs[parameterKey] = paramValue;
197+
let parameterDefaultValue = null;
198+
if (parameterMetadata && osparc.service.Utils.getParameterType(parameterMetadata) === "number") {
199+
parameterDefaultValue = new qx.ui.form.TextField(String(paramValue));
200+
parameterDefaultValue.addListener("changeValue", e => {
201+
const newValue = e.getData();
202+
const oldValue = e.getOldData();
203+
if (newValue === oldValue) {
204+
return;
205+
}
206+
const curatedValue = (!isNaN(parseFloat(newValue))) ? parseFloat(newValue) : parseFloat(oldValue);
207+
defaultInputs[parameterKey] = curatedValue;
208+
parameterDefaultValue.setValue(String(curatedValue));
209+
});
210+
} else {
211+
parameterDefaultValue = new qx.ui.basic.Label(String(paramValue));
212+
}
193213
inputsLayout.add(parameterDefaultValue, {
194214
row,
195215
column,
@@ -274,12 +294,12 @@ qx.Class.define("osparc.study.CreateFunction", {
274294
});
275295
createFunctionBtn.addListener("execute", () => {
276296
if (this.__form.validate()) {
277-
this.__createFunction(exposedInputs, exposedOutputs);
297+
this.__createFunction(defaultInputs, exposedInputs, exposedOutputs);
278298
}
279299
}, this);
280300
},
281301

282-
__createFunction: function(exposedInputs, exposedOutputs) {
302+
__createFunction: function(defaultInputs, exposedInputs, exposedOutputs) {
283303
this.__createFunctionBtn.setFetching(true);
284304

285305
// first publish it as a hidden template
@@ -300,7 +320,7 @@ qx.Class.define("osparc.study.CreateFunction", {
300320
task.addListener("resultReceived", e => {
301321
const templateData = e.getData();
302322
this.__updateTemplateMetadata(templateData);
303-
this.__registerFunction(templateData, exposedInputs, exposedOutputs);
323+
this.__registerFunction(templateData, defaultInputs, exposedInputs, exposedOutputs);
304324
});
305325
})
306326
.catch(err => {
@@ -325,11 +345,11 @@ qx.Class.define("osparc.study.CreateFunction", {
325345
.catch(err => console.error(err));
326346
},
327347

328-
__registerFunction: function(templateData, exposedInputs, exposedOutputs) {
348+
__registerFunction: function(templateData, defaultInputs, exposedInputs, exposedOutputs) {
329349
const nameField = this.__form.getItem("name");
330350
const descriptionField = this.__form.getItem("description");
331351

332-
const functionData = this.self().createFunctionData(templateData, nameField.getValue(), descriptionField.getValue(), exposedInputs, exposedOutputs);
352+
const functionData = this.self().createFunctionData(templateData, nameField.getValue(), descriptionField.getValue(), defaultInputs, exposedInputs, exposedOutputs);
333353
const params = {
334354
data: functionData,
335355
};

0 commit comments

Comments
 (0)