@@ -21,56 +21,63 @@ import {
21
21
import { createAddressesWizard } from './createAddresses.js' ;
22
22
import { SupportedCdcType , supportedCdcTypes } from '../foundation/cdc.js' ;
23
23
import { PROTOCOL_104_PRIVATE } from '../foundation/private.js' ;
24
- import { getDoElements , getTypeAttribute } from '../foundation/foundation.js' ;
24
+ import {
25
+ getCdcValueFromDOElement ,
26
+ getDoElements ,
27
+ } from '../foundation/foundation.js' ;
25
28
26
29
/**
27
- * Check if there are DO Elements that aren't initiated and are supported by the 104 protocol available .
30
+ * Check if the passed DO Element is supported by the 104 protocol and isn't initiated .
28
31
*
29
- * @param parent - The parent element of the child, mainly needed to link the LN Element to the DO Elements .
30
- * @param child - The child to check if it should still be displayed in the finder list .
32
+ * @param lnElement - The LN Element used to search for Address Element below DOI, if available .
33
+ * @param doElement - The DO Element to check.
31
34
*/
32
- function filterAvailableDOElements ( parent : Element , child : Element ) : boolean {
33
- if ( child . tagName === 'DO' ) {
34
- // First check if this DO Element is supported by the 104 Protocol.
35
- const doType = getTypeAttribute ( child ) ?? '' ;
36
- const doTypeElement = child . ownerDocument . querySelector (
37
- `DOType[id="${ doType } "]`
38
- ) ;
39
- const cdc = doTypeElement ?. getAttribute ( 'cdc' ) ?? '' ;
40
- if ( ! supportedCdcTypes . includes ( < SupportedCdcType > cdc ) ) {
41
- return false ;
42
- }
35
+ function filterAvailableDOElements (
36
+ lnElement : Element ,
37
+ doElement : Element
38
+ ) : boolean {
39
+ // First check if this DO Element is supported by the 104 Protocol.
40
+ const cdc = getCdcValueFromDOElement ( doElement ) ?? '' ;
41
+ if ( ! supportedCdcTypes . includes ( < SupportedCdcType > cdc ) ) {
42
+ return false ;
43
+ }
43
44
44
- // Use the parent (LN) to find the DOI that's linked to the DO Element
45
- const doName = getNameAttribute ( child ) ;
46
- return (
47
- Array . from (
48
- parent . querySelectorAll (
49
- `:scope > DOI[name="${ doName } "] DAI > Private[type="${ PROTOCOL_104_PRIVATE } "] > Address`
50
- )
51
- ) . length <= 0
52
- ) ;
53
- } else {
54
- // For other elements create a list of LN Elements for processing the DO Element from the LN Elements.
55
- let lnElements : Element [ ] ;
56
- if ( [ 'LN0' , 'LN' ] . includes ( child . tagName ) ) {
57
- lnElements = [ child ] ;
58
- } else {
59
- // For the other Elements we will just retrieve all the DOI Elements.
60
- lnElements = Array . from ( child . querySelectorAll ( 'LN0, LN' ) ) ;
61
- }
45
+ // Use the parent (LN) to find the DOI that's linked to the DO Element
46
+ // And check if there is DOI if it doesn't already contain Address Elements for the 104 Protocol.
47
+ const doName = getNameAttribute ( doElement ) ;
48
+ return (
49
+ lnElement . querySelectorAll (
50
+ `:scope > DOI[name="${ doName } "] DAI > Private[type="${ PROTOCOL_104_PRIVATE } "] > Address`
51
+ ) . length <= 0
52
+ ) ;
53
+ }
62
54
63
- // If after filtering there are still LN/DO Element(s) to be displayed, this element will be included.
64
- return (
65
- lnElements . filter (
66
- lnElement =>
67
- // Check if there are available DO Elements that aren't initiated and supported by 104 protocol
68
- getDoElements ( lnElement ) . filter ( doElement =>
69
- filterAvailableDOElements ( lnElement , doElement )
70
- ) . length > 0
71
- ) . length > 0
72
- ) ;
55
+ /**
56
+ * Check if there are DO Elements that aren't initiated and are supported by the 104 protocol. If this is the
57
+ * case the Element can be shown in the Finder.
58
+ *
59
+ * @param child - The child to check if it should still be displayed in the finder list.
60
+ */
61
+ function filterAvailableElements ( child : Element ) : boolean {
62
+ // For other elements create a list of LN Elements for processing the DO Element from the LN Elements.
63
+ let lnElements : Element [ ] ;
64
+ if ( [ 'LN0' , 'LN' ] . includes ( child . tagName ) ) {
65
+ lnElements = [ child ] ;
66
+ } else {
67
+ // For the other Elements we will just retrieve all the DOI Elements.
68
+ lnElements = Array . from ( child . querySelectorAll ( 'LN0, LN' ) ) ;
73
69
}
70
+
71
+ // If after filtering there are still LN/DO Element(s) to be displayed, this element will be included.
72
+ return (
73
+ lnElements . filter (
74
+ lnElement =>
75
+ // Check if there are available DO Elements that aren't initiated and supported by 104 protocol
76
+ getDoElements ( lnElement ) . filter ( doElement =>
77
+ filterAvailableDOElements ( lnElement , doElement )
78
+ ) . length > 0
79
+ ) . length > 0
80
+ ) ;
74
81
}
75
82
76
83
/**
@@ -85,23 +92,29 @@ export function getDataChildren(parent: Element): Element[] {
85
92
// For LN Element we will not search for the children, but the DO Element linked to LN from the Template Section.
86
93
const lnType = parent . getAttribute ( 'lnType' ) ?? '' ;
87
94
children = Array . from (
88
- parent . ownerDocument . querySelectorAll ( `LNodeType[id="${ lnType } "] > DO` )
89
- ) . sort ( ( a , b ) => compareNames ( `${ identity ( a ) } ` , `${ identity ( b ) } ` ) ) ;
95
+ parent . ownerDocument . querySelectorAll (
96
+ `:root > DataTypeTemplates > LNodeType[id="${ lnType } "] > DO`
97
+ )
98
+ )
99
+ . filter ( child => filterAvailableDOElements ( parent , child ) )
100
+ . sort ( ( a , b ) => compareNames ( `${ identity ( a ) } ` , `${ identity ( b ) } ` ) ) ;
90
101
} else if ( parent . tagName === 'AccessPoint' ) {
91
102
// From the Access Point we will skip directly to the LDevice Element and skip the Server element.
92
- children = Array . from ( parent . querySelectorAll ( 'LDevice' ) ) . sort ( ( a , b ) =>
93
- compareNames ( `${ identity ( a ) } ` , `${ identity ( b ) } ` )
94
- ) ;
103
+ // Or retrieve the LN Elements directly below the AccessPoint.
104
+ children = Array . from ( parent . querySelectorAll ( 'LDevice, :scope > LN' ) )
105
+ . filter ( child => filterAvailableElements ( child ) )
106
+ . sort ( ( a , b ) => compareNames ( `${ identity ( a ) } ` , `${ identity ( b ) } ` ) ) ;
95
107
} else {
96
108
// The other element, just retrieve the children and if the tagName is one we need return that child.
97
109
children = Array . from ( parent . children )
98
110
. filter ( child =>
99
111
[ 'IED' , 'AccessPoint' , 'LN0' , 'LN' ] . includes ( child . tagName )
100
112
)
113
+ . filter ( child => filterAvailableElements ( child ) )
101
114
. sort ( ( a , b ) => compareNames ( `${ identity ( a ) } ` , `${ identity ( b ) } ` ) ) ;
102
115
}
103
116
104
- return children . filter ( child => filterAvailableDOElements ( parent , child ) ) ;
117
+ return children ;
105
118
}
106
119
107
120
/**
0 commit comments