@@ -8,7 +8,7 @@ import {newLogEvent, newPendingStateEvent, newWizardEvent, Wizard, WizardInput}
8
8
import { CompasChangeSetRadiogroup } from "./CompasChangeSet.js" ;
9
9
import { CompasScltypeRadiogroup } from "./CompasScltypeRadiogroup.js" ;
10
10
import { CompasSclDataService } from "../compas-services/CompasSclDataService.js" ;
11
- import { createLogEvent } from "../compas-services/foundation.js" ;
11
+ import { createLogEvent , NOT_FOUND_ERROR } from "../compas-services/foundation.js" ;
12
12
import { getOpenScdElement , getTypeFromDocName , stripExtensionFromName , updateDocumentInOpenSCD } from "./foundation.js" ;
13
13
import './CompasChangeSet.js' ;
14
14
import './CompasScltypeRadiogroup.js' ;
@@ -20,6 +20,30 @@ export class CompasSaveTo extends LitElement {
20
20
@property ( { type : String } )
21
21
docId ! : string ;
22
22
23
+ @property ( { type : Boolean } )
24
+ existInCompas ?: boolean ;
25
+
26
+ firstUpdated ( ) : void {
27
+ this . checkExistInCompas ( ) ;
28
+ }
29
+
30
+ checkExistInCompas ( ) : void {
31
+ if ( this . docId ) {
32
+ const docType = getTypeFromDocName ( this . docName ) ;
33
+ // Use the versions call to check if any exist, because then the document also exists
34
+ // And it safes bandwidth not to retrieve the whole document.
35
+ CompasSclDataService ( ) . listVersions ( docType , this . docId )
36
+ . then ( ( ) => this . existInCompas = true )
37
+ . catch ( reason => {
38
+ if ( reason . type && reason . type === NOT_FOUND_ERROR ) {
39
+ this . existInCompas = false ;
40
+ }
41
+ } ) ;
42
+ } else {
43
+ this . existInCompas = false ;
44
+ }
45
+ }
46
+
23
47
getNameField ( ) : TextFieldBase {
24
48
return < TextFieldBase > this . shadowRoot ! . querySelector ( 'mwc-textfield[id="name"]' ) ;
25
49
}
@@ -39,7 +63,7 @@ export class CompasSaveTo extends LitElement {
39
63
}
40
64
41
65
valid ( ) : boolean {
42
- if ( ! this . docId ) {
66
+ if ( ! this . existInCompas ) {
43
67
return this . getNameField ( ) . checkValidity ( )
44
68
&& this . getSclTypeRadioGroup ( ) . valid ( ) ;
45
69
}
@@ -108,7 +132,7 @@ export class CompasSaveTo extends LitElement {
108
132
}
109
133
110
134
async saveToCompas ( wizard : Element , docId : string , docName : string , doc : XMLDocument ) : Promise < void > {
111
- if ( ! docId ) {
135
+ if ( ! this . existInCompas ) {
112
136
await this . addSclToCompas ( wizard , doc ) ;
113
137
} else {
114
138
await this . updateSclInCompas ( wizard , docId , docName , doc ) ;
@@ -126,7 +150,14 @@ export class CompasSaveTo extends LitElement {
126
150
}
127
151
128
152
render ( ) : TemplateResult {
129
- if ( ! this . docId ) {
153
+ if ( this . existInCompas === undefined ) {
154
+ return html `
155
+ < mwc-list >
156
+ < mwc-list-item > ${ translate ( "compas.loading" ) } </ mwc-list-item >
157
+ </ mwc-list > `
158
+ }
159
+
160
+ if ( ! this . existInCompas ) {
130
161
return html `
131
162
< mwc-textfield dialogInitialFocus id ="name " label ="${ translate ( 'scl.name' ) } "
132
163
value ="${ this . docName } " required >
@@ -137,8 +168,7 @@ export class CompasSaveTo extends LitElement {
137
168
${ this . renderCommentTextField ( ) }
138
169
` ;
139
170
}
140
-
141
- return html `
171
+ return html `
142
172
< compas-changeset-radiogroup > </ compas-changeset-radiogroup >
143
173
144
174
${ this . renderCommentTextField ( ) }
0 commit comments