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