Skip to content

Commit 6c1b5ff

Browse files
author
Dennis Labordus
committed
Made a Compas version of Update Station and fixed small bugs.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 136687a commit 6c1b5ff

File tree

9 files changed

+96
-61
lines changed

9 files changed

+96
-61
lines changed

__snapshots__/open-scd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@
853853
mwc-list-item=""
854854
selected=""
855855
tabindex="-1"
856-
value="/src/menu/UpdateSubstation.js"
856+
value="/src/menu/CompasUpdateSubstation.js"
857857
>
858858
<mwc-icon slot="meta">
859859
merge_type

public/js/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const officialPlugins = [
105105
},
106106
{
107107
name: 'Update Substation',
108-
src: '/src/menu/UpdateSubstation.js',
108+
src: '/src/menu/CompasUpdateSubstation.js',
109109
icon: 'merge_type',
110110
default: true,
111111
kind: 'menu',

src/compas-editors/CompasVersions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,7 @@ function confirmRestoreVersionCompasWizard(docName: string, docId: string, versi
306306
const type = getTypeFromDocName(docName);
307307

308308
CompasSclDataService().getSclDocumentVersion(type, docId, version)
309-
.then(response => {
310-
// Copy the SCL Result from the Response and create a new Document from it.
311-
const sclData = response.querySelectorAll("SclData").item(0).textContent;
312-
const sclDocument = new DOMParser().parseFromString(sclData??'', 'application/xml');
313-
309+
.then(sclDocument => {
314310
updateDocumentInOpenSCD(sclDocument);
315311

316312
openScd.dispatchEvent(

src/compas-services/CompasSclDataService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ export function CompasSclDataService() {
7878
return fetch(sclUrl)
7979
.catch(handleError)
8080
.then(handleResponse)
81-
.then(parseXml);
81+
.then(parseXml)
82+
.then(extractSclFromResponse);
8283
},
8384

8485
deleteSclDocumentVersion(type: string, id: string, version: string): Promise<string> {

src/compas/CompasCompareDialog.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function compareWizardAction(
4040
options?: MergeOptions
4141
): WizardActor {
4242
return (_, wizard: Element): EditorAction[] => {
43-
let acted = false;
4443
const checkList = wizard.shadowRoot!.querySelector('mwc-list')!;
4544

4645
const selectedChildDiffs = (<ListItem[]>checkList.selected)
@@ -49,7 +48,6 @@ function compareWizardAction(
4948
if (selectedChildDiffs.length) {
5049
for (const diff of selectedChildDiffs)
5150
if (diff.oldValue && diff.newValue) {
52-
acted = true;
5351
wizard.dispatchEvent(
5452
newWizardEvent(
5553
compareWizard(diff.oldValue, diff.newValue, {
@@ -61,10 +59,6 @@ function compareWizardAction(
6159
}
6260
}
6361

64-
if (!acted) {
65-
wizard.dispatchEvent(newWizardEvent());
66-
}
67-
6862
return [
6963
{
7064
actions: [],

src/menu/CompasUpdateSubstation.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {html, LitElement} from 'lit-element';
2+
import {get} from "lit-translate";
3+
4+
import {newWizardEvent, Wizard} from '../foundation.js';
5+
6+
import {DocRetrievedEvent} from "../compas/CompasOpen.js";
7+
import {mergeSubstation} from "./UpdateSubstation.js";
8+
9+
import "../compas/CompasOpen.js";
10+
11+
export default class CompasOpenMenuPlugin extends LitElement {
12+
doc!: XMLDocument;
13+
14+
async run(): Promise<void> {
15+
this.dispatchEvent(newWizardEvent(substationCompasWizard(this.doc)));
16+
}
17+
}
18+
19+
function substationCompasWizard(doc: Document): Wizard {
20+
return [
21+
{
22+
title: get('compas.updateSubstation.title'),
23+
content: [
24+
html`<compas-open @docRetrieved=${(evt: DocRetrievedEvent) => {
25+
mergeSubstation(doc, evt.detail.doc);
26+
const element = evt.detail.element;
27+
element.dispatchEvent(newWizardEvent());
28+
}}>
29+
</compas-open>
30+
`,
31+
],
32+
},
33+
];
34+
}

src/menu/UpdateSubstation.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -79,51 +79,57 @@ export function isValidReference(
7979
);
8080
}
8181

82+
export function mergeSubstation(currentDoc: Document, docWithSubstation: Document): void {
83+
// FIXME: Dirty hack should not be necessary!
84+
document.querySelector('open-scd')!.dispatchEvent(
85+
newWizardEvent(
86+
mergeWizard(
87+
// FIXME: doesn't work with multiple Substations!
88+
currentDoc.documentElement,
89+
docWithSubstation.documentElement,
90+
{
91+
title: get('updatesubstation.title'),
92+
selected: (diff: Diff<Element | string>): boolean =>
93+
diff.theirs instanceof Element
94+
? diff.theirs.tagName === 'LNode'
95+
? currentDoc.querySelector(
96+
selector('LNode', identity(diff.theirs))
97+
) === null &&
98+
isValidReference(docWithSubstation, identity(diff.theirs))
99+
: diff.theirs.tagName === 'Substation' ||
100+
!tags['SCL'].children.includes(
101+
<SCLTag>diff.theirs.tagName
102+
)
103+
: diff.theirs !== null,
104+
disabled: (diff: Diff<Element | string>): boolean =>
105+
diff.theirs instanceof Element &&
106+
diff.theirs.tagName === 'LNode' &&
107+
(currentDoc.querySelector(
108+
selector('LNode', identity(diff.theirs))
109+
) !== null ||
110+
!isValidReference(docWithSubstation, identity(diff.theirs))),
111+
auto: (): boolean => true,
112+
}
113+
)
114+
)
115+
);
116+
}
117+
82118
export default class UpdateSubstationPlugin extends LitElement {
83119
doc!: XMLDocument;
84120

85-
@query('#update-substation-plugin-input') pluginFileUI!: HTMLInputElement;
121+
@query('#update-substation-plugin-input')
122+
pluginFileUI!: HTMLInputElement;
123+
124+
async updateSubstation(event: Event): Promise<void> {
125+
const file = (<HTMLInputElement | null>event.target)?.files?.item(0) ?? false;
126+
if (!file) {
127+
return;
128+
}
86129

87-
updateSubstation(event: Event): void {
88-
const file =
89-
(<HTMLInputElement | null>event.target)?.files?.item(0) ?? false;
90-
if (file)
91-
file.text().then(text => {
92-
const doc = new DOMParser().parseFromString(text, 'application/xml');
93-
// FIXME: Dirty hack should not be necessary!
94-
document.querySelector('open-scd')!.dispatchEvent(
95-
newWizardEvent(
96-
mergeWizard(
97-
// FIXME: doesn't work with multiple Substations!
98-
this.doc.documentElement,
99-
doc.documentElement,
100-
{
101-
title: get('updatesubstation.title'),
102-
selected: (diff: Diff<Element | string>): boolean =>
103-
diff.theirs instanceof Element
104-
? diff.theirs.tagName === 'LNode'
105-
? this.doc.querySelector(
106-
selector('LNode', identity(diff.theirs))
107-
) === null &&
108-
isValidReference(doc, identity(diff.theirs))
109-
: diff.theirs.tagName === 'Substation' ||
110-
!tags['SCL'].children.includes(
111-
<SCLTag>diff.theirs.tagName
112-
)
113-
: diff.theirs !== null,
114-
disabled: (diff: Diff<Element | string>): boolean =>
115-
diff.theirs instanceof Element &&
116-
diff.theirs.tagName === 'LNode' &&
117-
(this.doc.querySelector(
118-
selector('LNode', identity(diff.theirs))
119-
) !== null ||
120-
!isValidReference(doc, identity(diff.theirs))),
121-
auto: (): boolean => true,
122-
}
123-
)
124-
)
125-
);
126-
});
130+
const text = await file.text()
131+
const doc = new DOMParser().parseFromString(text, 'application/xml');
132+
mergeSubstation(this.doc, doc);
127133
this.pluginFileUI.onchange = null;
128134
}
129135

@@ -132,11 +138,9 @@ export default class UpdateSubstationPlugin extends LitElement {
132138
}
133139

134140
render(): TemplateResult {
135-
return html`<input @click=${(event: MouseEvent) =>
136-
((<HTMLInputElement>event.target).value = '')} @change=${(e: Event) =>
137-
this.updateSubstation(
138-
e
139-
)} id="update-substation-plugin-input" accept=".sed,.scd,.ssd,.iid,.cid" type="file"></input>`;
141+
return html`<input @click=${(event: MouseEvent) => ((<HTMLInputElement>event.target).value = '')}
142+
@change=${this.updateSubstation}
143+
id="update-substation-plugin-input" accept=".sed,.scd,.ssd,.iid,.cid" type="file"></input>`;
140144
}
141145

142146
static styles = css`

src/translations/de.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ export const de: Translations = {
419419
addSuccess: '???',
420420
updateSuccess: '???',
421421
},
422+
updateSubstation: {
423+
title: '???',
424+
},
422425
uploadVersion: {
423426
title: '???',
424427
selectButton: '???...',

src/translations/en.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ export const en = {
416416
addSuccess: 'Project added to CoMPAS.',
417417
updateSuccess: 'Project updated in CoMPAS',
418418
},
419+
updateSubstation: {
420+
title: 'Update substation',
421+
},
419422
uploadVersion: {
420423
title: 'Upload new version of project to CoMPAS',
421424
selectButton: 'Select file...',
@@ -446,7 +449,7 @@ export const en = {
446449
compare: {
447450
title: 'Compare version {{oldVersion}} with version {{newVersion}}',
448451
elementTitle: 'Compare {{oldValue}} with {{newValue}} ({{tag}})',
449-
primaryButton: 'Show details',
452+
primaryButton: 'Continue...',
450453
children: 'Child elements',
451454
},
452455
settings: {

0 commit comments

Comments
 (0)