1515
1616************************************************************************ */ 
1717
18+ /** 
19+   Supports: 
20+   "categories": [{ 
21+     "id": "string", // required 
22+     "title": "string", // required 
23+     "description": "string" // optional 
24+   }], 
25+   "resources": [{ 
26+     "resourceType": "study", // it will start an empty study 
27+     "title": "string", // required 
28+     "icon": "fontAwesome inner link | url", // optional 
29+     "newStudyLabel": "string", // optional 
30+     "idToWidget": "string" // optional 
31+   }, { 
32+     "resourceType": "template", // it will create a study from the template 
33+     "expectedTemplateLabel": "string", // required 
34+     "title": "string", // required 
35+     "icon": "fontAwesome inner link | url", // optional 
36+     "newStudyLabel": "string", // optional 
37+     "category": "categories.id", // optional 
38+     "idToWidget": "string" // optional 
39+   }, { 
40+     "resourceType": "service", // it will create a study from the service 
41+     "expectedKey": "service.key", // required 
42+     "title": "string", // required 
43+     "icon": "fontAwesome inner link | url", // optional 
44+     "newStudyLabel": "string", // optional 
45+     "category": "categories.id", // optional 
46+     "idToWidget": "string" // optional 
47+   }, { 
48+     "showDisabled": true, // it will show a disabled button on the defined item 
49+     "title": "string", // required 
50+     "icon": "fontAwesome inner link | url", // optional 
51+     "reason": "string", // optional 
52+     "newStudyLabel": "string", // optional 
53+     "category": "categories.id", // optional 
54+     "idToWidget": "string" // optional 
55+   }] 
56+  */ 
1857qx . Class . define ( "osparc.dashboard.NewPlusMenu" ,  { 
1958  extend : qx . ui . menu . Menu , 
2059
@@ -51,6 +90,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
5190        "replace_me_product_name" , 
5291        osparc . store . StaticInfo . getInstance ( ) . getDisplayName ( ) 
5392      ) ; 
93+       title  =  title . replace ( / < b r > / g,  " " ) ; 
5494      const  menuButton  =  new  qx . ui . menu . Button ( ) . set ( { 
5595        icon : icon  ||  null , 
5696        label : title , 
@@ -66,7 +106,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
66106      } ) ; 
67107      if  ( infoText )  { 
68108        infoText  =  osparc . utils . Utils . replaceTokens ( 
69-           title , 
109+           infoText , 
70110          "replace_me_product_name" , 
71111          osparc . store . StaticInfo . getInstance ( ) . getDisplayName ( ) 
72112        ) ; 
@@ -116,27 +156,24 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
116156    } , 
117157
118158    __addNewStudyItems : async  function ( )  { 
119-       await  Promise . all ( [ 
120-         osparc . store . Products . getInstance ( ) . getNewStudyConfig ( ) , 
121-         osparc . data . Resources . get ( "templates" ) 
122-       ] ) . then ( values  =>  { 
123-         const  newStudiesData  =  values [ 0 ] ; 
124-         const  templates  =  values [ 1 ] ; 
125-         if  ( newStudiesData [ "categories" ] )  { 
126-           this . __addCategories ( newStudiesData [ "categories" ] ) ; 
127-         } 
128-         newStudiesData [ "resources" ] . forEach ( newStudyData  =>  { 
129-           if  ( newStudyData [ "showDisabled" ] )  { 
130-             this . __addDisabledButton ( newStudyData ) ; 
131-           }  else  if  ( newStudyData [ "resourceType" ]  ===  "study" )  { 
132-             this . __addEmptyStudyButton ( newStudyData ) ; 
133-           }  else  if  ( newStudyData [ "resourceType" ]  ===  "template" )  { 
134-             this . __addFromTemplateButton ( newStudyData ,  templates ) ; 
135-           }  else  if  ( newStudyData [ "resourceType" ]  ===  "service" )  { 
136-             this . __addFromServiceButton ( newStudyData ) ; 
159+       await  osparc . data . Resources . get ( "templates" ) 
160+         . then ( templates  =>  { 
161+           const  plusButtonConfig  =  osparc . store . Products . getInstance ( ) . getPlusButtonUiConfig ( ) ; 
162+           if  ( plusButtonConfig [ "categories" ] )  { 
163+             this . __addCategories ( plusButtonConfig [ "categories" ] ) ; 
137164          } 
165+           plusButtonConfig [ "resources" ] . forEach ( newStudyData  =>  { 
166+             if  ( newStudyData [ "showDisabled" ] )  { 
167+               this . __addDisabledButton ( newStudyData ) ; 
168+             }  else  if  ( newStudyData [ "resourceType" ]  ===  "study" )  { 
169+               this . __addEmptyStudyButton ( newStudyData ) ; 
170+             }  else  if  ( newStudyData [ "resourceType" ]  ===  "template" )  { 
171+               this . __addFromTemplateButton ( newStudyData ,  templates ) ; 
172+             }  else  if  ( newStudyData [ "resourceType" ]  ===  "service" )  { 
173+               this . __addFromServiceButton ( newStudyData ) ; 
174+             } 
175+           } ) ; 
138176        } ) ; 
139-       } ) ; 
140177    } , 
141178
142179    __getLastIdxFromCategory : function ( categoryId )  { 
@@ -165,7 +202,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
165202    __addIcon : function ( menuButton ,  resourceInfo ,  resourceMetadata )  { 
166203      let  source  =  null ; 
167204      if  ( resourceInfo  &&  "icon"  in  resourceInfo )  { 
168-         // first the one set in the new_studies  
205+         // first the one set in the ui_config  
169206        source  =  resourceInfo [ "icon" ] ; 
170207      }  else  if  ( resourceMetadata  &&  "thumbnail"  in  resourceMetadata )  { 
171208        // second the one from the resource 
@@ -200,55 +237,55 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
200237    } , 
201238
202239    __addDisabledButton : function ( newStudyData )  { 
203-       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData . title ,  newStudyData . reason ) ; 
204-       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData . idToWidget ) ; 
240+       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData [ " title" ] ,  newStudyData [ " reason" ] ) ; 
241+       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData [ " idToWidget" ] ) ; 
205242      menuButton . setEnabled ( false ) ; 
206243
207244      this . __addIcon ( menuButton ,  newStudyData ) ; 
208-       this . __addFromResourceButton ( menuButton ,  newStudyData . category ) ; 
245+       this . __addFromResourceButton ( menuButton ,  newStudyData [ " category" ] ) ; 
209246    } , 
210247
211248    __addEmptyStudyButton : function ( newStudyData )  { 
212-       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData . title ) ; 
213-       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData . idToWidget ) ; 
249+       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData [ " title" ] ) ; 
250+       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData [ " idToWidget" ] ) ; 
214251
215252      menuButton . addListener ( "tap" ,  ( )  =>  { 
216253        this . fireDataEvent ( "newEmptyStudyClicked" ,  { 
217-           newStudyLabel : newStudyData . newStudyLabel , 
254+           newStudyLabel : newStudyData [ " newStudyLabel" ] , 
218255        } ) ; 
219256      } ) ; 
220257
221258      this . __addIcon ( menuButton ,  newStudyData ) ; 
222-       this . __addFromResourceButton ( menuButton ,  newStudyData . category ) ; 
259+       this . __addFromResourceButton ( menuButton ,  newStudyData [ " category" ] ) ; 
223260    } , 
224261
225262    __addFromTemplateButton : function ( newStudyData ,  templates )  { 
226-       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData . title ) ; 
227-       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData . idToWidget ) ; 
263+       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData [ " title" ] ) ; 
264+       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData [ " idToWidget" ] ) ; 
228265      // disable it until found in templates store 
229266      menuButton . setEnabled ( false ) ; 
230267
231-       let  templateMetadata  =  templates . find ( t  =>  t . name  ===  newStudyData . expectedTemplateLabel ) ; 
268+       let  templateMetadata  =  templates . find ( t  =>  t . name  ===  newStudyData [ " expectedTemplateLabel" ] ) ; 
232269      if  ( templateMetadata )  { 
233270        menuButton . setEnabled ( true ) ; 
234271        menuButton . addListener ( "tap" ,  ( )  =>  { 
235272          this . fireDataEvent ( "newStudyFromTemplateClicked" ,  { 
236273            templateData : templateMetadata , 
237-             newStudyLabel : newStudyData . newStudyLabel , 
274+             newStudyLabel : newStudyData [ " newStudyLabel" ] , 
238275          } ) ; 
239276        } ) ; 
240277        this . __addIcon ( menuButton ,  newStudyData ,  templateMetadata ) ; 
241-         this . __addFromResourceButton ( menuButton ,  newStudyData . category ) ; 
278+         this . __addFromResourceButton ( menuButton ,  newStudyData [ " category" ] ) ; 
242279      } 
243280    } , 
244281
245282    __addFromServiceButton : function ( newStudyData )  { 
246-       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData . title ) ; 
247-       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData . idToWidget ) ; 
283+       const  menuButton  =  this . self ( ) . createMenuButton ( null ,  newStudyData [ " title" ] ) ; 
284+       osparc . utils . Utils . setIdToWidget ( menuButton ,  newStudyData [ " idToWidget" ] ) ; 
248285      // disable it until found in services store 
249286      menuButton . setEnabled ( false ) ; 
250287
251-       const  key  =  newStudyData . expectedKey ; 
288+       const  key  =  newStudyData [ " expectedKey" ] ; 
252289      // Include deprecated versions, they should all be updatable to a non deprecated version 
253290      const  versions  =  osparc . service . Utils . getVersions ( key ,  false ) ; 
254291      if  ( versions . length  &&  newStudyData )  { 
@@ -265,7 +302,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
265302            menuButton . addListener ( "tap" ,  ( )  =>  { 
266303              this . fireDataEvent ( "newStudyFromServiceClicked" ,  { 
267304                serviceMetadata : latestMetadata , 
268-                 newStudyLabel : newStudyData . newStudyLabel , 
305+                 newStudyLabel : newStudyData [ " newStudyLabel" ] , 
269306              } ) ; 
270307            } ) ; 
271308
@@ -283,7 +320,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
283320            menuButton . _add ( infoButton ,  { column : 2 } ) ; 
284321
285322            this . __addIcon ( menuButton ,  newStudyData ,  latestMetadata ) ; 
286-             this . __addFromResourceButton ( menuButton ,  newStudyData . category ) ; 
323+             this . __addFromResourceButton ( menuButton ,  newStudyData [ " category" ] ) ; 
287324          } ) 
288325      } 
289326    } , 
0 commit comments