Skip to content

Commit

Permalink
fix(104): change options between different tis when selecting a doi (#…
Browse files Browse the repository at this point in the history
…1380)

* fix: inverted monitor switch enables selectively

Signed-off-by: Stef3st <[email protected]>

* fix: inverted monitor switch enables selectively

Signed-off-by: Stef3st <[email protected]>

* chore: added inverted property to correct tis

Signed-off-by: Stef3st <[email protected]>

* chore: added null check and removed unneeded split

Signed-off-by: Stef3st <[email protected]>

* chore: split is necessary

Signed-off-by: Stef3st <[email protected]>

---------

Signed-off-by: Stef3st <[email protected]>
  • Loading branch information
Stef3st authored Dec 7, 2023
1 parent 0e74294 commit cb80080
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
21 changes: 20 additions & 1 deletion packages/open-scd/src/editors/protocol104/foundation/cdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export const cdcProcessings: Record<
{ path: ['neut'] },
],
create: createAddressAction,
inverted: false,
},
},
control: {},
Expand Down Expand Up @@ -149,6 +148,7 @@ export const cdcProcessings: Record<
'36': {
daPaths: [{ path: ['mxVal', 'f'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -165,6 +165,7 @@ export const cdcProcessings: Record<
'63': {
daPaths: [{ path: ['setMag', 'f'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -174,6 +175,7 @@ export const cdcProcessings: Record<
'36': {
daPaths: [{ path: ['mxVal', 'f'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -190,6 +192,7 @@ export const cdcProcessings: Record<
'37': {
daPaths: [{ path: ['actVal'] }, { path: ['frVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -199,6 +202,7 @@ export const cdcProcessings: Record<
'32': {
daPaths: [{ path: ['valWTr', 'posVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -215,10 +219,12 @@ export const cdcProcessings: Record<
'35': {
daPaths: [{ path: ['mag', 'i'] }, { path: ['ang', 'i'] }],
create: createAddressAction,
inverted: true,
},
'36': {
daPaths: [{ path: ['mag', 'f'] }, { path: ['ang', 'f'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -228,6 +234,7 @@ export const cdcProcessings: Record<
'31': {
daPaths: [{ path: ['stVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -244,6 +251,7 @@ export const cdcProcessings: Record<
'31': {
daPaths: [{ path: ['stVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -253,10 +261,12 @@ export const cdcProcessings: Record<
'58': {
daPaths: [{ path: ['setVal'] }],
create: createAddressWithExpectValueAction,
inverted: true,
},
'62': {
daPaths: [{ path: ['setVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -266,6 +276,7 @@ export const cdcProcessings: Record<
'35': {
daPaths: [{ path: ['stVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -282,6 +293,7 @@ export const cdcProcessings: Record<
'62': {
daPaths: [{ path: ['setVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -296,10 +308,12 @@ export const cdcProcessings: Record<
'33': {
daPaths: [{ path: ['stVal'] }],
create: createAddressAction,
inverted: true,
},
'35': {
daPaths: [{ path: ['stVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -309,6 +323,7 @@ export const cdcProcessings: Record<
'32': {
daPaths: [{ path: ['valWTr', 'posVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {
Expand All @@ -325,10 +340,12 @@ export const cdcProcessings: Record<
'35': {
daPaths: [{ path: ['mag', 'i'] }],
create: createAddressAction,
inverted: true,
},
'36': {
daPaths: [{ path: ['mag', 'f'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -338,6 +355,7 @@ export const cdcProcessings: Record<
'37': {
daPaths: [{ path: ['cnt'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand All @@ -364,6 +382,7 @@ export const cdcProcessings: Record<
'58': {
daPaths: [{ path: ['setVal'] }],
create: createAddressAction,
inverted: true,
},
},
control: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { get, translate } from 'lit-translate';
import { html, TemplateResult } from 'lit-element';
import { Select } from '@material/mwc-select';
import { SelectedEvent } from '@material/mwc-list/mwc-list-foundation';

import { Switch } from '@material/mwc-switch';

Expand Down Expand Up @@ -169,6 +171,18 @@ export function disableInvertedSwitch(
return disableSwitch;
}

export function disableMonitorInvertedSwitch(
tiInfo: Record<string, TiInformation>,
tiNumberInfo: string
): boolean {
let disableSwitch = true;
const tiNumber = tiNumberInfo.split(' (')[0];

if (!isNaN(+tiNumber)) disableSwitch = !tiInfo[tiNumber].inverted;

return disableSwitch;
}

export function createAddressesWizard(
lnElement: Element,
doElement: Element
Expand All @@ -184,6 +198,20 @@ export function createAddressesWizard(
const iedElement = lnElement.closest('IED');
const fullPath = getFullPath(lnElement, 'IED');

function setMonitorInvertedSwitch(e: SelectedEvent): void {
const selectedTi = (<Select>e.target).selected!.value;
const selectElement = (<Select>e.target).parentElement!.querySelector(
'mwc-switch[id="monitorInverted"]'
);

if (!selectElement) return;

(<Switch>selectElement).disabled = disableMonitorInvertedSwitch(
cdcProcessing.monitor,
selectedTi
);
}

// Add the basic fields to the list.
const fields = [
html`<wizard-textfield
Expand Down Expand Up @@ -220,13 +248,17 @@ export function createAddressesWizard(

if (monitorTis.length > 0) {
fields.push(html`<wizard-divider></wizard-divider>`);
let disabledSwitchByDefault = true;
if (monitorTis.length > 1) {
fields.push(
html`<wizard-select
label="monitorTi"
helper="${translate('protocol104.wizard.monitorTiHelper')}"
fixedMenuPosition
required
@selected=${(e: SelectedEvent) => {
setMonitorInvertedSwitch(e);
}}
>
${monitorTis.map(
monitorTi =>
Expand All @@ -239,6 +271,10 @@ export function createAddressesWizard(
</wizard-select>`
);
} else {
disabledSwitchByDefault = disableMonitorInvertedSwitch(
cdcProcessing.monitor,
monitorTis[0]
);
fields.push(
html`<wizard-textfield
label="monitorTi"
Expand All @@ -256,7 +292,7 @@ export function createAddressesWizard(
>
<mwc-switch
id="monitorInverted"
.disabled="${disableInvertedSwitch(cdcProcessing.monitor)}"
.disabled="${disabledSwitchByDefault}"
>
</mwc-switch>
</mwc-formfield>`
Expand Down

0 comments on commit cb80080

Please sign in to comment.