Skip to content

Commit 5e1327c

Browse files
authored
Merge pull request #38 from com-pas/cim-mapping-plugin
Added CIM Mapping as plugin
2 parents 51e2f13 + 15d8f3e commit 5e1327c

19 files changed

+450
-62
lines changed

__snapshots__/compas-scl-list.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# `compas-scl-list`
22

3-
#### `looks like the latest snapshot`
3+
## `show-loading`
4+
5+
#### `looks like the latest snapshot`
46

57
```html
68
<mwc-list>
@@ -15,3 +17,52 @@
1517

1618
```
1719

20+
## `no-items-in-list`
21+
22+
#### `looks like the latest snapshot`
23+
24+
```html
25+
<mwc-list>
26+
<mwc-list-item
27+
aria-disabled="false"
28+
mwc-list-item=""
29+
tabindex="0"
30+
>
31+
[compas.open.noScls]
32+
</mwc-list-item>
33+
</mwc-list>
34+
35+
```
36+
37+
## `after-list-loaded`
38+
39+
#### `looks like the latest snapshot`
40+
41+
```html
42+
<mwc-list>
43+
<mwc-list-item
44+
aria-disabled="false"
45+
mwc-list-item=""
46+
tabindex="0"
47+
>
48+
Station-Utrecht-0001 (
49+
<version>
50+
2.1.0
51+
</version>
52+
)
53+
</mwc-list-item>
54+
<mwc-list-item
55+
aria-disabled="false"
56+
mwc-list-item=""
57+
tabindex="-1"
58+
>
59+
Station-Utrecht-0002 (
60+
<version>
61+
1.3.0
62+
</version>
63+
)
64+
</mwc-list-item>
65+
</mwc-list>
66+
67+
```
68+

__snapshots__/compas-settings.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
value="http://localhost:9090/compas-scl-data-service"
1212
>
1313
</mwc-textfield>
14+
<mwc-textfield
15+
dialoginitialfocus=""
16+
id="cimMappingServiceUrl"
17+
label="[compas.settings.cimMappingServiceUrl]"
18+
required=""
19+
value="http://localhost:9091/compas-cim-mapping"
20+
>
21+
</mwc-textfield>
1422
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)">
1523
[reset]
1624
</mwc-button>

__snapshots__/open-scd.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@
7070
<mwc-linear-progress indeterminate="">
7171
</mwc-linear-progress>
7272
</mwc-list-item>
73+
<mwc-list-item
74+
aria-disabled="false"
75+
class="top"
76+
graphic="icon"
77+
iconid="input"
78+
mwc-list-item=""
79+
tabindex="-1"
80+
>
81+
<mwc-icon slot="graphic">
82+
input
83+
</mwc-icon>
84+
<span>
85+
New project from CIM
86+
</span>
87+
<mwc-linear-progress indeterminate="">
88+
</mwc-linear-progress>
89+
</mwc-list-item>
7390
<mwc-list-item
7491
aria-disabled="true"
7592
class="top"
@@ -427,6 +444,14 @@
427444
New project
428445
</div>
429446
</mwc-icon-button>
447+
<mwc-icon-button
448+
class="landing_icon"
449+
icon="input"
450+
>
451+
<div class="landing_label">
452+
New project from CIM
453+
</div>
454+
</mwc-icon-button>
430455
</div>
431456
<mwc-dialog
432457
heading="Log"
@@ -702,6 +727,22 @@
702727
</mwc-icon>
703728
New project
704729
</mwc-check-list-item>
730+
<mwc-check-list-item
731+
aria-disabled="false"
732+
class="official"
733+
graphic="control"
734+
hasmeta=""
735+
left=""
736+
mwc-list-item=""
737+
selected=""
738+
tabindex="-1"
739+
value="/src/menu/CompasCimMapping.js"
740+
>
741+
<mwc-icon slot="meta">
742+
input
743+
</mwc-icon>
744+
New project from CIM
745+
</mwc-check-list-item>
705746
<mwc-check-list-item
706747
aria-disabled="false"
707748
class="official"

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ export const officialPlugins = [
5555
requireDoc: false,
5656
position: 'top'
5757
},
58+
{
59+
name: 'New project from CIM',
60+
src: '/src/menu/CompasCimMapping.js',
61+
icon: 'input',
62+
default: true,
63+
kind: 'menu',
64+
requireDoc: false,
65+
position: 'top'
66+
},
5867
{
5968
name: 'Save project',
6069
src: '/src/menu/SaveProject.js',

src/compas-editors/CompasVersions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ function openScl(docName: string, docId: string, version: string) {
103103
return function () {
104104
const type = getTypeFromDocName(docName);
105105
CompasSclDataService().getSclDocumentVersion(type, docId, version)
106-
.then(doc => {
107-
updateDocumentInOpenSCD(doc);
106+
.then(response => {
107+
// Copy the SCL Result from the Response and create a new Document from it.
108+
const sclElement = response.querySelectorAll("SCL").item(0);
109+
const sclDocument = document.implementation.createDocument("", "", null);
110+
sclDocument.getRootNode().appendChild(sclElement.cloneNode(true));
111+
112+
updateDocumentInOpenSCD(sclDocument);
108113
});
109114

110115
// Close the Restore Dialog.

src/compas/CompasCimMappingService.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {CompasSettings} from "./CompasSettingsElement.js";
2+
3+
export const CMS_NAMESPACE = 'https://www.lfenergy.org/compas/CimMappingService';
4+
5+
export interface CimData {
6+
name: string,
7+
doc: Document;
8+
}
9+
10+
export interface MapRequestBody {
11+
cimData: CimData[]
12+
}
13+
14+
export function CompasCimMappingService() {
15+
16+
function getCompasSettings() {
17+
return CompasSettings().compasSettings;
18+
}
19+
20+
return {
21+
map(body: MapRequestBody): Promise<Document> {
22+
const cmsUrl = getCompasSettings().cimMappingServiceUrl + '/cim/v1/map';
23+
return fetch(cmsUrl, {
24+
method: 'POST',
25+
headers: {
26+
'Content-Type': 'application/xml'
27+
},
28+
body: `<?xml version="1.0" encoding="UTF-8"?>
29+
<cms:MapRequest xmlns:cms="${CMS_NAMESPACE}">
30+
${body.cimData.map(cimData => {
31+
return `
32+
<cms:CimData>
33+
<cms:Name>${cimData.name}</cms:Name>
34+
${new XMLSerializer().serializeToString(cimData.doc.documentElement)}
35+
</cms:CimData>`;
36+
}) }
37+
</cms:MapRequest>`
38+
})
39+
.then(response => response.text())
40+
.then(str => new DOMParser().parseFromString(str, 'application/xml'))
41+
},
42+
}
43+
}

src/compas/CompasSaveTo.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ export class CompasSaveTo extends LitElement {
6060

6161
function getSclDocument(type: string, id: string): void {
6262
CompasSclDataService().getSclDocument(type, id)
63-
.then(doc => {
64-
updateDocumentInOpenSCD(doc);
63+
.then(response => {
64+
// Copy the SCL Result from the Response and create a new Document from it.
65+
const sclElement = response.querySelectorAll("SCL").item(0);
66+
const sclDocument = document.implementation.createDocument("", "", null);
67+
sclDocument.getRootNode().appendChild(sclElement.cloneNode(true));
68+
69+
updateDocumentInOpenSCD(sclDocument);
6570
});
6671
}
6772

src/compas/CompasScl.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class CompasScl extends LitElement {
1717
scls!: Element[];
1818

1919
firstUpdated() {
20+
this.fetchData();
21+
}
22+
23+
fetchData() {
2024
CompasSclDataService().listScls(this.type)
2125
.then(xmlResponse => {
2226
this.scls = Array.from(xmlResponse.querySelectorAll('Item') ?? [])
@@ -28,8 +32,14 @@ export class CompasScl extends LitElement {
2832
}
2933

3034
private async getSclDocument(id?: string): Promise<void> {
31-
const doc = await CompasSclDataService().getSclDocument(this.type, id ?? '');
32-
updateDocumentInOpenSCD(doc);
35+
const response = await CompasSclDataService().getSclDocument(this.type, id ?? '');
36+
37+
// Copy the SCL Result from the Response and create a new Document from it.
38+
const sclElement = response.querySelectorAll("SCL").item(0);
39+
const sclDocument = document.implementation.createDocument("", "", null);
40+
sclDocument.getRootNode().appendChild(sclElement.cloneNode(true));
41+
42+
updateDocumentInOpenSCD(sclDocument);
3343
}
3444

3545
render(): TemplateResult {

src/compas/CompasSclDataService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ export function CompasSclDataService() {
5151
},
5252

5353
getSclDocument(type: string, id: string): Promise<Document> {
54-
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id + '/scl';
54+
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id;
5555
return fetch(sclUrl)
5656
.then(response => response.text())
5757
.then(str => new DOMParser().parseFromString(str, 'application/xml'))
5858
},
5959

6060
getSclDocumentVersion(type: string, id: string, version: string): Promise<Document> {
61-
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id + '/' + version + '/scl';
61+
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id + '/' + version;
6262
return fetch(sclUrl)
6363
.then(response => response.text())
6464
.then(str => new DOMParser().parseFromString(str, 'application/xml'))

src/compas/CompasSettingsElement.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {TextFieldBase} from "@material/mwc-textfield/mwc-textfield-base";
77

88
export type CompasSettingsRecord = {
99
sclDataServiceUrl: string;
10+
cimMappingServiceUrl: string;
1011
};
1112
export const defaults: CompasSettingsRecord = {
12-
sclDataServiceUrl: 'http://localhost:9090/compas-scl-data-service'
13+
sclDataServiceUrl: 'http://localhost:9090/compas-scl-data-service',
14+
cimMappingServiceUrl: 'http://localhost:9091/compas-cim-mapping'
1315
};
1416

1517
export function CompasSettings() {
@@ -18,6 +20,7 @@ export function CompasSettings() {
1820
get compasSettings(): CompasSettingsRecord {
1921
return {
2022
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
23+
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
2124
};
2225
},
2326

@@ -45,8 +48,13 @@ export class CompasSettingsElement extends LitElement {
4548
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="sclDataServiceUrl"]');
4649
}
4750

51+
getCimMappingServiceUrlField(): TextFieldBase {
52+
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="cimMappingServiceUrl"]');
53+
}
54+
4855
valid(): boolean {
49-
return this.getSclDataServiceUrlField().checkValidity();
56+
return this.getSclDataServiceUrlField().checkValidity()
57+
&& this.getCimMappingServiceUrlField().checkValidity();
5058
}
5159

5260
save(): boolean {
@@ -56,6 +64,7 @@ export class CompasSettingsElement extends LitElement {
5664

5765
// Update settings from TextField.
5866
CompasSettings().setCompasSetting('sclDataServiceUrl', this.getSclDataServiceUrlField().value);
67+
CompasSettings().setCompasSetting('cimMappingServiceUrl', this.getCimMappingServiceUrlField().value);
5968
return true;
6069
}
6170

@@ -78,6 +87,10 @@ export class CompasSettingsElement extends LitElement {
7887
label="${translate('compas.settings.sclDataServiceUrl')}"
7988
value="${this.compasSettings.sclDataServiceUrl}" required>
8089
</mwc-textfield>
90+
<mwc-textfield dialogInitialFocus id="cimMappingServiceUrl"
91+
label="${translate('compas.settings.cimMappingServiceUrl')}"
92+
value="${this.compasSettings.cimMappingServiceUrl}" required>
93+
</mwc-textfield>
8194
8295
<mwc-button style="--mdc-theme-primary: var(--mdc-theme-error)"
8396
@click=${() => {

0 commit comments

Comments
 (0)