@@ -130,25 +130,40 @@ export default class CompasVersionsPlugin extends LitElement {
130
130
131
131
private confirmRestoreVersionWizard ( version : string ) : Wizard {
132
132
function openScl ( plugin : CompasVersionsPlugin ) {
133
- return function ( ) {
134
- const type = getTypeFromDocName ( plugin . docName ) ;
135
-
136
- CompasSclDataService ( )
137
- . getSclDocumentVersion ( type , plugin . docId , version )
138
- . then ( sclDocument => {
139
- updateDocumentInOpenSCD ( plugin , sclDocument ) ;
133
+ function updateDocument ( sclDocument : Document ) : void {
134
+ updateDocumentInOpenSCD ( plugin , sclDocument ) ;
140
135
141
- plugin . dispatchEvent (
142
- newLogEvent ( {
143
- kind : 'info' ,
144
- title : get ( 'compas.versions.restoreVersionSuccess' , {
145
- version : version ,
146
- } ) ,
147
- } )
148
- ) ;
136
+ plugin . dispatchEvent (
137
+ newLogEvent ( {
138
+ kind : 'info' ,
139
+ title : get ( 'compas.versions.restoreVersionSuccess' , {
140
+ version : version ,
141
+ } ) ,
149
142
} )
150
- . catch ( reason => createLogEvent ( plugin , reason ) ) ;
143
+ ) ;
144
+ }
151
145
146
+ return function ( ) {
147
+ const type = getTypeFromDocName ( plugin . docName ) ;
148
+
149
+ const service = CompasSclDataService ( ) ;
150
+ if ( service . useWebsocket ( ) ) {
151
+ service . getSclDocumentVersionUsingWebsockets (
152
+ plugin ,
153
+ type ,
154
+ plugin . docId ,
155
+ version ,
156
+ ( sclDocument ) => {
157
+ updateDocument ( sclDocument ) ;
158
+ } )
159
+ } else {
160
+ service
161
+ . getSclDocumentVersionUsingRest ( type , plugin . docId , version )
162
+ . then ( sclDocument => {
163
+ updateDocument ( sclDocument ) ;
164
+ } )
165
+ . catch ( reason => createLogEvent ( plugin , reason ) ) ;
166
+ }
152
167
// Close the Restore Dialog.
153
168
plugin . dispatchEvent ( newWizardEvent ( ) ) ;
154
169
@@ -285,15 +300,17 @@ export default class CompasVersionsPlugin extends LitElement {
285
300
const oldScl = await this . getVersion ( oldVersion ) ;
286
301
const newScl = this . doc . documentElement ;
287
302
288
- this . dispatchEvent (
289
- newWizardEvent (
290
- compareWizard ( this , oldScl , newScl , {
291
- title : get ( 'compas.compare.titleCurrent' , {
292
- oldVersion : oldVersion ,
293
- } ) ,
294
- } )
295
- )
296
- ) ;
303
+ if ( oldScl && newScl ) {
304
+ this . dispatchEvent (
305
+ newWizardEvent (
306
+ compareWizard ( this , oldScl , newScl , {
307
+ title : get ( 'compas.compare.titleCurrent' , {
308
+ oldVersion : oldVersion ,
309
+ } ) ,
310
+ } )
311
+ )
312
+ ) ;
313
+ }
297
314
} else {
298
315
this . dispatchEvent (
299
316
newWizardEvent (
@@ -318,16 +335,18 @@ export default class CompasVersionsPlugin extends LitElement {
318
335
const oldScl = await this . getVersion ( oldVersion ) ;
319
336
const newScl = await this . getVersion ( newVersion ) ;
320
337
321
- this . dispatchEvent (
322
- newWizardEvent (
323
- compareWizard ( this , oldScl , newScl , {
324
- title : get ( 'compas.compare.title' , {
325
- oldVersion : oldVersion ,
326
- newVersion : newVersion ,
327
- } ) ,
328
- } )
329
- )
330
- ) ;
338
+ if ( oldScl && newScl ) {
339
+ this . dispatchEvent (
340
+ newWizardEvent (
341
+ compareWizard ( this , oldScl , newScl , {
342
+ title : get ( 'compas.compare.title' , {
343
+ oldVersion : oldVersion ,
344
+ newVersion : newVersion ,
345
+ } ) ,
346
+ } )
347
+ )
348
+ ) ;
349
+ }
331
350
} else {
332
351
this . dispatchEvent (
333
352
newWizardEvent (
@@ -351,13 +370,31 @@ export default class CompasVersionsPlugin extends LitElement {
351
370
] ;
352
371
}
353
372
354
- private async getVersion ( version : string ) {
373
+ private async getVersion ( version : string ) : Promise < void | Element > {
355
374
const type = getTypeFromDocName ( this . docName ) ;
356
- return CompasSclDataService ( )
357
- . getSclDocumentVersion ( type , this . docId , version )
358
- . then ( sclDocument => {
359
- return Promise . resolve ( sclDocument . documentElement ) ;
375
+ const service = CompasSclDataService ( ) ;
376
+
377
+ if ( service . useWebsocket ( ) ) {
378
+ return new Promise ( ( resolve ) => {
379
+ service . getSclDocumentVersionUsingWebsockets (
380
+ this ,
381
+ type ,
382
+ this . docId ,
383
+ version ,
384
+ ( sclDocument ) => {
385
+ resolve ( sclDocument . documentElement ) ;
386
+ } )
360
387
} ) ;
388
+ } else {
389
+ return service
390
+ . getSclDocumentVersionUsingRest ( type , this . docId , version )
391
+ . then ( sclDocument => {
392
+ return Promise . resolve ( < Element > sclDocument . documentElement ) ;
393
+ } )
394
+ . catch ( reason => {
395
+ createLogEvent ( this , reason )
396
+ } ) ;
397
+ }
361
398
}
362
399
363
400
private openEditWizard ( ) : void {
0 commit comments