Skip to content

Commit

Permalink
Added new Communication 104 Editor framework.
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Labordus <dennis.labordus@alliander.com>
  • Loading branch information
Dennis Labordus committed May 17, 2022
1 parent 2f0bad9 commit 3364eab
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 10 deletions.
7 changes: 7 additions & 0 deletions public/js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export const officialPlugins = [
default: true,
kind: 'editor',
},
{
name: '104',
src: '/src/editors/Communication104.js',
icon: 'settings_ethernet',
default: false,
kind: 'editor',
},
{
name: 'Templates',
src: '/src/editors/Templates.js',
Expand Down
106 changes: 106 additions & 0 deletions src/editors/Communication104.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import {
css,
html,
LitElement,
property,
query,
TemplateResult
} from "lit-element";
import {translate} from "lit-translate";

import '@material/mwc-fab';
import '@material/mwc-radio';
import '@material/mwc-formfield';

import {RadioListItem} from "@material/mwc-list/mwc-radio-list-item";

import './communication104/network-container.js'
import './communication104/values-container.js'

import {
newViewEvent,
View,
VIEW_EVENT_NAME,
ViewEvent
} from "./communication104/foundation/foundation.js";

/** Defining view outside the class, which makes it persistent. */
let selectedViewCommunication104Plugin: View = View.VALUES;

/** An editor [[`plugin`]] for editing the `IED` section. */
export default class Communication104Plugin extends LitElement {
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
@property()
doc!: XMLDocument;

@query('#byValuesRadio')
byValuesRadio!: RadioListItem;

@query('#byNetworkRadio')
byNetworkRadio!: RadioListItem;

@query('div[class="container"]')
listDiv!: Element;

constructor() {
super();

this.addEventListener(VIEW_EVENT_NAME, (evt: ViewEvent) => {
selectedViewCommunication104Plugin = evt.detail.view;
this.requestUpdate();
});
}

firstUpdated(): void {
selectedViewCommunication104Plugin == View.VALUES
? this.byValuesRadio.setAttribute('checked', '')
: this.byNetworkRadio.setAttribute('checked', '')
}

render(): TemplateResult {
return html`<div>
<mwc-formfield label="${translate('communication104.view.valuesView')}">
<mwc-radio
id="byValuesRadio"
name="view"
value="values"
@checked=${() => this.listDiv.dispatchEvent(newViewEvent(View.VALUES))}
></mwc-radio>
</mwc-formfield>
<mwc-formfield label="${translate('communication104.view.networkView')}">
<mwc-radio
id="byNetworkRadio"
name="view"
value="network"
@checked=${() => this.listDiv.dispatchEvent(newViewEvent(View.NETWORK))}
></mwc-radio>
</mwc-formfield>
<div class="container">
${selectedViewCommunication104Plugin == View.VALUES
? html`<values-104-container class="row" .doc=${this.doc}></values-104-container>`
: html`<network-104-container class="row" .doc=${this.doc}></network-104-container>`
}
</div>
</div>`;
}

static styles = css`
:host {
width: 100vw;
}
.container {
display: flex;
padding: 8px 6px 16px;
height: 86vh;
}
.row {
flex: 50%;
margin: 0px 6px 0px;
min-width: 300px;
height: 100%;
overflow-y: scroll;
}
`;
}
32 changes: 32 additions & 0 deletions src/editors/communication104/foundation/foundation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Enumeration stating the current view of the 104 plugin.
*/
export enum View {
VALUES,
NETWORK
}

export const VIEW_EVENT_NAME = 'view-change-104-plugin';

// Objects needed to register and fire the change of a view within the Communication 104 Plugin
export interface ViewDetail {
view: View;
}
export type ViewEvent = CustomEvent<ViewDetail>;
export function newViewEvent(
view: View,
eventInitDict?: CustomEventInit<ViewDetail>
): ViewEvent {
return new CustomEvent<ViewDetail>(VIEW_EVENT_NAME, {
bubbles: true,
composed: true,
...eventInitDict,
detail: { view, ...eventInitDict?.detail },
});
}

declare global {
interface ElementEventMap {
[VIEW_EVENT_NAME]: ViewEvent;
}
}
13 changes: 13 additions & 0 deletions src/editors/communication104/network-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {css, customElement, html, LitElement, TemplateResult} from "lit-element";

@customElement('network-104-container')
export class NetworkContainer extends LitElement {
render(): TemplateResult {
return html`
<p>Network Container</p>
`;
}

static styles = css`
`;
}
13 changes: 13 additions & 0 deletions src/editors/communication104/values-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {css, customElement, html, LitElement, TemplateResult} from "lit-element";

@customElement('values-104-container')
export class ValuesContainer extends LitElement {
render(): TemplateResult {
return html`
<p>Values Container</p>
`;
}

static styles = css`
`;
}
6 changes: 6 additions & 0 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ export const de: Translations = {
noSampledValuesSelected: 'Keinen Kontrollblock ausgewählt',
},
},
communication104: {
view: {
valuesView: 'Values',
networkView: 'Network',
}
},
'enum-val': {
wizard: {
title: {
Expand Down
6 changes: 6 additions & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ export const en = {
noSampledValuesSelected: 'No control block selected',
},
},
communication104: {
view: {
valuesView: 'Values',
networkView: 'Network',
}
},
'enum-val': {
wizard: {
title: {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/__snapshots__/open-scd.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,21 @@ snapshots["open-scd looks like its snapshot"] =
</mwc-icon>
Communication
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
graphic="control"
hasmeta=""
left=""
mwc-list-item=""
tabindex="-1"
value="/src/editors/Communication104.js"
>
<mwc-icon slot="meta">
settings_ethernet
</mwc-icon>
104
</mwc-check-list-item>
<mwc-check-list-item
aria-disabled="false"
class="official"
Expand Down
44 changes: 44 additions & 0 deletions test/integration/editors/Communication104.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { html, fixture, expect } from '@open-wc/testing';

import '../../mock-wizard.js';

import Communication104 from '../../../src/editors/Communication104.js';
import { Editing } from '../../../src/Editing.js';
import { Wizarding } from '../../../src/Wizarding.js';

describe('Communication 104 Plugin', () => {
customElements.define(
'communication104-plugin',
Wizarding(Editing(Communication104))
);
let element: Communication104;
let doc: XMLDocument;

beforeEach(async () => {
doc = await fetch('/test/testfiles/communication.scd')
.then(response => response.text())
.then(str => new DOMParser().parseFromString(str, 'application/xml'));

element = await fixture(
html`<communication104-plugin .doc=${doc}></communication104-plugin>`
);
});

describe('in Values view', () => {
it('the plugin looks like the latest snapshot', async () => {
await expect(element).shadowDom.to.equalSnapshot();
});
});

describe('in Network view', () => {
beforeEach(async () => {
const radioButton = element.shadowRoot?.querySelector('#byNetworkRadio');
(<HTMLElement>radioButton).click();
await element.updateComplete;
});

it('the plugin looks like the latest snapshot', async () => {
await expect(element).shadowDom.to.equalSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { html, fixture, expect } from '@open-wc/testing';

import '../../../mock-wizard.js';
import '../../mock-wizard.js';

import SampledValues from '../../../../src/editors/SampledValues.js';
import { Editing } from '../../../../src/Editing.js';
import { Wizarding } from '../../../../src/Wizarding.js';
import SampledValues from '../../../src/editors/SampledValues.js';
import { Editing } from '../../../src/Editing.js';
import { Wizarding } from '../../../src/Wizarding.js';

describe('Sampled Values Plugin', () => {
customElements.define('smv-plugin', Wizarding(Editing(SampledValues)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { html, fixture, expect } from '@open-wc/testing';

import '../../../mock-wizard.js';
import '../../mock-wizard.js';

import Subscription from '../../../../src/editors/Subscription.js';
import { Editing } from '../../../../src/Editing.js';
import { Wizarding } from '../../../../src/Wizarding.js';
import Subscription from '../../../src/editors/Subscription.js';
import { Editing } from '../../../src/Editing.js';
import { Wizarding } from '../../../src/Wizarding.js';

describe('Subscription Plugin', () => {
customElements.define(
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('Subscription Plugin', () => {
(<HTMLElement>radioButton).click();
await element.updateComplete;
});

describe('initially', () => {
it('the plugin looks like the latest snapshot', async () => {
await expect(element).shadowDom.to.equalSnapshot();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["Communication 104 Plugin in Values view the plugin looks like the latest snapshot"] =
`<div>
<mwc-formfield label="[communication104.view.valuesView]">
<mwc-radio
checked=""
id="byValuesRadio"
name="view"
value="values"
>
</mwc-radio>
</mwc-formfield>
<mwc-formfield label="[communication104.view.networkView]">
<mwc-radio
id="byNetworkRadio"
name="view"
value="network"
>
</mwc-radio>
</mwc-formfield>
<div class="container">
<values-104-container class="row">
</values-104-container>
</div>
</div>
<wizard-dialog>
</wizard-dialog>
`;
/* end snapshot Communication 104 Plugin in Values view the plugin looks like the latest snapshot */

snapshots["Communication 104 Plugin in Network view the plugin looks like the latest snapshot"] =
`<div>
<mwc-formfield label="[communication104.view.valuesView]">
<mwc-radio
id="byValuesRadio"
name="view"
value="values"
>
</mwc-radio>
</mwc-formfield>
<mwc-formfield label="[communication104.view.networkView]">
<mwc-radio
checked=""
id="byNetworkRadio"
name="view"
value="network"
>
</mwc-radio>
</mwc-formfield>
<div class="container">
<network-104-container class="row">
</network-104-container>
</div>
</div>
<wizard-dialog>
</wizard-dialog>
`;
/* end snapshot Communication 104 Plugin in Network view the plugin looks like the latest snapshot */

1 change: 0 additions & 1 deletion test/unit/editors/importieds.test.ts

This file was deleted.

File renamed without changes.
File renamed without changes.

0 comments on commit 3364eab

Please sign in to comment.