@@ -79,51 +79,57 @@ export function isValidReference(
79
79
) ;
80
80
}
81
81
82
+ export function mergeSubstation ( currentDoc : Document , docWithSubstation : Document ) : void {
83
+ // FIXME: Dirty hack should not be necessary!
84
+ document . querySelector ( 'open-scd' ) ! . dispatchEvent (
85
+ newWizardEvent (
86
+ mergeWizard (
87
+ // FIXME: doesn't work with multiple Substations!
88
+ currentDoc . documentElement ,
89
+ docWithSubstation . documentElement ,
90
+ {
91
+ title : get ( 'updatesubstation.title' ) ,
92
+ selected : ( diff : Diff < Element | string > ) : boolean =>
93
+ diff . theirs instanceof Element
94
+ ? diff . theirs . tagName === 'LNode'
95
+ ? currentDoc . querySelector (
96
+ selector ( 'LNode' , identity ( diff . theirs ) )
97
+ ) === null &&
98
+ isValidReference ( docWithSubstation , identity ( diff . theirs ) )
99
+ : diff . theirs . tagName === 'Substation' ||
100
+ ! tags [ 'SCL' ] . children . includes (
101
+ < SCLTag > diff . theirs . tagName
102
+ )
103
+ : diff . theirs !== null ,
104
+ disabled : ( diff : Diff < Element | string > ) : boolean =>
105
+ diff . theirs instanceof Element &&
106
+ diff . theirs . tagName === 'LNode' &&
107
+ ( currentDoc . querySelector (
108
+ selector ( 'LNode' , identity ( diff . theirs ) )
109
+ ) !== null ||
110
+ ! isValidReference ( docWithSubstation , identity ( diff . theirs ) ) ) ,
111
+ auto : ( ) : boolean => true ,
112
+ }
113
+ )
114
+ )
115
+ ) ;
116
+ }
117
+
82
118
export default class UpdateSubstationPlugin extends LitElement {
83
119
doc ! : XMLDocument ;
84
120
85
- @query ( '#update-substation-plugin-input' ) pluginFileUI ! : HTMLInputElement ;
121
+ @query ( '#update-substation-plugin-input' )
122
+ pluginFileUI ! : HTMLInputElement ;
123
+
124
+ async updateSubstation ( event : Event ) : Promise < void > {
125
+ const file = ( < HTMLInputElement | null > event . target ) ?. files ?. item ( 0 ) ?? false ;
126
+ if ( ! file ) {
127
+ return ;
128
+ }
86
129
87
- updateSubstation ( event : Event ) : void {
88
- const file =
89
- ( < HTMLInputElement | null > event . target ) ?. files ?. item ( 0 ) ?? false ;
90
- if ( file )
91
- file . text ( ) . then ( text => {
92
- const doc = new DOMParser ( ) . parseFromString ( text , 'application/xml' ) ;
93
- // FIXME: Dirty hack should not be necessary!
94
- document . querySelector ( 'open-scd' ) ! . dispatchEvent (
95
- newWizardEvent (
96
- mergeWizard (
97
- // FIXME: doesn't work with multiple Substations!
98
- this . doc . documentElement ,
99
- doc . documentElement ,
100
- {
101
- title : get ( 'updatesubstation.title' ) ,
102
- selected : ( diff : Diff < Element | string > ) : boolean =>
103
- diff . theirs instanceof Element
104
- ? diff . theirs . tagName === 'LNode'
105
- ? this . doc . querySelector (
106
- selector ( 'LNode' , identity ( diff . theirs ) )
107
- ) === null &&
108
- isValidReference ( doc , identity ( diff . theirs ) )
109
- : diff . theirs . tagName === 'Substation' ||
110
- ! tags [ 'SCL' ] . children . includes (
111
- < SCLTag > diff . theirs . tagName
112
- )
113
- : diff . theirs !== null ,
114
- disabled : ( diff : Diff < Element | string > ) : boolean =>
115
- diff . theirs instanceof Element &&
116
- diff . theirs . tagName === 'LNode' &&
117
- ( this . doc . querySelector (
118
- selector ( 'LNode' , identity ( diff . theirs ) )
119
- ) !== null ||
120
- ! isValidReference ( doc , identity ( diff . theirs ) ) ) ,
121
- auto : ( ) : boolean => true ,
122
- }
123
- )
124
- )
125
- ) ;
126
- } ) ;
130
+ const text = await file . text ( )
131
+ const doc = new DOMParser ( ) . parseFromString ( text , 'application/xml' ) ;
132
+ mergeSubstation ( this . doc , doc ) ;
127
133
this . pluginFileUI . onchange = null ;
128
134
}
129
135
@@ -132,11 +138,9 @@ export default class UpdateSubstationPlugin extends LitElement {
132
138
}
133
139
134
140
render ( ) : TemplateResult {
135
- return html `<input @click = ${ ( event : MouseEvent ) =>
136
- ( ( < HTMLInputElement > event . target ) . value = '' ) } @change = ${ ( e : Event ) =>
137
- this . updateSubstation (
138
- e
139
- ) } id= "update-substation-plugin-input" accept = ".sed,.scd,.ssd,.iid,.cid" type = "file" > </ input> `;
141
+ return html `<input @click = ${ ( event : MouseEvent ) => ( ( < HTMLInputElement > event . target ) . value = '' ) }
142
+ @change = ${ this . updateSubstation }
143
+ id= "update-substation-plugin-input" accept = ".sed,.scd,.ssd,.iid,.cid" type = "file" > </ input> ` ;
140
144
}
141
145
142
146
static styles = css `
0 commit comments