Skip to content

Commit 246d6b6

Browse files
author
Dennis Labordus
committed
Merge branch 'main' into merge-v080
2 parents 5788997 + 342f921 commit 246d6b6

17 files changed

+466
-43
lines changed

.github/workflows/build-project.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- '**'
7-
- '!main'
87
pull_request:
98
branches:
109
- 'main'

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ export const officialPlugins = [
127127
requireDoc: true,
128128
position: 'middle'
129129
},
130+
{
131+
name: 'Auto Align SLD',
132+
src: '/src/menu/CompasAutoAlignment.js',
133+
icon: 'dashboard',
134+
default: true,
135+
kind: 'menu',
136+
requireDoc: true,
137+
position: 'middle'
138+
},
130139
{
131140
name: 'CoMPAS Settings',
132141
src: '/src/menu/CompasSettings.js',
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {CompasSettings} from "../compas/CompasSettings.js";
2+
import {extractSclFromResponse, handleError, handleResponse, parseXml} from "./foundation.js";
3+
4+
export const SAA_NAMESPACE = 'https://www.lfenergy.org/compas/SclAutoAlignmentService/v1';
5+
6+
export function CompasSclAutoAlignmentService() {
7+
function getCompasSettings() {
8+
return CompasSettings().compasSettings;
9+
}
10+
11+
return {
12+
updateSCL(doc: Document, substationNames: string[]): Promise<Document> {
13+
const saaUrl = getCompasSettings().sclAutoAlignmentServiceUrl + '/auto/alignment/v1';
14+
return fetch(saaUrl, {
15+
method: 'POST',
16+
headers: {
17+
'Content-Type': 'application/xml'
18+
},
19+
body: `<?xml version="1.0" encoding="UTF-8"?>
20+
<saa:SclAutoAlignRequest xmlns:saa="${SAA_NAMESPACE}">
21+
${substationNames.map(substationName => {
22+
return `
23+
<saa:SubstationName>${substationName}</saa:SubstationName>
24+
`;
25+
})}
26+
<saa:SclData><![CDATA[${new XMLSerializer().serializeToString(doc.documentElement)}]]></saa:SclData>
27+
</saa:SclAutoAlignRequest>`
28+
}).catch(handleError)
29+
.then(handleResponse)
30+
.then(parseXml)
31+
.then(extractSclFromResponse);
32+
},
33+
}
34+
}

src/compas/CompasAutoAlignment.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {css, customElement, html, LitElement, property, TemplateResult} from "lit-element";
2+
import {get, translate} from "lit-translate";
3+
4+
import {newLogEvent, newOpenDocEvent, newWizardEvent} from "../foundation.js";
5+
import {getOpenScdElement} from "./foundation.js";
6+
7+
import {CompasSclAutoAlignmentService} from "../compas-services/CompasSclAutoAlignmentService.js";
8+
import {createLogEvent} from "../compas-services/foundation.js";
9+
10+
@customElement('compas-auto-alignment')
11+
export default class CompasAutoAlignmentElement extends LitElement {
12+
@property({type: Document})
13+
doc!: XMLDocument;
14+
@property({type: String})
15+
docName!: string;
16+
@property({type: String})
17+
docId?: string;
18+
19+
getSelectedValues() : string[] {
20+
const selectedItems: string[] = [];
21+
this.shadowRoot!.querySelectorAll('mwc-check-list-item').forEach((item, key) => {
22+
if (item.selected) {
23+
selectedItems[key] = item.value;
24+
}
25+
});
26+
return selectedItems;
27+
}
28+
29+
valid(): boolean {
30+
return this.getSelectedValues().length > 0;
31+
}
32+
33+
async execute(): Promise<void> {
34+
if (this.valid()) {
35+
await CompasSclAutoAlignmentService().updateSCL(this.doc, this.getSelectedValues())
36+
.then(sclDocument => {
37+
const openScd = getOpenScdElement();
38+
openScd.dispatchEvent(newLogEvent({kind: 'reset'}));
39+
openScd.dispatchEvent(newOpenDocEvent(sclDocument, this.docName, {detail: {docId: this.docId}}));
40+
41+
openScd.dispatchEvent(
42+
newLogEvent({
43+
kind: 'info',
44+
title: get('compas.autoAlignment.success')
45+
}));
46+
47+
// Close the Save Dialog.
48+
this.dispatchEvent(newWizardEvent());
49+
})
50+
.catch(createLogEvent);
51+
52+
// Close the Save Dialog.
53+
this.dispatchEvent(newWizardEvent());
54+
}
55+
}
56+
57+
render(): TemplateResult {
58+
return html `
59+
${this.doc?.querySelector(':root > Substation')
60+
? html`
61+
<section id="substationsToAlign" tabindex="0">
62+
<mwc-list multi required>
63+
${Array.from(this.doc.querySelectorAll(':root > Substation') ?? [])
64+
.map(substation =>
65+
html`
66+
<mwc-check-list-item left value="${substation.getAttribute('name')}">
67+
${substation.getAttribute('name')}
68+
${substation.getAttribute('desc') ? html `(${substation.getAttribute('desc')})`: html ``}
69+
</mwc-check-list-item>
70+
`
71+
)}
72+
</mwc-list>
73+
</section>
74+
`
75+
: html`
76+
<section id="noSubstationsToAlign" tabindex="0">
77+
<span>${translate('compas.autoAlignment.missing')}</span>
78+
</section>
79+
`}
80+
`;
81+
}
82+
83+
static styles = css`
84+
#noSubstationsToAlign > span {
85+
color: var(--base1)
86+
}
87+
`
88+
}

src/compas/CompasSave.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import './CompasLoading.js';
2323
import './CompasSclTypeRadiogroup.js';
2424

2525
@customElement('compas-save')
26-
export class CompasSaveElement extends CompasExistsIn(LitElement) {
26+
export default class CompasSaveElement extends CompasExistsIn(LitElement) {
2727
@property({type: Document})
2828
doc!: XMLDocument;
2929

src/compas/CompasSettings.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {getOpenScdElement} from "./foundation.js";
1111
export type CompasSettingsRecord = {
1212
sclDataServiceUrl: string;
1313
cimMappingServiceUrl: string;
14+
sclAutoAlignmentServiceUrl: string;
1415
};
1516

1617
export function CompasSettings() {
@@ -20,13 +21,15 @@ export function CompasSettings() {
2021
return {
2122
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
2223
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
24+
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl'),
2325
};
2426
},
2527

2628
get defaultSettings(): CompasSettingsRecord {
2729
return {
2830
sclDataServiceUrl: '/compas-scl-data-service',
29-
cimMappingServiceUrl: '/compas-cim-mapping'
31+
cimMappingServiceUrl: '/compas-cim-mapping',
32+
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment'
3033
}
3134
},
3235

@@ -58,9 +61,14 @@ export class CompasSettingsElement extends LitElement {
5861
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="cimMappingServiceUrl"]');
5962
}
6063

64+
getSclAutoAlignmentServiceUrlField(): TextFieldBase {
65+
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="sclAutoAlignmentServiceUrl"]');
66+
}
67+
6168
valid(): boolean {
6269
return this.getSclDataServiceUrlField().checkValidity()
63-
&& this.getCimMappingServiceUrlField().checkValidity();
70+
&& this.getCimMappingServiceUrlField().checkValidity()
71+
&& this.getSclAutoAlignmentServiceUrlField().checkValidity();
6472
}
6573

6674
save(): boolean {
@@ -71,6 +79,7 @@ export class CompasSettingsElement extends LitElement {
7179
// Update settings from TextField.
7280
CompasSettings().setCompasSetting('sclDataServiceUrl', this.getSclDataServiceUrlField().value);
7381
CompasSettings().setCompasSetting('cimMappingServiceUrl', this.getCimMappingServiceUrlField().value);
82+
CompasSettings().setCompasSetting('sclAutoAlignmentServiceUrl', this.getSclAutoAlignmentServiceUrlField().value);
7483
return true;
7584
}
7685

@@ -93,13 +102,16 @@ export class CompasSettingsElement extends LitElement {
93102
label="${translate('compas.settings.sclDataServiceUrl')}"
94103
value="${this.compasSettings.sclDataServiceUrl}" required>
95104
</mwc-textfield>
96-
<mwc-textfield dialogInitialFocus id="cimMappingServiceUrl"
105+
<mwc-textfield id="cimMappingServiceUrl"
97106
label="${translate('compas.settings.cimMappingServiceUrl')}"
98107
value="${this.compasSettings.cimMappingServiceUrl}" required>
99108
</mwc-textfield>
109+
<mwc-textfield id="sclAutoAlignmentServiceUrl"
110+
label="${translate('compas.settings.sclAutoAlignmentServiceUrl')}"
111+
value="${this.compasSettings.sclAutoAlignmentServiceUrl}" required>
112+
</mwc-textfield>
100113
101-
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)"
102-
@click=${() => {
114+
<mwc-button @click=${() => {
103115
if (this.reset()) {
104116
this.close();
105117
}
@@ -117,6 +129,10 @@ export class CompasSettingsElement extends LitElement {
117129
margin: 10px;
118130
width: 100%;
119131
}
132+
133+
mwc-button {
134+
--mdc-theme-primary: var(--mdc-theme-error)
135+
}
120136
`
121137
}
122138

src/menu/CompasAutoAlignment.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {html, LitElement} from 'lit-element';
2+
import {get} from "lit-translate";
3+
4+
import {newPendingStateEvent, newWizardEvent, Wizard, WizardInput} from '../foundation.js';
5+
6+
import CompasAutoAlignmentElement from "../compas/CompasAutoAlignment.js";
7+
import {getOpenScdElement} from "../compas/foundation.js";
8+
9+
import "../compas/CompasAutoAlignment.js";
10+
11+
export default class CompasAutoAlignmentMenuPlugin extends LitElement {
12+
doc!: XMLDocument;
13+
docName!: string;
14+
docId?: string;
15+
16+
private autoAlignmentCompasWizard(): Wizard {
17+
function execute() {
18+
return function (inputs: WizardInput[], wizard: Element) {
19+
const compasAutoAlignmentElement = <CompasAutoAlignmentElement>wizard.shadowRoot!.querySelector('compas-auto-alignment')
20+
if (!compasAutoAlignmentElement.valid()) {
21+
return [];
22+
}
23+
24+
getOpenScdElement().dispatchEvent(newPendingStateEvent(compasAutoAlignmentElement.execute()));
25+
return [];
26+
};
27+
}
28+
29+
return [
30+
{
31+
title: get('compas.autoAlignment.title'),
32+
primary: {
33+
icon: 'dashboard',
34+
label: get('compas.autoAlignment.button'),
35+
action: execute(),
36+
},
37+
content: [
38+
html `
39+
<compas-auto-alignment .doc="${this.doc}" .docName="${this.docName}" .docId="${this.docId}">
40+
</compas-auto-alignment>
41+
`,
42+
],
43+
},
44+
];
45+
}
46+
47+
async run(): Promise<void> {
48+
this.dispatchEvent(newWizardEvent(this.autoAlignmentCompasWizard()));
49+
}
50+
}

src/menu/CompasSave.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {get} from "lit-translate";
33

44
import {newPendingStateEvent, newWizardEvent, Wizard, WizardInput} from '../foundation.js';
55

6-
import {CompasSaveElement} from "../compas/CompasSave.js";
6+
import CompasSaveElement from "../compas/CompasSave.js";
77
import {getOpenScdElement} from "../compas/foundation.js";
88

99
import "../compas/CompasSave.js";
@@ -13,41 +13,38 @@ export default class CompasSaveMenuPlugin extends LitElement {
1313
docName!: string;
1414
docId?: string;
1515

16-
async run(): Promise<void> {
17-
this.dispatchEvent(newWizardEvent(saveToCompasWizard(this.doc, {docId: this.docId, docName: this.docName})));
18-
}
19-
}
16+
private saveToCompasWizard(): Wizard {
17+
function saveToCompas() {
18+
return function (inputs: WizardInput[], wizard: Element) {
19+
const compasSave = <CompasSaveElement>wizard.shadowRoot!.querySelector('compas-save')
20+
if (!compasSave.valid()) {
21+
return [];
22+
}
2023

21-
interface SaveToCompasWizardOptions {
22-
docName: string,
23-
docId?: string,
24-
}
25-
function saveToCompasWizard(doc: XMLDocument, saveToOptions: SaveToCompasWizardOptions): Wizard {
26-
function saveToCompas() {
27-
return function (inputs: WizardInput[], wizard: Element) {
28-
const compasSave = <CompasSaveElement>wizard.shadowRoot!.querySelector('compas-save')
29-
if (!doc || !compasSave.valid()) {
24+
getOpenScdElement().dispatchEvent(newPendingStateEvent(compasSave.saveToCompas()));
3025
return [];
31-
}
32-
33-
getOpenScdElement().dispatchEvent(newPendingStateEvent(compasSave.saveToCompas()));
34-
return [];
35-
};
26+
};
27+
}
28+
29+
return [
30+
{
31+
title: get('compas.save.title'),
32+
primary: {
33+
icon: 'save',
34+
label: get('save'),
35+
action: saveToCompas(),
36+
},
37+
content: [
38+
html `<compas-save .doc="${this.doc}" .docName="${this.docName}" .docId="${this.docId}">
39+
</compas-save>`
40+
],
41+
},
42+
];
3643
}
3744

38-
return [
39-
{
40-
title: get('compas.save.title'),
41-
primary: {
42-
icon: 'save',
43-
label: get('save'),
44-
action: saveToCompas(),
45-
},
46-
content: [
47-
html `<compas-save .doc="${doc}" .docName="${saveToOptions.docName}" .docId="${saveToOptions.docId}">
48-
</compas-save>
49-
` ],
50-
},
51-
];
45+
async run(): Promise<void> {
46+
this.dispatchEvent(newWizardEvent(this.saveToCompasWizard()));
47+
}
5248
}
5349

50+

src/translations/de.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ export const de: Translations = {
459459
merge: {
460460
title: '???',
461461
},
462+
autoAlignment: {
463+
title: '???',
464+
button: '???',
465+
missing: '???',
466+
success: '???',
467+
},
462468
uploadVersion: {
463469
title: '???',
464470
selectButton: '???...',
@@ -495,6 +501,7 @@ export const de: Translations = {
495501
title: 'CoMPAS Einstellungen',
496502
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
497503
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
504+
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
498505
},
499506
session: {
500507
headingExpiring: '???',

0 commit comments

Comments
 (0)