Skip to content

Commit

Permalink
Add supervision indicator, closes openscd#1037
Browse files Browse the repository at this point in the history
  • Loading branch information
danyill committed Oct 30, 2022
1 parent 36ded24 commit 7a71957
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
26 changes: 26 additions & 0 deletions src/editors/subscription/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Create,
createElement,
Delete,
findControlBlocks,
getSclSchemaVersion,
minAvailableLnInst,
} from '../../foundation.js';
Expand Down Expand Up @@ -343,6 +344,31 @@ export function findOrCreateAvailableLNInst(
return newElement;
}

/** Returns an new or existing LN instance available for supervision instantiation
*
* @param extRef - The extRef SCL element in the subscribing IED.
* @param controlBlock - The publishing IED control block.
* @returns The supervision LN instance or null if no LN instance could be found or created.
*/
export function getExistingSupervision(
extRef: Element,
controlBlock: Element
): Element | undefined {
const subscriberIED = extRef.closest('IED')!;
const supervisionType =
controlBlock.tagName === 'GSEControl' ? 'LGOS' : 'LSVS';
const refSelector =
supervisionType === 'LGOS' ? 'DOI[name="GoCBRef"]' : 'DOI[name="SvCBRef"]';
const supervisionElement = Array.from(
subscriberIED.querySelectorAll(`LN[lnClass="${supervisionType}"]`)
).find(
ln =>
ln.querySelector(`${refSelector}>DAI[name="setSrcRef"]>Val`)
?.textContent === controlBlockReference(controlBlock)
);
return supervisionElement;
}

/**
* Counts the number of LN instances with proper supervision for the given control block set up.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../../foundation.js';

import {
getExistingSupervision,
styles,
updateExtRefElement,
instantiateSubscriptionSupervision,
Expand Down Expand Up @@ -213,6 +214,34 @@ export class ExtRefLaterBindingList extends LitElement {
</h1>`;
}

private renderExtRefElement(extRefElement: Element): TemplateResult {
const supervisionNode = getExistingSupervision(
extRefElement,
<Element>this.currentSelectedControlElement,
);
return html` <mwc-list-item
graphic="large"
?hasMeta=${supervisionNode !== null}
twoline
@click=${() => this.unsubscribe(extRefElement)}
value="${identity(extRefElement)}"
>
<span>
${extRefElement.getAttribute('intAddr')}
${getDescriptionAttribute(extRefElement)
? html` (${getDescriptionAttribute(extRefElement)})`
: nothing}
</span>
<span slot="secondary">${identity(extRefElement)}</span>
<mwc-icon slot="graphic">swap_horiz</mwc-icon>
${supervisionNode !== undefined
? html`<mwc-icon title="${identity(supervisionNode)}" slot="meta"
>monitor_heart</mwc-icon
>`
: nothing}
</mwc-list-item>`;
}

private renderSubscribedExtRefs(): TemplateResult {
const subscribedExtRefs = this.getSubscribedExtRefElements();
return html`
Expand All @@ -231,22 +260,8 @@ export class ExtRefLaterBindingList extends LitElement {
</mwc-list-item>
<li divider role="separator"></li>
${subscribedExtRefs.length > 0
? html`${subscribedExtRefs.map(
extRefElement => html` <mwc-list-item
graphic="large"
twoline
@click=${() => this.unsubscribe(extRefElement)}
value="${identity(extRefElement)}"
>
<span>
${extRefElement.getAttribute('intAddr')}
${getDescriptionAttribute(extRefElement)
? html` (${getDescriptionAttribute(extRefElement)})`
: nothing}
</span>
<span slot="secondary">${identity(extRefElement)}</span>
<mwc-icon slot="graphic">swap_horiz</mwc-icon>
</mwc-list-item>`
? html`${subscribedExtRefs.map(extRefElement =>
this.renderExtRefElement(extRefElement)
)}`
: html`<mwc-list-item graphic="large" noninteractive>
${translate(
Expand Down

0 comments on commit 7a71957

Please sign in to comment.