Skip to content

Commit

Permalink
refactor(wizards/lnode): combine reference type and instace type wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobVogelsang committed May 23, 2022
1 parent f49c5d6 commit 8882420
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 45 deletions.
14 changes: 9 additions & 5 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ export const de: Translations = {
none: 'Keine Verbindung vorhanden',
publisherGoose: {
title: 'GOOSE-Publizierer',
subscriberTitle: 'Verbunden mit {{ selected }}'
subscriberTitle: 'Verbunden mit {{ selected }}',
},
subscriberGoose: {
title: 'IED-Publizierer',
publisherTitle: 'GOOSE(s) verbunden mit {{selected}}'
publisherTitle: 'GOOSE(s) verbunden mit {{selected}}',
},
subscriber: {
subscribed: 'Verbunden',
Expand All @@ -338,9 +338,9 @@ export const de: Translations = {
noIedSelected: 'Keine IED ausgewählt',
},
view: {
publisherView: "Zeigt verbundene IED(s) der ausgewählten GOOSE",
subscriberView: "Zeigt verbundene GOOSE(s) des ausgewählten IED"
}
publisherView: 'Zeigt verbundene IED(s) der ausgewählten GOOSE',
subscriberView: 'Zeigt verbundene GOOSE(s) des ausgewählten IED',
},
},
sampledvalues: {
none: 'Keine Verbindung vorhanden',
Expand Down Expand Up @@ -460,8 +460,12 @@ export const de: Translations = {
selectIEDs: 'Auswahl IEDs',
selectLDs: 'Auswahl logische Geräte',
selectLNs: 'Auswahl logische Knoten',
selectLNodeTypes: 'Auswahl logische Knoten Type',
},
placeholder: 'Bitte laden Sie eine SCL-Datei, die IED-Elemente enthält.',
uniquewarning: 'Logische Knoten Klasse existiert bereits',
reference: 'Reference auf bestehenden logischen Knoten erstellen',
instance: 'Referenz auf logischen Knoten Typ erstellen',
},
tooltip: 'Referenz zu logischen Knoten erstellen',
},
Expand Down
14 changes: 9 additions & 5 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ export const en = {
none: 'None',
publisherGoose: {
title: 'GOOSE Publisher',
subscriberTitle: 'Subscriber of {{ selected }}'
subscriberTitle: 'Subscriber of {{ selected }}',
},
subscriberGoose: {
title: 'GOOSE Subscriber',
publisherTitle: 'GOOSE(s) subscribed by {{selected}}'
publisherTitle: 'GOOSE(s) subscribed by {{selected}}',
},
subscriber: {
subscribed: 'Subscribed',
Expand All @@ -335,9 +335,9 @@ export const en = {
noIedSelected: 'No IED selected',
},
view: {
publisherView: "Show subscriber IED(s) per selected GOOSE",
subscriberView: "Show subscribed GOOSE publisher for selected IED"
}
publisherView: 'Show subscriber IED(s) per selected GOOSE',
subscriberView: 'Show subscribed GOOSE publisher for selected IED',
},
},
sampledvalues: {
none: 'none',
Expand Down Expand Up @@ -457,8 +457,12 @@ export const en = {
selectIEDs: 'Select IEDs',
selectLDs: 'Select logical devices',
selectLNs: 'Select logical nodes',
selectLNodeTypes: 'Select logical node types',
},
placeholder: 'Please load an SCL file that contains IED elements.',
uniquewarning: 'Logical node class already exist',
reference: 'Add reference to existing logical node',
instance: 'Add reference to logical node type',
},
tooltip: 'Create logical nodes reference',
},
Expand Down
71 changes: 58 additions & 13 deletions src/wizards/lnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
getChildElementsByTagName,
identity,
isPublic,
newWizardEvent,
referencePath,
selector,
Wizard,
WizardActor,
WizardInputElement,
WizardMenuActor,
} from '../foundation.js';

function getUniqueLnInst(parent: Element, lnClass: string): number {
Expand Down Expand Up @@ -91,15 +93,28 @@ function createLNodeAction(parent: Element): WizardActor {
};
}

/** @returns a Wizard for creating `LNode` instances within parent. */
export function createLNodeWizard(parent: Element): Wizard {
function openLNodeReferenceWizard(parent: Element): WizardMenuActor {
return (wizard: Element): void => {
wizard.dispatchEvent(newWizardEvent());
wizard.dispatchEvent(newWizardEvent(lNodeReferenceWizard(parent)));
};
}

function lNodeInstanceWizard(parent: Element): Wizard {
const lNodeTypes = Array.from(
parent.ownerDocument.querySelectorAll('LNodeType')
);

return [
{
title: get('wizard.title.add', { tagName: 'LNode' }),
title: get('lnode.wizard.title.selectLNodeTypes'),
menuActions: [
{
icon: '',
label: get('lnode.wizard.reference'),
action: openLNodeReferenceWizard(parent),
},
],
primary: {
icon: 'save',
label: get('save'),
Expand All @@ -110,17 +125,23 @@ export function createLNodeWizard(parent: Element): Wizard {
>${lNodeTypes.map(lNodeType => {
const isDesabled =
(lNodeType.getAttribute('lnClass') === 'LLN0' &&
parent.querySelector('LNode[lnClass="LLN0"]') !== null) ||
getChildElementsByTagName(parent, 'LNode').some(
lnode => lnode.getAttribute('lnClass') === 'LLN0'
)) ||
(lNodeType.getAttribute('lnClass') === 'LPHD' &&
parent.querySelector('LNode[lnClass="LPHD"]') !== null);
getChildElementsByTagName(parent, 'LNode').some(
lnode => lnode.getAttribute('lnClass') === 'LPHD'
));

return html`<mwc-check-list-item
twoline
value="${identity(lNodeType)}"
?disabled=${isDesabled}
><span>${lNodeType.getAttribute('lnClass')}</span
><span slot="secondary"
>${identity(lNodeType)}</span
>${isDesabled
? get('lnode.wizard.uniquewarning')
: identity(lNodeType)}</span
></mwc-check-list-item
>`;
})}</filtered-list
Expand Down Expand Up @@ -375,26 +396,50 @@ function renderIEDPage(element: Element): TemplateResult {
</mwc-list-item>`;
}

/** @returns a Wizard for editing `element`'s `LNode` children. */
export function lNodeWizard(element: Element): Wizard {
function openLNodeInstanceWizard(parent: Element): WizardMenuActor {
return (wizard: Element): void => {
wizard.dispatchEvent(newWizardEvent());
wizard.dispatchEvent(newWizardEvent(lNodeInstanceWizard(parent)));
};
}

function lNodeReferenceWizard(parent: Element): Wizard {
return [
{
title: get('lnode.wizard.title.selectIEDs'),
element,
content: [renderIEDPage(element)],
menuActions: [
{
icon: '',
label: get('lnode.wizard.instance'),
action: openLNodeInstanceWizard(parent),
},
],
content: [renderIEDPage(parent)],
},
{
initial: Array.from(element.children).some(
initial: Array.from(parent.children).some(
child => child.tagName === 'LNode'
),
title: get('lnode.wizard.title.selectLNs'),
element,
primary: {
icon: 'save',
label: get('save'),
action: lNodeWizardAction(element),
action: lNodeWizardAction(parent),
},
content: [html`<filtered-list multi id="lnList"></filtered-list>`],
},
];
}

/** @returns a Wizard for editing `element`'s `LNode` children. */
export function lNodeWizard(parent: Element): Wizard {
if (
parent.tagName === 'Function' ||
parent.tagName === 'SubFunction' ||
parent.tagName === 'EqFunction' ||
parent.tagName === 'EqSubFunction'
)
return lNodeInstanceWizard(parent);

return lNodeReferenceWizard(parent);
}
2 changes: 1 addition & 1 deletion src/wizards/wizard-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const wizards: Record<
},
LNode: {
edit: lNodeWizard,
create: createLNodeWizard,
create: lNodeWizard,
},
LNodeType: {
edit: emptyWizard,
Expand Down
Loading

0 comments on commit 8882420

Please sign in to comment.