Skip to content

Commit c6a8097

Browse files
author
Flurb
committed
Implemented Import from API plugin
Signed-off-by: Flurb <[email protected]>
1 parent 95cbf83 commit c6a8097

File tree

10 files changed

+148
-9
lines changed

10 files changed

+148
-9
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export const officialPlugins = [
8484
},
8585
{
8686
name: 'Import from API',
87-
src: '/src/menu/CompasImportFromLiander.js',
88-
icon: 'create_new_folder',
87+
src: '/src/menu/CompasImportFromApi.js',
88+
icon: 'cloud_download',
8989
default: false,
9090
kind: 'menu',
9191
requireDoc: false,

src/compas/CompasImportFromApi.ts

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

src/compas/CompasSettings.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type CompasSettingsRecord = {
1313
sclValidatorServiceUrl: string;
1414
cimMappingServiceUrl: string;
1515
sclAutoAlignmentServiceUrl: string;
16+
importFromApiUrl: string;
1617
};
1718

1819
export function CompasSettings() {
@@ -24,6 +25,7 @@ export function CompasSettings() {
2425
sclValidatorServiceUrl: this.getCompasSetting('sclValidatorServiceUrl'),
2526
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
2627
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl'),
28+
importFromApiUrl: this.getCompasSetting('importFromApiUrl'),
2729
};
2830
},
2931

@@ -32,7 +34,8 @@ export function CompasSettings() {
3234
sclDataServiceUrl: '/compas-scl-data-service',
3335
sclValidatorServiceUrl: '/compas-scl-validator',
3436
cimMappingServiceUrl: '/compas-cim-mapping',
35-
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment'
37+
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment',
38+
importFromApiUrl: '/public/cim'
3639
}
3740
},
3841

@@ -72,11 +75,16 @@ export class CompasSettingsElement extends LitElement {
7275
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="sclAutoAlignmentServiceUrl"]');
7376
}
7477

78+
getImportFromApiUrlField(): TextFieldBase {
79+
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="importFromApiUrl"]');
80+
}
81+
7582
valid(): boolean {
7683
return this.getSclDataServiceUrlField().checkValidity()
7784
&& this.getSclValidatorServiceUrlField().checkValidity()
7885
&& this.getCimMappingServiceUrlField().checkValidity()
79-
&& this.getSclAutoAlignmentServiceUrlField().checkValidity();
86+
&& this.getSclAutoAlignmentServiceUrlField().checkValidity()
87+
&& this.getImportFromApiUrlField().checkValidity();
8088
}
8189

8290
save(): boolean {
@@ -89,6 +97,7 @@ export class CompasSettingsElement extends LitElement {
8997
CompasSettings().setCompasSetting('sclValidatorServiceUrl', this.getSclValidatorServiceUrlField().value);
9098
CompasSettings().setCompasSetting('cimMappingServiceUrl', this.getCimMappingServiceUrlField().value);
9199
CompasSettings().setCompasSetting('sclAutoAlignmentServiceUrl', this.getSclAutoAlignmentServiceUrlField().value);
100+
CompasSettings().setCompasSetting('importFromApiUrl', this.getImportFromApiUrlField().value);
92101
return true;
93102
}
94103

@@ -122,6 +131,10 @@ export class CompasSettingsElement extends LitElement {
122131
label="${translate('compas.settings.sclAutoAlignmentServiceUrl')}"
123132
value="${this.compasSettings.sclAutoAlignmentServiceUrl}" required>
124133
</mwc-textfield>
134+
<mwc-textfield id="importFromApiUrl"
135+
label="${translate('compas.settings.importFromApiUrl')}"
136+
value="${this.compasSettings.importFromApiUrl}" required>
137+
</mwc-textfield>
125138
126139
<mwc-button @click=${() => {
127140
if (this.reset()) {

src/menu/CompasImportFromLiander.ts renamed to src/menu/CompasImportFromApi.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import {
88
Wizard,
99
} from '../foundation.js';
1010

11+
import "../compas/CompasImportFromApi.js";
12+
1113
export default class ImportFromApiPlugin extends LitElement {
14+
1215
private importFromApiWizard(): Wizard {
1316
return [
1417
{
1518
title: get('compas.import.title'),
1619
content: [
17-
html`<filtered-list>
18-
19-
</filtered-list>`,
20+
html`<compas-import-from-api></compas-import-from-api>`,
2021
],
2122
},
2223
];

src/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ export const de: Translations = {
640640
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
641641
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
642642
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
643+
importFromApiUrl: 'CoMPAS Import from API URL',
643644
},
644645
session: {
645646
headingExpiring: '???',

src/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ export const en = {
636636
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
637637
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
638638
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
639+
importFromApiUrl: 'CoMPAS Import from API URL',
639640
},
640641
session: {
641642
headingExpiring: 'Your session is about to expire!',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,10 @@ snapshots["open-scd looks like its snapshot"] =
858858
left=""
859859
mwc-list-item=""
860860
tabindex="-1"
861-
value="/src/menu/CompasImportFromLiander.js"
861+
value="/src/menu/CompasImportFromApi.js"
862862
>
863863
<mwc-icon slot="meta">
864-
create_new_folder
864+
cloud_download
865865
</mwc-icon>
866866
Import from API
867867
</mwc-check-list-item>
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+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* @web/test-runner snapshot v1 */
2+
export const snapshots = {};
3+
4+
snapshots["compas-import-from-api looks like the latest snapshot"] =
5+
`<filtered-list>
6+
<mwc-list-item
7+
aria-disabled="false"
8+
mwc-list-item=""
9+
tabindex="-1"
10+
>
11+
cim-eq-hoorn-v3
12+
</mwc-list-item>
13+
<mwc-list-item
14+
aria-disabled="false"
15+
mwc-list-item=""
16+
tabindex="-1"
17+
>
18+
cim-eq-makkum
19+
</mwc-list-item>
20+
<mwc-list-item
21+
aria-disabled="false"
22+
mwc-list-item=""
23+
tabindex="-1"
24+
>
25+
cim-eq-winselingseweg-voorbeeld
26+
</mwc-list-item>
27+
<mwc-list-item
28+
aria-disabled="false"
29+
mwc-list-item=""
30+
tabindex="-1"
31+
>
32+
EQ-entsoe-voorbeeld
33+
</mwc-list-item>
34+
</filtered-list>
35+
`;
36+
/* end snapshot compas-import-from-api looks like the latest snapshot */
37+

0 commit comments

Comments
 (0)