@@ -64,7 +64,8 @@ qx.Class.define("osparc.data.model.Study", {
64
64
this . setWorkbench ( workbench ) ;
65
65
workbench . setStudy ( this ) ;
66
66
67
- this . setUi ( new osparc . data . model . StudyUI ( studyData . ui ) ) ;
67
+ const workbenchUi = new osparc . data . model . StudyUI ( studyData . ui ) ;
68
+ this . setUi ( workbenchUi ) ;
68
69
69
70
this . getWorkbench ( ) . buildWorkbench ( ) ;
70
71
} ,
@@ -229,13 +230,16 @@ qx.Class.define("osparc.data.model.Study", {
229
230
} ,
230
231
231
232
// deep clones object with study-only properties
232
- deepCloneStudyObject : function ( src ) {
233
- const studyObject = osparc . utils . Utils . deepCloneObject ( src ) ;
233
+ deepCloneStudyObject : function ( obj , ignoreExtra = false ) {
234
+ const studyObject = osparc . utils . Utils . deepCloneObject ( obj ) ;
234
235
const studyPropKeys = osparc . data . model . Study . getProperties ( ) ;
235
236
Object . keys ( studyObject ) . forEach ( key => {
236
237
if ( ! studyPropKeys . includes ( key ) ) {
237
238
delete studyObject [ key ] ;
238
239
}
240
+ if ( ignoreExtra && osparc . data . model . Study . IgnoreSerializationProps . includes ( key ) ) {
241
+ delete studyObject [ key ] ;
242
+ }
239
243
} ) ;
240
244
return studyObject ;
241
245
} ,
@@ -316,6 +320,30 @@ qx.Class.define("osparc.data.model.Study", {
316
320
} ,
317
321
318
322
members : {
323
+ serialize : function ( clean = true ) {
324
+ let jsonObject = { } ;
325
+ const propertyKeys = this . self ( ) . getProperties ( ) ;
326
+ propertyKeys . forEach ( key => {
327
+ if ( this . self ( ) . IgnoreSerializationProps . includes ( key ) ) {
328
+ return ;
329
+ }
330
+ if ( key === "workbench" ) {
331
+ jsonObject [ key ] = this . getWorkbench ( ) . serialize ( clean ) ;
332
+ return ;
333
+ }
334
+ if ( key === "ui" ) {
335
+ jsonObject [ key ] = this . getUi ( ) . serialize ( ) ;
336
+ return ;
337
+ }
338
+ const value = this . get ( key ) ;
339
+ if ( value !== null ) {
340
+ // only put the value in the payload if there is a value
341
+ jsonObject [ key ] = value ;
342
+ }
343
+ } ) ;
344
+ return jsonObject ;
345
+ } ,
346
+
319
347
initStudy : function ( ) {
320
348
this . getWorkbench ( ) . initWorkbench ( ) ;
321
349
} ,
@@ -549,80 +577,80 @@ qx.Class.define("osparc.data.model.Study", {
549
577
return ! this . getUi ( ) . getSlideshow ( ) . isEmpty ( ) ;
550
578
} ,
551
579
552
- serializeStudyData : function ( ) {
553
- let studyData = { } ;
554
- const propertyKeys = this . self ( ) . getProperties ( ) ;
555
- propertyKeys . forEach ( key => {
556
- if ( key === "workbench" ) {
557
- studyData [ key ] = this . getWorkbench ( ) . serialize ( ) ;
558
- return ;
559
- }
560
- if ( key === "ui" ) {
561
- studyData [ key ] = this . getUi ( ) . serialize ( ) ;
562
- return ;
563
- }
564
- const value = this . get ( key ) ;
565
- studyData [ key ] = value ;
566
- } ) ;
567
- return studyData ;
568
- } ,
569
-
570
- serialize : function ( clean = true ) {
571
- let jsonObject = { } ;
572
- const propertyKeys = this . self ( ) . getProperties ( ) ;
573
- propertyKeys . forEach ( key => {
574
- if ( this . self ( ) . IgnoreSerializationProps . includes ( key ) ) {
575
- return ;
576
- }
577
- if ( key === "workbench" ) {
578
- jsonObject [ key ] = this . getWorkbench ( ) . serialize ( clean ) ;
579
- return ;
580
- }
581
- if ( key === "ui" ) {
582
- jsonObject [ key ] = this . getUi ( ) . serialize ( ) ;
583
- return ;
584
- }
585
- const value = this . get ( key ) ;
586
- if ( value !== null ) {
587
- // only put the value in the payload if there is a value
588
- jsonObject [ key ] = value ;
589
- }
590
- } ) ;
591
- return jsonObject ;
592
- } ,
593
-
594
- patchStudy : function ( fieldKey , value ) {
580
+ patchStudy : function ( studyChanges ) {
595
581
return new Promise ( ( resolve , reject ) => {
596
- const patchData = { } ;
597
- patchData [ fieldKey ] = value ;
598
582
const params = {
599
583
url : {
600
584
"studyId" : this . getUuid ( )
601
585
} ,
602
- data : patchData
586
+ data : studyChanges
603
587
} ;
604
588
osparc . data . Resources . fetch ( "studies" , "patch" , params )
605
589
. then ( ( ) => {
606
- const upKey = qx . lang . String . firstUp ( fieldKey ) ;
607
- const setter = "set" + upKey ;
608
- this [ setter ] ( value ) ;
590
+ Object . keys ( studyChanges ) . forEach ( fieldKey => {
591
+ const upKey = qx . lang . String . firstUp ( fieldKey ) ;
592
+ const setter = "set" + upKey ;
593
+ this [ setter ] ( studyChanges [ fieldKey ] ) ;
594
+ } )
609
595
// A bit hacky, but it's not sent back to the backend
610
596
this . set ( {
611
597
lastChangeDate : new Date ( )
612
598
} ) ;
613
- const studyData = this . serializeStudyData ( ) ;
599
+ const studyData = this . serialize ( ) ;
614
600
resolve ( studyData ) ;
615
601
} )
616
602
. catch ( err => reject ( err ) ) ;
617
603
} ) ;
618
604
} ,
619
605
620
- updateStudy : function ( params , run = false ) {
606
+ /**
607
+ * Call patch Study, but the changes were already applied on the frontend
608
+ * @param studyDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes.
609
+ */
610
+ patchStudyDelayed : function ( studyDiffs ) {
611
+ const promises = [ ] ;
612
+ let workbenchDiffs = { } ;
613
+ if ( "workbench" in studyDiffs ) {
614
+ workbenchDiffs = studyDiffs [ "workbench" ] ;
615
+ promises . push ( this . getWorkbench ( ) . patchWorkbenchDelayed ( workbenchDiffs ) ) ;
616
+ delete studyDiffs [ "workbench" ] ;
617
+ }
618
+ const fieldKeys = Object . keys ( studyDiffs ) ;
619
+ if ( fieldKeys . length ) {
620
+ const patchData = { } ;
621
+ const params = {
622
+ url : {
623
+ "studyId" : this . getUuid ( )
624
+ } ,
625
+ data : patchData
626
+ } ;
627
+ fieldKeys . forEach ( fieldKey => {
628
+ if ( fieldKey === "ui" ) {
629
+ patchData [ fieldKey ] = this . getUi ( ) . serialize ( ) ;
630
+ } else {
631
+ const upKey = qx . lang . String . firstUp ( fieldKey ) ;
632
+ const getter = "get" + upKey ;
633
+ patchData [ fieldKey ] = this [ getter ] ( studyDiffs [ fieldKey ] ) ;
634
+ }
635
+ promises . push ( osparc . data . Resources . fetch ( "studies" , "patch" , params ) )
636
+ } ) ;
637
+ }
638
+ return Promise . all ( promises )
639
+ . then ( ( ) => {
640
+ // A bit hacky, but it's not sent back to the backend
641
+ this . set ( {
642
+ lastChangeDate : new Date ( )
643
+ } ) ;
644
+ const studyData = this . serialize ( ) ;
645
+ return studyData ;
646
+ } ) ;
647
+ } ,
648
+
649
+ updateStudy : function ( params ) {
621
650
return new Promise ( ( resolve , reject ) => {
622
651
osparc . data . Resources . fetch ( "studies" , "put" , {
623
652
url : {
624
- "studyId" : this . getUuid ( ) ,
625
- run
653
+ "studyId" : this . getUuid ( )
626
654
} ,
627
655
data : {
628
656
...this . serialize ( ) ,
0 commit comments