Skip to content

Commit

Permalink
feat(wizards/smv): add edit wizard and allow access from sampledvalue…
Browse files Browse the repository at this point in the history
…control wizard (#519)

* fix(wiazrds/address): wrong wizard input definition

* fix(translation): complex action title

* feat(wizards/smv): add edit wizard

* feat(wiazrds/sampledvaluecontrol): allow access to scm wizard
  • Loading branch information
JakobVogelsang committed Feb 3, 2022
1 parent b6f7ea1 commit aff0367
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 89 deletions.
5 changes: 5 additions & 0 deletions src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ export const de: Translations = {
addaddress: 'GSE bearbeitet ({{identity}})',
},
},
smv: {
action: {
addaddress: 'SMV bearbeitet ({{identity}})',
},
},
subscriber: {
title: 'Subscriber Update',
description: 'GOOSE Ziele aktualisieren: ',
Expand Down
5 changes: 5 additions & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ export const en = {
addaddress: 'Edit GSE ({{identity}})',
},
},
smv: {
action: {
addaddress: 'Edit SMV ({{identity}})',
},
},
subscriber: {
title: 'Subscriber update',
description: 'Subscriber update: ',
Expand Down
1 change: 1 addition & 0 deletions src/wizards/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function renderGseSmvAddress(parent: Element): TemplateResult[] {
?.innerHTML.trim() ?? null}
?nullable=${typeNullable[ptype]}
pattern="${ifDefined(typePattern[ptype])}"
required
></wizard-textfield>`
)}`,
];
Expand Down
32 changes: 32 additions & 0 deletions src/wizards/sampledvaluecontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ import {
} from '../foundation.js';
import { securityEnableEnum, smpModEnum } from './foundation/enums.js';
import { maxLength, patterns } from './foundation/limits.js';
import { editSMvWizard } from './smv.js';

function getSMV(element: Element): Element | null {
const cbName = element.getAttribute('name');
const iedName = element.closest('IED')?.getAttribute('name');
const apName = element.closest('AccessPoint')?.getAttribute('name');
const ldInst = element.closest('LDevice')?.getAttribute('inst');

return (
element
.closest('SCL')
?.querySelector(
`:root > Communication > SubNetwork > ` +
`ConnectedAP[iedName="${iedName}"][apName="${apName}"] > ` +
`SMV[ldInst="${ldInst}"][cbName="${cbName}"]`
) ?? null
);
}

interface ContentOptions {
name: string | null;
Expand Down Expand Up @@ -159,6 +177,8 @@ export function editSampledValueControlWizard(element: Element): Wizard {
const nofASDU = element.getAttribute('nofASDU');
const securityEnable = element.getAttribute('securityEnabled');

const sMV = getSMV(element);

return [
{
title: get('wizard.title.edit', { tagName: element.tagName }),
Expand All @@ -179,6 +199,18 @@ export function editSampledValueControlWizard(element: Element): Wizard {
nofASDU,
securityEnable,
}),
sMV
? html`<mwc-button
id="editsmv"
label=${translate('scl.Communication')}
icon="edit"
@click="${(e: MouseEvent) => {
e.target?.dispatchEvent(
newSubWizardEvent(() => editSMvWizard(sMV))
);
}}}"
></mwc-button>`
: html``,
],
},
];
Expand Down
51 changes: 51 additions & 0 deletions src/wizards/smv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { get } from 'lit-translate';

import { Checkbox } from '@material/mwc-checkbox';

import {
ComplexAction,
identity,
Wizard,
WizardAction,
WizardActor,
WizardInput,
} from '../foundation.js';
import { renderGseSmvAddress, updateAddress } from './address.js';

export function updateSmvAction(element: Element): WizardActor {
return (inputs: WizardInput[], wizard: Element): WizardAction[] => {
const complexAction: ComplexAction = {
actions: [],
title: get('smv.action.addaddress', {
identity: identity(element),
}),
};

const instType: boolean = (<Checkbox>(
wizard.shadowRoot?.querySelector('#instType')
))?.checked;
const addressActions = updateAddress(element, inputs, instType);
if (!addressActions.length) return [];

addressActions.forEach(action => {
complexAction.actions.push(action);
});

return [complexAction];
};
}

export function editSMvWizard(element: Element): Wizard {
return [
{
title: get('wizard.title.edit', { tagName: element.tagName }),
element,
primary: {
label: get('save'),
icon: 'edit',
action: updateSmvAction(element),
},
content: [...renderGseSmvAddress(element)],
},
];
}
9 changes: 9 additions & 0 deletions test/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export function ipV6(): Arbitrary<string> {
);
}

export function MAC(): Arbitrary<string> {
const h16Arb = hexaString({ minLength: 2, maxLength: 2 });
const ls32Arb = tuple(h16Arb, h16Arb).map(([a, b]) => `${a}-${b}`);
return tuple(array(h16Arb, { minLength: 4, maxLength: 4 }), ls32Arb).map(
([eh, l]) => `${eh.join('-')}-${l}`
);
}

export function ipV6SubNet(): Arbitrary<string> {
return integer({ min: 1, max: 127 }).map(num => `/${num}`);
}
Expand All @@ -47,6 +55,7 @@ export const regExp = {
desc: new RegExp(`^${patterns.normalizedString}$`),
IPv4: /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/,
IPv6: /^([0-9A-F]{2}-){5}[0-9A-F]{2}$/,
MAC: /^([0-9A-F]{2}-){5}[0-9A-F]{2}$/,
OSI: /^[0-9A-F]+$/,
OSIAPi: /^[0-9\u002C]+$/,
OSIid: /^[0-9]+$/,
Expand Down
Loading

0 comments on commit aff0367

Please sign in to comment.