Skip to content

Commit

Permalink
feat(editors/dotype-wizard): add functional constraints selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Vogelsang authored and ca-d committed Jun 11, 2021
1 parent 234d1dc commit 86bfeaa
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 16 deletions.
236 changes: 236 additions & 0 deletions __snapshots__/DOType wizards.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
>
</mwc-button>
</mwc-dialog>

```

## `defines a dOTypeWizard`
Expand Down Expand Up @@ -583,6 +584,7 @@
>
</mwc-button>
</mwc-dialog>

```

## `defines a dAWizard to edit an existing DA`
Expand Down Expand Up @@ -1188,6 +1190,123 @@
false
</mwc-list-item>
</mwc-select>
<mwc-select
fixedmenuposition=""
helper="[scl.fc]"
label="fc"
required=""
>
<mwc-list-item
aria-disabled="false"
aria-selected="true"
mwc-list-item=""
role="option"
selected=""
tabindex="0"
value="ST"
>
ST
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="MX"
>
MX
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SP"
>
SP
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SV"
>
SV
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="CF"
>
CF
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="DC"
>
DC
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SG"
>
SG
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SE"
>
SE
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SR"
>
SR
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="OR"
>
OR
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="BL"
>
BL
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="EX"
>
EX
</mwc-list-item>
</mwc-select>
</div>
<mwc-button
dialogaction="close"
Expand All @@ -1205,6 +1324,7 @@
>
</mwc-button>
</mwc-dialog>

```

## `defines a dAWizard to create a new DA element`
Expand Down Expand Up @@ -1808,6 +1928,121 @@
false
</mwc-list-item>
</mwc-select>
<mwc-select
fixedmenuposition=""
helper="[scl.fc]"
label="fc"
required=""
>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="0"
value="ST"
>
ST
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="MX"
>
MX
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SP"
>
SP
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SV"
>
SV
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="CF"
>
CF
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="DC"
>
DC
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SG"
>
SG
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SE"
>
SE
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="SR"
>
SR
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="OR"
>
OR
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="BL"
>
BL
</mwc-list-item>
<mwc-list-item
aria-disabled="false"
mwc-list-item=""
role="option"
tabindex="-1"
value="EX"
>
EX
</mwc-list-item>
</mwc-select>
</div>
<mwc-button
dialogaction="close"
Expand All @@ -1825,6 +2060,7 @@
>
</mwc-button>
</mwc-dialog>

```

## `defines a sDOWizard to edit an existing SDO`
Expand Down
14 changes: 14 additions & 0 deletions src/editors/templates/dotype-wizards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
addReferencedDataTypes,
allDataTypeSelector,
buildListFromStringArray,
functionalConstraintEnum,
predefinedBasicTypeEnum,
valKindEnum,
} from './foundation.js';
Expand Down Expand Up @@ -307,6 +308,7 @@ function dAWizard(options: WizardOptions): Wizard | undefined {
sAddr,
valKindList,
valImportList,
fcList,
] = da
? [
get('da.wizard.title.edit'),
Expand Down Expand Up @@ -342,6 +344,10 @@ function dAWizard(options: WizardOptions): Wizard | undefined {
[null, 'true', 'false'],
da.getAttribute('valImport')
),
buildListFromStringArray(
functionalConstraintEnum,
da.getAttribute('fc')
),
]
: [
get('da.wizard.title.add'),
Expand All @@ -354,6 +360,7 @@ function dAWizard(options: WizardOptions): Wizard | undefined {
null,
buildListFromStringArray(valKindEnum, null),
buildListFromStringArray([null, 'true', 'false'], null),
buildListFromStringArray(functionalConstraintEnum, null),
];

const types = Array.from(doc.querySelectorAll('DAType, EnumType'))
Expand Down Expand Up @@ -449,6 +456,13 @@ function dAWizard(options: WizardOptions): Wizard | undefined {
helper="${translate('scl.valImport')}"
>${valImportList}</mwc-select
>`,
html`<mwc-select
label="fc"
helper="${translate('scl.fc')}"
required
fixedMenuPosition
>${fcList}</mwc-select
>`,
],
},
];
Expand Down
45 changes: 31 additions & 14 deletions src/editors/templates/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ export function addReferencedDataTypes(
.filter(isPublic)
.map(type => type.getAttribute('id'));

const types = Array.from(element.children)
.map(child => child.getAttribute('type'))
.filter(type => type)
.filter(type => !ids.includes(type));

const adjacents = types
.map(
type =>
templates.querySelector(
`LNodeType[id="${type}"],DOType[id="${type}"],DAType[id="${type}"],EnumType[id="${type}"]`
)!
)
.filter(isPublic);
const types = new Set(
<string[]>Array.from(element.children)
.map(child => child.getAttribute('type'))
.filter(type => type !== null)
.filter(type => !ids.includes(type))
);

const adjacents: Element[] = [];
types.forEach(type => {
const adjacent = templates.querySelector(
`LNodeType[id="${type}"],DOType[id="${type}"],DAType[id="${type}"],EnumType[id="${type}"]`
)!;

if (adjacent !== null && isPublic(adjacent)) adjacents.push(adjacent);
});

const actions: EditorAction[] = [];
adjacents
Expand All @@ -80,7 +82,7 @@ export function addReferencedDataTypes(
actions.push({
new: {
parent,
element: adjacent,
element: <Element>adjacent.cloneNode(true),
reference: getReference(parent, <SCLTag>adjacent.tagName),
},
})
Expand Down Expand Up @@ -139,6 +141,21 @@ export const predefinedBasicTypeEnum = [
'EntryID',
];

export const functionalConstraintEnum = [
'ST',
'MX',
'SP',
'SV',
'CF',
'DC',
'SG',
'SE',
'SR',
'OR',
'BL',
'EX',
];

export const valKindEnum = [null, 'Spec', 'Conf', 'RO', 'Set'];

/** Common `CSS` styles used by DataTypeTemplate subeditors */
Expand Down
Loading

0 comments on commit 86bfeaa

Please sign in to comment.