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(open-scd): add project handling including landing dialog #73

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 20 additions & 8 deletions src/Editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ import {
} from './foundation.js';

/** Returns a new empty SCD document, i.e. one containing `<SCL></SCL>` */
export function newEmptySCD(): XMLDocument {
return document.implementation.createDocument(
'http://www.iec.ch/61850/2003/SCL',
'SCL',
null
);
export function newEmptySCD(
id: string,
version: string | null,
revision: string | null,
release: string | null
): XMLDocument {
const markup = `<?xml version="1.0" encoding="UTF-8"?>
<SCL xmlns="http://www.iec.ch/61850/2003/SCL" ${
version ? `version="${version}"` : ``
} ${revision ? `revision="${revision}"` : ``} ${
release ? `release="${release}"` : ``
}>
<Header id="${id}"/>
</SCL>`;
return new DOMParser().parseFromString(markup, 'application/xml');
}

/** Mixin that edits an `XML` `doc`, listening to [[`EditorActionEvent`]]s */
Expand All @@ -36,7 +45,7 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
class EditingElement extends Base {
/** The `XMLDocument` to be edited */
@property()
doc: XMLDocument = newEmptySCD();
doc: XMLDocument | null = null;

private checkCreateValidity(create: Create): boolean {
if (create.checkValidity !== undefined) return create.checkValidity();
Expand All @@ -57,7 +66,10 @@ export function Editing<TBase extends LitElementConstructor>(Base: TBase) {
name: create.new.element.tagName,
}),
message: get('editing.error.nameClash', {
parent: create.new.parent.tagName,
parent:
create.new.parent instanceof HTMLElement
? create.new.parent.tagName
: 'Document',
child: create.new.element.tagName,
name: create.new.element.getAttribute('name')!,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/editors/Substation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class SubstationPlugin extends LitElement {
}

render(): TemplateResult {
if (!this.doc.querySelector(selectors.Substation))
if (!this.doc?.querySelector(selectors.Substation))
return html`<h1>
<span style="color: var(--base1)"
>${translate('substation.missing')}</span
Expand Down
12 changes: 12 additions & 0 deletions src/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,15 @@ export const restrictions = {
decimal: '((-|\\+)?([0-9]+(\\.[0-9]*)?|\\.[0-9]+))',
unsigned: '\\+?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)',
};

export type SchemaVersion = {
version: string | null;
revision: string | null;
release: string | null;
};

export const versionSupport = {
edition1: { version: null, revision: null, release: null },
edition2: { version: '2007', revision: 'A', release: null },
edition21: { version: '2007', revision: 'B', release: '4' },
};
Loading