1717
1818/**
1919 * @asset (osparc/ui_config.json")
20+ * @asset (form/product-ui.json)
21+ * @asset (object-path/object-path-0-11-4.min.js)
22+ * @asset (ajv/ajv-6-11-0.min.js)
23+ * @ignore (Ajv)
2024 */
2125
2226qx . Class . define ( "osparc.store.Products" , {
@@ -27,31 +31,48 @@ qx.Class.define("osparc.store.Products", {
2731 __uiConfig : null ,
2832
2933 fetchUiConfig : function ( ) {
30- if ( osparc . auth . Data . getInstance ( ) . isGuest ( ) ) {
31- return new Promise ( resolve => {
34+ return new Promise ( resolve => {
35+ if ( osparc . auth . Data . getInstance ( ) . isGuest ( ) ) {
3236 this . __uiConfig = { } ;
3337 resolve ( this . __uiConfig ) ;
34- } ) ;
35- }
38+ }
3639
37- return Promise . all ( [
38- osparc . data . Resources . fetch ( "productMetadata" , "getUiConfig" ) ,
39- osparc . utils . Utils . fetchJSON ( "/resource/osparc/ui_config.json" ) ,
40- ] )
41- . then ( values => {
42- let uiConfig = { } ;
43- if ( values [ 0 ] && values [ 0 ] [ "ui" ] && Object . keys ( values [ 0 ] [ "ui" ] ) . length ) {
44- uiConfig = values [ 0 ] [ "ui" ] ;
45- } else {
46- const product = osparc . product . Utils . getProductName ( ) ;
47- if ( values [ 1 ] && product in values [ 1 ] ) {
48- uiConfig = values [ 1 ] [ product ] ;
40+ Promise . all ( [
41+ osparc . data . Resources . fetch ( "productMetadata" , "getUiConfig" ) ,
42+ osparc . utils . Utils . fetchJSON ( "/resource/osparc/ui_config.json" ) ,
43+ osparc . utils . Utils . fetchJSON ( "/resource/form/product-ui.json" ) ,
44+ ] )
45+ . then ( values => {
46+ let uiConfig = { } ;
47+ if ( values [ 0 ] && values [ 0 ] [ "ui" ] && Object . keys ( values [ 0 ] [ "ui" ] ) . length ) {
48+ uiConfig = values [ 0 ] [ "ui" ] ;
49+ } else {
50+ const product = osparc . product . Utils . getProductName ( ) ;
51+ if ( values [ 1 ] && product in values [ 1 ] ) {
52+ uiConfig = values [ 1 ] [ product ] ;
53+ }
4954 }
50- }
51- this . __uiConfig = uiConfig ;
52- return this . __uiConfig ;
53- } )
54- . catch ( console . error ) ;
55+ const schema = values [ 2 ] ;
56+ const ajvLoader = new qx . util . DynamicScriptLoader ( [
57+ "/resource/ajv/ajv-6-11-0.min.js" ,
58+ "/resource/object-path/object-path-0-11-4.min.js"
59+ ] ) ;
60+ ajvLoader . addListener ( "ready" , ( ) => {
61+ this . __ajv = new Ajv ( ) ;
62+ if ( this . __validate ( schema . $schema , schema ) ) {
63+ // Schema is valid
64+ if ( this . __validate ( schema , uiConfig ) ) {
65+ // Validate data if present
66+ this . __uiConfig = uiConfig ;
67+ }
68+ resolve ( this . __uiConfig ) ;
69+ } else {
70+ console . error ( "wrong ui_config" )
71+ }
72+ } ) ;
73+ } )
74+ . catch ( console . error ) ;
75+ } ) ;
5576 } ,
5677
5778 getPlusButtonUiConfig : function ( ) {
0 commit comments