@@ -3,6 +3,7 @@ import {get, translate} from 'lit-translate';
3
3
import { newLogEvent , newWizardEvent , Wizard } from "../foundation.js" ;
4
4
5
5
import { CompasSclDataService , SDS_NAMESPACE } from "../compas-services/CompasSclDataService.js" ;
6
+ import { createLogEvent } from "../compas-services/foundation.js" ;
6
7
import { getTypeFromDocName , updateDocumentInOpenSCD } from "../compas/foundation.js" ;
7
8
import { getOpenScdElement , styles } from './foundation.js' ;
8
9
@@ -29,7 +30,8 @@ export default class CompasVersionsPlugin extends LitElement {
29
30
CompasSclDataService ( ) . listVersions ( type , this . docId )
30
31
. then ( xmlResponse => {
31
32
this . scls = Array . from ( xmlResponse . querySelectorAll ( 'Item' ) ?? [ ] )
32
- } ) ;
33
+ } )
34
+ . catch ( createLogEvent ) ;
33
35
}
34
36
35
37
confirmRestoreCompas ( version : string ) : void {
@@ -136,29 +138,27 @@ export default class CompasVersionsPlugin extends LitElement {
136
138
` ;
137
139
}
138
140
139
- function fetchScl ( type : string , docId : string , version : string ) {
140
- CompasSclDataService ( ) . getSclDocumentVersion ( type , docId , version )
141
- . then ( response => {
142
- // Copy the SCL Result from the Response and create a new Document from it.
143
- const sclElement = response . querySelectorAll ( "SCL" ) . item ( 0 ) ;
144
- const sclDocument = document . implementation . createDocument ( "" , "" , null ) ;
145
- sclDocument . getRootNode ( ) . appendChild ( sclElement . cloneNode ( true ) ) ;
146
-
147
- updateDocumentInOpenSCD ( sclDocument ) ;
148
- } ) ;
149
- }
150
-
151
141
function openScl ( docName : string , docId : string , version : string ) {
152
142
return function ( ) {
143
+ const openScd = getOpenScdElement ( ) ;
153
144
const type = getTypeFromDocName ( docName ) ;
154
- fetchScl ( type , docId , version ) ;
155
145
156
- const openScd = getOpenScdElement ( ) ;
157
- openScd . dispatchEvent (
158
- newLogEvent ( {
159
- kind : 'info' ,
160
- title : get ( 'compas.versions.restoreVersionSuccess' , { version : version } )
161
- } ) ) ;
146
+ CompasSclDataService ( ) . getSclDocumentVersion ( type , docId , version )
147
+ . then ( response => {
148
+ // Copy the SCL Result from the Response and create a new Document from it.
149
+ const sclElement = response . querySelectorAll ( "SCL" ) . item ( 0 ) ;
150
+ const sclDocument = document . implementation . createDocument ( "" , "" , null ) ;
151
+ sclDocument . getRootNode ( ) . appendChild ( sclElement . cloneNode ( true ) ) ;
152
+
153
+ updateDocumentInOpenSCD ( sclDocument ) ;
154
+
155
+ openScd . dispatchEvent (
156
+ newLogEvent ( {
157
+ kind : 'info' ,
158
+ title : get ( 'compas.versions.restoreVersionSuccess' , { version : version } )
159
+ } ) ) ;
160
+ } )
161
+ . catch ( createLogEvent ) ;
162
162
163
163
// Close the Restore Dialog.
164
164
openScd . dispatchEvent ( newWizardEvent ( ) ) ;
@@ -169,16 +169,20 @@ function openScl(docName: string, docId: string, version: string) {
169
169
170
170
function deleteScl ( docName : string , docId : string ) {
171
171
return function ( ) {
172
+ const openScd = getOpenScdElement ( ) ;
172
173
const type = getTypeFromDocName ( docName ) ;
173
- CompasSclDataService ( ) . deleteSclDocument ( type , docId ) ;
174
174
175
- const openScd = getOpenScdElement ( ) ;
176
- openScd . docId = '' ;
177
- openScd . dispatchEvent (
178
- newLogEvent ( {
179
- kind : 'info' ,
180
- title : get ( 'compas.versions.deleteSuccess' )
181
- } ) ) ;
175
+ CompasSclDataService ( )
176
+ . deleteSclDocument ( type , docId )
177
+ . then ( ( ) => {
178
+ openScd . docId = '' ;
179
+ openScd . dispatchEvent (
180
+ newLogEvent ( {
181
+ kind : 'info' ,
182
+ title : get ( 'compas.versions.deleteSuccess' )
183
+ } ) ) ;
184
+ } )
185
+ . catch ( createLogEvent ) ;
182
186
183
187
// Close the Restore Dialog.
184
188
openScd . dispatchEvent ( newWizardEvent ( ) ) ;
@@ -189,15 +193,19 @@ function deleteScl(docName: string, docId: string) {
189
193
190
194
function deleteSclVersion ( docName : string , docId : string , version : string ) {
191
195
return function ( ) {
196
+ const openScd = getOpenScdElement ( ) ;
192
197
const type = getTypeFromDocName ( docName ) ;
193
- CompasSclDataService ( ) . deleteSclDocumentVersion ( type , docId , version ) ;
194
198
195
- const openScd = getOpenScdElement ( ) ;
196
- openScd . dispatchEvent (
197
- newLogEvent ( {
198
- kind : 'info' ,
199
- title : get ( 'compas.versions.deleteVersionSuccess' , { version : version } )
200
- } ) ) ;
199
+ CompasSclDataService ( )
200
+ . deleteSclDocumentVersion ( type , docId , version )
201
+ . then ( ( ) => {
202
+ openScd . dispatchEvent (
203
+ newLogEvent ( {
204
+ kind : 'info' ,
205
+ title : get ( 'compas.versions.deleteVersionSuccess' , { version : version } )
206
+ } ) ) ;
207
+ } )
208
+ . catch ( createLogEvent ) ;
201
209
202
210
// Close the Restore Dialog.
203
211
openScd . dispatchEvent ( newWizardEvent ( ) ) ;
0 commit comments