forked from openscd/open-scd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new Communication 104 Editor framework.
Signed-off-by: Dennis Labordus <dennis.labordus@alliander.com>
- Loading branch information
Dennis Labordus
committed
May 17, 2022
1 parent
2f0bad9
commit 3364eab
Showing
17 changed files
with
312 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
8 changes: 4 additions & 4 deletions
8
...itors/sampledvalues/SampledValues.test.ts → ...integration/editors/SampledValues.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
test/integration/editors/__snapshots__/Communication104.test.snap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
|
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.