@@ -18,16 +18,18 @@ import {
18
18
Create ,
19
19
createElement ,
20
20
Delete ,
21
- identity ,
22
21
newActionEvent ,
23
- selector ,
24
22
} from '../../foundation.js' ;
25
23
import {
26
24
SampledValuesSelectEvent ,
27
25
IEDSampledValuesSubscriptionEvent ,
28
26
styles ,
29
27
SubscribeStatus ,
30
28
} from './foundation.js' ;
29
+ import {
30
+ emptyInputsDeleteActions ,
31
+ getFcdaReferences
32
+ } from "../../foundation/ied.js" ;
31
33
32
34
/**
33
35
* An IED within this IED list has 2 properties:
@@ -39,33 +41,6 @@ interface IED {
39
41
partial ?: boolean ;
40
42
}
41
43
42
- /**
43
- * All available FCDA references that are used to link ExtRefs.
44
- */
45
- const fcdaReferences = [
46
- 'ldInst' ,
47
- 'lnClass' ,
48
- 'lnInst' ,
49
- 'prefix' ,
50
- 'doName' ,
51
- 'daName' ,
52
- ] ;
53
-
54
- /**
55
- * Get all the FCDA attributes containing values from a specific element.
56
- * @param elementContainingFcdaReferences - The element to use
57
- * @returns FCDA references
58
- */
59
- function getFcdaReferences ( elementContainingFcdaReferences : Element ) : string {
60
- return fcdaReferences
61
- . map ( fcdaRef =>
62
- elementContainingFcdaReferences . getAttribute ( fcdaRef )
63
- ? `[${ fcdaRef } ="${ elementContainingFcdaReferences . getAttribute ( fcdaRef ) } "]`
64
- : ''
65
- )
66
- . join ( '' ) ;
67
- }
68
-
69
44
/** An sub element for subscribing and unsubscribing IEDs to Sampled Values messages. */
70
45
@customElement ( 'subscriber-ied-list-smv' )
71
46
export class SubscriberIEDListSmv extends LitElement {
@@ -261,56 +236,17 @@ export class SubscriberIEDListSmv extends LitElement {
261
236
} ) ;
262
237
} ) ;
263
238
239
+ // Check if empty Input Element should also be removed.
240
+ actions . push ( ...emptyInputsDeleteActions ( actions ) ) ;
241
+
264
242
this . dispatchEvent (
265
243
newActionEvent ( {
266
244
title : 'Disconnect' ,
267
- actions : this . extendDeleteActions ( actions ) ,
245
+ actions : actions ,
268
246
} )
269
247
) ;
270
248
}
271
249
272
- /**
273
- * Creating Delete actions in case Inputs elements are empty.
274
- * @param extRefDeleteActions - All Delete actions for ExtRefs.
275
- * @returns Possible delete actions for empty Inputs elements.
276
- */
277
- private extendDeleteActions ( extRefDeleteActions : Delete [ ] ) : Delete [ ] {
278
- if ( ! extRefDeleteActions . length ) return [ ] ;
279
-
280
- // Initialize with the already existing ExtRef Delete actions.
281
- const extendedDeleteActions : Delete [ ] = extRefDeleteActions ;
282
- const inputsMap : Record < string , Element > = { } ;
283
-
284
- for ( const extRefDeleteAction of extRefDeleteActions ) {
285
- const extRef = < Element > extRefDeleteAction . old . element ;
286
- const inputsElement = < Element > extRefDeleteAction . old . parent ;
287
-
288
- const id = identity ( inputsElement ) ;
289
- if ( ! inputsMap [ id ] ) inputsMap [ id ] = < Element > ( inputsElement . cloneNode ( true ) ) ;
290
-
291
- const linkedExtRef = inputsMap [ id ] . querySelector ( `ExtRef[iedName=${ extRef . getAttribute ( 'iedName' ) } ]` +
292
- `${ getFcdaReferences ( extRef ) } ` ) ;
293
-
294
- if ( linkedExtRef ) inputsMap [ id ] . removeChild ( linkedExtRef ) ;
295
- }
296
-
297
- // create delete action for each empty inputs
298
- Object . entries ( inputsMap ) . forEach ( ( [ key , value ] ) => {
299
- if ( value . children . length ! == 0 ) {
300
- const doc = extRefDeleteActions [ 0 ] . old . parent . ownerDocument ! ;
301
- const inputs = doc . querySelector ( selector ( 'Inputs' , key ) ) ;
302
-
303
- if ( inputs && inputs . parentElement ) {
304
- extendedDeleteActions . push ( {
305
- old : { parent : inputs . parentElement , element : inputs } ,
306
- } ) ;
307
- }
308
- }
309
- } ) ;
310
-
311
- return extendedDeleteActions ;
312
- }
313
-
314
250
protected updated ( ) : void {
315
251
if ( this . subscriberWrapper ) {
316
252
this . subscriberWrapper . scrollTo ( 0 , 0 ) ;
0 commit comments