@@ -79,46 +79,54 @@ 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
+ }
114
+
82
115
export default class UpdateSubstationPlugin extends LitElement {
83
116
doc ! : XMLDocument ;
84
117
85
118
@query ( '#update-substation-plugin-input' ) pluginFileUI ! : HTMLInputElement ;
86
119
87
- updateSubstation ( event : Event ) : void {
120
+ async updateSubstation ( event : Event ) : Promise < void > {
88
121
const file =
89
122
( < 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
- ? find ( this . doc , 'LNode' , identity ( diff . theirs ) ) ===
105
- null && isValidReference ( doc , identity ( diff . theirs ) )
106
- : diff . theirs . tagName === 'Substation' ||
107
- ! tags [ 'SCL' ] . children . includes (
108
- < SCLTag > diff . theirs . tagName
109
- )
110
- : diff . theirs !== null ,
111
- disabled : ( diff : Diff < Element | string > ) : boolean =>
112
- diff . theirs instanceof Element &&
113
- diff . theirs . tagName === 'LNode' &&
114
- ( find ( this . doc , 'LNode' , identity ( diff . theirs ) ) !== null ||
115
- ! isValidReference ( doc , identity ( diff . theirs ) ) ) ,
116
- auto : ( ) : boolean => true ,
117
- }
118
- )
119
- )
120
- ) ;
121
- } ) ;
123
+ if ( ! file ) {
124
+ return ;
125
+ }
126
+ const text = await file . text ( ) ;
127
+ const doc = new DOMParser ( ) . parseFromString ( text , 'application/xml' ) ;
128
+
129
+ mergeSubstation ( this , this . doc , doc ) ;
122
130
this . pluginFileUI . onchange = null ;
123
131
}
124
132
0 commit comments