Skip to content

Commit 5ccf677

Browse files
author
Dennis Labordus
authored
Merge pull request openscd#820 from openscd/104-expected-value-refactor
feat(104/ExpectedValue): Handling Enum Values as Expected Values in 104 address elements.
2 parents 6f1e388 + 243e043 commit 5ccf677

34 files changed

+2712
-1037
lines changed

src/editors/protocol104/doi-container.ts

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,31 @@ import {
55
LitElement,
66
property,
77
query,
8-
TemplateResult
9-
} from "lit-element";
10-
import { translate } from "lit-translate";
11-
import { nothing } from "lit-html";
8+
TemplateResult,
9+
} from 'lit-element';
10+
import { translate } from 'lit-translate';
11+
import { nothing } from 'lit-html';
1212

13-
import { IconButtonToggle } from "@material/mwc-icon-button-toggle";
13+
import { IconButtonToggle } from '@material/mwc-icon-button-toggle';
1414

1515
import '@material/mwc-icon';
1616
import '@material/mwc-icon-button';
1717
import '@material/mwc-icon-button-toggle';
1818
import '@material/mwc-list';
1919
import '@material/mwc-list/mwc-list-item';
2020

21-
import { newWizardEvent } from "../../foundation.js";
21+
import { newWizardEvent } from '../../foundation.js';
2222

2323
import '../../action-pane.js';
2424

2525
import {
2626
get104DetailsLine,
2727
getCdcValue,
2828
getFullPath,
29-
PRIVATE_TYPE_104
30-
} from "./foundation/foundation.js";
31-
import { editAddressWizard } from "./wizards/address.js";
32-
import { showDOIInfoWizard } from "./wizards/doi.js";
33-
import { } from "./foundation/private.js";
34-
29+
PRIVATE_TYPE_104,
30+
} from './foundation/foundation.js';
31+
import { editAddressWizard } from './wizards/address.js';
32+
import { showDOIInfoWizard } from './wizards/doi.js';
3533

3634
/**
3735
* Container showing all the DAI Elements, related to the 104 Protocol, of the passed DOI Element in a list.
@@ -45,89 +43,112 @@ export class Doi104Container extends LitElement {
4543
@query('#toggleButton')
4644
toggleButton!: IconButtonToggle | undefined;
4745

48-
private getDaiElements(): Element[] {
46+
@property()
47+
get daiElements(): Element[] {
4948
return Array.from(this.element.querySelectorAll(`DAI`))
50-
.filter(daiElement => daiElement.querySelector(`Private[type="${PRIVATE_TYPE_104}"]`) !== null)
51-
.sort((dai1, dai2) => getFullPath(dai1, 'DOI').localeCompare(getFullPath(dai2, 'DOI')) );
49+
.filter(
50+
daiElement =>
51+
daiElement.querySelector(`Private[type="${PRIVATE_TYPE_104}"]`) !==
52+
null
53+
)
54+
.sort((dai1, dai2) =>
55+
getFullPath(dai1, 'DOI').localeCompare(getFullPath(dai2, 'DOI'))
56+
);
5257
}
5358

5459
private getAddressElements(daiElement: Element): Element[] {
55-
return Array.from(daiElement.querySelectorAll(`Private[type="${PRIVATE_TYPE_104}"] > Address`))
56-
.sort((addr1, addr2) => (addr1.getAttribute('ioa') ?? '').localeCompare(addr2.getAttribute('ioa') ?? '') );
60+
return Array.from(
61+
daiElement.querySelectorAll(
62+
`Private[type="${PRIVATE_TYPE_104}"] > Address`
63+
)
64+
).sort((addr1, addr2) =>
65+
(addr1.getAttribute('ioa') ?? '').localeCompare(
66+
addr2.getAttribute('ioa') ?? ''
67+
)
68+
);
5769
}
5870

5971
protected firstUpdated(): void {
6072
this.requestUpdate();
6173
}
6274

63-
private openEditAddressWizard(daiElement: Element, addressElement: Element): void {
64-
this.dispatchEvent(newWizardEvent(editAddressWizard(daiElement, addressElement)));
75+
private openEditAddressWizard(
76+
daiElement: Element,
77+
addressElement: Element
78+
): void {
79+
this.dispatchEvent(
80+
newWizardEvent(editAddressWizard(daiElement, addressElement))
81+
);
6582
}
6683

6784
private openEditTiWizard(): void {
6885
this.dispatchEvent(newWizardEvent(showDOIInfoWizard(this.element)));
6986
}
7087

71-
private header(): TemplateResult {
72-
const fullPath = getFullPath(this.element, 'IED')
88+
@property()
89+
get header(): TemplateResult {
90+
const fullPath = getFullPath(this.element, 'IED');
7391
const cdc = getCdcValue(this.element);
7492

7593
return html`${fullPath}${cdc ? html` (${cdc})` : nothing}`;
7694
}
7795

7896
private renderAddressList(daiElement: Element): TemplateResult {
7997
const addresses = this.getAddressElements(daiElement);
80-
return html `${addresses.map(addressElement => {
98+
return html`${addresses.map(addressElement => {
8199
return html`
82-
<mwc-list-item graphic="icon" hasMeta>
83-
<span slot="graphic">&nbsp;</span>
84-
<span>${get104DetailsLine(addressElement)}</span>
85-
<span slot="meta">
86-
<mwc-icon-button
87-
icon="edit"
88-
@click=${() => this.openEditAddressWizard(daiElement, addressElement)}>
89-
</mwc-icon-button>
90-
</span>
91-
</mwc-list-item>
92-
`;
100+
<mwc-list-item graphic="icon" hasMeta>
101+
<span slot="graphic">&nbsp;</span>
102+
<span>${get104DetailsLine(daiElement, addressElement)}</span>
103+
<span slot="meta">
104+
<mwc-icon-button
105+
icon="edit"
106+
@click=${() =>
107+
this.openEditAddressWizard(daiElement, addressElement)}
108+
>
109+
</mwc-icon-button>
110+
</span>
111+
</mwc-list-item>
112+
`;
93113
})}`;
94114
}
95115

96116
private renderDaiList(): TemplateResult {
97-
const daiElements = this.getDaiElements();
98-
return html `${daiElements.map(daiElement => {
99-
return html`
100-
<mwc-list-item noninteractive>
101-
<span>${getFullPath(daiElement, 'DOI')}</span>
102-
</mwc-list-item>
103-
${this.renderAddressList(daiElement)}
104-
`;
117+
const daiElements = this.daiElements;
118+
return html`${daiElements.map(daiElement => {
119+
return html`
120+
<mwc-list-item noninteractive>
121+
<span>${getFullPath(daiElement, 'DOI')}</span>
122+
</mwc-list-item>
123+
${this.renderAddressList(daiElement)}
124+
`;
105125
})}`;
106126
}
107127

108128
render(): TemplateResult {
109129
return html`
110-
<action-pane .label="${this.header()}">
130+
<action-pane .label="${this.header}">
111131
<abbr slot="action" title="${translate('edit')}">
112132
<mwc-icon-button
113133
icon="info"
114134
@click=${() => this.openEditTiWizard()}
115135
></mwc-icon-button>
116136
</abbr>
117-
<abbr slot="action" title="${translate('protocol104.toggleChildElements')}">
137+
<abbr
138+
slot="action"
139+
title="${translate('protocol104.toggleChildElements')}"
140+
>
118141
<mwc-icon-button-toggle
119142
id="toggleButton"
120143
on
121144
onIcon="keyboard_arrow_up"
122145
offIcon="keyboard_arrow_down"
123-
@click=${() => this.requestUpdate()}>
146+
@click=${() => this.requestUpdate()}
147+
>
124148
</mwc-icon-button-toggle>
125149
</abbr>
126150
${this.toggleButton?.on
127-
? html`
128-
<mwc-list id="dailist">
129-
${this.renderDaiList()}
130-
</mwc-list>`
151+
? html` <mwc-list id="dailist"> ${this.renderDaiList()} </mwc-list>`
131152
: nothing}
132153
</action-pane>
133154
`;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { Create, newWizardEvent } from '../../../foundation.js';
2+
3+
import { editAddressWizard } from '../wizards/address.js';
4+
import { TiInformation } from './cdc.js';
5+
6+
/**
7+
* Create a list of Create Actions using the parameters passed. First search for the DAI Elements
8+
* that can be effected. Next create the action and add it to this list, also start the Edit
9+
* Address Element wizard for all Address Elements created.
10+
*
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.
16+
* @returns A list of Create Action that will be added to the complex action.
17+
*/
18+
export function createActions(
19+
doiElement: Element,
20+
wizard: Element,
21+
ti: string,
22+
inverted: boolean,
23+
tiInformation: TiInformation
24+
): 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;
51+
}
52+
53+
/**
54+
* Create a list of Create Actions using the parameters passed. First search for the DAI Elements [name="Check"].
55+
* Next create the action and add it to this list, also start the Edit Address Element wizard for all Address Elements
56+
* created.
57+
*
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.
62+
* @returns A list of Create Action that will be added to the complex action.
63+
*/
64+
export function createCheckActions(
65+
doiElement: Element,
66+
wizard: Element,
67+
ti: string,
68+
tiInformation: TiInformation
69+
): 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+
}
94+
}
95+
return actions;
96+
}

0 commit comments

Comments
 (0)