Skip to content

Commit

Permalink
Merge pull request #251 from com-pas/updating_0320
Browse files Browse the repository at this point in the history
Updating 0320
  • Loading branch information
Stef3st committed May 30, 2023
2 parents 2c052e8 + ab9eedb commit 1148b2e
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 195 deletions.
20 changes: 10 additions & 10 deletions public/js/plugins.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const officialPlugins = [
{
name: 'Substation',
src: '/src/editors/Substation.js',
icon: 'margin',
name: 'IED',
src: '/src/editors/IED.js',
icon: 'developer_board',
default: true,
kind: 'editor',
},
{
name: 'IED',
src: '/src/editors/IED.js',
icon: 'developer_board',
name: 'Substation',
src: '/src/editors/Substation.js',
icon: 'margin',
default: true,
kind: 'editor',
},
Expand All @@ -24,14 +24,14 @@ export const officialPlugins = [
name: 'Subscriber Message Binding (GOOSE)',
src: '/src/editors/GooseSubscriberMessageBinding.js',
icon: 'link',
default: true,
default: false,
kind: 'editor',
},
{
name: 'Subscriber Data Binding (GOOSE)',
src: '/src/editors/GooseSubscriberDataBinding.js',
icon: 'link',
default: true,
default: false,
kind: 'editor',
},
{
Expand All @@ -45,14 +45,14 @@ export const officialPlugins = [
name: 'Subscriber Message Binding (SMV)',
src: '/src/editors/SMVSubscriberMessageBinding.js',
icon: 'link',
default: true,
default: false,
kind: 'editor',
},
{
name: 'Subscriber Data Binding (SMV)',
src: '/src/editors/SMVSubscriberDataBinding.js',
icon: 'link',
default: true,
default: false,
kind: 'editor',
},
{
Expand Down
5 changes: 4 additions & 1 deletion src/Hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export function Hosting<
renderMenuItem(me: MenuItem | 'divider'): TemplateResult {
if (me === 'divider')
return html`<li divider padded role="separator"></li>`;
if (me.actionItem) return html``;
return html`
<mwc-list-item
class="${me.kind}"
Expand Down Expand Up @@ -297,7 +298,9 @@ export function Hosting<
// if clause not neccassary when oscd... compenents in open-scd not list
if (ae.target instanceof List)
(<MenuItem>(
this.menu.filter(item => item !== 'divider')[ae.detail.index]
this.menu.filter(
item => item !== 'divider' && !item.actionItem
)[ae.detail.index]
))?.action?.(ae);
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/editors/ied/access-point-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AccessPointContainer extends Container {
return html``;
}

return html` <abbr slot="action" title="${translate('settings')}">
return html` <abbr slot="action" title="${translate('iededitor.settings')}">
<mwc-icon-button
icon="settings"
@click=${() => this.openSettingsWizard(services)}
Expand Down
2 changes: 1 addition & 1 deletion src/editors/ied/ied-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class IedContainer extends Container {
return html``;
}

return html` <abbr slot="action" title="${translate('settings')}">
return html` <abbr slot="action" title="${translate('iededitor.settings')}">
<mwc-icon-button
icon="settings"
@click=${() => this.openSettingsWizard(services)}
Expand Down
3 changes: 2 additions & 1 deletion src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ export const de: Translations = {
},
iededitor: {
iedSelector: 'IED auswählen',
lnFilter: '???',
lnFilter: 'Filter für logische Knoten',
missing: 'Kein IED vorhanden',
toggleChildElements: 'Kindelemente umschalten',
settings: 'Services für IED or AccessPoint',
wizard: {
daTitle: 'DA Informationen anzeigen',
doTitle: 'DO Informationen anzeigen',
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const en = {
lnFilter: 'Logical Node Filter',
missing: 'No IED',
toggleChildElements: 'Toggle child elements',
settings: 'Show Services the IED/AccessPoint provides',
wizard: {
daTitle: 'Show DA Info',
doTitle: 'Show DO Info',
Expand Down
91 changes: 79 additions & 12 deletions src/wizards/dai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,41 @@ export function createValue(
parent: Element,
element: Element,
newElement: Element,
instanceElement: Element
instanceElement: Element,
numberOfmultipleSettings?: number
): WizardActor {
return (inputs: WizardInputElement[]): EditorAction[] => {
const bType = element.getAttribute('bType')!;
const newValue = getCustomField()[<DaiFieldTypes>bType].value(inputs);

let valElement = instanceElement.querySelector('Val');
if (!valElement) {
valElement = parent.ownerDocument.createElementNS(SCL_NAMESPACE, 'Val');
instanceElement.append(valElement);
if (numberOfmultipleSettings) {
//Should we remove all Val elements before adding new ones?
Array.from(instanceElement.querySelectorAll('Val')).forEach(item =>
item.remove()
);
// Adds a new Val element for each sGroup value from the wizard
[...Array(numberOfmultipleSettings)].forEach((item, i) => {
const newValue = getCustomField()[<DaiFieldTypes>bType].value(
inputs,
i + 1
);

const valElement = parent.ownerDocument.createElementNS(
SCL_NAMESPACE,
'Val'
);
valElement.textContent = newValue;
valElement.setAttribute('sGroup', `${i + 1}`);
instanceElement.append(valElement);
});
} else {
const newValue = getCustomField()[<DaiFieldTypes>bType].value(inputs);

let valElement = instanceElement.querySelector('Val');
if (!valElement) {
valElement = parent.ownerDocument.createElementNS(SCL_NAMESPACE, 'Val');
instanceElement.append(valElement);
}
valElement.textContent = newValue;
}
valElement.textContent = newValue;

const name = instanceElement.getAttribute('name');
const complexAction: ComplexAction = {
Expand All @@ -65,15 +88,17 @@ export function createValue(

export function renderDAIWizard(
element: Element,
instanceElement?: Element
instanceElement?: Element,
numberOfmultipleSettings: number | null = null
): TemplateResult[] {
const bType = element.getAttribute('bType')!;
const daValue = element.querySelector('Val')?.textContent?.trim() ?? '';

return [
html` ${getCustomField()[<DaiFieldTypes>bType].render(
element,
instanceElement
instanceElement,
numberOfmultipleSettings
)}
${daValue
? html`<wizard-textfield
Expand All @@ -88,12 +113,44 @@ export function renderDAIWizard(
];
}

/**
* Checks if the DAI corresponds to a multiple setting group
*
* @param parent The parent element of the DAI
* @param element The BDA/DA element
* @returns The number of setting groups if the DAI is a multiple setting group, null otherwise
*/
function checkForMultipleSettings(
parent: Element,
element: Element
): number | undefined {
// Look for the DA element to validate that the DAI has the functional constraint SG or SE
let da = element;
if (element.tagName === 'BDA')
da = (<Element>element.getRootNode()).querySelector(
`DOType>DA[type="${element.parentElement!.id}"]`
)!;
const fc = da.getAttribute('fc') ?? '';
// Check if the closest IED to the parent element has a SettingControl element with a numOfSGs attribute
const ied = parent.closest('IED');
const settingControl = ied?.querySelector('SettingControl');
const numOfSGsAttribute = settingControl?.getAttribute('numOfSGs') ?? '';
const numberOfmultipleSettings = parseInt(numOfSGsAttribute);
// If the DA has the functional constraint SG or SE and the IED has a SettingControl element with a numOfSGs attribute, then the DAI is a multiple setting group
return (fc === 'SG' || fc === 'SE') &&
numOfSGsAttribute !== '' &&
!isNaN(numberOfmultipleSettings)
? numberOfmultipleSettings
: undefined;
}

export function createDAIWizard(
parent: Element,
newElement: Element,
element: Element
): Wizard {
// Retrieve the created DAI, can be the new element or one of the child elements below.
const numberOfmultipleSettings = checkForMultipleSettings(parent, element);
const instanceElement =
newElement.tagName === 'DAI'
? newElement
Expand All @@ -108,9 +165,19 @@ export function createDAIWizard(
primary: {
icon: 'edit',
label: get('save'),
action: createValue(parent, element, newElement, instanceElement),
action: createValue(
parent,
element,
newElement,
instanceElement,
numberOfmultipleSettings
),
},
content: renderDAIWizard(element, instanceElement),
content: renderDAIWizard(
element,
instanceElement,
numberOfmultipleSettings
),
},
];
}
Expand Down
Loading

0 comments on commit 1148b2e

Please sign in to comment.