Skip to content

Commit 342f921

Browse files
author
Rob Tjalma
authored
Merge pull request #102 from com-pas/auto-alignment-menu
Added SCL Auto Alignment Menu.
2 parents 9501b12 + d88c2d3 commit 342f921

17 files changed

+508
-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'
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# `compas-auto-alignment`
2+
3+
## `document with substations`
4+
5+
#### `looks like the latest snapshot`
6+
7+
```html
8+
<section
9+
id="substationsToAlign"
10+
tabindex="0"
11+
>
12+
<mwc-list
13+
multi=""
14+
required=""
15+
>
16+
<mwc-check-list-item
17+
aria-disabled="false"
18+
graphic="control"
19+
left=""
20+
mwc-list-item=""
21+
tabindex="0"
22+
value="_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4"
23+
>
24+
_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4
25+
(Substation 1)
26+
</mwc-check-list-item>
27+
<mwc-check-list-item
28+
aria-disabled="false"
29+
graphic="control"
30+
left=""
31+
mwc-list-item=""
32+
tabindex="-1"
33+
value="_974565b1-ac55-4901-9f48-afc7ef5486df"
34+
>
35+
_974565b1-ac55-4901-9f48-afc7ef5486df
36+
(Sub3)
37+
</mwc-check-list-item>
38+
<mwc-check-list-item
39+
aria-disabled="false"
40+
graphic="control"
41+
left=""
42+
mwc-list-item=""
43+
tabindex="-1"
44+
value="_d6056127-34f1-43a9-b029-23fddb913bd5"
45+
>
46+
_d6056127-34f1-43a9-b029-23fddb913bd5
47+
(Sub4)
48+
</mwc-check-list-item>
49+
<mwc-check-list-item
50+
aria-disabled="false"
51+
graphic="control"
52+
left=""
53+
mwc-list-item=""
54+
tabindex="-1"
55+
value="_b3e5b4de-b74d-43b4-8db9-784302a12acf"
56+
>
57+
_b3e5b4de-b74d-43b4-8db9-784302a12acf
58+
(Sub5)
59+
</mwc-check-list-item>
60+
</mwc-list>
61+
</section>
62+
63+
```
64+
65+
## `document without substations`
66+
67+
#### `looks like the latest snapshot`
68+
69+
```html
70+
<section
71+
id="noSubstationsToAlign"
72+
tabindex="0"
73+
>
74+
<span>
75+
[compas.autoAlignment.missing]
76+
</span>
77+
</section>
78+
79+
```
80+

__snapshots__/compas-save-to.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# `compas-save-to`
2+
3+
## `still determining if document exists in CoMPAS`
4+
5+
#### `looks like the latest snapshot`
6+
7+
```html
8+
<compas-loading>
9+
</compas-loading>
10+
11+
```
12+
13+
## `new document in compas`
14+
15+
#### `looks like the latest snapshot`
16+
17+
```html
18+
<mwc-textfield
19+
dialoginitialfocus=""
20+
id="name"
21+
label="[scl.name]"
22+
required=""
23+
value="station123.scd"
24+
>
25+
</mwc-textfield>
26+
<compas-scltype-radiogroup>
27+
</compas-scltype-radiogroup>
28+
<compas-comment>
29+
</compas-comment>
30+
31+
```
32+
33+
## `existing document in compas`
34+
35+
#### `looks like the latest snapshot`
36+
37+
```html
38+
<compas-changeset-radiogroup>
39+
</compas-changeset-radiogroup>
40+
<compas-comment>
41+
</compas-comment>
42+
43+
```
44+

__snapshots__/compas-settings.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
>
1313
</mwc-textfield>
1414
<mwc-textfield
15-
dialoginitialfocus=""
1615
id="cimMappingServiceUrl"
1716
label="[compas.settings.cimMappingServiceUrl]"
1817
required=""
1918
value="/compas-cim-mapping"
2019
>
2120
</mwc-textfield>
22-
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)">
21+
<mwc-textfield
22+
id="sclAutoAlignmentServiceUrl"
23+
label="[compas.settings.sclAutoAlignmentServiceUrl]"
24+
required=""
25+
value="/compas-scl-auto-alignment"
26+
>
27+
</mwc-textfield>
28+
<mwc-button>
2329
[reset]
2430
</mwc-button>
2531

__snapshots__/open-scd.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,24 @@
270270
<mwc-linear-progress indeterminate="">
271271
</mwc-linear-progress>
272272
</mwc-list-item>
273+
<mwc-list-item
274+
aria-disabled="true"
275+
class="middle"
276+
disabled=""
277+
graphic="icon"
278+
iconid="dashboard"
279+
mwc-list-item=""
280+
tabindex="-1"
281+
>
282+
<mwc-icon slot="graphic">
283+
dashboard
284+
</mwc-icon>
285+
<span>
286+
Auto Align SLD
287+
</span>
288+
<mwc-linear-progress indeterminate="">
289+
</mwc-linear-progress>
290+
</mwc-list-item>
273291
<li
274292
divider=""
275293
padded=""
@@ -860,6 +878,22 @@
860878
</mwc-icon>
861879
Update Substation
862880
</mwc-check-list-item>
881+
<mwc-check-list-item
882+
aria-disabled="false"
883+
class="official"
884+
graphic="control"
885+
hasmeta=""
886+
left=""
887+
mwc-list-item=""
888+
selected=""
889+
tabindex="-1"
890+
value="/src/menu/CompasAutoAlignment.js"
891+
>
892+
<mwc-icon slot="meta">
893+
dashboard
894+
</mwc-icon>
895+
Auto Align SLD
896+
</mwc-check-list-item>
863897
<li
864898
divider=""
865899
inset=""

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ export const officialPlugins = [
112112
requireDoc: true,
113113
position: 'middle'
114114
},
115+
{
116+
name: 'Auto Align SLD',
117+
src: '/src/menu/CompasAutoAlignment.js',
118+
icon: 'dashboard',
119+
default: true,
120+
kind: 'menu',
121+
requireDoc: true,
122+
position: 'middle'
123+
},
115124
{
116125
name: 'CoMPAS Settings',
117126
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
@@ -17,7 +17,7 @@ import './CompasChangeSetRadiogroup.js';
1717
import './CompasSclTypeRadiogroup.js';
1818

1919
@customElement('compas-save')
20-
export class CompasSaveElement extends CompasExistsIn(LitElement) {
20+
export default class CompasSaveElement extends CompasExistsIn(LitElement) {
2121
@property({type: Document})
2222
doc!: XMLDocument;
2323

0 commit comments

Comments
 (0)