@@ -41,64 +41,124 @@ qx.Class.define("osparc.component.snapshots.SnapshotsView", {
4141 members : {
4242 __snapshotsSection : null ,
4343 __snapshotsTable : null ,
44+ __gitGraphLayout : null ,
45+ __gitGraphWrapper : null ,
4446 __snapshotPreview : null ,
45- __selectedSnapshot : null ,
4647 __editSnapshotBtn : null ,
4748 __openSnapshotBtn : null ,
49+ __snapshots : null ,
50+ __currentSnapshot : null ,
51+ __selectedSnapshotId : null ,
4852
4953 __buildLayout : function ( ) {
5054 const snapshotsSection = this . __snapshotsSection = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 5 ) ) ;
5155 this . _add ( snapshotsSection , {
5256 flex : 1
5357 } ) ;
54- this . __rebuildSnapshotsTable ( ) ;
58+ this . __rebuildSnapshots ( ) ;
5559 this . __buildSnapshotPreview ( ) ;
5660
5761 const buttonsSection = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( ) ) ;
5862 this . _add ( buttonsSection ) ;
5963
6064 const editSnapshotBtn = this . __editSnapshotBtn = this . __createEditSnapshotBtn ( ) ;
6165 editSnapshotBtn . setEnabled ( false ) ;
62- editSnapshotBtn . addListener ( "execute" , ( ) => this . __editSnapshot ( ) ) ;
66+ editSnapshotBtn . addListener ( "execute" , ( ) => {
67+ if ( this . __selectedSnapshotId ) {
68+ this . __editSnapshot ( this . __selectedSnapshotId ) ;
69+ }
70+ } ) ;
6371 buttonsSection . add ( editSnapshotBtn ) ;
6472
6573 const openSnapshotBtn = this . __openSnapshotBtn = this . __createOpenSnapshotBtn ( ) ;
6674 openSnapshotBtn . setEnabled ( false ) ;
6775 openSnapshotBtn . addListener ( "execute" , ( ) => {
68- if ( this . __selectedSnapshot ) {
69- this . fireDataEvent ( "openSnapshot" , this . __selectedSnapshot ) ;
76+ if ( this . __selectedSnapshotId ) {
77+ this . fireDataEvent ( "openSnapshot" , this . __selectedSnapshotId ) ;
7078 }
7179 } ) ;
7280 buttonsSection . add ( openSnapshotBtn ) ;
7381 } ,
7482
83+ __rebuildSnapshots : function ( ) {
84+ Promise . all ( [
85+ this . __study . getSnapshots ( ) ,
86+ this . __study . getCurrentSnapshot ( )
87+ ] )
88+ . then ( values => {
89+ this . __snapshots = values [ 0 ] ;
90+ this . __currentSnapshot = values [ 1 ] ;
91+ this . __rebuildSnapshotsTable ( ) ;
92+ this . __rebuildSnapshotsGraph ( ) ;
93+ } ) ;
94+ } ,
95+
7596 __rebuildSnapshotsTable : function ( ) {
7697 if ( this . __snapshotsTable ) {
7798 this . __snapshotsSection . remove ( this . __snapshotsTable ) ;
7899 }
79100
80- const snapshotsTable = this . __snapshotsTable = new osparc . component . snapshots . Snapshots ( this . __study ) ;
101+ const snapshotsTable = this . __snapshotsTable = new osparc . component . snapshots . Snapshots ( ) ;
102+ snapshotsTable . populateTable ( this . __snapshots ) ;
81103 snapshotsTable . addListener ( "cellTap" , e => {
82- this . __snapshotsSelected ( e ) ;
104+ const selectedRow = e . getRow ( ) ;
105+ const snapshotId = snapshotsTable . getRowData ( selectedRow ) [ "Id" ] ;
106+ this . __snapshotSelected ( snapshotId ) ;
83107 } ) ;
84108
85109 this . __snapshotsSection . addAt ( snapshotsTable , 0 , {
86- width : "50%"
110+ width : "40%"
111+ } ) ;
112+ } ,
113+
114+ __rebuildSnapshotsGraph : function ( ) {
115+ if ( this . __gitGraphLayout ) {
116+ this . __snapshotsSection . remove ( this . __gitGraphLayout ) ;
117+ }
118+
119+ const gitGraphLayout = this . __gitGraphLayout = new qx . ui . container . Composite ( new qx . ui . layout . Canvas ( ) ) ;
120+ const gitGraphCanvas = new qx . ui . container . Composite ( new qx . ui . layout . Canvas ( ) ) ;
121+ const gitGraphInteract = new qx . ui . container . Composite ( new qx . ui . layout . VBox ( ) ) ;
122+ gitGraphLayout . add ( gitGraphCanvas , {
123+ top : 20 ,
124+ right : 0 ,
125+ bottom : 0 ,
126+ left : 0
127+ } ) ;
128+ gitGraphLayout . add ( gitGraphInteract , {
129+ top : 20 + 2 ,
130+ right : 0 ,
131+ bottom : 0 ,
132+ left : 0
133+ } ) ;
134+
135+ gitGraphCanvas . addListenerOnce ( "appear" , ( ) => {
136+ const gitGraphWrapper = this . __gitGraphWrapper = new osparc . wrapper . GitGraph ( ) ;
137+ gitGraphWrapper . init ( gitGraphCanvas , gitGraphInteract )
138+ . then ( ( ) => gitGraphWrapper . populateGraph ( this . __snapshots , this . __currentSnapshot ) ) ;
139+ gitGraphWrapper . addListener ( "snapshotTap" , e => {
140+ const snapshotId = e . getData ( ) ;
141+ this . __snapshotSelected ( snapshotId ) ;
142+ } ) ;
143+ } ) ;
144+
145+ this . __snapshotsSection . addAt ( gitGraphLayout , 1 , {
146+ width : "20%"
87147 } ) ;
88148 } ,
89149
90150 __buildSnapshotPreview : function ( ) {
91151 const snapshotPreview = this . __snapshotPreview = new osparc . component . workbench . WorkbenchUIPreview ( ) ;
92- this . __snapshotsSection . addAt ( snapshotPreview , 1 , {
93- width : "50 %"
152+ this . __snapshotsSection . addAt ( snapshotPreview , 2 , {
153+ width : "40 %"
94154 } ) ;
95155 } ,
96156
97- __loadSnapshotsPreview : function ( snapshotData ) {
157+ __loadSnapshotsPreview : function ( snapshotId ) {
98158 const params = {
99159 url : {
100160 "studyId" : this . __study . getUuid ( ) ,
101- "snapshotId" : snapshotData [ "Id" ]
161+ "snapshotId" : snapshotId
102162 }
103163 } ;
104164 osparc . data . Resources . fetch ( "snapshots" , "preview" , params )
@@ -130,20 +190,21 @@ qx.Class.define("osparc.component.snapshots.SnapshotsView", {
130190 return openSnapshotBtn ;
131191 } ,
132192
133- __editSnapshot : function ( ) {
134- if ( this . __selectedSnapshot ) {
193+ __editSnapshot : function ( snapshotId ) {
194+ const selectedSnapshot = this . __snapshots . find ( snapshot => snapshot [ "id" ] === snapshotId ) ;
195+ if ( selectedSnapshot ) {
135196 const editSnapshotView = new osparc . component . snapshots . EditSnapshotView ( ) ;
136197 const tagCtrl = editSnapshotView . getChildControl ( "tags" ) ;
137- tagCtrl . setValue ( this . __selectedSnapshot [ "Tags" ] ) ;
198+ tagCtrl . setValue ( selectedSnapshot [ "tags" ] [ 0 ] ) ;
138199 const msgCtrl = editSnapshotView . getChildControl ( "message" ) ;
139- msgCtrl . setValue ( this . __selectedSnapshot [ "Message "] ) ;
200+ msgCtrl . setValue ( selectedSnapshot [ "message "] ) ;
140201 const title = this . tr ( "Edit Snapshot" ) ;
141202 const win = osparc . ui . window . Window . popUpInWindow ( editSnapshotView , title , 400 , 180 ) ;
142203 editSnapshotView . addListener ( "takeSnapshot" , ( ) => {
143204 const params = {
144205 url : {
145206 "studyId" : this . __study . getUuid ( ) ,
146- "snapshotId" : this . __selectedSnapshot [ "Id" ]
207+ "snapshotId" : snapshotId
147208 } ,
148209 data : {
149210 "tag" : editSnapshotView . getTag ( ) ,
@@ -152,7 +213,7 @@ qx.Class.define("osparc.component.snapshots.SnapshotsView", {
152213 } ;
153214 osparc . data . Resources . fetch ( "snapshots" , "updateSnapshot" , params )
154215 . then ( ( ) => {
155- this . __rebuildSnapshotsTable ( ) ;
216+ this . __rebuildSnapshots ( ) ;
156217 } )
157218 . catch ( err => osparc . component . message . FlashMessenger . getInstance ( ) . logAs ( err . message , "ERROR" ) ) ;
158219 win . close ( ) ;
@@ -163,11 +224,18 @@ qx.Class.define("osparc.component.snapshots.SnapshotsView", {
163224 }
164225 } ,
165226
166- __snapshotsSelected : function ( e ) {
167- const selectedRow = e . getRow ( ) ;
168- this . __selectedSnapshot = this . __snapshotsTable . getRowData ( selectedRow ) ;
227+ __snapshotSelected : function ( snapshotId ) {
228+ this . __selectedSnapshotId = snapshotId ;
229+
230+ if ( this . __snapshotsTable ) {
231+ this . __snapshotsTable . setSelection ( snapshotId ) ;
232+ }
233+
234+ if ( this . __gitGraphWrapper ) {
235+ this . __gitGraphWrapper . setSelection ( snapshotId ) ;
236+ }
169237
170- this . __loadSnapshotsPreview ( this . __selectedSnapshot ) ;
238+ this . __loadSnapshotsPreview ( snapshotId ) ;
171239
172240 if ( this . __editSnapshotBtn ) {
173241 this . __editSnapshotBtn . setEnabled ( true ) ;
0 commit comments