@@ -32,6 +32,71 @@ qx.Class.define("osparc.study.CreateFunction", {
3232 this . __buildLayout ( ) ;
3333 } ,
3434
35+ statics : {
36+ typeToFunctionType : function ( type ) {
37+ switch ( type ) {
38+ case "number" :
39+ return "float"
40+ case "data:*/*" :
41+ return "FileID"
42+ }
43+ return type ;
44+ } ,
45+
46+ createFunctionData : function ( projectData , name , description , exposedInputs , exposedOutputs ) {
47+ const functionData = {
48+ "project_id" : projectData [ "uuid" ] ,
49+ "name" : name ,
50+ "description" : description ,
51+ "function_class" : "project" ,
52+ "input_schema" : {
53+ "schema_dict" : {
54+ "type" : "object" ,
55+ "properties" : { }
56+ }
57+ } ,
58+ "output_schema" : {
59+ "schema_dict" : {
60+ "type" : "object" ,
61+ "properties" : { }
62+ }
63+ } ,
64+ "default_inputs" : { } ,
65+ } ;
66+
67+ const parameters = osparc . study . Utils . extractFunctionableParameters ( projectData [ "workbench" ] ) ;
68+ parameters . forEach ( parameter => {
69+ const parameterLabel = parameter [ "label" ] ;
70+ if ( exposedInputs [ parameterLabel ] ) {
71+ const parameterMetadata = osparc . store . Services . getMetadata ( parameter [ "key" ] , parameter [ "version" ] ) ;
72+ if ( parameterMetadata ) {
73+ const type = osparc . service . Utils . getParameterType ( parameterMetadata ) ;
74+ functionData [ "input_schema" ] [ "schema_dict" ] [ "properties" ] [ parameterLabel ] = {
75+ "type" : this . self ( ) . typeToFunctionType ( type ) ,
76+ } ;
77+ }
78+ functionData [ "default_inputs" ] [ parameterLabel ] = osparc . service . Utils . getParameterValue ( parameter ) ;
79+ }
80+ } ) ;
81+
82+ const probes = osparc . study . Utils . extractFunctionableProbes ( projectData [ "workbench" ] ) ;
83+ probes . forEach ( probe => {
84+ const probeLabel = probe [ "label" ] ;
85+ if ( exposedOutputs [ probeLabel ] ) {
86+ const probeMetadata = osparc . store . Services . getMetadata ( probe [ "key" ] , probe [ "version" ] ) ;
87+ if ( probeMetadata ) {
88+ const type = osparc . service . Utils . getProbeType ( probeMetadata ) ;
89+ functionData [ "output_schema" ] [ "schema_dict" ] [ "properties" ] [ probeLabel ] = {
90+ "type" : this . self ( ) . typeToFunctionType ( type ) ,
91+ } ;
92+ }
93+ }
94+ } ) ;
95+
96+ return functionData ;
97+ }
98+ } ,
99+
35100 members : {
36101 __studyData : null ,
37102 __form : null ,
@@ -248,53 +313,7 @@ qx.Class.define("osparc.study.CreateFunction", {
248313 const nameField = this . __form . getItem ( "name" ) ;
249314 const descriptionField = this . __form . getItem ( "description" ) ;
250315
251- const functionData = {
252- "name" : nameField . getValue ( ) ,
253- "description" : descriptionField . getValue ( ) ,
254- "project_id" : templateData [ "uuid" ] ,
255- "function_class" : "project" ,
256- "input_schema" : {
257- "schema_dict" : {
258- "type" : "object" ,
259- "properties" : { }
260- }
261- } ,
262- "output_schema" : {
263- "schema_dict" : {
264- "type" : "object" ,
265- "properties" : { }
266- }
267- } ,
268- "default_inputs" : { } ,
269- } ;
270-
271- const parameters = osparc . study . Utils . extractFunctionableParameters ( templateData [ "workbench" ] ) ;
272- parameters . forEach ( parameter => {
273- const parameterLabel = parameter [ "label" ] ;
274- if ( exposedInputs [ parameterLabel ] ) {
275- const parameterMetadata = osparc . store . Services . getMetadata ( parameter [ "key" ] , parameter [ "version" ] ) ;
276- if ( parameterMetadata ) {
277- functionData [ "input_schema" ] [ "schema_dict" ] [ "properties" ] [ parameterLabel ] = {
278- "type" : osparc . service . Utils . getParameterType ( parameterMetadata ) ,
279- } ;
280- }
281- functionData [ "default_inputs" ] [ parameterLabel ] = osparc . service . Utils . getParameterValue ( parameter ) ;
282- }
283- } ) ;
284-
285- const probes = osparc . study . Utils . extractFunctionableProbes ( templateData [ "workbench" ] ) ;
286- probes . forEach ( probe => {
287- const probeLabel = probe [ "label" ] ;
288- if ( exposedOutputs [ probeLabel ] ) {
289- const probeMetadata = osparc . store . Services . getMetadata ( probe [ "key" ] , probe [ "version" ] ) ;
290- if ( probeMetadata ) {
291- functionData [ "output_schema" ] [ "schema_dict" ] [ "properties" ] [ probeLabel ] = {
292- "type" : osparc . service . Utils . getProbeType ( probeMetadata ) ,
293- } ;
294- }
295- }
296- } ) ;
297-
316+ const functionData = this . self ( ) . createFunctionData ( templateData , nameField . getValue ( ) , descriptionField . getValue ( ) , exposedInputs , exposedOutputs ) ;
298317 console . log ( "functionData" , functionData ) ;
299318
300319 const params = {
0 commit comments