Skip to content

Commit 748e2e5

Browse files
author
Dennis Labordus
authored
Merge pull request openscd#826 from openscd/104-init-structure
feat(104/CreateAddresses): Use DO Template Structure to create DAI Elements
2 parents 5ccf677 + a328446 commit 748e2e5

29 files changed

+2310
-679
lines changed

src/editors/ied/da-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class DAContainer extends Container {
118118
// Next create all missing elements (DOI/SDI/DOI)
119119
const newElement = initializeElements(uninitializedTemplateStructure);
120120

121-
if (parentElement && newElement) {
121+
if (newElement) {
122122
const wizard = createDAIWizard(parentElement, newElement, this.element);
123123
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
124124
}

src/editors/protocol104/doi-container.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import '../../action-pane.js';
2424

2525
import {
2626
get104DetailsLine,
27-
getCdcValue,
27+
getCdcValueFromDOIElement,
2828
getFullPath,
29-
PRIVATE_TYPE_104,
3029
} from './foundation/foundation.js';
3130
import { editAddressWizard } from './wizards/address.js';
3231
import { showDOIInfoWizard } from './wizards/doi.js';
32+
import { PROTOCOL_104_PRIVATE } from './foundation/private.js';
3333

3434
/**
3535
* Container showing all the DAI Elements, related to the 104 Protocol, of the passed DOI Element in a list.
@@ -48,8 +48,9 @@ export class Doi104Container extends LitElement {
4848
return Array.from(this.element.querySelectorAll(`DAI`))
4949
.filter(
5050
daiElement =>
51-
daiElement.querySelector(`Private[type="${PRIVATE_TYPE_104}"]`) !==
52-
null
51+
daiElement.querySelector(
52+
`Private[type="${PROTOCOL_104_PRIVATE}"] > Address`
53+
) !== null
5354
)
5455
.sort((dai1, dai2) =>
5556
getFullPath(dai1, 'DOI').localeCompare(getFullPath(dai2, 'DOI'))
@@ -59,12 +60,16 @@ export class Doi104Container extends LitElement {
5960
private getAddressElements(daiElement: Element): Element[] {
6061
return Array.from(
6162
daiElement.querySelectorAll(
62-
`Private[type="${PRIVATE_TYPE_104}"] > Address`
63-
)
64-
).sort((addr1, addr2) =>
65-
(addr1.getAttribute('ioa') ?? '').localeCompare(
66-
addr2.getAttribute('ioa') ?? ''
63+
`Private[type="${PROTOCOL_104_PRIVATE}"] > Address`
6764
)
65+
).sort(
66+
(addr1, addr2) =>
67+
(addr1.getAttribute('casdu') ?? '').localeCompare(
68+
addr2.getAttribute('casdu') ?? ''
69+
) &&
70+
(addr1.getAttribute('ioa') ?? '').localeCompare(
71+
addr2.getAttribute('ioa') ?? ''
72+
)
6873
);
6974
}
7075

@@ -76,8 +81,12 @@ export class Doi104Container extends LitElement {
7681
daiElement: Element,
7782
addressElement: Element
7883
): void {
84+
const doiElement = daiElement.closest('DOI')!;
85+
const iedElement = doiElement.closest('IED')!;
7986
this.dispatchEvent(
80-
newWizardEvent(editAddressWizard(daiElement, addressElement))
87+
newWizardEvent(
88+
editAddressWizard(iedElement, doiElement, daiElement, addressElement)
89+
)
8190
);
8291
}
8392

@@ -88,7 +97,7 @@ export class Doi104Container extends LitElement {
8897
@property()
8998
get header(): TemplateResult {
9099
const fullPath = getFullPath(this.element, 'IED');
91-
const cdc = getCdcValue(this.element);
100+
const cdc = getCdcValueFromDOIElement(this.element);
92101

93102
return html`${fullPath}${cdc ? html` (${cdc})` : nothing}`;
94103
}
Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,71 @@
1-
import { Create, newWizardEvent } from '../../../foundation.js';
2-
3-
import { editAddressWizard } from '../wizards/address.js';
1+
import { Create } from '../../../foundation.js';
42
import { TiInformation } from './cdc.js';
53

64
/**
75
* Create a list of Create Actions using the parameters passed. First search for the DAI Elements
86
* that can be effected. Next create the action and add it to this list, also start the Edit
97
* Address Element wizard for all Address Elements created.
108
*
11-
* @param doiElement - The DOI 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.
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.
1616
* @returns A list of Create Action that will be added to the complex action.
1717
*/
1818
export function createActions(
19-
doiElement: Element,
19+
lnElement: Element,
20+
lnClonedElement: Element,
21+
doElement: Element,
2022
wizard: Element,
2123
ti: string,
2224
inverted: boolean,
2325
tiInformation: TiInformation
2426
): Create[] {
25-
const actions: Create[] = [];
26-
const daiElements = doiElement.querySelectorAll(tiInformation.filter);
27-
if (daiElements.length > 0) {
28-
daiElements.forEach(daiElement => {
29-
const createActions = tiInformation.create(
30-
daiElement,
31-
ti,
32-
tiInformation.inverted ? inverted : false // If the TI Allows it and the Engineer selected it, true will be passed.
33-
);
34-
actions.push(...createActions);
35-
36-
createActions.forEach(createAction => {
37-
const privateElement = <Element>createAction.new.element;
38-
Array.from(privateElement.querySelectorAll('Address')).forEach(
39-
addressElement => {
40-
wizard.dispatchEvent(
41-
newWizardEvent(() =>
42-
editAddressWizard(daiElement, addressElement)
43-
)
44-
);
45-
}
46-
);
47-
});
48-
});
49-
}
50-
return actions;
27+
return tiInformation.create(
28+
lnElement,
29+
lnClonedElement,
30+
doElement,
31+
wizard,
32+
ti,
33+
tiInformation.daPaths,
34+
// If the TI Allows inverted and the Engineer selected it, true will be passed.
35+
tiInformation.inverted ? inverted : false
36+
);
5137
}
5238

5339
/**
5440
* Create a list of Create Actions using the parameters passed. First search for the DAI Elements [name="Check"].
5541
* Next create the action and add it to this list, also start the Edit Address Element wizard for all Address Elements
5642
* created.
5743
*
58-
* @param doiElement - The DOI Element.
59-
* @param wizard - The Wizard to dispatch the Open Wizard event on.
60-
* @param ti - The TI Value set on the new Address Elements.
61-
* @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.
6250
* @returns A list of Create Action that will be added to the complex action.
6351
*/
6452
export function createCheckActions(
65-
doiElement: Element,
53+
lnElement: Element,
54+
lnClonedElement: Element,
55+
doElement: Element,
6656
wizard: Element,
6757
ti: string,
6858
tiInformation: TiInformation
6959
): Create[] {
70-
const actions: Create[] = [];
71-
if (tiInformation.checkFilter) {
72-
const daiElements = doiElement.querySelectorAll(tiInformation.checkFilter);
73-
if (daiElements.length > 0) {
74-
daiElements.forEach(daiElement => {
75-
if (tiInformation.checkCreate) {
76-
const createActions = tiInformation.checkCreate(daiElement, ti);
77-
actions.push(...createActions);
78-
79-
createActions.forEach(createAction => {
80-
const privateElement = <Element>createAction.new.element;
81-
Array.from(privateElement.querySelectorAll('Address')).forEach(
82-
addressElement => {
83-
wizard.dispatchEvent(
84-
newWizardEvent(() =>
85-
editAddressWizard(daiElement, addressElement)
86-
)
87-
);
88-
}
89-
);
90-
});
91-
}
92-
});
93-
}
60+
if (tiInformation.checkDaPaths && tiInformation.checkCreate) {
61+
return tiInformation.checkCreate(
62+
lnElement,
63+
lnClonedElement,
64+
doElement,
65+
wizard,
66+
ti,
67+
tiInformation.checkDaPaths
68+
);
9469
}
95-
return actions;
70+
return [];
9671
}

0 commit comments

Comments
 (0)