Skip to content

Commit 259ce39

Browse files
feat(templates): add val manipulation capability (#275)
* feat(abstractda): create valAction and renderWizard to be used by both BDA and DA wizards * fix(abstractda): name pattern and maxLength * fix(abstractda): name attributes limits * test(abstractda): update snapshot * refactor(bda): move bDAWizard to wizard-library * feat(bda): createBDaAction create Val * refactor(datype-wizards): remove unused bda eizards and actions * feat(da) add Val,dchg,achg,dupd to da wizards * feat(da): add Val,dchg,qchg,dupd to createDaWizard * fix(da and bda): minor fixes * refactor(wizards): rename foundation folder
1 parent 899988e commit 259ce39

28 files changed

+5896
-3724
lines changed

__snapshots__/BDA wizarding editing integration.md

Lines changed: 1198 additions & 0 deletions
Large diffs are not rendered by default.

__snapshots__/DA wizarding editing integration.md

Lines changed: 1695 additions & 0 deletions
Large diffs are not rendered by default.

__snapshots__/DAType wizards.md

Lines changed: 0 additions & 1154 deletions
Large diffs are not rendered by default.

__snapshots__/DOType wizards.md

Lines changed: 0 additions & 1476 deletions
Large diffs are not rendered by default.

__snapshots__/abstractda wizards.md

Lines changed: 521 additions & 0 deletions
Large diffs are not rendered by default.

src/editors/Templates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from './templates/enumtype-wizard.js';
1818
import {
1919
createDATypeWizard,
20-
dATypeWizard,
20+
editDaTypeWizard,
2121
} from './templates/datype-wizards.js';
2222
import {
2323
createDOTypeWizard,
@@ -84,7 +84,7 @@ export default class TemplatesPlugin extends LitElement {
8484
}
8585

8686
openDATypeWizard(identity: string): void {
87-
const wizard = dATypeWizard(identity, this.doc);
87+
const wizard = editDaTypeWizard(identity, this.doc);
8888
if (wizard) this.dispatchEvent(newWizardEvent(wizard));
8989
}
9090

src/editors/templates/datype-wizards.ts

Lines changed: 17 additions & 290 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { get, translate } from 'lit-translate';
33

44
import {
55
Create,
6-
createElement,
76
EditorAction,
87
getReference,
98
getValue,
109
identity,
11-
isPublic,
1210
newActionEvent,
1311
newWizardEvent,
1412
patterns,
@@ -21,297 +19,26 @@ import {
2119
import {
2220
addReferencedDataTypes,
2321
allDataTypeSelector,
24-
buildListFromStringArray,
25-
CreateOptions,
26-
predefinedBasicTypeEnum,
2722
unifyCreateActionArray,
2823
updateIDNamingAction,
29-
UpdateOptions,
30-
valKindEnum,
31-
WizardOptions,
3224
} from './foundation.js';
3325

3426
import { List } from '@material/mwc-list';
3527
import { ListItem } from '@material/mwc-list/mwc-list-item';
3628
import { Select } from '@material/mwc-select';
37-
import {
38-
SelectedEvent,
39-
SingleSelectedEvent,
40-
} from '@material/mwc-list/mwc-list-foundation';
41-
42-
function updateBDaAction(element: Element): WizardActor {
43-
return (inputs: WizardInput[]): EditorAction[] => {
44-
const name = getValue(inputs.find(i => i.label === 'name')!)!;
45-
const desc = getValue(inputs.find(i => i.label === 'desc')!);
46-
const bType = getValue(inputs.find(i => i.label === 'bType')!)!;
47-
const type =
48-
bType === 'Enum' || bType === 'Struct'
49-
? getValue(inputs.find(i => i.label === 'type')!)
50-
: null;
51-
const sAddr = getValue(inputs.find(i => i.label === 'sAddr')!);
52-
const valKind =
53-
getValue(inputs.find(i => i.label === 'valKind')!) !== ''
54-
? getValue(inputs.find(i => i.label === 'valKind')!)
55-
: null;
56-
const valImport =
57-
getValue(inputs.find(i => i.label === 'valImport')!) !== ''
58-
? getValue(inputs.find(i => i.label === 'valImport')!)
59-
: null;
60-
61-
const actions: EditorAction[] = [];
62-
if (
63-
name === element.getAttribute('name') &&
64-
desc === element.getAttribute('desc') &&
65-
bType === element.getAttribute('bType') &&
66-
type === element.getAttribute('type') &&
67-
sAddr === element.getAttribute('sAddr') &&
68-
valKind === element.getAttribute('valKind') &&
69-
valImport === element.getAttribute('valImprot')
70-
) {
71-
return [];
72-
}
73-
74-
const newElement = <Element>element.cloneNode(false);
75-
newElement.setAttribute('name', name);
76-
if (desc === null) newElement.removeAttribute('desc');
77-
else newElement.setAttribute('desc', desc);
78-
newElement.setAttribute('bType', bType);
79-
if (type === null) newElement.removeAttribute('type');
80-
else newElement.setAttribute('type', type);
81-
if (sAddr === null) newElement.removeAttribute('sAddr');
82-
else newElement.setAttribute('sAddr', sAddr);
83-
if (valKind === null) newElement.removeAttribute('valKind');
84-
else newElement.setAttribute('valKind', valKind);
85-
if (valImport === null) newElement.removeAttribute('valImport');
86-
else newElement.setAttribute('valImport', valImport);
87-
actions.push({
88-
old: { element },
89-
new: { element: newElement },
90-
});
91-
92-
return actions;
93-
};
94-
}
95-
96-
function createBDaAction(parent: Element): WizardActor {
97-
return (inputs: WizardInput[]): EditorAction[] => {
98-
const name = getValue(inputs.find(i => i.label === 'name')!)!;
99-
const desc = getValue(inputs.find(i => i.label === 'desc')!);
100-
const bType = getValue(inputs.find(i => i.label === 'bType')!)!;
101-
const type =
102-
bType === 'Enum' || bType === 'Struct'
103-
? getValue(inputs.find(i => i.label === 'type')!)
104-
: null;
105-
const sAddr = getValue(inputs.find(i => i.label === 'sAddr')!);
106-
const valKind =
107-
getValue(inputs.find(i => i.label === 'valKind')!) !== ''
108-
? getValue(inputs.find(i => i.label === 'valKind')!)
109-
: null;
110-
const valImport =
111-
getValue(inputs.find(i => i.label === 'valImport')!) !== ''
112-
? getValue(inputs.find(i => i.label === 'valImport')!)
113-
: null;
114-
115-
const actions: EditorAction[] = [];
116-
117-
const element = createElement(parent.ownerDocument, 'BDA', {
118-
name,
119-
desc,
120-
bType,
121-
type,
122-
sAddr,
123-
valKind,
124-
valImport,
125-
});
126-
actions.push({
127-
new: {
128-
parent,
129-
element,
130-
reference: getReference(parent, <SCLTag>element.tagName),
131-
},
132-
});
133-
134-
return actions;
135-
};
136-
}
137-
138-
function bDAWizard(options: WizardOptions): Wizard | undefined {
139-
const doc = (<UpdateOptions>options).doc
140-
? (<UpdateOptions>options).doc
141-
: (<CreateOptions>options).parent.ownerDocument;
142-
const bda =
143-
Array.from(
144-
doc.querySelectorAll(
145-
selector('BDA', (<UpdateOptions>options).identity ?? NaN)
146-
)
147-
).find(isPublic) ?? null;
148-
149-
const [
150-
title,
151-
action,
152-
type,
153-
deleteButton,
154-
name,
155-
desc,
156-
bTypeList,
157-
sAddr,
158-
valKindList,
159-
valImportList,
160-
] = bda
161-
? [
162-
get('bda.wizard.title.edit'),
163-
updateBDaAction(bda),
164-
bda.getAttribute('type'),
165-
html`<mwc-button
166-
icon="delete"
167-
trailingIcon
168-
label="${translate('delete')}"
169-
@click=${(e: MouseEvent) => {
170-
e.target!.dispatchEvent(newWizardEvent());
171-
e.target!.dispatchEvent(
172-
newActionEvent({
173-
old: {
174-
parent: bda.parentElement!,
175-
element: bda,
176-
reference: bda.nextSibling,
177-
},
178-
})
179-
);
180-
}}
181-
fullwidth
182-
></mwc-button> `,
183-
bda.getAttribute('name'),
184-
bda.getAttribute('desc'),
185-
buildListFromStringArray(
186-
predefinedBasicTypeEnum,
187-
bda.getAttribute('bType')
188-
),
189-
bda.getAttribute('sAddr'),
190-
buildListFromStringArray(valKindEnum, bda.getAttribute('valKind')),
191-
buildListFromStringArray(
192-
[null, 'true', 'false'],
193-
bda.getAttribute('valImport')
194-
),
195-
]
196-
: [
197-
get('bda.wizard.title.add'),
198-
createBDaAction((<CreateOptions>options).parent),
199-
null,
200-
html``,
201-
'',
202-
null,
203-
buildListFromStringArray(predefinedBasicTypeEnum, 'Struct'),
204-
null,
205-
buildListFromStringArray(valKindEnum, null),
206-
buildListFromStringArray([null, 'true', 'false'], null),
207-
];
208-
209-
const types = Array.from(doc.querySelectorAll('DAType, EnumType'))
210-
.filter(isPublic)
211-
.filter(type => type.getAttribute('id'));
212-
213-
return [
214-
{
215-
title,
216-
element: bda ?? undefined,
217-
primary: { icon: '', label: get('save'), action: action },
218-
content: [
219-
deleteButton,
220-
html`<wizard-textfield
221-
label="name"
222-
.maybeValue=${name}
223-
helper="${translate('scl.name')}"
224-
required
225-
pattern="${patterns.alphanumericFirstLowerCase}"
226-
dialogInitialFocus
227-
>
228-
></wizard-textfield
229-
>`,
230-
html`<wizard-textfield
231-
label="desc"
232-
helper="${translate('scl.desc')}"
233-
.maybeValue=${desc}
234-
nullable
235-
pattern="${patterns.normalizedString}"
236-
></wizard-textfield>`,
237-
html`<mwc-select
238-
fixedMenuPosition
239-
label="bType"
240-
helper="${translate('scl.bType')}"
241-
required
242-
@selected=${(e: SelectedEvent) => {
243-
const bTypeOriginal = bda?.getAttribute('bType') ?? '';
244-
const bType = (<Select>e.target).selected!.value!;
245-
246-
const typeUI = <Select>(
247-
(<Select>e.target).parentElement!.querySelector(
248-
'mwc-select[label="type"]'
249-
)!
250-
);
29+
import { SingleSelectedEvent } from '@material/mwc-list/mwc-list-foundation';
30+
import { createBDAWizard, editBDAWizard } from '../../wizards/bda.js';
25131

252-
Array.from(typeUI.children).forEach(child => {
253-
(<ListItem>child).disabled = !child.classList.contains(bType);
254-
(<ListItem>child).noninteractive =
255-
!child.classList.contains(bType);
256-
(<ListItem>child).style.display = !child.classList.contains(bType)
257-
? 'none'
258-
: '';
259-
(<ListItem>child).selected =
260-
bTypeOriginal === bType
261-
? (<ListItem>child).value === type
262-
: child.classList.contains(bType);
263-
});
264-
265-
typeUI.disabled = !(bType === 'Enum' || bType === 'Struct');
266-
typeUI.requestUpdate();
267-
}}
268-
>${bTypeList}</mwc-select
269-
>`,
270-
html`<mwc-select
271-
fixedMenuPosition
272-
label="type"
273-
helper="${translate('scl.type')}"
274-
>${types.map(
275-
dataType =>
276-
html`<mwc-list-item
277-
class="${dataType.tagName === 'EnumType' ? 'Enum' : 'Struct'}"
278-
value=${dataType.id}
279-
?selected=${dataType.id === type}
280-
>${dataType.id}</mwc-list-item
281-
>`
282-
)}</mwc-select
283-
>`,
284-
html`<wizard-textfield
285-
label="sAddr"
286-
helper="${translate('scl.sAddr')}"
287-
.maybeValue=${sAddr}
288-
nullable
289-
pattern="${patterns.normalizedString}"
290-
></wizard-textfield>`,
291-
html`<mwc-select
292-
label="valKind"
293-
helper="${translate('scl.valKind')}"
294-
fixedMenuPosition
295-
>${valKindList}</mwc-select
296-
>`,
297-
html`<mwc-select
298-
fixedMenuPosition
299-
label="valImport"
300-
helper="${translate('scl.valImport')}"
301-
>${valImportList}</mwc-select
302-
>`,
303-
],
304-
},
305-
];
306-
}
307-
308-
export function dATypeWizard(
32+
export function editDaTypeWizard(
30933
dATypeIdentity: string,
31034
doc: XMLDocument
31135
): Wizard | undefined {
31236
const datype = doc.querySelector(selector('DAType', dATypeIdentity));
31337
if (!datype) return undefined;
31438

39+
const id = datype.getAttribute('id');
40+
const desc = datype.getAttribute('desc');
41+
31542
return [
31643
{
31744
title: get('datype.wizard.title.edit'),
@@ -343,7 +70,7 @@ export function dATypeWizard(
34370
html`<wizard-textfield
34471
label="id"
34572
helper="${translate('scl.id')}"
346-
.maybeValue=${datype.getAttribute('id')}
73+
.maybeValue=${id}
34774
required
34875
maxlength="127"
34976
minlength="1"
@@ -353,7 +80,7 @@ export function dATypeWizard(
35380
html`<wizard-textfield
35481
label="desc"
35582
helper="${translate('scl.desc')}"
356-
.maybeValue=${datype.getAttribute('desc')}
83+
.maybeValue=${desc}
35784
nullable
35885
pattern="${patterns.normalizedString}"
35986
></wizard-textfield>`,
@@ -363,21 +90,21 @@ export function dATypeWizard(
36390
trailingIcon
36491
label="${translate('scl.DA')}"
36592
@click=${(e: Event) => {
366-
const wizard = bDAWizard({
367-
parent: datype,
368-
});
369-
if (wizard) e.target!.dispatchEvent(newWizardEvent(wizard));
93+
if (datype)
94+
e.target!.dispatchEvent(
95+
newWizardEvent(createBDAWizard(datype))
96+
);
37097
e.target!.dispatchEvent(newWizardEvent());
37198
}}
37299
></mwc-button>
373100
<mwc-list
374101
style="margin-top: 0px;"
375102
@selected=${(e: SingleSelectedEvent) => {
376-
const wizard = bDAWizard({
377-
identity: (<ListItem>(<List>e.target).selected).value,
378-
doc,
379-
});
380-
if (wizard) e.target!.dispatchEvent(newWizardEvent(wizard));
103+
const bdaIdentity = (<ListItem>(<List>e.target).selected).value;
104+
const bda = doc.querySelector(selector('BDA', bdaIdentity));
105+
106+
if (bda)
107+
e.target!.dispatchEvent(newWizardEvent(editBDAWizard(bda)));
381108
e.target!.dispatchEvent(newWizardEvent());
382109
}}
383110
>

0 commit comments

Comments
 (0)