Skip to content

Commit 2c6c856

Browse files
author
Flurb
committed
Missing Logic Link fields are also created now during editing
1 parent 86207e4 commit 2c6c856

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

src/editors/protocol104/connectedap-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ConnectedAP104Editor extends LitElement {
2424
newWizardEvent(() =>
2525
editConnectedApWizard(
2626
this.element,
27-
this.element.querySelectorAll('Address > P[type^="RG"]').length >= 8
27+
this.element.querySelectorAll('Address > P[type^="RG"]').length > 0
2828
)
2929
)
3030
);

src/editors/protocol104/wizards/logiclink.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,19 @@ function editLogicLinkAction(parent: Element, rGNumber: number, lLNumber: number
124124
const inputValue = getValue(inputs.find(i => i.label === type)!)!;
125125
const elementOriginal = parent.querySelector(`Address > P[type="RG${rGNumber}-LL${lLNumber}-${type}"]`);
126126

127-
if (inputValue !== elementOriginal?.textContent) {
127+
if (elementOriginal == null) {
128+
const element = createElement(parent.ownerDocument, 'P', {
129+
type: `RG${rGNumber}-LL${lLNumber}-${type}`
130+
});
131+
element.textContent = getValue(inputs.find(i => i.label === type)!)!;
132+
133+
actions.push({
134+
new: {
135+
parent: parent.querySelector('Address')!,
136+
element: element,
137+
}
138+
});
139+
} else if (inputValue !== elementOriginal?.textContent) {
128140
const elementClone = cloneElement(elementOriginal!, {});
129141
elementClone.textContent = inputValue;
130142

@@ -154,7 +166,6 @@ function editLogicLinkAction(parent: Element, rGNumber: number, lLNumber: number
154166

155167
function addLogicLinkAction(parent: Element, rGNumber: number, lLNumber: number): WizardActor {
156168
return (inputs: WizardInputElement[]): EditorAction[] => {
157-
const addressParent = parent.querySelector('Address')!;
158169
const complexAction: ComplexAction = {
159170
actions: [],
160171
title: get('protocol104.network.logicLink.wizard.addedLogicLink', {
@@ -172,7 +183,7 @@ function addLogicLinkAction(parent: Element, rGNumber: number, lLNumber: number)
172183

173184
complexAction.actions.push({
174185
new: {
175-
parent: addressParent,
186+
parent: parent.querySelector('Address')!,
176187
element: element,
177188
}
178189
});

src/editors/protocol104/wizards/redundancygroup.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export function editRedundancyGroupWizard(parent: Element, rGNumber: number): Wi
3333
{
3434
icon: 'playlist_add',
3535
label: get('protocol104.network.redundancyGroup.wizard.addLogicLink'),
36-
action: openLogicLinkWizard(parent, rGNumber, usedLLNumbers),
36+
action: (wizard: Element): void => {
37+
wizard.dispatchEvent(newSubWizardEvent(createLogicLinkWizard(parent, rGNumber, usedLLNumbers)));
38+
},
3739
},
3840
{
3941
icon: 'delete',
@@ -108,12 +110,6 @@ export function createRedundancyGroupWizard(parent: Element, occupiedRGNumbers:
108110
];
109111
}
110112

111-
function openLogicLinkWizard(parent: Element, rGNumber: number, lLNumber: number[]): WizardMenuActor {
112-
return (wizard: Element): void => {
113-
wizard.dispatchEvent(newSubWizardEvent(createLogicLinkWizard(parent, rGNumber, lLNumber)));
114-
};
115-
}
116-
117113
/**
118114
* Remove all P elements belonging to a single Redundancy Group.
119115
* @param parent - The parent element of the P elements to remove.
@@ -156,7 +152,19 @@ function editRedundancyGroupAction(parent: Element, rGNumber: number): WizardAct
156152
const inputValue = getValue(inputs.find(i => i.label === type)!)!;
157153
const elementOriginal = parent.querySelector(`Address > P[type="RG${rGNumber}-${type}"]`);
158154

159-
if (inputValue !== elementOriginal?.textContent) {
155+
if (elementOriginal == null) {
156+
const pElement = createElement(parent.ownerDocument, 'P', {
157+
type: `RG${rGNumber}-${type}`
158+
});
159+
pElement.textContent = inputValue;
160+
161+
actions.push({
162+
new: {
163+
parent: parent.querySelector('Address')!,
164+
element: pElement
165+
}
166+
});
167+
} else if (inputValue !== elementOriginal?.textContent) {
160168
const elementClone = cloneElement(elementOriginal!, {});
161169
elementClone.textContent = inputValue;
162170

test/unit/editors/protocol104/wizards/logiclink.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ describe('Wizards for the Logic Link SCL element group', () => {
7878
expect((<Replace>(action)).new.element.textContent).to.eql('192.128.0.12');
7979
});
8080

81+
it('properly creates a P element if not present', async () => {
82+
doc.querySelector('Communication > SubNetwork[name="W1"] > ConnectedAP[iedName="B1"] > Address > P[type="RG2-LL1-IP-SUBNET"]')?.remove();
83+
84+
input = <WizardTextField>inputs.find(input => input.label === 'IP-SUBNET');
85+
input.value = '200.200.200.2';
86+
await input.requestUpdate();
87+
88+
primaryAction.click();
89+
await element.requestUpdate();
90+
91+
const complexAction = <ComplexAction>actionEvent.args[0][0].detail.action;
92+
expect(complexAction.title).to.contain('edit');
93+
expect(complexAction.actions).to.have.lengthOf(1);
94+
95+
const action = complexAction.actions[0];
96+
expect(action).to.satisfy(isCreate);
97+
expect((<Create>(action)).new.element.textContent).to.eql('200.200.200.2');
98+
});
99+
81100
it('properly deletes a full Logic Link group', async () => {
82101
const deleteAction = <HTMLElement>(
83102
element.wizardUI.dialog?.querySelector(

test/unit/editors/protocol104/wizards/redundancygroup.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ describe('Wizards for the Redundancy Group SCL element group', () => {
7878
expect((<Replace>(action)).new.element.textContent).to.eql('18');
7979
});
8080

81+
it('properly creates a P element if not present', async () => {
82+
doc.querySelector('Communication > SubNetwork[name="W1"] > ConnectedAP[iedName="B1"] > Address > P[type="RG2-TIMEOUT-2"]')?.remove();
83+
84+
input = <WizardTextField>inputs.find(input => input.label === 'TIMEOUT-2');
85+
input.value = '77';
86+
await input.requestUpdate();
87+
88+
primaryAction.click();
89+
await element.requestUpdate();
90+
91+
const complexAction = <ComplexAction>actionEvent.args[0][0].detail.action;
92+
expect(complexAction.title).to.contain('edit');
93+
expect(complexAction.actions).to.have.lengthOf(1);
94+
95+
const action = complexAction.actions[0];
96+
expect(action).to.satisfy(isCreate);
97+
expect((<Create>(action)).new.element.textContent).to.eql('77');
98+
});
99+
81100
it('properly deletes a full Redundancy Group', async () => {
82101
const deleteAction = <HTMLElement>(
83102
element.wizardUI.dialog?.querySelectorAll(

0 commit comments

Comments
 (0)