Skip to content

Commit f9fc116

Browse files
author
Rob Tjalma
authored
Merge pull request #135 from com-pas/gui-cim-conversion-alliander-api
Import from API plugin
2 parents 6d1f5aa + 764dc8c commit f9fc116

File tree

11 files changed

+196
-4
lines changed

11 files changed

+196
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
/_site/
2020
/build/
2121
/out-tsc/
22+
23+
/public/cim/
24+
!/public/cim/README.md

public/cim/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Directory containing fixed files for the 'Import from API' plugin, namely:
2+
3+
- cim-eq-hoorn-v3.xml
4+
- cim-eq-makkum.xml
5+
- cim-eq-winselingseweg-voorbeeld.xml
6+
- EQ-entsoe-voorbeeld.xml
7+
8+
Without these files, the 'Import from API' doesn't work and the hardcoded files cannot be opened.

public/js/plugins.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ export const officialPlugins = [
8282
requireDoc: false,
8383
position: 'top'
8484
},
85+
{
86+
name: 'Import from API',
87+
src: '/src/menu/CompasImportFromApi.js',
88+
icon: 'cloud_download',
89+
default: false,
90+
kind: 'menu',
91+
requireDoc: false,
92+
position: 'top'
93+
},
8594
{
8695
name: 'Save project',
8796
src: '/src/menu/CompasSave.js',

src/compas/CompasImportFromApi.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {customElement, html, LitElement, TemplateResult} from "lit-element";
2+
3+
import '@material/mwc-button';
4+
5+
import {newOpenDocEvent, newPendingStateEvent, newWizardEvent} from "../foundation.js";
6+
7+
import {createLogEvent, handleError, handleResponse, parseXml} from "../compas-services/foundation.js";
8+
import {dispatchEventOnOpenScd} from "./foundation.js";
9+
10+
import '../WizardDivider.js';
11+
import './CompasSclTypeList.js';
12+
import './CompasScl.js';
13+
import { CompasCimMappingService } from "../compas-services/CompasCimMappingService.js";
14+
15+
@customElement('compas-import-from-api')
16+
export default class CompasImportFromApiElement extends LitElement {
17+
private async processCimFile(name: string) {
18+
const doc = await fetch('/public/cim/' + name + '.xml')
19+
.catch(handleError)
20+
.then(handleResponse)
21+
.then(parseXml);
22+
23+
await CompasCimMappingService().map({cimData: [{name: name + '.xml', doc: doc}]}).then(response => {
24+
const sclName = name + ".ssd";
25+
26+
const sclElement = response.querySelectorAll("SCL").item(0);
27+
const sclDocument = document.implementation.createDocument("", "", null);
28+
sclDocument.getRootNode().appendChild(sclElement.cloneNode(true));
29+
30+
dispatchEventOnOpenScd(newOpenDocEvent(sclDocument, sclName));
31+
}).catch(createLogEvent);
32+
33+
dispatchEventOnOpenScd(newWizardEvent());
34+
}
35+
36+
render(): TemplateResult {
37+
return html `
38+
<filtered-list>
39+
<mwc-list-item
40+
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
41+
this.processCimFile('cim-eq-hoorn-v3')
42+
))}>
43+
cim-eq-hoorn-v3
44+
</mwc-list-item>
45+
<mwc-list-item
46+
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
47+
this.processCimFile('cim-eq-makkum')
48+
))}>
49+
cim-eq-makkum
50+
</mwc-list-item>
51+
<mwc-list-item
52+
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
53+
this.processCimFile('cim-eq-winselingseweg-voorbeeld')
54+
))}>
55+
cim-eq-winselingseweg-voorbeeld
56+
</mwc-list-item>
57+
<mwc-list-item
58+
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
59+
this.processCimFile('EQ-entsoe-voorbeeld')
60+
))}>
61+
EQ-entsoe-voorbeeld
62+
</mwc-list-item>
63+
</filtered-list>
64+
`
65+
}
66+
}

src/compas/CompasSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function CompasSettings() {
2323
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
2424
sclValidatorServiceUrl: this.getCompasSetting('sclValidatorServiceUrl'),
2525
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
26-
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl'),
26+
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl')
2727
};
2828
},
2929

src/menu/CompasImportFromApi.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { html, LitElement } from 'lit-element';
2+
import { get } from 'lit-translate';
3+
4+
import '../filtered-list.js';
5+
import '../wizard-textfield.js';
6+
import {
7+
newWizardEvent,
8+
Wizard,
9+
} from '../foundation.js';
10+
11+
import "../compas/CompasImportFromApi.js";
12+
13+
export default class ImportFromApiPlugin extends LitElement {
14+
15+
private importFromApiWizard(): Wizard {
16+
return [
17+
{
18+
title: get('compas.import.title'),
19+
content: [
20+
html`<compas-import-from-api></compas-import-from-api>`,
21+
],
22+
},
23+
];
24+
}
25+
26+
async run(): Promise<void> {
27+
document
28+
.querySelector('open-scd')
29+
?.dispatchEvent(newWizardEvent(this.importFromApiWizard()));
30+
}
31+
}

src/translations/de.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ export const de: Translations = {
578578
minor: '???',
579579
patch: '???',
580580
},
581+
import: {
582+
title: '???'
583+
},
581584
open: {
582585
title: '???',
583586
localTitle: '???',
@@ -647,7 +650,7 @@ export const de: Translations = {
647650
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
648651
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
649652
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
650-
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
653+
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
651654
},
652655
session: {
653656
headingExpiring: '???',

src/translations/en.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ export const en = {
573573
minor: 'Minor change',
574574
patch: 'Patch change',
575575
},
576+
import: {
577+
title: 'Import from API'
578+
},
576579
open: {
577580
title: 'Open project',
578581
localTitle: 'Local',
@@ -642,7 +645,7 @@ export const en = {
642645
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
643646
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
644647
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
645-
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
648+
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
646649
},
647650
session: {
648651
headingExpiring: 'Your session is about to expire!',

test/integration/__snapshots__/open-scd.test.snap.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @web/test-runner snapshot v1 */
22
export const snapshots = {};
33

4-
snapshots["open-scd looks like its snapshot"] =
4+
snapshots["open-scd looks like its snapshot"] =
55
`<mwc-drawer
66
class="mdc-theme--surface"
77
hasheader=""
@@ -850,6 +850,21 @@ snapshots["open-scd looks like its snapshot"] =
850850
</mwc-icon>
851851
Project from CIM
852852
</mwc-check-list-item>
853+
<mwc-check-list-item
854+
aria-disabled="false"
855+
class="official"
856+
graphic="control"
857+
hasmeta=""
858+
left=""
859+
mwc-list-item=""
860+
tabindex="-1"
861+
value="/src/menu/CompasImportFromApi.js"
862+
>
863+
<mwc-icon slot="meta">
864+
cloud_download
865+
</mwc-icon>
866+
Import from API
867+
</mwc-check-list-item>
853868
<mwc-check-list-item
854869
aria-disabled="false"
855870
class="official"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {expect, fixtureSync, html} from '@open-wc/testing';
2+
import CompasImportFromApiElement from '../../../src/compas/CompasImportFromApi.js';
3+
4+
import "../../../src/compas/CompasImportFromApi.js";
5+
6+
describe('compas-import-from-api', () => {
7+
let element: CompasImportFromApiElement;
8+
9+
beforeEach(async () => {
10+
element = fixtureSync(html`<compas-import-from-api></compas-import-from-api>`);
11+
await element;
12+
});
13+
14+
it('looks like the latest snapshot', () => {
15+
expect(element).shadowDom.to.equalSnapshot();
16+
});
17+
});

0 commit comments

Comments
 (0)