Skip to content

Commit

Permalink
Allow new supervisions
Browse files Browse the repository at this point in the history
  • Loading branch information
danyill committed Sep 21, 2023
1 parent 6cf5d1e commit 15f8ba8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 51 deletions.
53 changes: 18 additions & 35 deletions foundation/subscription/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,47 +581,30 @@ export function instantiateSubscriptionSupervision(
});
}

let valElement = availableLN.querySelector(`Val`);
// TODO: Ask ca-d. Can't update an elements "content" directly so must remove and recreate?
const valTextContent = controlBlockReference(controlBlock);
const valElement = daiElement.querySelector(`Val`);
let newValElement: Element;

if (valElement) edits.push({ node: valElement });
if (valElement) {
// remove old element
edits.push({
node: valElement,
});
newValElement = <Element>valElement.cloneNode(true);
} else {
newValElement = subscriberIED.ownerDocument.createElementNS(
SCL_NAMESPACE,
'Val'
);
}
newValElement.textContent = valTextContent;

valElement = subscriberIED.ownerDocument.createElementNS(
SCL_NAMESPACE,
'Val'
);
// TODO: Fixed, this is not done like this or we do an update action
// TODO: We can't do that! This is a crime which must also be fixed in oscd-subscriber-later-binding
// This is not using the Action / Edit API !!!
valElement.textContent = controlBlockReference(controlBlock);
// add new element
edits.push({
parent: daiElement!,
reference: null,
node: valElement,
node: newValElement,
});

return edits;
}

// Old Code
// let valElement = availableLN.querySelector(`Val`);
// // TODO: Ask ca-d. Can't update an elements "content" directly so must remove and recreate?
// if (valElement) {
// edits.push({node: valElement})
// }

// if (!valElement) {
// valElement = subscriberIED.ownerDocument.createElementNS(
// SCL_NAMESPACE,
// 'Val'
// );
// // TODO: Fixed, this is not done like this or we do an update action
// // TODO: We can't do that! This is a crime which must also be fixed in oscd-subscriber-later-binding
// // This is not using the Action / Edit API !!!
// valElement.textContent = controlBlockReference(controlBlock);
// edits.push({
// parent: daiElement!,
// reference: null,
// node: valElement,
// });
// }
78 changes: 62 additions & 16 deletions oscd-supervision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { styles } from './foundation/styles/styles.js';

import {
controlBlockReference,
createNewSupervisionLnInst,
instantiateSubscriptionSupervision,
isSupervisionModificationAllowed,
maxSupervisions,
Expand Down Expand Up @@ -782,25 +783,67 @@ export default class Supervision extends LitElement {
selectedControl: Element,
selectedSupervision: Element | null,
newSupervision: boolean
) {
let edits: Edit[];
): void {
let edits: Edit[] | undefined;

if (newSupervision) {
edits = instantiateSubscriptionSupervision(
selectedControl,
this.selectedIed
);
this.createNewSupervision(selectedControl);
} else {
edits = instantiateSubscriptionSupervision(
selectedControl,
this.selectedIed,
selectedSupervision ?? undefined
);
this.dispatchEvent(newEditEvent(edits));
}
this.dispatchEvent(newEditEvent(edits));

this.updateSupervisedControlBlocks();
}

// TODO: restructure in terms of edits
private createNewSupervision(selectedControl: Element): void {
const subscriberIED = this.selectedIed!;
const supervisionType =
selectedControl?.tagName === 'GSEControl' ? 'LGOS' : 'LSVS';
const newLN = createNewSupervisionLnInst(
selectedControl,
subscriberIED,
supervisionType
);
let edits: Edit[];

const parent = subscriberIED.querySelector(
`LN[lnClass="${supervisionType}"]`
)?.parentElement;
if (parent && newLN) {
// use Insert edit for supervision LN
edits = [
{
parent,
node: newLN,
reference:
parent!.querySelector(`LN[lnClass="${supervisionType}"]:last-child`)
?.nextElementSibling ?? null,
},
];

const instanceNum = newLN?.getAttribute('inst');

// TODO: Explain To The User That They Have Erred And Can't Make Any New Subscriptions!
if (edits) {
this.dispatchEvent(newEditEvent(edits));
const instantiationEdit = instantiateSubscriptionSupervision(
selectedControl,
this.selectedIed,
parent!.querySelector(
`LN[lnClass="${supervisionType}"][inst="${instanceNum}"]`
)!
);
this.dispatchEvent(newEditEvent(instantiationEdit));
}
}
}

private renderUnusedControlList(): TemplateResult {
return html`<oscd-filtered-list
id="unusedControls"
Expand Down Expand Up @@ -851,7 +894,6 @@ export default class Supervision extends LitElement {
private renderUnusedSupervisionList(): TemplateResult {
return html`<oscd-filtered-list
id="unusedSupervisions"
activatable
@selected=${(ev: SingleSelectedEvent) => {
console.log('supervision');

Check warning on line 898 in oscd-supervision.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement

Check warning on line 898 in oscd-supervision.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Unexpected console statement
const selectedListItem = (<ListItemBase>(
Expand Down Expand Up @@ -882,11 +924,12 @@ export default class Supervision extends LitElement {
this.selectedSupervision,
this.newSupervision
);
this.selectedControl = null;
this.selectedSupervision = null;
this.newSupervision = false;
}
this.selectedControl = null;
this.selectedSupervision = null;
this.newSupervision = false;
this.clearListSelections();
}}
>
Expand All @@ -913,10 +956,12 @@ export default class Supervision extends LitElement {
</div>
<hr />
<div class="column-unused">
<h2 class="${this.selectedControl ? 'selected' : ''}">
${this.selectedControl
? msg('Select Supervision Logical Node')
: msg('Available Supervision Logical Nodes')}
<h2>
<span class="${this.selectedControl ? 'selected' : ''}"
>${this.selectedControl
? msg('Select Supervision Logical Node')
: msg('Available Supervision Logical Nodes')}
</span>
<mwc-icon-button
id="createNewLN"
title="${msg('New Supervision LN')}"
Expand Down Expand Up @@ -990,7 +1035,8 @@ export default class Supervision extends LitElement {
transition: background-color 150ms linear;
}
h2.selected {
h2.selected,
h2 .selected {
font-weight: 400;
color: var(--mdc-theme-primary, #6200ee);
}
Expand Down

0 comments on commit 15f8ba8

Please sign in to comment.