@@ -18,7 +18,9 @@ import {
18
18
Create ,
19
19
createElement ,
20
20
Delete ,
21
+ identity ,
21
22
newActionEvent ,
23
+ selector ,
22
24
} from '../../foundation.js' ;
23
25
import {
24
26
SampledValuesSelectEvent ,
@@ -50,6 +52,21 @@ const fcdaReferences = [
50
52
'daName' ,
51
53
] ;
52
54
55
+ /**
56
+ * Get all the FCDA attributes containing values from a specific element.
57
+ * @param elementContainingFcdaReferences - The element to use
58
+ * @returns FCDA references
59
+ */
60
+ function getFcdaReferences ( elementContainingFcdaReferences : Element ) : string {
61
+ return fcdaReferences
62
+ . map ( fcdaRef =>
63
+ elementContainingFcdaReferences . getAttribute ( fcdaRef )
64
+ ? `[${ fcdaRef } ="${ elementContainingFcdaReferences . getAttribute ( fcdaRef ) } "]`
65
+ : ''
66
+ )
67
+ . join ( '' ) ;
68
+ }
69
+
53
70
/**
54
71
* Internal persistent state, so it's not lost when
55
72
* subscribing / unsubscribing.
@@ -92,13 +109,13 @@ export class SubscriberIEDList extends LitElement {
92
109
this . onSampledValuesDataSetEvent = this . onSampledValuesDataSetEvent . bind ( this ) ;
93
110
this . onIEDSubscriptionEvent = this . onIEDSubscriptionEvent . bind ( this ) ;
94
111
95
- const openScdElement = document . querySelector ( 'open-scd ') ;
96
- if ( openScdElement ) {
97
- openScdElement . addEventListener (
112
+ const parentDiv = this . closest ( 'div[id="containerTemplates"] ') ;
113
+ if ( parentDiv ) {
114
+ parentDiv . addEventListener (
98
115
'sampled-values-select' ,
99
116
this . onSampledValuesDataSetEvent
100
117
) ;
101
- openScdElement . addEventListener (
118
+ parentDiv . addEventListener (
102
119
'ied-smv-subscription' ,
103
120
this . onIEDSubscriptionEvent
104
121
) ;
@@ -143,13 +160,7 @@ export class SubscriberIEDList extends LitElement {
143
160
if (
144
161
inputs . querySelector (
145
162
`ExtRef[iedName=${ localState . currentSampledValuesIEDName } ]` +
146
- `${ fcdaReferences
147
- . map ( fcdaRef =>
148
- fcda . getAttribute ( fcdaRef )
149
- ? `[${ fcdaRef } ="${ fcda . getAttribute ( fcdaRef ) } "]`
150
- : ''
151
- )
152
- . join ( '' ) } `
163
+ `${ getFcdaReferences ( fcda ) } `
153
164
)
154
165
) {
155
166
numberOfLinkedExtRefs ++ ;
@@ -167,7 +178,7 @@ export class SubscriberIEDList extends LitElement {
167
178
}
168
179
169
180
if (
170
- numberOfLinkedExtRefs = =
181
+ numberOfLinkedExtRefs > =
171
182
localState . currentDataset ! . querySelectorAll ( 'FCDA' ) . length
172
183
) {
173
184
localState . subscribedIeds . push ( { element : ied } ) ;
@@ -216,13 +227,7 @@ export class SubscriberIEDList extends LitElement {
216
227
if (
217
228
! inputsElement ! . querySelector (
218
229
`ExtRef[iedName=${ localState . currentSampledValuesIEDName } ]` +
219
- `${ fcdaReferences
220
- . map ( fcdaRef =>
221
- fcda . getAttribute ( fcdaRef )
222
- ? `[${ fcdaRef } ="${ fcda . getAttribute ( fcdaRef ) } "]`
223
- : ''
224
- )
225
- . join ( '' ) } `
230
+ `${ getFcdaReferences ( fcda ) } `
226
231
)
227
232
) {
228
233
const extRef = createElement ( ied . ownerDocument , 'ExtRef' , {
@@ -271,13 +276,7 @@ export class SubscriberIEDList extends LitElement {
271
276
localState . currentDataset ! . querySelectorAll ( 'FCDA' ) . forEach ( fcda => {
272
277
const extRef = inputs . querySelector (
273
278
`ExtRef[iedName=${ localState . currentSampledValuesIEDName } ]` +
274
- `${ fcdaReferences
275
- . map ( fcdaRef =>
276
- fcda . getAttribute ( fcdaRef )
277
- ? `[${ fcdaRef } ="${ fcda . getAttribute ( fcdaRef ) } "]`
278
- : ''
279
- )
280
- . join ( '' ) } `
279
+ `${ getFcdaReferences ( fcda ) } `
281
280
) ;
282
281
283
282
if ( extRef ) actions . push ( { old : { parent : inputs , element : extRef } } ) ;
@@ -287,7 +286,7 @@ export class SubscriberIEDList extends LitElement {
287
286
this . dispatchEvent (
288
287
newActionEvent ( {
289
288
title : 'Disconnect' ,
290
- actions,
289
+ actions : this . extendDeleteActions ( actions ) ,
291
290
} )
292
291
) ;
293
292
@@ -299,6 +298,48 @@ export class SubscriberIEDList extends LitElement {
299
298
) ;
300
299
}
301
300
301
+ /**
302
+ * Creating Delete actions in case Inputs elements are empty.
303
+ * @param extRefDeleteActions - All Delete actions for ExtRefs.
304
+ * @returns Possible delete actions for empty Inputs elements.
305
+ */
306
+ private extendDeleteActions ( extRefDeleteActions : Delete [ ] ) : Delete [ ] {
307
+ if ( ! extRefDeleteActions . length ) return [ ] ;
308
+
309
+ // Initialize with the already existing ExtRef Delete actions.
310
+ const extendedDeleteActions : Delete [ ] = extRefDeleteActions ;
311
+ const inputsMap : Record < string , Element > = { } ;
312
+
313
+ for ( const extRefDeleteAction of extRefDeleteActions ) {
314
+ const extRef = < Element > extRefDeleteAction . old . element ;
315
+ const inputsElement = < Element > extRefDeleteAction . old . parent ;
316
+
317
+ const id = identity ( inputsElement ) ;
318
+ if ( ! inputsMap [ id ] ) inputsMap [ id ] = < Element > ( inputsElement . cloneNode ( true ) ) ;
319
+
320
+ const linkedExtRef = inputsMap [ id ] . querySelector ( `ExtRef[iedName=${ extRef . getAttribute ( 'iedName' ) } ]` +
321
+ `${ getFcdaReferences ( extRef ) } ` ) ;
322
+
323
+ if ( linkedExtRef ) inputsMap [ id ] . removeChild ( linkedExtRef ) ;
324
+ }
325
+
326
+ // create delete action for each empty inputs
327
+ Object . entries ( inputsMap ) . forEach ( ( [ key , value ] ) => {
328
+ if ( value . children . length ! == 0 ) {
329
+ const doc = extRefDeleteActions [ 0 ] . old . parent . ownerDocument ! ;
330
+ const inputs = doc . querySelector ( selector ( 'Inputs' , key ) ) ;
331
+
332
+ if ( inputs && inputs . parentElement ) {
333
+ extendedDeleteActions . push ( {
334
+ old : { parent : inputs . parentElement , element : inputs } ,
335
+ } ) ;
336
+ }
337
+ }
338
+ } ) ;
339
+
340
+ return extendedDeleteActions ;
341
+ }
342
+
302
343
protected updated ( ) : void {
303
344
if ( this . subscriberWrapper ) {
304
345
this . subscriberWrapper . scrollTo ( 0 , 0 ) ;
@@ -309,6 +350,9 @@ export class SubscriberIEDList extends LitElement {
309
350
const partialSubscribedIeds = localState . availableIeds . filter (
310
351
ied => ied . partial
311
352
) ;
353
+ const availableIeds = localState . availableIeds . filter (
354
+ ied => ! ied . partial
355
+ ) ;
312
356
const smvControlName =
313
357
localState . currentSampledValuesControl ?. getAttribute ( 'name' ) ?? undefined ;
314
358
@@ -372,8 +416,8 @@ export class SubscriberIEDList extends LitElement {
372
416
>
373
417
</ mwc- lis t- item>
374
418
<li divider role= "separator" > </ li>
375
- ${ localState . availableIeds . length > 0
376
- ? localState . availableIeds . map (
419
+ ${ availableIeds . length > 0
420
+ ? availableIeds . map (
377
421
ied =>
378
422
html `<ied- element
379
423
.status = ${ SubscribeStatus . None }
0 commit comments