Skip to content

Commit 4d52a9a

Browse files
author
Dennis Labordus
authored
feat(wizard/dai): Set/Update a value for a type 'Timestamp' of Data Attribute Instance (openscd#959)
* Added functionality to add/edit Timestamp values by the Data Attributes. * Added some extra test for DAI Wizard. * Review comment processed.
1 parent cc48b0a commit 4d52a9a

File tree

12 files changed

+2290
-1510
lines changed

12 files changed

+2290
-1510
lines changed

src/editors/ied/da-container.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { IconButtonToggle } from '@material/mwc-icon-button-toggle';
1515
import '../../action-pane.js';
1616
import { getNameAttribute, newWizardEvent } from '../../foundation.js';
1717
import { wizards } from '../../wizards/wizard-library.js';
18-
import { DaiValidationTypes, getCustomField } from './foundation/foundation.js';
18+
import {
19+
DaiFieldTypes,
20+
getCustomField,
21+
} from '../../wizards/foundation/dai-field-type.js';
1922
import { createDaInfoWizard } from './da-wizard.js';
2023
import {
2124
Container,
@@ -108,10 +111,10 @@ export class DAContainer extends Container {
108111
['LN0', 'LN'].includes(element.tagName)
109112
)[0];
110113
const templateStructure = this.getTemplateStructure();
111-
// First determine where to start creating new elements (DOI/SDI/DOI)
114+
// First determine where to start creating new elements (DOI/SDI/DAI)
112115
const [parentElement, uninitializedTemplateStructure] =
113116
determineUninitializedStructure(lnElement, templateStructure);
114-
// Next create all missing elements (DOI/SDI/DOI)
117+
// Next create all missing elements (DOI/SDI/DAI)
115118
const newElement = initializeElements(uninitializedTemplateStructure);
116119

117120
if (newElement) {
@@ -172,17 +175,13 @@ export class DAContainer extends Container {
172175
${this.instanceElement
173176
? html`<mwc-icon-button
174177
icon="edit"
175-
.disabled="${!getCustomField()[
176-
<DaiValidationTypes>bType
177-
]}"
178+
.disabled="${!getCustomField()[<DaiFieldTypes>bType]}"
178179
@click=${() => this.openEditWizard()}
179180
>
180181
</mwc-icon-button>`
181182
: html`<mwc-icon-button
182183
icon="add"
183-
.disabled="${!getCustomField()[
184-
<DaiValidationTypes>bType
185-
]}"
184+
.disabled="${!getCustomField()[<DaiFieldTypes>bType]}"
186185
@click=${() => this.openCreateWizard()}
187186
>
188187
</mwc-icon-button>`}
@@ -215,7 +214,7 @@ export class DAContainer extends Container {
215214
font-weight: 300;
216215
margin: 0px;
217216
padding-left: 0.3em;
218-
word-break: break-word;
217+
word-break: break-word;
219218
white-space: pre-wrap;
220219
}
221220

src/editors/ied/foundation/foundation.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/wizards/dai.ts

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,78 @@
11
import { html, TemplateResult } from 'lit-element';
2-
import { nothing } from "lit-html";
2+
import { nothing } from 'lit-html';
33
import { get } from 'lit-translate';
4-
import { DaiValidationTypes, getCustomField } from '../editors/ied/foundation/foundation.js';
4+
5+
import { DaiFieldTypes, getCustomField } from './foundation/dai-field-type.js';
56

67
import '../../src/wizard-textfield.js';
78

89
import {
910
ComplexAction,
1011
EditorAction,
11-
getValue,
1212
Wizard,
1313
WizardActor,
1414
WizardInputElement,
1515
} from '../foundation.js';
16-
import { SCL_NAMESPACE } from "../schemas.js";
16+
import { SCL_NAMESPACE } from '../schemas.js';
1717

18-
export function updateValue(instanceElement: Element): WizardActor {
18+
export function updateValue(
19+
element: Element,
20+
instanceElement: Element
21+
): WizardActor {
1922
return (inputs: WizardInputElement[]): EditorAction[] => {
20-
const newValue = getValue(inputs.find(i => i.value)!)!;
21-
const name = instanceElement.getAttribute('name');
23+
const bType = element.getAttribute('bType')!;
24+
const newValue = getCustomField()[<DaiFieldTypes>bType].value(inputs);
2225

26+
const name = instanceElement.getAttribute('name');
2327
const complexAction: ComplexAction = {
2428
actions: [],
25-
title: get('dai.action.updatedai', {daiName: name!}),
29+
title: get('dai.action.updatedai', { daiName: name! }),
2630
};
2731

2832
const oldVal = instanceElement.querySelector('Val');
2933
if (oldVal) {
3034
const newVal = <Element>oldVal.cloneNode(false);
3135
newVal.textContent = newValue;
32-
complexAction.actions.push({old: {element: oldVal}, new: {element: newVal}});
36+
complexAction.actions.push({
37+
old: { element: oldVal },
38+
new: { element: newVal },
39+
});
3340
} else {
34-
const newVal = instanceElement.ownerDocument.createElementNS(SCL_NAMESPACE, 'Val');
41+
const newVal = instanceElement.ownerDocument.createElementNS(
42+
SCL_NAMESPACE,
43+
'Val'
44+
);
3545
newVal.textContent = newValue;
36-
complexAction.actions.push({new: {parent: instanceElement, element: newVal}});
46+
complexAction.actions.push({
47+
new: { parent: instanceElement, element: newVal },
48+
});
3749
}
3850
return [complexAction];
3951
};
4052
}
4153

42-
export function createValue(parent: Element, newElement: Element, instanceElement: Element): WizardActor {
54+
export function createValue(
55+
parent: Element,
56+
element: Element,
57+
newElement: Element,
58+
instanceElement: Element
59+
): WizardActor {
4360
return (inputs: WizardInputElement[]): EditorAction[] => {
44-
const newValue = getValue(inputs.find(i => i.value)!)!;
45-
const name = instanceElement.getAttribute('name');
46-
47-
const complexAction: ComplexAction = {
48-
actions: [],
49-
title: get('dai.action.createdai', {daiName: name!}),
50-
};
61+
const bType = element.getAttribute('bType')!;
62+
const newValue = getCustomField()[<DaiFieldTypes>bType].value(inputs);
5163

5264
let valElement = instanceElement.querySelector('Val');
5365
if (!valElement) {
5466
valElement = parent.ownerDocument.createElementNS(SCL_NAMESPACE, 'Val');
5567
instanceElement.append(valElement);
5668
}
5769
valElement.textContent = newValue;
58-
complexAction.actions.push({new: {parent, element: newElement}});
70+
71+
const name = instanceElement.getAttribute('name');
72+
const complexAction: ComplexAction = {
73+
actions: [{ new: { parent, element: newElement } }],
74+
title: get('dai.action.createdai', { daiName: name! }),
75+
};
5976
return [complexAction];
6077
};
6178
}
@@ -68,49 +85,64 @@ export function renderDAIWizard(
6885
const daValue = element.querySelector('Val')?.textContent?.trim() ?? '';
6986

7087
return [
71-
html`
72-
${getCustomField()[<DaiValidationTypes>bType].render(element, instanceElement)}
73-
${daValue
74-
? html`<wizard-textfield label="DA Template Value"
75-
.maybeValue=${daValue}
76-
readonly
77-
disabled>
78-
</wizard-textfield>`
79-
: nothing}`,
88+
html` ${getCustomField()[<DaiFieldTypes>bType].render(
89+
element,
90+
instanceElement
91+
)}
92+
${daValue
93+
? html`<wizard-textfield
94+
id="daVal"
95+
label="DA Template Value"
96+
.maybeValue=${daValue}
97+
readonly
98+
disabled
99+
>
100+
</wizard-textfield>`
101+
: nothing}`,
80102
];
81103
}
82104

83-
export function createDAIWizard(parent: Element, newElement: Element, element: Element): Wizard {
105+
export function createDAIWizard(
106+
parent: Element,
107+
newElement: Element,
108+
element: Element
109+
): Wizard {
84110
// Retrieve the created DAI, can be the new element or one of the child elements below.
85-
const instanceElement = (newElement.tagName === 'DAI') ? newElement : newElement.querySelector('DAI')!;
111+
const instanceElement =
112+
newElement.tagName === 'DAI'
113+
? newElement
114+
: newElement.querySelector('DAI')!;
86115

87116
return [
88117
{
89118
title: get('dai.wizard.title.create', {
90-
daiName: instanceElement?.getAttribute('name') ?? ''
119+
daiName: instanceElement?.getAttribute('name') ?? '',
91120
}),
92121
element: instanceElement,
93122
primary: {
94123
icon: 'edit',
95124
label: get('save'),
96-
action: createValue(parent, newElement, instanceElement),
125+
action: createValue(parent, element, newElement, instanceElement),
97126
},
98127
content: renderDAIWizard(element, instanceElement),
99128
},
100129
];
101130
}
102131

103-
export function editDAIWizard(element: Element, instanceElement?: Element): Wizard {
132+
export function editDAIWizard(
133+
element: Element,
134+
instanceElement?: Element
135+
): Wizard {
104136
return [
105137
{
106138
title: get('dai.wizard.title.edit', {
107-
daiName: instanceElement?.getAttribute('name') ?? ''
139+
daiName: instanceElement?.getAttribute('name') ?? '',
108140
}),
109141
element: instanceElement,
110142
primary: {
111143
icon: 'edit',
112144
label: get('save'),
113-
action: updateValue(instanceElement!),
145+
action: updateValue(element, instanceElement!),
114146
},
115147
content: renderDAIWizard(element, instanceElement),
116148
},

0 commit comments

Comments
 (0)