Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Settings): Handle difference in version before uploading nsdoc file #541

Merged
merged 47 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
50abca9
Implemented adding document to localStorage
Flurb Jan 19, 2022
89c1d4d
Refactor
Flurb Jan 19, 2022
a7e9b91
Fix unit tests
Flurb Jan 19, 2022
7e25543
Adding unit tests
Flurb Jan 19, 2022
15451f0
Refactor
Flurb Jan 20, 2022
2290b20
Refactor translation
Flurb Jan 20, 2022
2176a00
Fixing snapshot test
Flurb Jan 20, 2022
17b5051
Review comments
Flurb Jan 20, 2022
6098789
Added version text for NSDocs
Flurb Jan 23, 2022
38c9564
Review comments
Flurb Jan 24, 2022
f805dd9
Merge with stash
Flurb Jan 24, 2022
bf42d32
feat(wizards/settings): Added Nsdoc plugin + Show LN names (#516)
Flurb Jan 26, 2022
85bb0a8
Added refactored nsdoc foundation
Flurb Jan 27, 2022
d6c3e65
Added tests
Flurb Jan 27, 2022
ea82336
Merge with main
Flurb Jan 27, 2022
30011a2
Changed name of testfile to lowercase
Flurb Jan 27, 2022
9dced1a
Fixed double names
Jan 27, 2022
84fb5dc
review comments
Flurb Jan 27, 2022
217ff5a
Merge branch 'load-nsdoc-settings' of https://github.com/openscd/open…
Flurb Jan 27, 2022
13e1880
Added DO/DA description show
Flurb Jan 27, 2022
7e2f12f
Fix unit tests
Flurb Jan 27, 2022
cb80a19
Changed referenceInfoTags variable name
Flurb Jan 31, 2022
6cf51d0
Review comment
Flurb Jan 31, 2022
26de9f3
Merge with load-nsdoc-settings
Flurb Jan 31, 2022
75d3912
Removed the dots between toggle icon and info icon
Flurb Jan 31, 2022
9367321
Refactor
Flurb Jan 31, 2022
df5fef7
Added unit tests
Flurb Jan 31, 2022
2757ee6
Added unit tests
Flurb Jan 31, 2022
7d924c6
Removed not used nsdocs (yet)
Flurb Jan 31, 2022
933e585
Fixing weird console error
Flurb Feb 1, 2022
e80c715
Added SDO support
Flurb Feb 1, 2022
545b530
Added BDA support
Flurb Feb 1, 2022
dfe135c
Extended BDA support
Flurb Feb 1, 2022
34f38c6
Small refactoring
Flurb Feb 1, 2022
596e273
partial 8-1 support
Flurb Feb 2, 2022
f9033a8
Refactoring
Flurb Feb 2, 2022
e2da079
Small refactoring
Flurb Feb 2, 2022
ff560cd
Added DA 61850-8-1 support unit tests
Flurb Feb 2, 2022
f9c1ae5
Added unit tests
Flurb Feb 2, 2022
1f74ba9
Added unit tests
Flurb Feb 2, 2022
dd99883
Added separate SDO getDataDescription
Flurb Feb 3, 2022
ad27e89
Refactor getDataDescription signature
Flurb Feb 8, 2022
e1fc4be
Merge with main
Flurb Feb 8, 2022
7e2bbb5
First version
Flurb Feb 8, 2022
7d1c24e
Refactoring
Flurb Feb 8, 2022
7463840
Merged with main
Flurb Feb 11, 2022
8339edc
Added nsdoc72 to interface again
Flurb Feb 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 79 additions & 1 deletion src/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { Language, languages, loader } from './translations/loader.js';
import './WizardDivider.js';
import { WizardDialog } from './wizard-dialog.js';

import { iec6185072, iec6185073, iec6185074, iec6185081 } from "./validators/templates/foundation.js";

export type Settings = {
language: Language;
theme: 'light' | 'dark';
Expand All @@ -39,6 +41,19 @@ export const defaults: Settings = {
'IEC 61850-8-1': undefined
};

type NsdVersion = {
version: string | undefined,
revision: string | undefined,
release: string | undefined
}

type NsdVersions = {
'IEC 61850-7-2': NsdVersion;
'IEC 61850-7-3': NsdVersion;
'IEC 61850-7-4': NsdVersion;
'IEC 61850-8-1': NsdVersion;
}

/** Mixin that saves [[`Settings`]] to `localStorage`, reflecting them in the
* `settings` property, setting them through `setSetting(setting, value)`. */
export type SettingElement = Mixin<typeof Setting>;
Expand All @@ -60,6 +75,38 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
};
}

/**
* Get the versions of the current OpenSCD NSD files.
* @returns Current version, revision and release for all current OpenSCD NSD files.
*/
private async nsdVersions(): Promise<NsdVersions> {
const [nsd72, nsd73, nsd74, nsd81] = await Promise.all([iec6185072, iec6185073, iec6185074, iec6185081]);
const [nsd72Ns, nsd73Ns, nsd74Ns, nsd81Ns] = [nsd72.querySelector('NS'), nsd73.querySelector('NS'), nsd74.querySelector('NS'), nsd81.querySelector('ServiceNS')];

return {
'IEC 61850-7-2': {
version: nsd72Ns?.getAttribute('version') ?? undefined,
revision: nsd72Ns?.getAttribute('revision') ?? undefined,
release: nsd72Ns?.getAttribute('release') ?? undefined,
},
'IEC 61850-7-3': {
version: nsd73Ns?.getAttribute('version') ?? undefined,
revision: nsd73Ns?.getAttribute('revision') ?? undefined,
release: nsd73Ns?.getAttribute('release') ?? undefined,
},
'IEC 61850-7-4': {
version: nsd74Ns?.getAttribute('version') ?? undefined,
revision: nsd74Ns?.getAttribute('revision') ?? undefined,
release: nsd74Ns?.getAttribute('release') ?? undefined,
},
'IEC 61850-8-1': {
version: nsd81Ns?.getAttribute('version') ?? undefined,
revision: nsd81Ns?.getAttribute('revision') ?? undefined,
release: nsd81Ns?.getAttribute('release') ?? undefined,
}
}
}

@query('#settings')
settingsUI!: Dialog;
@query('#language')
Expand Down Expand Up @@ -133,14 +180,16 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
}

private async loadNsdocFile(evt: Event): Promise<void> {
const nsdVersions = await this.nsdVersions();
const files = Array.from(
(<HTMLInputElement | null>evt.target)?.files ?? []
);

if (files.length == 0) return;
files.forEach(async file => {
const text = await file.text();
const id = this.parseToXmlObject(text).querySelector('NSDoc')?.getAttribute('id');
const nsdocElement = this.parseToXmlObject(text).querySelector('NSDoc');
const id = nsdocElement?.getAttribute('id');
if (!id) {
document
.querySelector('open-scd')!
Expand All @@ -149,6 +198,25 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
);
return;
}
const nsdVersion = nsdVersions[id as keyof NsdVersions];
const nsdocVersion = {
version: nsdocElement!.getAttribute('version') ?? undefined,
revision: nsdocElement!.getAttribute('revision') ?? undefined,
release: nsdocElement!.getAttribute('release') ?? undefined
}

if (!this.isEqual(nsdVersion, nsdocVersion)) {
document
.querySelector('open-scd')!
.dispatchEvent(
newLogEvent({ kind: 'error', title: get('settings.invalidNsdocVersion', {
id: id,
nsdVersion: `${nsdVersion.version}${nsdVersion.revision}${nsdVersion.release}`,
nsdocVersion: `${nsdocVersion.version}${nsdocVersion.revision}${nsdocVersion.release}`
}) })
);
return;
}

this.setSetting(id as keyof Settings, text);
})
Expand All @@ -157,6 +225,16 @@ export function Setting<TBase extends LitElementConstructor>(Base: TBase) {
this.requestUpdate();
}

/**
* Check the equality of two NsdVersions.
* @param versionA - First version to compare.
* @param versionB - Second version to compare.
* @returns Are they equal or not.
*/
private isEqual(versionA: NsdVersion, versionB: NsdVersion): boolean {
return versionA.version == versionB.version && versionA.revision == versionB.revision && versionA.release == versionB.release;
}

/**
* Render one .nsdoc item in the Settings wizard
* @param key - The key of the nsdoc file in the settings.
Expand Down
3 changes: 2 additions & 1 deletion src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const de: Translations = {
showieds: 'Zeige IEDs im Substation-Editor',
selectFileButton: 'Datei auswählen',
loadNsdTranslations: 'NSDoc-Dateien hochladen',
invalidFileNoIdFound: 'Ungültiges NSDoc; kein \'id\'-Attribut in der Datei gefunden'
invalidFileNoIdFound: 'Ungültiges NSDoc; kein \'id\'-Attribut in der Datei gefunden',
invalidNsdocVersion: '???'
},
menu: {
new: 'Neues projekt',
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const en = {
showieds: 'Show IEDs in substation editor',
selectFileButton: 'Select file',
loadNsdTranslations: 'Uploading NSDoc files',
invalidFileNoIdFound: 'Invalid NSDoc; no \'id\' attribute found in file'
invalidFileNoIdFound: 'Invalid NSDoc; no \'id\' attribute found in file',
invalidNsdocVersion: 'The version of {{ id }} NSD ({{ nsdVersion }}) does not correlate with the version of the corresponding NSDoc ({{ nsdocVersion }})'
},
menu: {
new: 'New project',
Expand Down