@@ -356,12 +356,13 @@ export const cdcProcessings: Record<
356
356
* Creates a new SCL Private element and add 104 Address element(s) below this.
357
357
* Set the attribute value of 'ti' to the passed ti value.
358
358
*
359
- * @param lnElement - The LN(0) Element.
360
- * @param doElement - The DO Element.
361
- * @param wizard - Wizard Element to dispatch events on.
362
- * @param ti - The value to be set on the attribute 'ti'.
363
- * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
364
- * @param inverted - Indicates if extra Address Elements should be created with 'inverted=true'.
359
+ * @param lnElement - The LN(0) Element.
360
+ * @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
361
+ * @param doElement - The DO Element.
362
+ * @param wizard - Wizard Element to dispatch events on.
363
+ * @param ti - The value to be set on the attribute 'ti'.
364
+ * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
365
+ * @param inverted - Indicates if extra Address Elements should be created with 'inverted=true'.
365
366
* @returns An array of Create Action that the wizard action will return.
366
367
*/
367
368
function createAddressAction (
@@ -407,12 +408,13 @@ function createAddressAction(
407
408
* Creates a new SCL Private element and add 104 Address element(s) below this.
408
409
* Set the attribute value of 'ti' to the passed ti value.
409
410
*
410
- * @param lnElement - The LN(0) Element.
411
- * @param doElement - The DO Element.
412
- * @param wizard - Wizard Element to dispatch events on.
413
- * @param ti - The value to be set on the attribute 'ti'.
414
- * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
415
- * @param inverted - Indicates if extra Address Elements should be created with 'inverted=true'.
411
+ * @param lnElement - The LN(0) Element.
412
+ * @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
413
+ * @param doElement - The DO Element.
414
+ * @param wizard - Wizard Element to dispatch events on.
415
+ * @param ti - The value to be set on the attribute 'ti'.
416
+ * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
417
+ * @param inverted - Indicates if extra Address Elements should be created with 'inverted=true'.
416
418
* @returns An array of Create Action that the wizard action will return.
417
419
*/
418
420
function createAddressWithExpectValueAction (
@@ -470,11 +472,12 @@ function createAddressWithExpectValueAction(
470
472
* Create a new SCL Private element and add 104 Address element(s) below this.
471
473
* Set the attribute value of 'ti' to the passed ti value.
472
474
*
473
- * @param lnElement - The LN(0) Element.
474
- * @param doElement - The DO Element.
475
- * @param wizard - Wizard Element to dispatch events on.
476
- * @param ti - The value to be set on the attribute 'ti'.
477
- * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
475
+ * @param lnElement - The LN(0) Element.
476
+ * @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
477
+ * @param doElement - The DO Element.
478
+ * @param wizard - Wizard Element to dispatch events on.
479
+ * @param ti - The value to be set on the attribute 'ti'.
480
+ * @param daPaths - The Array of DAI Elements to search or create and add the Private Element on.
478
481
* @returns An array of Create Action that the wizard action will return.
479
482
*/
480
483
function createCheckAddressAction (
@@ -526,6 +529,14 @@ function createCheckAddressAction(
526
529
return actions ;
527
530
}
528
531
532
+ /**
533
+ * Create or update the 104 Private Element, if the Private already exists, the new Address Elements are
534
+ * added, otherwise a new Private Element is created to which the Address Elements are added.
535
+ * The correct Create Action is returned.
536
+ *
537
+ * @param daiElement - The DAI Element which will hold the new or existing Private Element
538
+ * @param addressElements - The Address Elements to be created with Create Actions.
539
+ */
529
540
export function createActionsForPrivate (
530
541
daiElement : Element ,
531
542
addressElements : Element [ ]
@@ -580,6 +591,16 @@ export function createAddressElements(
580
591
return addressElements ;
581
592
}
582
593
594
+ /**
595
+ * Use all Create Action to determine which Address Elements are created and start an Edit Address Wizard
596
+ * for every Address Element found.
597
+ *
598
+ * @param wizard - The current Wizard used to dispatch the new Wizards on.
599
+ * @param lnElement - The LN Element used to search for specific parent elements.
600
+ * @param lnClonedElement - The cloned LN Element to search for child elements.
601
+ * @param doElement - The DO Element for which the Address Elements where created.
602
+ * @param actions - The list of all the Create Actions.
603
+ */
583
604
function startEditWizards (
584
605
wizard : Element ,
585
606
lnElement : Element ,
@@ -588,6 +609,7 @@ function startEditWizards(
588
609
actions : Create [ ]
589
610
) : void {
590
611
actions . forEach ( createAction => {
612
+ // Loop over all Actions and collect all Address Elements in an Array.
591
613
const newElement = < Element > createAction . new . element ;
592
614
let addressElements : Element [ ] ;
593
615
if ( newElement . tagName === 'Address' ) {
@@ -619,6 +641,15 @@ function startEditWizards(
619
641
} ) ;
620
642
}
621
643
644
+ /**
645
+ * Use the DA Path configuration of a Common Data Class to search for all DO/BDA/DA Elements to create
646
+ * a structure for which DOI/SDI/DAI Elements should be created later. Null will be returned when an invalid
647
+ * Template Structure is described by the DA Path.
648
+ *
649
+ * @param doElement - The DO Element to start searching for DA/BDA Elements.
650
+ * @param daPath - The (B)DA Elements to find in the template structure.
651
+ * @returns List of Elements starting with the DO Element followed by one or more (B)DA Elements describing the structure.
652
+ */
622
653
function createTemplateStructure (
623
654
doElement : Element ,
624
655
daPath : DaSelector
@@ -656,6 +687,16 @@ function createTemplateStructure(
656
687
return templateStructure ;
657
688
}
658
689
690
+ /**
691
+ * Search for existing DAI Elements below the DO Element matching the DA Paths passed or create the DAI Element
692
+ * if the DA Path doesn't exist yet.
693
+ *
694
+ * @param lnElement - The LN(0) Element.
695
+ * @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
696
+ * @param doElement - The DO Element.
697
+ * @param wizard - The current Wizard to dispatch Log Events, if needed.
698
+ * @param daPaths - The DA Structures for which the DAI Structure needs to be created below the DO Element.
699
+ */
659
700
function findOrCreateDaiElements (
660
701
lnElement : Element ,
661
702
lnClonedElement : Element ,
@@ -666,12 +707,15 @@ function findOrCreateDaiElements(
666
707
const daiElements : Element [ ] = [ ] ;
667
708
const actions : Create [ ] = [ ] ;
668
709
710
+ // Start searching and creating for each DA Path passed.
669
711
daPaths . forEach ( daPath => {
670
712
const filter = createDaiFilter ( doElement , daPath ) ;
671
713
const foundDaiElements = lnClonedElement . querySelectorAll ( filter ) ;
672
714
if ( foundDaiElements . length > 0 ) {
715
+ // Existing DAI Element found, so use that Element.
673
716
daiElements . push ( ...Array . from ( foundDaiElements ) ) ;
674
717
} else {
718
+ // DAI Element doesn't exist yet, so create the structure using the DA Path.
675
719
const templateStructure = createTemplateStructure ( doElement , daPath ) ;
676
720
if ( templateStructure ) {
677
721
const [ parentClonedElement , uninitializedTemplateStructure ] =
@@ -682,7 +726,9 @@ function findOrCreateDaiElements(
682
726
// Always add it to the cloned LN Structure.
683
727
parentClonedElement . append ( newElement ) ;
684
728
685
- // If the parent is the LN Element then use the original LN Element in the action.
729
+ // Search if the parent already exists in the current LN Element Structure.
730
+ // If so we will add a new Create Action for it.
731
+ // If it is already there because one of the parents of the parent is used in a Create Action.
686
732
const parentElement = findElementInOriginalLNStructure (
687
733
lnElement ,
688
734
parentClonedElement
@@ -691,13 +737,15 @@ function findOrCreateDaiElements(
691
737
actions . push ( { new : { parent : parentElement , element : newElement } } ) ;
692
738
}
693
739
740
+ // Add new DAI Elements to the list to return.
694
741
if ( newElement . tagName === 'DAI' ) {
695
742
daiElements . push ( newElement ) ;
696
743
} else {
697
744
const daiElement = newElement . querySelector ( 'DAI' ) ! ;
698
745
daiElements . push ( daiElement ) ;
699
746
}
700
747
} else {
748
+ // The DA Path can't be mapped on the Template structure of the current document.
701
749
const cdc = getCdcValueFromDOElement ( doElement ) ?? '' ;
702
750
const doType = getTypeAttribute ( doElement ) ?? '' ;
703
751
wizard . dispatchEvent (
@@ -716,14 +764,21 @@ function findOrCreateDaiElements(
716
764
return [ actions , daiElements ] ;
717
765
}
718
766
767
+ /**
768
+ * Use the DO Element and a DA Selector to create a CSS Query to search for a DAI Element
769
+ * below the LN Element.
770
+ *
771
+ * @param doElement - The DO Element for which to search a DOI Element.
772
+ * @param daPath - The DA Selector to create the query to find the SDI/DAI Elements.
773
+ */
719
774
function createDaiFilter ( doElement : Element , daPath : DaSelector ) : string {
720
775
const doName = getNameAttribute ( doElement ) ;
721
776
let filter = `:scope > DOI[name="${ doName } "] > ` ;
722
777
daPath . path . forEach ( ( value , index ) => {
723
778
if ( index < daPath . path . length - 1 ) {
724
- filter = filter + ` SDI[name="${ value } "] > `;
779
+ filter = ` ${ filter } SDI[name="${ value } "] > `;
725
780
} else {
726
- filter = filter + ` DAI[name="${ value } "]`;
781
+ filter = ` ${ filter } DAI[name="${ value } "]`;
727
782
}
728
783
} ) ;
729
784
return filter ;
0 commit comments