Skip to content

Commit 04a0fc2

Browse files
author
Dennis Labordus
committed
Added test and documentation.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent c956fe0 commit 04a0fc2

File tree

7 files changed

+311
-171
lines changed

7 files changed

+311
-171
lines changed

src/editors/protocol104/foundation/actions.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { TiInformation } from './cdc.js';
66
* that can be effected. Next create the action and add it to this list, also start the Edit
77
* Address Element wizard for all Address Elements created.
88
*
9-
* @param lnElement - The LN Element.
10-
* @param doElement - The DO Element.
11-
* @param wizard - The Wizard to dispatch the Open Wizard event on.
12-
* @param ti - The TI Value set on the new Address Elements.
13-
* @param inverted - Indicates if the Engineer want to create inverted Address Elements, if applicable.
14-
* @param tiInformation - Information about how to create the Address Elements for the passed TI.
9+
* @param lnElement - The LN Element.
10+
* @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
11+
* @param doElement - The DO Element.
12+
* @param wizard - The Wizard to dispatch the Open Wizard event on.
13+
* @param ti - The TI Value set on the new Address Elements.
14+
* @param inverted - Indicates if the Engineer want to create inverted Address Elements, if applicable.
15+
* @param tiInformation - Information about how to create the Address Elements for the passed TI.
1516
* @returns A list of Create Action that will be added to the complex action.
1617
*/
1718
export function createActions(
@@ -40,11 +41,12 @@ export function createActions(
4041
* Next create the action and add it to this list, also start the Edit Address Element wizard for all Address Elements
4142
* created.
4243
*
43-
* @param lnElement - The LN Element.
44-
* @param doElement - The DO Element.
45-
* @param wizard - The Wizard to dispatch the Open Wizard event on.
46-
* @param ti - The TI Value set on the new Address Elements.
47-
* @param tiInformation - Information about how to create the Address Elements for the passed TI.
44+
* @param lnElement - The LN Element.
45+
* @param lnClonedElement - The Cloned LN Element, used to create new structure and determine which Create actions are needed.
46+
* @param doElement - The DO Element.
47+
* @param wizard - The Wizard to dispatch the Open Wizard event on.
48+
* @param ti - The TI Value set on the new Address Elements.
49+
* @param tiInformation - Information about how to create the Address Elements for the passed TI.
4850
* @returns A list of Create Action that will be added to the complex action.
4951
*/
5052
export function createCheckActions(

src/editors/protocol104/foundation/cdc.ts

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,13 @@ export const cdcProcessings: Record<
356356
* Creates a new SCL Private element and add 104 Address element(s) below this.
357357
* Set the attribute value of 'ti' to the passed ti value.
358358
*
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'.
365366
* @returns An array of Create Action that the wizard action will return.
366367
*/
367368
function createAddressAction(
@@ -407,12 +408,13 @@ function createAddressAction(
407408
* Creates a new SCL Private element and add 104 Address element(s) below this.
408409
* Set the attribute value of 'ti' to the passed ti value.
409410
*
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'.
416418
* @returns An array of Create Action that the wizard action will return.
417419
*/
418420
function createAddressWithExpectValueAction(
@@ -470,11 +472,12 @@ function createAddressWithExpectValueAction(
470472
* Create a new SCL Private element and add 104 Address element(s) below this.
471473
* Set the attribute value of 'ti' to the passed ti value.
472474
*
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.
478481
* @returns An array of Create Action that the wizard action will return.
479482
*/
480483
function createCheckAddressAction(
@@ -526,6 +529,14 @@ function createCheckAddressAction(
526529
return actions;
527530
}
528531

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+
*/
529540
export function createActionsForPrivate(
530541
daiElement: Element,
531542
addressElements: Element[]
@@ -580,6 +591,16 @@ export function createAddressElements(
580591
return addressElements;
581592
}
582593

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+
*/
583604
function startEditWizards(
584605
wizard: Element,
585606
lnElement: Element,
@@ -588,6 +609,7 @@ function startEditWizards(
588609
actions: Create[]
589610
): void {
590611
actions.forEach(createAction => {
612+
// Loop over all Actions and collect all Address Elements in an Array.
591613
const newElement = <Element>createAction.new.element;
592614
let addressElements: Element[];
593615
if (newElement.tagName === 'Address') {
@@ -619,6 +641,15 @@ function startEditWizards(
619641
});
620642
}
621643

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+
*/
622653
function createTemplateStructure(
623654
doElement: Element,
624655
daPath: DaSelector
@@ -656,6 +687,16 @@ function createTemplateStructure(
656687
return templateStructure;
657688
}
658689

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+
*/
659700
function findOrCreateDaiElements(
660701
lnElement: Element,
661702
lnClonedElement: Element,
@@ -666,12 +707,15 @@ function findOrCreateDaiElements(
666707
const daiElements: Element[] = [];
667708
const actions: Create[] = [];
668709

710+
// Start searching and creating for each DA Path passed.
669711
daPaths.forEach(daPath => {
670712
const filter = createDaiFilter(doElement, daPath);
671713
const foundDaiElements = lnClonedElement.querySelectorAll(filter);
672714
if (foundDaiElements.length > 0) {
715+
// Existing DAI Element found, so use that Element.
673716
daiElements.push(...Array.from(foundDaiElements));
674717
} else {
718+
// DAI Element doesn't exist yet, so create the structure using the DA Path.
675719
const templateStructure = createTemplateStructure(doElement, daPath);
676720
if (templateStructure) {
677721
const [parentClonedElement, uninitializedTemplateStructure] =
@@ -682,7 +726,9 @@ function findOrCreateDaiElements(
682726
// Always add it to the cloned LN Structure.
683727
parentClonedElement.append(newElement);
684728

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.
686732
const parentElement = findElementInOriginalLNStructure(
687733
lnElement,
688734
parentClonedElement
@@ -691,13 +737,15 @@ function findOrCreateDaiElements(
691737
actions.push({ new: { parent: parentElement, element: newElement } });
692738
}
693739

740+
// Add new DAI Elements to the list to return.
694741
if (newElement.tagName === 'DAI') {
695742
daiElements.push(newElement);
696743
} else {
697744
const daiElement = newElement.querySelector('DAI')!;
698745
daiElements.push(daiElement);
699746
}
700747
} else {
748+
// The DA Path can't be mapped on the Template structure of the current document.
701749
const cdc = getCdcValueFromDOElement(doElement) ?? '';
702750
const doType = getTypeAttribute(doElement) ?? '';
703751
wizard.dispatchEvent(
@@ -716,14 +764,21 @@ function findOrCreateDaiElements(
716764
return [actions, daiElements];
717765
}
718766

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+
*/
719774
function createDaiFilter(doElement: Element, daPath: DaSelector): string {
720775
const doName = getNameAttribute(doElement);
721776
let filter = `:scope > DOI[name="${doName}"] > `;
722777
daPath.path.forEach((value, index) => {
723778
if (index < daPath.path.length - 1) {
724-
filter = filter + `SDI[name="${value}"] > `;
779+
filter = `${filter} SDI[name="${value}"] > `;
725780
} else {
726-
filter = filter + `DAI[name="${value}"]`;
781+
filter = `${filter} DAI[name="${value}"]`;
727782
}
728783
});
729784
return filter;

src/editors/protocol104/wizards/address.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,22 @@ export function editAddressWizard(
188188
</wizard-textfield>`);
189189
}
190190

191-
if (addressElement.hasAttribute('expectedValue')) {
192-
const expectedValue = addressElement.getAttribute('expectedValue');
193-
if (expectedValue) {
194-
fields.push(html`<wizard-textfield
195-
label="expectedValue"
196-
.maybeValue="${expectedValue}"
197-
disabled
198-
readonly
199-
>
200-
</wizard-textfield>`);
201-
fields.push(html`<wizard-textfield
202-
label="enumValue"
203-
.maybeValue="${getEnumVal(daiElement, expectedValue)}"
204-
disabled
205-
readonly
206-
>
207-
</wizard-textfield>`);
208-
}
191+
const expectedValue = addressElement.getAttribute('expectedValue');
192+
if (expectedValue) {
193+
fields.push(html`<wizard-textfield
194+
label="expectedValue"
195+
.maybeValue="${expectedValue}"
196+
disabled
197+
readonly
198+
>
199+
</wizard-textfield>`);
200+
fields.push(html`<wizard-textfield
201+
label="enumValue"
202+
.maybeValue="${getEnumVal(daiElement, expectedValue)}"
203+
disabled
204+
readonly
205+
>
206+
</wizard-textfield>`);
209207
}
210208

211209
if (addressElement.hasAttribute('inverted')) {

0 commit comments

Comments
 (0)