Skip to content

Commit 04329d9

Browse files
JakobVogelsangca-dDennis Labordus
authored
refactor: remove OpenSCD as dispatcher (openscd#802)
* refactor: remove OpenSCD as dispatcher * fix(wizard-dialog): change wording from cancel to close * Fixed snapshot test. Co-authored-by: Christian Dinkel <[email protected]> Co-authored-by: Dennis Labordus <[email protected]>
1 parent 9826999 commit 04329d9

File tree

69 files changed

+666
-1668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+666
-1668
lines changed

src/Setting.ts

Lines changed: 108 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ import { Dialog } from '@material/mwc-dialog';
1212
import { Select } from '@material/mwc-select';
1313
import { Switch } from '@material/mwc-switch';
1414

15-
import { ifImplemented, LitElementConstructor, Mixin, newLogEvent } from './foundation.js';
15+
import {
16+
ifImplemented,
17+
LitElementConstructor,
18+
Mixin,
19+
newLogEvent,
20+
} from './foundation.js';
1621
import { Language, languages, loader } from './translations/loader.js';
1722

1823
import './WizardDivider.js';
1924
import { WizardDialog } from './wizard-dialog.js';
2025

21-
import { iec6185072, iec6185073, iec6185074, iec6185081 } from "./validators/templates/foundation.js";
26+
import {
27+
iec6185072,
28+
iec6185073,
29+
iec6185074,
30+
iec6185081,
31+
} from './validators/templates/foundation.js';
2232
import { initializeNsdoc, Nsdoc } from './foundation/nsdoc.js';
2333

2434
export type Settings = {
@@ -39,21 +49,21 @@ export const defaults: Settings = {
3949
'IEC 61850-7-2': undefined,
4050
'IEC 61850-7-3': undefined,
4151
'IEC 61850-7-4': undefined,
42-
'IEC 61850-8-1': undefined
52+
'IEC 61850-8-1': undefined,
4353
};
4454

4555
type NsdVersion = {
46-
version: string | undefined,
47-
revision: string | undefined,
48-
release: string | undefined
49-
}
56+
version: string | undefined;
57+
revision: string | undefined;
58+
release: string | undefined;
59+
};
5060

5161
type NsdVersions = {
5262
'IEC 61850-7-2': NsdVersion;
5363
'IEC 61850-7-3': NsdVersion;
5464
'IEC 61850-7-4': NsdVersion;
5565
'IEC 61850-8-1': NsdVersion;
56-
}
66+
};
5767

5868
/** Represents a document to be opened. */
5969
export interface LoadNsdocDetail {
@@ -89,7 +99,7 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
8999
'IEC 61850-7-2': this.getSetting('IEC 61850-7-2'),
90100
'IEC 61850-7-3': this.getSetting('IEC 61850-7-3'),
91101
'IEC 61850-7-4': this.getSetting('IEC 61850-7-4'),
92-
'IEC 61850-8-1': this.getSetting('IEC 61850-8-1')
102+
'IEC 61850-8-1': this.getSetting('IEC 61850-8-1'),
93103
};
94104
}
95105
/** Object containing all *.nsdoc files and a function extracting element's label form them*/
@@ -101,8 +111,18 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
101111
* @returns Current version, revision and release for all current OpenSCD NSD files.
102112
*/
103113
private async nsdVersions(): Promise<NsdVersions> {
104-
const [nsd72, nsd73, nsd74, nsd81] = await Promise.all([iec6185072, iec6185073, iec6185074, iec6185081]);
105-
const [nsd72Ns, nsd73Ns, nsd74Ns, nsd81Ns] = [nsd72.querySelector('NS'), nsd73.querySelector('NS'), nsd74.querySelector('NS'), nsd81.querySelector('ServiceNS')];
114+
const [nsd72, nsd73, nsd74, nsd81] = await Promise.all([
115+
iec6185072,
116+
iec6185073,
117+
iec6185074,
118+
iec6185081,
119+
]);
120+
const [nsd72Ns, nsd73Ns, nsd74Ns, nsd81Ns] = [
121+
nsd72.querySelector('NS'),
122+
nsd73.querySelector('NS'),
123+
nsd74.querySelector('NS'),
124+
nsd81.querySelector('ServiceNS'),
125+
];
106126

107127
return {
108128
'IEC 61850-7-2': {
@@ -124,8 +144,8 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
124144
version: nsd81Ns?.getAttribute('version') ?? undefined,
125145
revision: nsd81Ns?.getAttribute('revision') ?? undefined,
126146
release: nsd81Ns?.getAttribute('release') ?? undefined,
127-
}
128-
}
147+
},
148+
};
129149
}
130150

131151
@query('#settings')
@@ -189,15 +209,26 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
189209
}
190210

191211
private renderFileSelect(): TemplateResult {
192-
return html `
193-
<input id="nsdoc-file" accept=".nsdoc" type="file" hidden required multiple
194-
@change=${(evt: Event) => this.uploadNsdocFile(evt)}}>
195-
<mwc-button label="${translate('settings.selectFileButton')}"
196-
id="selectFileButton"
197-
@click=${() => {
198-
const input = <HTMLInputElement | null>this.shadowRoot!.querySelector("#nsdoc-file");
199-
input?.click();
200-
}}>
212+
return html`
213+
<input
214+
id="nsdoc-file"
215+
accept=".nsdoc"
216+
type="file"
217+
hidden
218+
required
219+
multiple
220+
@change="${(evt: Event) => this.uploadNsdocFile(evt)}}"
221+
/>
222+
<mwc-button
223+
label="${translate('settings.selectFileButton')}"
224+
id="selectFileButton"
225+
@click=${() => {
226+
const input = <HTMLInputElement | null>(
227+
this.shadowRoot!.querySelector('#nsdoc-file')
228+
);
229+
input?.click();
230+
}}
231+
>
201232
</mwc-button>
202233
`;
203234
}
@@ -210,29 +241,28 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
210241
if (files.length == 0) return;
211242
for (const file of files) {
212243
const text = await file.text();
213-
document
214-
.querySelector('open-scd')!
215-
.dispatchEvent(
216-
newLoadNsdocEvent(text, file.name)
217-
);
244+
this.dispatchEvent(newLoadNsdocEvent(text, file.name));
218245
}
219246

220247
this.nsdocFileUI.value = '';
221248
this.requestUpdate();
222249
}
223250

224251
private async onLoadNsdoc(event: LoadNsdocEvent) {
225-
const nsdocElement = this.parseToXmlObject(event.detail.nsdoc).querySelector('NSDoc');
252+
const nsdocElement = this.parseToXmlObject(
253+
event.detail.nsdoc
254+
).querySelector('NSDoc');
226255

227256
const id = nsdocElement?.getAttribute('id');
228257
if (!id) {
229-
document
230-
.querySelector('open-scd')!
231-
.dispatchEvent(
232-
newLogEvent({ kind: 'error', title: get('settings.invalidFileNoIdFound', {
233-
filename: event.detail.filename
234-
}) })
235-
);
258+
this.dispatchEvent(
259+
newLogEvent({
260+
kind: 'error',
261+
title: get('settings.invalidFileNoIdFound', {
262+
filename: event.detail.filename,
263+
}),
264+
})
265+
);
236266
return;
237267
}
238268

@@ -241,20 +271,21 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
241271
const nsdocVersion = {
242272
version: nsdocElement!.getAttribute('version') ?? '',
243273
revision: nsdocElement!.getAttribute('revision') ?? '',
244-
release: nsdocElement!.getAttribute('release') ?? ''
245-
}
274+
release: nsdocElement!.getAttribute('release') ?? '',
275+
};
246276

247277
if (!this.isEqual(nsdVersion, nsdocVersion)) {
248-
document
249-
.querySelector('open-scd')!
250-
.dispatchEvent(
251-
newLogEvent({ kind: 'error', title: get('settings.invalidNsdocVersion', {
252-
id: id,
253-
filename: event.detail.filename,
254-
nsdVersion: `${nsdVersion.version}${nsdVersion.revision}${nsdVersion.release}`,
255-
nsdocVersion: `${nsdocVersion.version}${nsdocVersion.revision}${nsdocVersion.release}`
256-
}) })
257-
);
278+
this.dispatchEvent(
279+
newLogEvent({
280+
kind: 'error',
281+
title: get('settings.invalidNsdocVersion', {
282+
id: id,
283+
filename: event.detail.filename,
284+
nsdVersion: `${nsdVersion.version}${nsdVersion.revision}${nsdVersion.release}`,
285+
nsdocVersion: `${nsdocVersion.version}${nsdocVersion.revision}${nsdocVersion.release}`,
286+
}),
287+
})
288+
);
258289
return;
259290
}
260291

@@ -269,7 +300,11 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
269300
* @returns Are they equal or not.
270301
*/
271302
private isEqual(versionA: NsdVersion, versionB: NsdVersion): boolean {
272-
return versionA.version == versionB.version && versionA.revision == versionB.revision && versionA.release == versionB.release;
303+
return (
304+
versionA.version == versionB.version &&
305+
versionA.revision == versionB.revision &&
306+
versionA.release == versionB.release
307+
);
273308
}
274309

275310
/**
@@ -290,14 +325,32 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
290325
nsdRelease = nsdoc?.getAttribute('release');
291326
}
292327

293-
return html`<mwc-list-item id=${key} graphic="avatar" hasMeta twoline .disabled=${!nsdSetting}>
328+
return html`<mwc-list-item
329+
id=${key}
330+
graphic="avatar"
331+
hasMeta
332+
twoline
333+
.disabled=${!nsdSetting}
334+
>
294335
<span>${key}</span>
295-
${nsdSetting ? html`<span slot="secondary">${nsdVersion}${nsdRevision}${nsdRelease}</span>` :
296-
html``}
297-
${nsdSetting ? html`<mwc-icon slot="graphic" style="color:green;">done</mwc-icon>` :
298-
html`<mwc-icon slot="graphic" style="color:red;">close</mwc-icon>`}
299-
${nsdSetting ? html`<mwc-icon id="deleteNsdocItem" slot="meta" @click=${() => {this.removeSetting(key)}}>delete</mwc-icon>` :
300-
html``}
336+
${nsdSetting
337+
? html`<span slot="secondary"
338+
>${nsdVersion}${nsdRevision}${nsdRelease}</span
339+
>`
340+
: html``}
341+
${nsdSetting
342+
? html`<mwc-icon slot="graphic" style="color:green;">done</mwc-icon>`
343+
: html`<mwc-icon slot="graphic" style="color:red;">close</mwc-icon>`}
344+
${nsdSetting
345+
? html`<mwc-icon
346+
id="deleteNsdocItem"
347+
slot="meta"
348+
@click=${() => {
349+
this.removeSetting(key);
350+
}}
351+
>delete</mwc-icon
352+
>`
353+
: html``}
301354
</mwc-list-item>`;
302355
}
303356

0 commit comments

Comments
 (0)