@@ -3,39 +3,29 @@ import {
3
3
html ,
4
4
LitElement ,
5
5
property ,
6
+ PropertyValues ,
6
7
state ,
7
8
TemplateResult ,
8
9
} from 'lit-element' ;
10
+ import { translate } from 'lit-translate' ;
11
+ import { nothing } from 'lit-html' ;
12
+
13
+ import '@material/mwc-list/mwc-check-list-item' ;
14
+ import '@material/mwc-list/mwc-radio-list-item' ;
9
15
10
- import '@material/mwc-fab' ;
11
- import '@material/mwc-select' ;
12
- import '@material/mwc-list/mwc-list-item' ;
16
+ import '../oscd-filter-button.js' ;
17
+ import { SelectedItemsChangedEvent } from '../oscd-filter-button.js' ;
13
18
14
19
import './ied/ied-container.js' ;
15
20
import './ied/element-path.js' ;
16
21
17
- import { translate } from 'lit-translate' ;
18
- import { SingleSelectedEvent } from '@material/mwc-list/mwc-list-foundation' ;
19
22
import {
20
23
compareNames ,
21
24
getDescriptionAttribute ,
22
25
getNameAttribute ,
23
26
} from '../foundation.js' ;
24
27
import { Nsdoc } from '../foundation/nsdoc.js' ;
25
-
26
- /*
27
- * We need a variable outside the plugin to save the selected IED, because the Plugin is created
28
- * more than once during working with the IED Editor, for instance when opening a Wizard to edit the IED.
29
- */
30
- let iedEditorSelectedIed : Element | undefined ;
31
- /*
32
- * We will also add an Event Listener when a new document is opened. We then want to reset the selection
33
- * so setting it to undefined will set the selected IED again on the first in the list.
34
- */
35
- function onOpenDocResetSelectedIed ( ) {
36
- iedEditorSelectedIed = undefined ;
37
- }
38
- addEventListener ( 'open-doc' , onOpenDocResetSelectedIed ) ;
28
+ import { getIcon } from '../icons/icons.js' ;
39
29
40
30
/** An editor [[`plugin`]] for editing the `IED` section. */
41
31
export default class IedPlugin extends LitElement {
@@ -47,7 +37,14 @@ export default class IedPlugin extends LitElement {
47
37
@property ( )
48
38
nsdoc ! : Nsdoc ;
49
39
50
- private get alphabeticOrderedIeds ( ) : Element [ ] {
40
+ @state ( )
41
+ selectedIEDs : string [ ] = [ ] ;
42
+
43
+ @state ( )
44
+ selectedLNClasses : string [ ] = [ ] ;
45
+
46
+ @state ( )
47
+ private get iedList ( ) : Element [ ] {
51
48
return this . doc
52
49
? Array . from ( this . doc . querySelectorAll ( ':root > IED' ) ) . sort ( ( a , b ) =>
53
50
compareNames ( a , b )
@@ -56,60 +53,131 @@ export default class IedPlugin extends LitElement {
56
53
}
57
54
58
55
@state ( )
59
- private set selectedIed ( element : Element | undefined ) {
60
- iedEditorSelectedIed = element ;
56
+ private get lnClassList ( ) : string [ ] [ ] {
57
+ const currentIed = this . selectedIed ;
58
+ const uniqueLNClassList : string [ ] = [ ] ;
59
+ if ( currentIed ) {
60
+ return Array . from ( currentIed . querySelectorAll ( 'LN0, LN' ) )
61
+ . filter ( element => element . hasAttribute ( 'lnClass' ) )
62
+ . filter ( element => {
63
+ const lnClass = element . getAttribute ( 'lnClass' ) ?? '' ;
64
+ if ( uniqueLNClassList . includes ( lnClass ) ) {
65
+ return false ;
66
+ }
67
+ uniqueLNClassList . push ( lnClass ) ;
68
+ return true ;
69
+ } )
70
+ . map ( element => {
71
+ const lnClass = element . getAttribute ( 'lnClass' ) ;
72
+ const label = this . nsdoc . getDataDescription ( element ) . label ;
73
+ return [ lnClass , label ] ;
74
+ } ) as string [ ] [ ] ;
75
+ }
76
+ return [ ] ;
61
77
}
62
78
79
+ @state ( )
63
80
private get selectedIed ( ) : Element | undefined {
64
81
// When there is no IED selected, or the selected IED has no parent (IED has been removed)
65
82
// select the first IED from the List.
66
- if (
67
- iedEditorSelectedIed === undefined ||
68
- iedEditorSelectedIed . parentElement === null
69
- ) {
70
- const iedList = this . alphabeticOrderedIeds ;
71
- if ( iedList . length > 0 ) {
72
- iedEditorSelectedIed = iedList [ 0 ] ;
73
- }
83
+ if ( this . selectedIEDs . length >= 1 ) {
84
+ const iedList = this . iedList ;
85
+ return iedList . find ( element => {
86
+ const iedName = getNameAttribute ( element ) ;
87
+ return this . selectedIEDs [ 0 ] === iedName ;
88
+ } ) ;
74
89
}
75
- return iedEditorSelectedIed ;
90
+ return undefined ;
76
91
}
77
92
78
- private onSelect ( event : SingleSelectedEvent ) : void {
79
- this . selectedIed = this . alphabeticOrderedIeds [ event . detail . index ] ;
80
- this . requestUpdate ( 'selectedIed' ) ;
93
+ protected updated ( _changedProperties : PropertyValues ) : void {
94
+ super . updated ( _changedProperties ) ;
95
+
96
+ // When the document is updated, we reset the selected IED.
97
+ if ( _changedProperties . has ( 'doc' ) || _changedProperties . has ( 'nsdoc' ) ) {
98
+ this . selectedIEDs = [ ] ;
99
+ this . selectedLNClasses = [ ] ;
100
+
101
+ const iedList = this . iedList ;
102
+ if ( iedList . length > 0 ) {
103
+ const iedName = getNameAttribute ( iedList [ 0 ] ) ;
104
+ if ( iedName ) {
105
+ this . selectedIEDs = [ iedName ] ;
106
+ }
107
+ }
108
+ this . selectedLNClasses = this . lnClassList . map (
109
+ lnClassInfo => lnClassInfo [ 0 ]
110
+ ) ;
111
+ }
81
112
}
82
113
83
114
render ( ) : TemplateResult {
84
- const iedList = this . alphabeticOrderedIeds ;
115
+ const iedList = this . iedList ;
85
116
if ( iedList . length > 0 ) {
86
117
return html `<section>
87
118
<div class= "header" >
88
- <mwc- select
89
- class= "iedSelect"
90
- label = "${ translate ( 'iededitor.searchHelper' ) } "
91
- @selected = ${ this . onSelect }
119
+ <h1> ${ translate ( 'filters' ) } : </ h1>
120
+
121
+ <oscd- filter- butto n
122
+ id= "iedFilter"
123
+ icon = "developer_board"
124
+ .header = ${ translate ( 'iededitor.iedSelector' ) }
125
+ @selected-items-changed = "${ ( e : SelectedItemsChangedEvent ) => {
126
+ this . selectedIEDs = e . detail . selectedItems ;
127
+ this . selectedLNClasses = this . lnClassList . map (
128
+ lnClassInfo => lnClassInfo [ 0 ]
129
+ ) ;
130
+ this . requestUpdate ( 'selectedIed' ) ;
131
+ } } "
92
132
>
93
133
${ iedList . map ( ied => {
94
134
const name = getNameAttribute ( ied ) ;
95
135
const descr = getDescriptionAttribute ( ied ) ;
96
- return html ` <mwc- lis t- item
97
- ?selected= ${ ied == this . selectedIed }
136
+ const type = ied . getAttribute ( 'type' ) ;
137
+ const manufacturer = ied . getAttribute ( 'manufacturer' ) ;
138
+ return html ` <mwc- radio- lis t- item
98
139
value= "${ name } "
99
- > ${ name }
100
- ${ descr
101
- ? translate ( 'iededitor.searchHelperDesc' , {
102
- description : descr ,
103
- } )
104
- : '' }
105
- </ mwc- lis t- item> ` ;
140
+ ?twoline= "${ type && manufacturer } "
141
+ ?selected= "${ this . selectedIEDs . includes ( name ?? '' ) } "
142
+ >
143
+ ${ name } ${ descr ? html ` (${ descr } )` : html `` }
144
+ <span slot= "secondary" >
145
+ ${ type } ${ type && manufacturer ? html `& mdash;` : nothing }
146
+ ${ manufacturer }
147
+ </ span>
148
+ </ mwc- radio- lis t- item> ` ;
149
+ } ) }
150
+ </ oscd- filter- butto n>
151
+
152
+ <oscd- filter- butto n
153
+ id= "lnClassesFilter"
154
+ multi = "true"
155
+ .header = "${ translate ( 'iededitor.lnFilter' ) } "
156
+ @selected-items-changed = "${ ( e : SelectedItemsChangedEvent ) => {
157
+ this . selectedLNClasses = e . detail . selectedItems ;
158
+ this . requestUpdate ( 'selectedIed' ) ;
159
+ } } "
160
+ >
161
+ <span slot= "icon" > ${ getIcon ( 'lNIcon' ) } </ span>
162
+ ${ this . lnClassList . map ( lnClassInfo => {
163
+ const value = lnClassInfo [ 0 ] ;
164
+ const label = lnClassInfo [ 1 ] ;
165
+ return html `<mwc- check- lis t- item
166
+ value= "${ value } "
167
+ ?selected= "${ this . selectedLNClasses . includes ( value ) } "
168
+ >
169
+ ${ label }
170
+ </ mwc- check- lis t- item> ` ;
106
171
} ) }
107
- </ mwc- select>
172
+ </ oscd- filter- butto n>
173
+
108
174
<element- path class= "elementPath" > </ element- path>
109
175
</ div>
176
+
110
177
<ied- container
111
178
.doc = ${ this . doc }
112
179
.element = ${ this . selectedIed }
180
+ .selectedLNClasses = ${ this . selectedLNClasses }
113
181
.nsdoc = ${ this . nsdoc }
114
182
> </ ied- container>
115
183
</ section> ` ;
@@ -128,20 +196,10 @@ export default class IedPlugin extends LitElement {
128
196
padding : 8px 12px 16px ;
129
197
}
130
198
131
- .iedSelect {
132
- width : 35vw ;
133
- padding-bottom : 20px ;
134
- }
135
-
136
199
.header {
137
200
display : flex;
138
201
}
139
202
140
- .elementPath {
141
- margin-left : auto;
142
- padding-right : 12px ;
143
- }
144
-
145
203
h1 {
146
204
color : var (--mdc-theme-on-surface );
147
205
font-family : 'Roboto' , sans-serif;
@@ -153,5 +211,10 @@ export default class IedPlugin extends LitElement {
153
211
line-height : 48px ;
154
212
padding-left : 0.3em ;
155
213
}
214
+
215
+ .elementPath {
216
+ margin-left : auto;
217
+ padding-right : 12px ;
218
+ }
156
219
` ;
157
220
}
0 commit comments