Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
/_site/
/build/
/out-tsc/

/public/cim/
!/public/cim/README.md
8 changes: 8 additions & 0 deletions public/cim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Directory containing fixed files for the 'Import from API' plugin, namely:

- cim-eq-hoorn-v3.xml
- cim-eq-makkum.xml
- cim-eq-winselingseweg-voorbeeld.xml
- EQ-entsoe-voorbeeld.xml

Without these files, the 'Import from API' doesn't work and the hardcoded files cannot be opened.
9 changes: 9 additions & 0 deletions public/js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export const officialPlugins = [
requireDoc: false,
position: 'top'
},
{
name: 'Import from API',
src: '/src/menu/CompasImportFromApi.js',
icon: 'cloud_download',
default: false,
kind: 'menu',
requireDoc: false,
position: 'top'
},
{
name: 'Save project',
src: '/src/menu/CompasSave.js',
Expand Down
66 changes: 66 additions & 0 deletions src/compas/CompasImportFromApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {customElement, html, LitElement, TemplateResult} from "lit-element";

import '@material/mwc-button';

import {newOpenDocEvent, newPendingStateEvent, newWizardEvent} from "../foundation.js";

import {createLogEvent, handleError, handleResponse, parseXml} from "../compas-services/foundation.js";
import {dispatchEventOnOpenScd} from "./foundation.js";

import '../WizardDivider.js';
import './CompasSclTypeList.js';
import './CompasScl.js';
import { CompasCimMappingService } from "../compas-services/CompasCimMappingService.js";

@customElement('compas-import-from-api')
export default class CompasImportFromApiElement extends LitElement {
private async processCimFile(name: string) {
const doc = await fetch('/public/cim/' + name + '.xml')
.catch(handleError)
.then(handleResponse)
.then(parseXml);

await CompasCimMappingService().map({cimData: [{name: name + '.xml', doc: doc}]}).then(response => {
const sclName = name + ".ssd";

const sclElement = response.querySelectorAll("SCL").item(0);
const sclDocument = document.implementation.createDocument("", "", null);
sclDocument.getRootNode().appendChild(sclElement.cloneNode(true));

dispatchEventOnOpenScd(newOpenDocEvent(sclDocument, sclName));
}).catch(createLogEvent);

dispatchEventOnOpenScd(newWizardEvent());
}

render(): TemplateResult {
return html `
<filtered-list>
<mwc-list-item
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
this.processCimFile('cim-eq-hoorn-v3')
))}>
cim-eq-hoorn-v3
</mwc-list-item>
<mwc-list-item
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
this.processCimFile('cim-eq-makkum')
))}>
cim-eq-makkum
</mwc-list-item>
<mwc-list-item
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
this.processCimFile('cim-eq-winselingseweg-voorbeeld')
))}>
cim-eq-winselingseweg-voorbeeld
</mwc-list-item>
<mwc-list-item
@click=${() => dispatchEventOnOpenScd(newPendingStateEvent(
this.processCimFile('EQ-entsoe-voorbeeld')
))}>
EQ-entsoe-voorbeeld
</mwc-list-item>
</filtered-list>
`
}
}
2 changes: 1 addition & 1 deletion src/compas/CompasSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function CompasSettings() {
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
sclValidatorServiceUrl: this.getCompasSetting('sclValidatorServiceUrl'),
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl'),
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl')
};
},

Expand Down
31 changes: 31 additions & 0 deletions src/menu/CompasImportFromApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { html, LitElement } from 'lit-element';
import { get } from 'lit-translate';

import '../filtered-list.js';
import '../wizard-textfield.js';
import {
newWizardEvent,
Wizard,
} from '../foundation.js';

import "../compas/CompasImportFromApi.js";

export default class ImportFromApiPlugin extends LitElement {

private importFromApiWizard(): Wizard {
return [
{
title: get('compas.import.title'),
content: [
html`<compas-import-from-api></compas-import-from-api>`,
],
},
];
}

async run(): Promise<void> {
document
.querySelector('open-scd')
?.dispatchEvent(newWizardEvent(this.importFromApiWizard()));
}
}
5 changes: 4 additions & 1 deletion src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ export const de: Translations = {
minor: '???',
patch: '???',
},
import: {
title: '???'
},
open: {
title: '???',
localTitle: '???',
Expand Down Expand Up @@ -636,7 +639,7 @@ export const de: Translations = {
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
},
session: {
headingExpiring: '???',
Expand Down
5 changes: 4 additions & 1 deletion src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ export const en = {
minor: 'Minor change',
patch: 'Patch change',
},
import: {
title: 'Import from API'
},
open: {
title: 'Open project',
localTitle: 'Local',
Expand Down Expand Up @@ -632,7 +635,7 @@ export const en = {
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
},
session: {
headingExpiring: 'Your session is about to expire!',
Expand Down
17 changes: 16 additions & 1 deletion test/integration/__snapshots__/open-scd.test.snap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["open-scd looks like its snapshot"] =
snapshots["open-scd looks like its snapshot"] =
`<mwc-drawer
class="mdc-theme--surface"
hasheader=""
Expand Down Expand Up @@ -850,6 +850,21 @@ snapshots["open-scd looks like its snapshot"] =
</mwc-icon>
Project from CIM
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
graphic="control"
hasmeta=""
left=""
mwc-list-item=""
tabindex="-1"
value="/src/menu/CompasImportFromApi.js"
>
<mwc-icon slot="meta">
cloud_download
</mwc-icon>
Import from API
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
Expand Down
17 changes: 17 additions & 0 deletions test/unit/compas/CompasImportFromApi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {expect, fixtureSync, html} from '@open-wc/testing';
import CompasImportFromApiElement from '../../../src/compas/CompasImportFromApi.js';

import "../../../src/compas/CompasImportFromApi.js";

describe('compas-import-from-api', () => {
let element: CompasImportFromApiElement;

beforeEach(async () => {
element = fixtureSync(html`<compas-import-from-api></compas-import-from-api>`);
await element;
});

it('looks like the latest snapshot', () => {
expect(element).shadowDom.to.equalSnapshot();
});
});
37 changes: 37 additions & 0 deletions test/unit/compas/__snapshots__/CompasImportFromApi.test.snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["compas-import-from-api looks like the latest snapshot"] =
`<filtered-list>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
>
cim-eq-hoorn-v3
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
>
cim-eq-makkum
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
>
cim-eq-winselingseweg-voorbeeld
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
tabindex="-1"
>
EQ-entsoe-voorbeeld
</mwc-list-item>
</filtered-list>
`;
/* end snapshot compas-import-from-api looks like the latest snapshot */