@@ -9,14 +9,19 @@ import '@material/mwc-list/mwc-list-item';
9
9
import '@material/mwc-list/mwc-check-list-item' ;
10
10
11
11
import { newLogEvent , newWizardEvent , Wizard } from "../foundation.js" ;
12
+ import { MultiSelectedEvent } from "@material/mwc-list/mwc-list-foundation" ;
12
13
13
14
import { CompasSclDataService , SDS_NAMESPACE } from "../compas-services/CompasSclDataService.js" ;
14
15
import { createLogEvent } from "../compas-services/foundation.js" ;
15
- import { getTypeFromDocName , updateDocumentInOpenSCD } from "../compas/foundation.js" ;
16
- import { getElementByName , getOpenScdElement , styles } from './foundation.js' ;
16
+ import {
17
+ dispatchEventOnOpenScd ,
18
+ getOpenScdElement ,
19
+ getTypeFromDocName ,
20
+ updateDocumentInOpenSCD
21
+ } from "../compas/foundation.js" ;
17
22
import { addVersionToCompasWizard } from "../compas/CompasUploadVersion.js" ;
18
23
import { compareWizard } from "../compas/CompasCompareDialog.js" ;
19
- import { MultiSelectedEvent } from "@material/mwc-list/mwc-list- foundation" ;
24
+ import { getElementByName , styles } from './ foundation.js' ;
20
25
21
26
// Save the selection for the current document.
22
27
let selectedVersionsOnCompasVersionsEditor : Set < number > = new Set ( ) ;
@@ -38,7 +43,7 @@ export default class CompasVersionsPlugin extends LitElement {
38
43
39
44
// Add event to get a notification when a new document is opened.
40
45
const openSCD = getOpenScdElement ( ) ;
41
- if ( openSCD ) {
46
+ if ( openSCD !== null ) {
42
47
openSCD . addEventListener ( 'open-doc' , this . resetSelection ) ;
43
48
}
44
49
}
@@ -273,23 +278,25 @@ export default class CompasVersionsPlugin extends LitElement {
273
278
function confirmDeleteCompasWizard ( docName : string , docId : string ) : Wizard {
274
279
function deleteScl ( docName : string , docId : string ) {
275
280
return function ( ) {
276
- const openScd = getOpenScdElement ( ) ;
277
281
const type = getTypeFromDocName ( docName ) ;
278
282
279
283
CompasSclDataService ( )
280
284
. deleteSclDocument ( type , docId )
281
285
. then ( ( ) => {
282
- openScd . docId = '' ;
283
- openScd . dispatchEvent (
284
- newLogEvent ( {
285
- kind : 'info' ,
286
- title : get ( 'compas.versions.deleteSuccess' )
287
- } ) ) ;
286
+ const openScd = getOpenScdElement ( ) ;
287
+ if ( openScd !== null ) {
288
+ openScd . docId = '' ;
289
+ openScd . dispatchEvent (
290
+ newLogEvent ( {
291
+ kind : 'info' ,
292
+ title : get ( 'compas.versions.deleteSuccess' )
293
+ } ) ) ;
294
+ }
288
295
} )
289
296
. catch ( createLogEvent ) ;
290
297
291
298
// Close the Restore Dialog.
292
- openScd . dispatchEvent ( newWizardEvent ( ) ) ;
299
+ dispatchEventOnOpenScd ( newWizardEvent ( ) ) ;
293
300
294
301
return [ ] ;
295
302
}
@@ -313,14 +320,13 @@ function confirmDeleteCompasWizard(docName: string, docId: string): Wizard {
313
320
function confirmRestoreVersionCompasWizard ( docName : string , docId : string , version : string ) : Wizard {
314
321
function openScl ( docName : string , docId : string , version : string ) {
315
322
return function ( ) {
316
- const openScd = getOpenScdElement ( ) ;
317
323
const type = getTypeFromDocName ( docName ) ;
318
324
319
325
CompasSclDataService ( ) . getSclDocumentVersion ( type , docId , version )
320
326
. then ( sclDocument => {
321
327
updateDocumentInOpenSCD ( sclDocument ) ;
322
328
323
- openScd . dispatchEvent (
329
+ dispatchEventOnOpenScd (
324
330
newLogEvent ( {
325
331
kind : 'info' ,
326
332
title : get ( 'compas.versions.restoreVersionSuccess' , { version : version } )
@@ -329,7 +335,7 @@ function confirmRestoreVersionCompasWizard(docName: string, docId: string, versi
329
335
. catch ( createLogEvent ) ;
330
336
331
337
// Close the Restore Dialog.
332
- openScd . dispatchEvent ( newWizardEvent ( ) ) ;
338
+ dispatchEventOnOpenScd ( newWizardEvent ( ) ) ;
333
339
334
340
return [ ] ;
335
341
}
@@ -353,13 +359,12 @@ function confirmRestoreVersionCompasWizard(docName: string, docId: string, versi
353
359
function confirmDeleteVersionCompasWizard ( docName : string , docId : string , version : string ) : Wizard {
354
360
function deleteSclVersion ( docName : string , docId : string , version : string ) {
355
361
return function ( ) {
356
- const openScd = getOpenScdElement ( ) ;
357
362
const type = getTypeFromDocName ( docName ) ;
358
363
359
364
CompasSclDataService ( )
360
365
. deleteSclDocumentVersion ( type , docId , version )
361
366
. then ( ( ) => {
362
- openScd . dispatchEvent (
367
+ dispatchEventOnOpenScd (
363
368
newLogEvent ( {
364
369
kind : 'info' ,
365
370
title : get ( 'compas.versions.deleteVersionSuccess' , { version : version } )
@@ -368,7 +373,7 @@ function confirmDeleteVersionCompasWizard(docName: string, docId: string, versio
368
373
. catch ( createLogEvent ) ;
369
374
370
375
// Close the Restore Dialog.
371
- openScd . dispatchEvent ( newWizardEvent ( ) ) ;
376
+ dispatchEventOnOpenScd ( newWizardEvent ( ) ) ;
372
377
373
378
return [ ] ;
374
379
}
0 commit comments