Skip to content

Commit

Permalink
feat(substation): read only Function and SubFunction container (#700)
Browse files Browse the repository at this point in the history
* feat(zeroline): add showfunctions toggle button

* feat(zeroline): write toggle buttons state to localhost

* feat(zeroline/function-editor): add function-editor web-component

* feat(zeroline): add function-editor to zeroline

* refactor: linter format

* test(zeroline): add snapshot tests

* refactor(zeroline): pass showfunction though properties

* feat(zeroline): add read-only subfuction-editor (#706)
  • Loading branch information
JakobVogelsang authored Apr 29, 2022
1 parent 865f7ab commit 3d7b2ef
Show file tree
Hide file tree
Showing 22 changed files with 771 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const de: Translations = {
zeroline: {
iedsloading: 'IEDs werden geladen...',
showieds: 'IEDs im Substation-Editor anzeigen/ausblenden',
showfunctions: 'Funktionselemente in der Ansicht filtern',
commmap: 'Kommunikationszuordnung',
reportcontrol: 'Reports anzeigen',
gsecontrol: 'GOOSEs anzeigen',
Expand Down Expand Up @@ -391,7 +392,7 @@ export const de: Translations = {
},
action: {
updatedai: 'DAI "{{daiName}} bearbeitet"',
}
},
},
sdo: {
wizard: {
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const en = {
zeroline: {
iedsloading: 'Loading IEDs...',
showieds: 'Show/hide IEDs in substation editor',
showfunctions: 'Filter function type elements',
commmap: 'Communication mapping',
reportcontrol: 'Show all Reports',
gsecontrol: 'Show all GOOSEs',
Expand Down Expand Up @@ -388,7 +389,7 @@ export const en = {
},
action: {
updatedai: 'Edited DAI "{{daiName}}"',
}
},
},
sdo: {
wizard: {
Expand Down
25 changes: 25 additions & 0 deletions src/zeroline-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function setShowIEDs(value: Settings['showieds']) {
localStorage.setItem('showieds', value);
}

function shouldShowFunctions(): boolean {
return localStorage.getItem('showfunctions') === 'on';
}

function setShowFunctions(value: 'on' | 'off') {
localStorage.setItem('showfunctions', value);
}

/** [[`Zeroline`]] pane for displaying `Substation` and/or `IED` sections. */
@customElement('zeroline-pane')
export class ZerolinePane extends LitElement {
Expand All @@ -48,6 +56,7 @@ export class ZerolinePane extends LitElement {

@query('#commmap') commmap!: IconButton;
@query('#showieds') showieds!: IconButtonToggle;
@query('#showfunctions') showfunctions!: IconButtonToggle;
@query('#gsecontrol') gsecontrol!: IconButton;
@query('#smvcontrol') smvcontrol!: IconButton;
@query('#reportcontrol') reportcontrol!: IconButton;
Expand Down Expand Up @@ -90,6 +99,12 @@ export class ZerolinePane extends LitElement {
this.requestUpdate();
}

toggleShowFunctions(): void {
if (shouldShowFunctions()) setShowFunctions('off');
else setShowFunctions('on');
this.requestUpdate();
}

renderIedContainer(): TemplateResult {
this.getAttachedIeds = shouldShowIEDs()
? getAttachedIeds(this.doc)
Expand Down Expand Up @@ -124,6 +139,15 @@ export class ZerolinePane extends LitElement {
offIcon="developer_board_off"
></mwc-icon-button-toggle>
</abbr>
<abbr title="${translate('zeroline.showfunctions')}">
<mwc-icon-button-toggle
?on=${shouldShowFunctions()}
@click=${() => this.toggleShowFunctions()}
id="showfunctions"
onIcon="layers"
offIcon="layers_clear"
></mwc-icon-button-toggle>
</abbr>
<abbr title="${translate('zeroline.commmap')}">
<mwc-icon-button
id="commmap"
Expand Down Expand Up @@ -165,6 +189,7 @@ export class ZerolinePane extends LitElement {
.element=${substation}
.getAttachedIeds=${this.getAttachedIeds}
?readonly=${this.readonly}
?showfunctions=${shouldShowFunctions()}
></substation-editor>`
)}
</section>`
Expand Down
24 changes: 17 additions & 7 deletions src/zeroline/bay-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import {
tags,
} from '../foundation.js';
import { emptyWizard, wizards } from '../wizards/wizard-library.js';
import {
cloneSubstationElement,
startMove,
styles,
} from './foundation.js';
import { cloneSubstationElement, startMove, styles } from './foundation.js';

function childTags(element: Element | null | undefined): SCLTag[] {
if (!element) return [];
Expand All @@ -48,6 +44,9 @@ export class BayEditor extends LitElement {
element!: Element;
@property({ type: Boolean })
readonly = false;
/** Wheter `Function` and `SubFunction` are rendered */
@property({ type: Boolean })
showfunctions = false;

@property({ type: String })
get header(): string {
Expand Down Expand Up @@ -99,6 +98,15 @@ export class BayEditor extends LitElement {
this.addMenu.anchor = <HTMLElement>this.addButton;
}

renderFunctions(): TemplateResult {
if (!this.showfunctions) return html``;

const functions = getChildElementsByTagName(this.element, 'Function');
return html` ${functions.map(
fUnction => html`<function-editor .element=${fUnction}></function-editor>`
)}`;
}

renderIedContainer(): TemplateResult {
const ieds = this.getAttachedIeds?.(this.element) ?? [];
return ieds?.length
Expand Down Expand Up @@ -168,13 +176,15 @@ export class BayEditor extends LitElement {
>${this.renderAddButtons()}</mwc-menu
>
</abbr>
${this.renderIedContainer()}
${this.renderIedContainer()} ${this.renderFunctions()}
<div id="ceContainer">
${Array.from(
getChildElementsByTagName(this.element, 'PowerTransformer')
).map(
pwt =>
html`<powertransformer-editor .element=${pwt}></powertransformer-editor>`
html`<powertransformer-editor
.element=${pwt}
></powertransformer-editor>`
)}
${Array.from(
getChildElementsByTagName(this.element, 'ConductingEquipment')
Expand Down
21 changes: 12 additions & 9 deletions src/zeroline/foundation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css, TemplateResult } from 'lit-element';

import './function-editor.js';
import { newActionEvent, isPublic } from '../foundation.js';
import {
circuitBreakerIcon,
Expand Down Expand Up @@ -156,12 +157,8 @@ export type ElementEditorClass<T extends ElementEditor> = new () => T;
export function startMove<
E extends ElementEditor,
C extends ElementEditorClass<ElementEditor>,
P extends ElementEditorClass<ElementEditor>>
(
editor: E,
childClass: C,
parentClasses: P[]
): void {
P extends ElementEditorClass<ElementEditor>
>(editor: E, childClass: C, parentClasses: P[]): void {
if (!editor.element) return;

editor.classList.add('moving');
Expand All @@ -184,8 +181,13 @@ export function startMove<

if (e instanceof KeyboardEvent && e.key === 'Escape') return;

const targetEditor = e.composedPath()
.find(et => et instanceof childClass || checkInstanceOfParentClass(et, parentClasses));
const targetEditor = e
.composedPath()
.find(
et =>
et instanceof childClass ||
checkInstanceOfParentClass(et, parentClasses)
);
if (targetEditor === undefined || targetEditor === editor) return;

const destination =
Expand Down Expand Up @@ -227,7 +229,8 @@ export function startMove<
*/
function checkInstanceOfParentClass<E extends ElementEditor>(
et: EventTarget,
classes: ElementEditorClass<E>[]): boolean {
classes: ElementEditorClass<E>[]
): boolean {
const targetEditor = classes.find(clazz => et instanceof clazz);
return targetEditor !== undefined;
}
Expand Down
46 changes: 46 additions & 0 deletions src/zeroline/function-editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
html,
LitElement,
TemplateResult,
property,
customElement,
state,
} from 'lit-element';

import '../action-pane.js';
import './subfunction-editor.js';
import { getChildElementsByTagName } from '../foundation.js';

/** Pane rendering `Function` element with its children */
@customElement('function-editor')
export class FunctionEditor extends LitElement {
/** The edited `Function` element */
@property({ attribute: false })
element!: Element;
@state()
get header(): string {
const name = this.element.getAttribute('name');
const desc = this.element.getAttribute('desc');
const type = this.element.getAttribute('type');

return `${name}${desc ? ` - ${desc}` : ''}${type ? ` (${type})` : ''}`;
}

renderSubFunctions(): TemplateResult {
const subfunctions = getChildElementsByTagName(this.element, 'SubFunction');
return html` ${subfunctions.map(
subFunction =>
html`<subfunction-editor .element=${subFunction}></subfunction-editor>`
)}`;
}

render(): TemplateResult {
return html`<action-pane
label="${this.header}"
icon="functions"
secondary
highlighted
>${this.renderSubFunctions()}</action-pane
>`;
}
}
42 changes: 42 additions & 0 deletions src/zeroline/subfunction-editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
html,
LitElement,
TemplateResult,
property,
customElement,
state,
} from 'lit-element';

import '../action-pane.js';
import './subfunction-editor.js';
import { getChildElementsByTagName } from '../foundation.js';

/** Pane rendering `SubFunction` element with its children */
@customElement('subfunction-editor')
export class SubFunctionEditor extends LitElement {
/** The edited `SubFunction` element */
@property({ attribute: false })
element!: Element;
@state()
get header(): string {
const name = this.element.getAttribute('name');
const desc = this.element.getAttribute('desc');
const type = this.element.getAttribute('type');

return `${name}${desc ? ` - ${desc}` : ''}${type ? ` (${type})` : ''}`;
}

renderSubFunctions(): TemplateResult {
const subfunctions = getChildElementsByTagName(this.element, 'SubFunction');
return html` ${subfunctions.map(
subFunction =>
html`<subfunction-editor .element=${subFunction}></subfunction-editor>`
)}`;
}

render(): TemplateResult {
return html`<action-pane label="${this.header}" icon="functions" secondary
>${this.renderSubFunctions()}</action-pane
>`;
}
}
38 changes: 33 additions & 5 deletions src/zeroline/substation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import '../action-pane.js';
import './ied-editor.js';
import './powertransformer-editor.js';
import './voltage-level-editor.js';
import { newActionEvent, newWizardEvent, SCLTag, tags } from '../foundation.js';
import {
getChildElementsByTagName,
newActionEvent,
newWizardEvent,
SCLTag,
tags,
} from '../foundation.js';
import { emptyWizard, wizards } from '../wizards/wizard-library.js';
import {
cloneSubstationElement,
Expand All @@ -43,6 +49,9 @@ export class SubstationEditor extends LitElement {
element!: Element;
@property({ type: Boolean })
readonly = false;
/** Wheter `Function` and `SubFunction` are rendered */
@property({ type: Boolean })
showfunctions = false;

@property({ type: String })
get header(): string {
Expand Down Expand Up @@ -95,6 +104,15 @@ export class SubstationEditor extends LitElement {
this.addMenu.anchor = <HTMLElement>this.addButton;
}

renderFunctions(): TemplateResult {
if (!this.showfunctions) return html``;

const functions = getChildElementsByTagName(this.element, 'Function');
return html` ${functions.map(
fUnction => html`<function-editor .element=${fUnction}></function-editor>`
)}`;
}

renderIedContainer(): TemplateResult {
const ieds = this.getAttachedIeds?.(this.element) ?? [];
return ieds?.length
Expand All @@ -105,11 +123,20 @@ export class SubstationEditor extends LitElement {
}

renderPowerTransformerContainer(): TemplateResult {
const pwts = Array.from(this.element?.querySelectorAll(selectors.Substation + ' > PowerTransformer') ?? []);
const pwts = Array.from(
this.element?.querySelectorAll(
selectors.Substation + ' > PowerTransformer'
) ?? []
);
return pwts?.length
? html`<div id="powertransformercontainer">
${pwts.map(pwt => html`<powertransformer-editor .element=${pwt}></powertransformer-editor>`)}
</div>`
${pwts.map(
pwt =>
html`<powertransformer-editor
.element=${pwt}
></powertransformer-editor>`
)}
</div>`
: html``;
}

Expand Down Expand Up @@ -173,14 +200,15 @@ export class SubstationEditor extends LitElement {
>${this.renderAddButtons()}</mwc-menu
>
</abbr>
${this.renderIedContainer()}
${this.renderIedContainer()}${this.renderFunctions()}
${this.renderPowerTransformerContainer()}
${Array.from(this.element.querySelectorAll(selectors.VoltageLevel)).map(
voltageLevel =>
html`<voltage-level-editor
.element=${voltageLevel}
.getAttachedIeds=${this.getAttachedIeds}
?readonly=${this.readonly}
?showfunctions=${this.showfunctions}
></voltage-level-editor>`
)}</action-pane
>`;
Expand Down
Loading

0 comments on commit 3d7b2ef

Please sign in to comment.