@@ -12,9 +12,11 @@ import { MultiSelectedEvent } from '@material/mwc-list/mwc-list-foundation';
12
12
import '../filtered-list.js' ;
13
13
import {
14
14
Create ,
15
+ cloneElement ,
15
16
createElement ,
16
17
EditorAction ,
17
18
getChildElementsByTagName ,
19
+ getValue ,
18
20
identity ,
19
21
isPublic ,
20
22
newLogEvent ,
@@ -26,6 +28,7 @@ import {
26
28
WizardInputElement ,
27
29
WizardMenuActor ,
28
30
} from '../foundation.js' ;
31
+ import { patterns } from './foundation/limits.js' ;
29
32
30
33
const maxLnInst = 99 ;
31
34
const lnInstRange = Array ( maxLnInst )
@@ -489,3 +492,130 @@ export function lNodeWizard(parent: Element): Wizard {
489
492
490
493
return lNodeReferenceWizard ( parent ) ;
491
494
}
495
+
496
+ interface ContentOptions {
497
+ iedName : string | null ;
498
+ ldInst : string | null ;
499
+ prefix : string | null ;
500
+ lnClass : string | null ;
501
+ lnInst : string | null ;
502
+ reservedLnInst : string [ ] ;
503
+ }
504
+
505
+ function contentLNodeWizard ( options : ContentOptions ) : TemplateResult [ ] {
506
+ const isIedRef = options . iedName !== 'None' ;
507
+
508
+ return [
509
+ html `< wizard-textfield
510
+ label ="iedName "
511
+ .maybeValue =${ options . iedName }
512
+ helper ="${ translate ( 'scl.iedName' ) } "
513
+ helperPersistent
514
+ disabled
515
+ > </ wizard-textfield > ` ,
516
+ html `< wizard-textfield
517
+ label ="ldInst "
518
+ .maybeValue =${ options . ldInst }
519
+ helper ="${ translate ( 'scl.ldInst' ) } "
520
+ helperPersistent
521
+ nullable
522
+ disabled
523
+ > </ wizard-textfield > ` ,
524
+ html `< wizard-textfield
525
+ label ="prefix "
526
+ .maybeValue =${ options . prefix }
527
+ helper ="${ translate ( 'scl.prefix' ) } "
528
+ pattern="${ patterns . asciName } "
529
+ maxLength="11"
530
+ helperPersistent
531
+ nullable
532
+ ?disabled=${ isIedRef }
533
+ > </ wizard-textfield > ` ,
534
+ html `< wizard-textfield
535
+ label ="lnClass "
536
+ .maybeValue =${ options . lnClass }
537
+ helper ="${ translate ( 'scl.lnClass' ) } "
538
+ helperPersistent
539
+ disabled
540
+ > </ wizard-textfield > ` ,
541
+ html `< wizard-textfield
542
+ label ="lnInst "
543
+ .maybeValue =${ options . lnInst }
544
+ helper ="${ translate ( 'scl.lnInst' ) } "
545
+ helperPersistent
546
+ type="number"
547
+ min="1"
548
+ max="99"
549
+ .reservedValues=${ options . reservedLnInst }
550
+ ?disabled=${ isIedRef }
551
+ > </ wizard-textfield > ` ,
552
+ ] ;
553
+ }
554
+
555
+ function updateLNodeAction ( element : Element ) : WizardActor {
556
+ return ( inputs : WizardInputElement [ ] ) : EditorAction [ ] => {
557
+ const attributes : Record < string , string | null > = { } ;
558
+ const attributeKeys = [ 'iedName' , 'ldInst' , 'prefix' , 'lnClass' , 'lnInst' ] ;
559
+
560
+ attributeKeys . forEach ( key => {
561
+ attributes [ key ] = getValue ( inputs . find ( i => i . label === key ) ! ) ;
562
+ } ) ;
563
+
564
+ let lNodeAction : EditorAction | null = null ;
565
+ if (
566
+ attributeKeys . some ( key => attributes [ key ] !== element . getAttribute ( key ) )
567
+ ) {
568
+ const newElement = cloneElement ( element , attributes ) ;
569
+ lNodeAction = {
570
+ old : { element } ,
571
+ new : { element : newElement } ,
572
+ } ;
573
+ return [ lNodeAction ] ;
574
+ }
575
+
576
+ return [ ] ;
577
+ } ;
578
+ }
579
+
580
+ export function editLNodeWizard ( element : Element ) : Wizard {
581
+ const [ iedName , ldInst , prefix , lnClass , lnInst ] = [
582
+ 'iedName' ,
583
+ 'ldInst' ,
584
+ 'prefix' ,
585
+ 'lnClass' ,
586
+ 'lnInst' ,
587
+ ] . map ( attr => element . getAttribute ( attr ) ) ;
588
+
589
+ const reservedLnInst = getChildElementsByTagName (
590
+ element . parentElement ,
591
+ 'LNode'
592
+ )
593
+ . filter (
594
+ sibling =>
595
+ sibling !== element &&
596
+ sibling . getAttribute ( 'lnClass' ) === element . getAttribute ( 'lnClass' )
597
+ )
598
+ . map ( sibling => sibling . getAttribute ( 'lnInst' ) ! ) ;
599
+
600
+ return [
601
+ {
602
+ title : get ( 'wizard.title.edit' , { tagName : 'LNode' } ) ,
603
+ element,
604
+ primary : {
605
+ label : get ( 'save' ) ,
606
+ icon : 'save' ,
607
+ action : updateLNodeAction ( element ) ,
608
+ } ,
609
+ content : [
610
+ ...contentLNodeWizard ( {
611
+ iedName,
612
+ ldInst,
613
+ prefix,
614
+ lnClass,
615
+ lnInst,
616
+ reservedLnInst,
617
+ } ) ,
618
+ ] ,
619
+ } ,
620
+ ] ;
621
+ }
0 commit comments