1
- import { html } from 'lit-element' ;
1
+ import { html , TemplateResult } from 'lit-element' ;
2
2
import { translate , get } from 'lit-translate' ;
3
3
4
4
import '@material/mwc-checkbox' ;
5
+ import '@material/mwc-switch' ;
5
6
import '@material/mwc-formfield' ;
6
7
import '@material/mwc-list/mwc-list-item' ;
7
8
import '@material/mwc-list/mwc-check-list-item' ;
@@ -15,24 +16,32 @@ import '../../../filtered-list.js';
15
16
import {
16
17
pTypes104 ,
17
18
stationTypeOptions ,
18
- typeDescriptiveNameKeys
19
+ typeDescriptiveNameKeys ,
20
+ typePattern
19
21
} from '../foundation/p-types.js' ;
20
22
import {
23
+ cloneElement ,
21
24
compareNames ,
22
25
ComplexAction ,
23
26
createElement ,
24
27
EditorAction ,
25
28
getValue ,
26
29
identity ,
27
30
isPublic ,
31
+ newSubWizardEvent ,
32
+ newWizardEvent ,
28
33
Wizard ,
29
34
WizardActor ,
30
- WizardInputElement
35
+ WizardInputElement ,
36
+ WizardMenuActor
31
37
} from '../../../foundation.js' ;
32
38
import {
33
- createPTextField ,
34
39
createTypeRestrictionCheckbox
35
40
} from '../../../wizards/connectedap.js' ;
41
+ import { SingleSelectedEvent } from '@material/mwc-list/mwc-list-foundation' ;
42
+ import { ifDefined } from 'lit-html/directives/if-defined' ;
43
+ import { typeMaxLength } from '../../../wizards/foundation/p-types.js' ;
44
+ import { createRedundancyGroupWizard , editRedundancyGroupWizard } from './redundancygroup.js' ;
36
45
37
46
interface AccessPointDescription {
38
47
element : Element ;
@@ -164,7 +173,85 @@ function createAddressElement(
164
173
return element ;
165
174
}
166
175
167
- export function updateConnectedApAction ( parent : Element ) : WizardActor {
176
+ /** @returns single page [[`Wizard`]] to edit SCL element ConnectedAP for the 104 plugin. */
177
+ export function editConnectedApWizard ( parent : Element , redundancy ?: boolean ) : Wizard {
178
+ const redundancyGroupNumbers = getRedundancyGroupNumbers ( parent ) ;
179
+ return [
180
+ {
181
+ title : get ( 'protocol104.network.connectedAp.wizard.title.edit' ) ,
182
+ element : parent ,
183
+ menuActions : redundancy
184
+ ? [ {
185
+ icon : 'playlist_add' ,
186
+ label : get ( 'protocol104.network.connectedAp.wizard.addRedundancyGroup' ) ,
187
+ action : openRedundancyGroupWizard ( parent , redundancyGroupNumbers ) ,
188
+ } ]
189
+ : undefined ,
190
+ primary : {
191
+ icon : 'save' ,
192
+ label : get ( 'save' ) ,
193
+ action : editConnectedApAction ( parent , redundancy ) ,
194
+ } ,
195
+ content : [
196
+ html `< mwc-formfield label ="${ get ( 'protocol104.network.connectedAp.wizard.redundancySwitchLabel' ) } ">
197
+ < mwc-switch
198
+ id ="redundancy "
199
+ ?checked =${ redundancy }
200
+ @change =${ ( event : Event ) => {
201
+ event . target ! . dispatchEvent ( newWizardEvent ( ) ) ;
202
+ event . target ! . dispatchEvent (
203
+ newSubWizardEvent ( ( ) =>
204
+ editConnectedApWizard (
205
+ parent ,
206
+ ! redundancy
207
+ )
208
+ )
209
+ ) ;
210
+ } }
211
+ > </ mwc-switch >
212
+ </ mwc-formfield >
213
+ < wizard-divider > </ wizard-divider >
214
+ ${ createTypeRestrictionCheckbox ( parent ) }
215
+ < wizard-select
216
+ label ="StationType "
217
+ .maybeValue =${ parent . querySelector (
218
+ `Address > P[type="StationType"]`
219
+ ) ?. innerHTML ?? null }
220
+ required
221
+ fixedMenuPosition
222
+ helper ="${ translate ( typeDescriptiveNameKeys [ "StationType" ] ) } "
223
+ >
224
+ ${ stationTypeOptions . map (
225
+ option => html `< mwc-list-item value ="${ option } "> ${ option } </ mwc-list-item > `
226
+ ) }
227
+ </ wizard-select >
228
+ ${ redundancy
229
+ ? html `< h3 > ${ get ( 'protocol104.network.connectedAp.wizard.redundancyGroupTitle' ) } </ h3 >
230
+ < mwc-list
231
+ @selected =${ ( e : SingleSelectedEvent ) => {
232
+ e . target ! . dispatchEvent (
233
+ newSubWizardEvent ( ( ) =>
234
+ editRedundancyGroupWizard (
235
+ parent ,
236
+ redundancyGroupNumbers [ e . detail . index ]
237
+ )
238
+ )
239
+ ) ;
240
+ } } >
241
+ ${ redundancyGroupNumbers . length != 0
242
+ ? redundancyGroupNumbers . map ( number => html `< mwc-list-item > Redundancy Group ${ number } </ mwc-list-item > ` )
243
+ : html `< p > ${ get ( 'protocol104.network.connectedAp.wizard.noRedundancyGroupsAvailable' ) } </ p > ` }
244
+ </ mwc-list > `
245
+ : html `${ pTypes104 . map (
246
+ pType => html `${ createEditTextField ( parent , pType ) } `
247
+ ) } `}
248
+ ` ,
249
+ ] ,
250
+ } ,
251
+ ] ;
252
+ }
253
+
254
+ function editConnectedApAction ( parent : Element , redundancy ?: boolean ) : WizardActor {
168
255
return ( inputs : WizardInputElement [ ] , wizard : Element ) : EditorAction [ ] => {
169
256
const typeRestriction : boolean =
170
257
( < Checkbox > wizard . shadowRoot ?. querySelector ( '#typeRestriction' ) )
@@ -180,7 +267,24 @@ export function updateConnectedApAction(parent: Element): WizardActor {
180
267
apName : parent . getAttribute ( 'apName' ) ?? '' ,
181
268
} ) ,
182
269
} ;
183
- if ( oldAddress !== null && ! isEqualAddress ( oldAddress , newAddress ) ) {
270
+ // When we have a redundanct ConnectedAP, we are only interested in the StationType value.
271
+ // All redundancy group actions are done in those wizards itself.
272
+ if ( redundancy ) {
273
+ const stationTypeValue = getValue ( inputs . find ( i => i . label === 'StationType' ) ! ) ! ;
274
+ const originalElement = oldAddress ?. querySelector ( 'P[type="StationType"]' ) ;
275
+
276
+ const elementClone = cloneElement ( originalElement ! , { } ) ;
277
+ elementClone ! . textContent = stationTypeValue ;
278
+
279
+ complexAction . actions . push ( {
280
+ old : {
281
+ element : originalElement !
282
+ } ,
283
+ new : {
284
+ element : elementClone
285
+ }
286
+ } ) ;
287
+ } else if ( oldAddress !== null && ! isEqualAddress ( oldAddress , newAddress ) ) {
184
288
//address & child elements P are changed: cannot use replace editor action
185
289
complexAction . actions . push ( {
186
290
old : {
@@ -206,35 +310,44 @@ export function updateConnectedApAction(parent: Element): WizardActor {
206
310
} ;
207
311
}
208
312
209
- /** @returns single page [[`Wizard`]] to edit SCL element ConnectedAP for the 104 plugin. */
210
- export function editConnectedAp104Wizard ( element : Element ) : Wizard {
211
- return [
212
- {
213
- title : get ( 'wizard.title.edit' , { tagName : element . tagName } ) ,
214
- element,
215
- primary : {
216
- icon : 'save' ,
217
- label : get ( 'save' ) ,
218
- action : updateConnectedApAction ( element ) ,
219
- } ,
220
- content : [
221
- html `${ createTypeRestrictionCheckbox ( element ) }
222
- < wizard-select
223
- label ="StationType "
224
- .maybeValue =${ element . querySelector (
225
- `Address > P[type="StationType"]`
226
- ) ?. innerHTML ?? null }
227
- required
228
- helper ="${ translate ( typeDescriptiveNameKeys [ "StationType" ] ) } "
229
- > ${ stationTypeOptions . map (
230
- option =>
231
- html `< mwc-list-item value ="${ option } "> ${ option } </ mwc-list-item > `
232
- ) } </ wizard-select >
233
- ${ pTypes104 . map (
234
- pType =>
235
- html `${ createPTextField ( element , pType ) } `
236
- ) } `,
237
- ] ,
238
- } ,
239
- ] ;
313
+ function openRedundancyGroupWizard ( element : Element , rGNumbers : number [ ] ) : WizardMenuActor {
314
+ return ( wizard : Element ) : void => {
315
+ wizard . dispatchEvent ( newSubWizardEvent ( createRedundancyGroupWizard ( element , rGNumbers ) ) ) ;
316
+ } ;
240
317
}
318
+
319
+ /**
320
+ * Get all the current used Redundancy Group numbers.
321
+ * @param parent - The parent element of all the P elements.
322
+ * @returns An array with all the Redundancy Group numbers.
323
+ */
324
+ function getRedundancyGroupNumbers ( parent : Element ) : number [ ] {
325
+ const groupNumbers : number [ ] = [ ] ;
326
+
327
+ parent . querySelectorAll ( `Address > P[type^="RG"]` ) . forEach ( p => {
328
+ const redundancyGroupPart = p . getAttribute ( 'type' ) ?. split ( '-' ) [ 0 ] ;
329
+ const number = Number ( redundancyGroupPart ?. substring ( 2 ) ) ;
330
+
331
+ if ( ! groupNumbers . includes ( number ) ) groupNumbers . push ( number )
332
+ } )
333
+
334
+ return groupNumbers . sort ( ) ;
335
+ }
336
+
337
+ /**
338
+ * Create a wizard-textfield element for the Edit wizard.
339
+ * @param parent - The parent element of the P to create.
340
+ * @param pType - The type of P a Text Field has to be created for.
341
+ * @returns - A Text Field created for a specific type for the Edit wizard.
342
+ */
343
+ function createEditTextField ( parent : Element , pType : string ) : TemplateResult {
344
+ return html `< wizard-textfield
345
+ required
346
+ label ="${ pType } "
347
+ pattern ="${ ifDefined ( typePattern [ pType ] ) } "
348
+ .maybeValue =${ parent . querySelector (
349
+ `Address > P[type="${ pType } "]`
350
+ ) ?. innerHTML ?? null }
351
+ maxLength ="${ ifDefined ( typeMaxLength [ pType ] ) } "
352
+ > </ wizard-textfield > `
353
+ }
0 commit comments