Skip to content

Commit ff122d3

Browse files
committed
create template first
1 parent 4a0408a commit ff122d3

File tree

2 files changed

+83
-9
lines changed

2 files changed

+83
-9
lines changed

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,18 @@ qx.Class.define("osparc.data.Resources", {
586586
}
587587
}
588588
},
589+
/*
590+
* FUNCTIONS
591+
*/
592+
"functions": {
593+
useCache: false,
594+
endpoints: {
595+
getPage: {
596+
method: "POST",
597+
url: statics.API + "/functions"
598+
}
599+
}
600+
},
589601
/*
590602
* TASKS
591603
*/

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

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ qx.Class.define("osparc.study.CreateFunction", {
2727

2828
this._setLayout(new qx.ui.layout.VBox(20));
2929

30-
this.__studyDataClone = osparc.data.model.Study.deepCloneStudyObject(studyData);
30+
this.__studyData = studyData;
3131

3232
this.__buildLayout();
3333
},
3434

3535
members: {
36-
__studyDataClone: null,
36+
__studyData: null,
3737
__form: null,
3838
__createFunctionBtn: null,
3939

@@ -43,7 +43,7 @@ qx.Class.define("osparc.study.CreateFunction", {
4343

4444
const title = new qx.ui.form.TextField().set({
4545
required: true,
46-
value: this.__studyDataClone.name,
46+
value: this.__studyData.name,
4747
});
4848
this.addListener("appear", () => {
4949
title.focus();
@@ -56,22 +56,84 @@ qx.Class.define("osparc.study.CreateFunction", {
5656
});
5757
form.add(description, this.tr("Description"), null, "description");
5858

59-
const createFunctionBtn = this.__createFunctionBtn = new qx.ui.form.Button().set({
59+
const createFunctionBtn = this.__createFunctionBtn = new qx.ui.form.FetchButton().set({
6060
appearance: "strong-button",
6161
label: this.tr("Create"),
6262
allowGrowX: false,
6363
alignX: "right"
6464
});
65-
createFunctionBtn.addListener("execute", () => this.__createFunction(), this);
65+
createFunctionBtn.addListener("execute", () => {
66+
if (this.__form.validate()) {
67+
this.__createFunction();
68+
}
69+
}, this);
6670
this._add(createFunctionBtn);
6771
},
6872

6973
__createFunction: function() {
70-
const name = this.__form.getItem("name");
71-
const description = this.__form.getItem("description");
74+
this.__createFunctionBtn.setFetching(true);
75+
76+
// first publish it as a template
77+
const params = {
78+
url: {
79+
"study_id": this.__studyData["uuid"],
80+
"copy_data": true,
81+
},
82+
};
83+
const options = {
84+
pollTask: true
85+
};
86+
const fetchPromise = osparc.data.Resources.fetch("studies", "postToTemplate", params, options);
87+
const pollTasks = osparc.store.PollTasks.getInstance();
88+
pollTasks.createPollingTask(fetchPromise)
89+
.then(task => {
90+
task.addListener("resultReceived", e => {
91+
const templateData = e.getData();
92+
this.__doCreateFunction(templateData);
93+
});
94+
})
95+
.catch(err => {
96+
this.__createFunctionBtn.setFetching(false);
97+
osparc.FlashMessenger.logError(err);
98+
});
99+
},
72100

73-
console.log("Creating function with name: ", name.getValue());
74-
console.log("Creating function with description: ", description.getValue());
101+
__doCreateFunction: function(templateData) {
102+
const nameField = this.__form.getItem("name");
103+
const descriptionField = this.__form.getItem("description");
104+
105+
const functionData = {
106+
"name": nameField.getValue(),
107+
"description": descriptionField.getValue(),
108+
"project_id": templateData["uuid"],
109+
"function_class": "project",
110+
"input_schema": {
111+
"schema_dict": {
112+
"type": "object",
113+
"properties": {
114+
"input1": {
115+
"type": "integer" // InputTypes: TypeAlias = FileID | float | int | bool | str | list
116+
}
117+
}
118+
}
119+
},
120+
"output_schema": {
121+
"schema_dict": {
122+
"type": "object",
123+
"properties": {
124+
"output1": {
125+
"type": "integer" // OutputTypes: TypeAlias = FileID | float | int | bool | str | list
126+
}
127+
}
128+
}
129+
},
130+
"default_inputs": {
131+
"input1": 5
132+
},
133+
};
134+
console.log("Creating function with data: ", functionData);
135+
136+
this.__createFunctionBtn.setFetching(false);
75137
},
76138

77139
getCreateFunctionButton: function() {

0 commit comments

Comments
 (0)