Skip to content

Commit

Permalink
Merge branch 'main' into locamation-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Labordus committed Feb 21, 2022
2 parents 512215e + 67c06d6 commit d7d2f2b
Show file tree
Hide file tree
Showing 72 changed files with 1,949 additions and 1,619 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.10.0](https://github.com/openscd/open-scd/compare/v0.9.0...v0.10.0) (2022-02-21)


### Features

* **editors/IED:** display IED data attributes namespace description ([#522](https://github.com/openscd/open-scd/issues/522)) ([02b8d97](https://github.com/openscd/open-scd/commits/02b8d97ddb066a1c0134b97aa1e50243f2628048)), closes [#516](https://github.com/openscd/open-scd/issues/516)
* **Settings:** Handle difference in version before uploading nsdoc file ([#541](https://github.com/openscd/open-scd/issues/541)) ([2e470cb](https://github.com/openscd/open-scd/commits/2e470cb3da26adc46c111840d4c9322eb3af14b1))
* **wizard-checkbox:** web component for xs:boolean XML attributes ([#537](https://github.com/openscd/open-scd/issues/537)) ([2b11ae8](https://github.com/openscd/open-scd/commits/2b11ae8ddcfb43a01f7b5d6fe7dae1bee128da39))
* **wizard/sampledvaluecontrol:** allow removing including referenced elements ([#536](https://github.com/openscd/open-scd/issues/536)) ([1940571](https://github.com/openscd/open-scd/commits/194057113de4398209f963262fb8135fd9f5bc03))

## [0.9.0](https://github.com/openscd/open-scd/compare/v0.8.2...v0.9.0) (2022-02-04)


Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
"purpose": "maskable"
}
],
"version": "0.9.0"
"version": "0.10.0"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-scd",
"version": "0.9.0",
"version": "0.10.0",
"repository": "https://github.com/openscd/open-scd.git",
"description": "A bottom-up substation configuration designer for projects described using SCL `IEC 61850-6` Edition 2 or greater.",
"keywords": [
Expand Down
10 changes: 8 additions & 2 deletions src/Plugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,17 @@ export function Plugging<TBase extends new (...args: any[]) => EditingElement>(
>
</mwc-button>
<mwc-button
raised
slot="secondaryAction"
icon=""
label="${translate('close')}"
dialogAction="close"
></mwc-button>
<mwc-button
outlined
trailingIcon
slot="primaryAction"
icon="library_add"
label="${translate('add')}&hellip;"
label="${translate('plugins.add.heading')}&hellip;"
@click=${() => this.pluginDownloadUI.show()}
>
</mwc-button>
Expand Down
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
58 changes: 33 additions & 25 deletions src/editors/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { translate, get } from 'lit-translate';

import '@material/mwc-fab';

import './communication/subnetwork-editor.js';
import {
newWizardEvent,
newActionEvent,
createElement,
isPublic,
} from '../foundation.js';
import { selectors, styles } from './communication/foundation.js';
import './communication/subnetwork-editor.js';
import { subNetworkWizard } from './communication/subnetwork-editor.js';
import { createSubNetworkWizard } from '../wizards/subnetwork.js';

/** An editor [[`plugin`]] for editing the `Communication` section. */
export default class CommunicationPlugin extends LitElement {
/** The document being edited as provided to plugins by [[`OpenSCD`]]. */
@property()
doc!: XMLDocument;

createCommunication(): void {
private createCommunication(): void {
this.dispatchEvent(
newActionEvent({
new: {
Expand All @@ -30,21 +30,15 @@ export default class CommunicationPlugin extends LitElement {
}

/** Opens a [[`WizardDialog`]] for creating a new `SubNetwork` element. */
openCreateSubNetworkWizard(): void {
if (!this.doc.querySelector(selectors.Communication))
this.createCommunication();
private openCreateSubNetworkWizard(): void {
const parent = this.doc.querySelector(':root > Communication');
if (!parent) this.createCommunication();

this.dispatchEvent(
newWizardEvent(
subNetworkWizard({
parent: this.doc.querySelector('Communication')!,
})
)
);
this.dispatchEvent(newWizardEvent(createSubNetworkWizard(parent!)));
}

render(): TemplateResult {
if (!this.doc?.querySelector(selectors.SubNetwork))
if (!this.doc?.querySelector(':root > Communication >SubNetwork'))
return html`<h1>
<span style="color: var(--base1)"
>${translate('communication.missing')}</span
Expand All @@ -55,29 +49,43 @@ export default class CommunicationPlugin extends LitElement {
@click=${() => this.openCreateSubNetworkWizard()}
></mwc-fab>
</h1>`;

return html`<mwc-fab
extended
icon="add"
label="${get('subnetwork.wizard.title.add')}"
@click=${() => this.openCreateSubNetworkWizard()}
></mwc-fab
>${Array.from(this.doc.querySelectorAll(selectors.SubNetwork) ?? []).map(
subnetwork =>
html`<subnetwork-editor .element=${subnetwork}></subnetwork-editor>`
)}`;
></mwc-fab>
<section>
${Array.from(this.doc.querySelectorAll('SubNetwork') ?? [])
.filter(isPublic)
.map(
subnetwork =>
html`<subnetwork-editor
.element=${subnetwork}
></subnetwork-editor>`
)}
</section> `;
}

static styles = css`
${styles}
:host {
width: 100vw;
}
section {
outline: none;
padding: 8px 12px 16px;
}
subnetwork-editor {
margin: 8px 12px 16px;
}
mwc-fab {
position: fixed;
bottom: 32px;
right: 32px;
}
:host {
width: 100vw;
}
`;
}
Loading

0 comments on commit d7d2f2b

Please sign in to comment.