@@ -21,39 +21,47 @@ import '../WizardDivider.js';
21
21
import './CompasSclTypeList.js' ;
22
22
import './CompasSclList.js' ;
23
23
24
+ import { nothing } from 'lit-html' ;
25
+ import { buildDocName } from './foundation.js' ;
26
+
24
27
/* Event that will be used when an SCL Document is retrieved. */
25
28
export interface DocRetrievedDetail {
26
29
localFile : boolean ;
27
30
doc : Document ;
28
31
docName ?: string ;
32
+ docId ?: string ;
29
33
}
30
34
export type DocRetrievedEvent = CustomEvent < DocRetrievedDetail > ;
31
35
export function newDocRetrievedEvent (
32
36
localFile : boolean ,
33
37
doc : Document ,
34
- docName ?: string
38
+ docName ?: string ,
39
+ docId ?: string
35
40
) : DocRetrievedEvent {
36
41
return new CustomEvent < DocRetrievedDetail > ( 'doc-retrieved' , {
37
42
bubbles : true ,
38
43
composed : true ,
39
- detail : { localFile, doc, docName } ,
44
+ detail : { localFile, doc, docName, docId } ,
40
45
} ) ;
41
46
}
42
47
43
48
@customElement ( 'compas-open' )
44
49
export default class CompasOpenElement extends LitElement {
45
50
@property ( )
46
51
selectedType : string | undefined ;
52
+ @property ( )
53
+ allowLocalFile = true ;
47
54
48
55
@query ( '#scl-file' )
49
56
private sclFileUI ! : HTMLInputElement ;
50
57
51
- private async getSclDocument ( id ?: string ) : Promise < void > {
52
- const sclDocument = await CompasSclDataService ( )
53
- . getSclDocument ( this . selectedType ?? '' , id ?? '' )
58
+ private async getSclDocument ( docId ?: string ) : Promise < void > {
59
+ const doc = await CompasSclDataService ( )
60
+ . getSclDocument ( this . selectedType ?? '' , docId ?? '' )
54
61
. catch ( reason => createLogEvent ( this , reason ) ) ;
55
- if ( sclDocument instanceof Document ) {
56
- this . dispatchEvent ( newDocRetrievedEvent ( false , sclDocument ) ) ;
62
+ if ( doc instanceof Document ) {
63
+ const docName = buildDocName ( doc . documentElement ) ;
64
+ this . dispatchEvent ( newDocRetrievedEvent ( false , doc , docName , docId ) ) ;
57
65
}
58
66
}
59
67
@@ -66,7 +74,6 @@ export default class CompasOpenElement extends LitElement {
66
74
const doc = new DOMParser ( ) . parseFromString ( text , 'application/xml' ) ;
67
75
68
76
this . dispatchEvent ( newDocRetrievedEvent ( true , doc , docName ) ) ;
69
- this . sclFileUI . onchange = null ;
70
77
}
71
78
72
79
private renderFileSelect ( ) : TemplateResult {
@@ -84,10 +91,8 @@ export default class CompasOpenElement extends LitElement {
84
91
< mwc-button
85
92
label ="${ translate ( 'compas.open.selectFileButton' ) } "
86
93
@click =${ ( ) => {
87
- const input = < HTMLInputElement | null > (
88
- this . shadowRoot ! . querySelector ( '#scl-file' )
89
- ) ;
90
- input ?. click ( ) ;
94
+ this . sclFileUI . value = '' ;
95
+ this . sclFileUI . click ( ) ;
91
96
} }
92
97
>
93
98
</ mwc-button >
@@ -129,11 +134,13 @@ export default class CompasOpenElement extends LitElement {
129
134
130
135
render ( ) : TemplateResult {
131
136
return html `
132
- < wizard-divider > </ wizard-divider >
133
- < section >
134
- < h3 > ${ translate ( 'compas.open.localTitle' ) } </ h3 >
135
- ${ this . renderFileSelect ( ) }
136
- </ section >
137
+ ${ this . allowLocalFile
138
+ ? html `< wizard-divider > </ wizard-divider >
139
+ < section >
140
+ < h3 > ${ translate ( 'compas.open.localTitle' ) } </ h3 >
141
+ ${ this . renderFileSelect ( ) }
142
+ </ section > `
143
+ : nothing }
137
144
< wizard-divider > </ wizard-divider >
138
145
< section >
139
146
< h3 > ${ translate ( 'compas.open.compasTitle' ) } </ h3 >
0 commit comments