Skip to content

Commit 27d5bee

Browse files
author
Rob Tjalma
authored
Merge pull request #62 from com-pas/delete-scl-from-compas
Delete SCL (Versions) from CoMPAS
2 parents eadf9d7 + c16c7f5 commit 27d5bee

File tree

9 files changed

+221
-15
lines changed

9 files changed

+221
-15
lines changed

__snapshots__/compas-versions-plugin.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,63 @@
6666
<section tabindex="0">
6767
<h1>
6868
[compas.versions.title]
69+
<mwc-icon-button icon="delete_forever">
70+
</mwc-icon-button>
6971
</h1>
7072
<mwc-list>
7173
<mwc-list-item
7274
aria-disabled="false"
75+
graphic="control"
7376
mwc-list-item=""
7477
tabindex="0"
7578
>
7679
demo_station1 (1.0.0)
80+
<span
81+
slot="graphic"
82+
style="width: 90px"
83+
>
84+
<mwc-icon>
85+
restore
86+
</mwc-icon>
87+
<mwc-icon>
88+
delete
89+
</mwc-icon>
90+
</span>
7791
</mwc-list-item>
7892
<mwc-list-item
7993
aria-disabled="false"
94+
graphic="control"
8095
mwc-list-item=""
8196
tabindex="-1"
8297
>
8398
demo_station1 (2.0.0)
99+
<span
100+
slot="graphic"
101+
style="width: 90px"
102+
>
103+
<mwc-icon>
104+
restore
105+
</mwc-icon>
106+
<mwc-icon>
107+
delete
108+
</mwc-icon>
109+
</span>
84110
</mwc-list-item>
85111
<mwc-list-item
86112
aria-disabled="false"
113+
graphic="control"
87114
mwc-list-item=""
88115
tabindex="-1"
89116
>
90117
3b572a56-51cc-479b-97fd-e404ebf9ae67 (2.1.0)
118+
<span
119+
slot="graphic"
120+
style="width: 90px"
121+
>
122+
<mwc-icon>
123+
restore
124+
</mwc-icon>
125+
</span>
91126
</mwc-list-item>
92127
</mwc-list>
93128
</section>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
In the CoMPAS Editor the different versions of an SCL XML File are shown that are stored in CoMPAS.
2+
3+
- <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M13 3c-4.97 0-9 4.03-9 9H1l4 3.99L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.25 2.52.77-1.28-3.52-2.09V8z"/></svg>:
4+
Restore a specific version from CoMPAS. <br/>
5+
By pressing the icon and confirming the action that specific version will be loaded in OpenSCD.
6+
That version isn't saved yet in CoMPAS as the latest version. By saving it using the menu 'Save CoMPAS'
7+
the loaded version can be saved as the latest version.
8+
- <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-3.5l-1-1zM18 7H6v12c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7z"/></svg>:
9+
Remove a specific version from CoMPAS.<br/>
10+
By pressing the icon and confirming the action that specific version will be removed from CoMPAS.
11+
- <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M14.12 10.47L12 12.59l-2.13-2.12-1.41 1.41L10.59 14l-2.12 2.12 1.41 1.41L12 15.41l2.12 2.12 1.41-1.41L13.41 14l2.12-2.12zM15.5 4l-1-1h-5l-1 1H5v2h14V4zM6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM8 9h8v10H8V9z"/></svg>:
12+
Remove the SCL XML File completely from CoMPAS, all versions.<br/>
13+
By pressing the icon and confirming the action all versions will be removed from CoMPAS.

public/md/Home.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
This is an open repository of information on OpenSCD and IEC 61850-6. You are welcome to share your knowledge with the rest of the world at https://github.com/openscd/open-scd/wiki/Home/_edit 😄 . Welcome aboard!
22

3-
So far we have documented some essential [general OpenSCD editor features](https://github.com/openscd/open-scd/wiki/OpenSCD-Editor-Features) and features regarding the individual [sections of an SCL file](https://github.com/openscd/open-scd/wiki/SCL-Sections) .
3+
So far we have documented some essential [general OpenSCD editor features](https://github.com/openscd/open-scd/wiki/OpenSCD-Editor-Features) and features regarding the individual [sections of an SCL file](https://github.com/openscd/open-scd/wiki/SCL-Sections).
4+
And for CoMPAS there is some documentation about the [CoMPAS Version Editor](https://github.com/openscd/open-scd/wiki/CoMPAS-Versions-Editor).

public/md/_Sidebar.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
### DataTypeTemplates
2222

2323
- [DataTypeTemplate editor](https://github.com/openscd/open-scd/wiki/DataTypeTemplate-editor)
24+
25+
## CoMPASS
26+
27+
- [CoMPAS Versions Editor](https://github.com/openscd/open-scd/wiki/CoMPAS-Versions-Editor)

src/compas-editors/CompasVersions.ts

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {css, html, LitElement, property, TemplateResult} from 'lit-element';
22
import {get, translate} from 'lit-translate';
3-
import {newWizardEvent, Wizard} from "../foundation.js";
3+
import {newLogEvent, newWizardEvent, Wizard} from "../foundation.js";
44

55
import {CompasSclDataService, SDS_NAMESPACE} from "../compas-services/CompasSclDataService.js";
66
import {getTypeFromDocName, updateDocumentInOpenSCD} from "../compas/foundation.js";
@@ -36,6 +36,14 @@ export default class CompasVersionsPlugin extends LitElement {
3636
this.dispatchEvent(newWizardEvent(confirmRestoreCompasWizard(this.docName, this.docId, version)))
3737
}
3838

39+
confirmDeleteCompas(): void {
40+
this.dispatchEvent(newWizardEvent(confirmDeleteCompasWizard(this.docName, this.docId)))
41+
}
42+
43+
confirmDeleteVersionCompas(version: string): void {
44+
this.dispatchEvent(newWizardEvent(confirmDeleteVersionCompasWizard(this.docName, this.docId, version)))
45+
}
46+
3947
private getElementbyName(parent: Element, namespace: string, tagName: string): Element | null {
4048
const elements = parent.getElementsByTagNameNS(namespace, tagName);
4149
if (elements.length > 0) {
@@ -63,20 +71,42 @@ export default class CompasVersionsPlugin extends LitElement {
6371
return html`
6472
<div id="containerCompasVersions">
6573
<section tabindex="0">
66-
<h1>${translate('compas.versions.title')}</h1>
74+
<h1>
75+
${translate('compas.versions.title')}
76+
<mwc-icon-button icon="delete_forever"
77+
@click=${() => {
78+
this.confirmDeleteCompas();
79+
}}></mwc-icon-button>
80+
</h1>
6781
<mwc-list>
68-
${this.scls.map( item => {
82+
${this.scls.map( (item, index, items) => {
6983
let element = this.getElementbyName(item, SDS_NAMESPACE, "Name");
7084
if (element === null) {
7185
element = this.getElementbyName(item, SDS_NAMESPACE, "Id");
7286
}
7387
const name = element!.textContent ?? '';
7488
const version = this.getElementbyName(item, SDS_NAMESPACE, "Version")!.textContent ?? '';
89+
if (items.length - 1 === index) {
90+
return html`<mwc-list-item tabindex="0" graphic="control">
91+
${name} (${version})
92+
<span slot="graphic" style="width: 90px">
93+
<mwc-icon @click=${() => {
94+
this.confirmRestoreCompas(version);
95+
}}>restore</mwc-icon>
96+
</span>
97+
</mwc-list-item>`
98+
}
7599
return html`<mwc-list-item tabindex="0"
76-
@click=${() => {
77-
this.confirmRestoreCompas(version);
78-
}}>
100+
graphic="control">
79101
${name} (${version})
102+
<span slot="graphic" style="width: 90px">
103+
<mwc-icon @click=${() => {
104+
this.confirmRestoreCompas(version);
105+
}}>restore</mwc-icon>
106+
<mwc-icon @click=${() => {
107+
this.confirmDeleteVersionCompas(version);
108+
}}>delete</mwc-icon>
109+
</span>
80110
</mwc-list-item>`
81111
})}
82112
</mwc-list>
@@ -123,8 +153,54 @@ function openScl(docName: string, docId: string, version: string) {
123153
const type = getTypeFromDocName(docName);
124154
fetchScl(type, docId, version);
125155

156+
const openScd = getOpenScdElement();
157+
openScd.dispatchEvent(
158+
newLogEvent({
159+
kind: 'info',
160+
title: get('compas.versions.restoreVersionSuccess', {version : version})
161+
}));
162+
163+
// Close the Restore Dialog.
164+
openScd.dispatchEvent(newWizardEvent());
165+
166+
return [];
167+
}
168+
}
169+
170+
function deleteScl(docName: string, docId: string) {
171+
return function () {
172+
const type = getTypeFromDocName(docName);
173+
CompasSclDataService().deleteSclDocument(type, docId);
174+
175+
const openScd = getOpenScdElement();
176+
openScd.docId = '';
177+
openScd.dispatchEvent(
178+
newLogEvent({
179+
kind: 'info',
180+
title: get('compas.versions.deleteSuccess')
181+
}));
182+
126183
// Close the Restore Dialog.
127-
getOpenScdElement().dispatchEvent(newWizardEvent());
184+
openScd.dispatchEvent(newWizardEvent());
185+
186+
return [];
187+
}
188+
}
189+
190+
function deleteSclVersion(docName: string, docId: string, version: string) {
191+
return function () {
192+
const type = getTypeFromDocName(docName);
193+
CompasSclDataService().deleteSclDocumentVersion(type, docId, version);
194+
195+
const openScd = getOpenScdElement();
196+
openScd.dispatchEvent(
197+
newLogEvent({
198+
kind: 'info',
199+
title: get('compas.versions.deleteVersionSuccess', {version : version})
200+
}));
201+
202+
// Close the Restore Dialog.
203+
openScd.dispatchEvent(newWizardEvent());
128204

129205
return [];
130206
}
@@ -133,14 +209,46 @@ function openScl(docName: string, docId: string, version: string) {
133209
function confirmRestoreCompasWizard(docName: string, docId: string, version: string): Wizard {
134210
return [
135211
{
136-
title: get('compas.versions.confirmTitle'),
212+
title: get('compas.versions.confirmRestoreTitle'),
137213
primary: {
138214
icon: '',
139215
label: get('compas.versions.confirmButton'),
140216
action: openScl(docName, docId, version),
141217
},
142218
content: [
143-
html`<span>${translate('compas.versions.confirm')}</span>`,
219+
html`<span>${translate('compas.versions.confirmRestore', {version : version})}</span>`,
220+
],
221+
},
222+
];
223+
}
224+
225+
function confirmDeleteCompasWizard(docName: string, docId: string): Wizard {
226+
return [
227+
{
228+
title: get('compas.versions.confirmDeleteTitle'),
229+
primary: {
230+
icon: '',
231+
label: get('compas.versions.confirmButton'),
232+
action: deleteScl(docName, docId),
233+
},
234+
content: [
235+
html`<span>${translate('compas.versions.confirmDelete')}</span>`,
236+
],
237+
},
238+
];
239+
}
240+
241+
function confirmDeleteVersionCompasWizard(docName: string, docId: string, version: string): Wizard {
242+
return [
243+
{
244+
title: get('compas.versions.confirmDeleteVersionTitle'),
245+
primary: {
246+
icon: '',
247+
label: get('compas.versions.confirmButton'),
248+
action: deleteSclVersion(docName, docId, version),
249+
},
250+
content: [
251+
html`<span>${translate('compas.versions.confirmDeleteVersion', {version : version})}</span>`,
144252
],
145253
},
146254
];

src/compas-services/CompasSclDataService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ export function CompasSclDataService() {
6969
.then(str => new DOMParser().parseFromString(str, 'application/xml'))
7070
},
7171

72+
deleteSclDocumentVersion(type: string, id: string, version: string): Promise<Response> {
73+
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id + '/' + version;
74+
return fetch(sclUrl, {method: 'DELETE'});
75+
},
76+
77+
deleteSclDocument(type: string, id: string): Promise<Response> {
78+
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase() + '/' + id;
79+
return fetch(sclUrl, {method: 'DELETE'});
80+
},
81+
7282
addSclDocument(type: string, body: CreateRequestBody): Promise<Document> {
7383
const sclUrl = getCompasSettings().sclDataServiceUrl + '/scl/v1/' + type?.toUpperCase();
7484
return fetch(sclUrl, {

src/translations/de.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,15 @@ export const de: Translations = {
412412
title: '???',
413413
noVersions: "???",
414414
noScls: "???",
415-
confirmTitle: "???",
416-
confirm: "???",
415+
confirmRestoreTitle: "???",
416+
confirmRestore: "??? {{version}}?",
417+
restoreVersionSuccess: '??? {{version}}',
418+
confirmDeleteTitle: '???',
419+
confirmDelete: '???',
420+
deleteSuccess: '???',
421+
confirmDeleteVersionTitle: '???',
422+
confirmDeleteVersion: '??? {{version}}?',
423+
deleteVersionSuccess: '??? {{version}}',
417424
confirmButton: "???",
418425
},
419426
settings: {

src/translations/en.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,15 @@ export const en = {
409409
title: 'CoMPAS Versions',
410410
noVersions: 'No CoMPAS versions found',
411411
noScls: 'No versions found for this SCL in CoMPAS',
412-
confirmTitle: 'Restore?',
413-
confirm: 'Are you sure to restore previous version?',
412+
confirmRestoreTitle: 'Restore version?',
413+
confirmRestore: 'Are you sure to restore version {{version}}?',
414+
restoreVersionSuccess: 'Restored version {{version}}',
415+
confirmDeleteTitle: 'Delete SCL?',
416+
confirmDelete: 'Are you sure to delete all version(s)?',
417+
deleteSuccess: 'Removed SCL from CoMPAS',
418+
confirmDeleteVersionTitle: 'Delete version?',
419+
confirmDeleteVersion: 'Are you sure to delete version {{version}}?',
420+
deleteVersionSuccess: 'Removed version {{version}} from CoMPAS',
414421
confirmButton: 'Confirm',
415422
},
416423
settings: {

test/integration/compas-editors/CompasVersions.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,28 @@ describe('compas-versions-plugin', () => {
118118

119119
it('has 3 item entries', () => {
120120
expect(element.shadowRoot!.querySelectorAll('mwc-list > mwc-list-item'))
121-
.to.have.length(3)
121+
.to.have.length(3);
122+
});
123+
124+
it('first entry has correct buttons', () => {
125+
expect(element.shadowRoot!.querySelectorAll('mwc-list > mwc-list-item').length)
126+
.to.be.greaterThan(1);
127+
// Retrieve the first item after checking that there are items.
128+
const item = element.shadowRoot!.querySelectorAll('mwc-list > mwc-list-item')[0];
129+
// There should be 2 buttons, first the restore, second the delete.
130+
expect(item.querySelectorAll('span > mwc-icon')).to.have.length(2);
131+
expect(item.querySelectorAll('span > mwc-icon')[0].textContent).to.be.equal('restore');
132+
expect(item.querySelectorAll('span > mwc-icon')[1].textContent).to.be.equal('delete');
133+
});
134+
135+
it('last entry has one buttons', () => {
136+
expect(element.shadowRoot!.querySelectorAll('mwc-list > mwc-list-item'))
137+
.to.have.length(3);
138+
// Retrieve the last item after checking that there are 3 items.
139+
const item = element.shadowRoot!.querySelectorAll('mwc-list > mwc-list-item')[2];
140+
// There should be 1 buttons, the restore button.
141+
expect(item.querySelectorAll('span > mwc-icon')).to.have.length(1);
142+
expect(item.querySelectorAll('span > mwc-icon')[0].textContent).to.be.equal('restore');
122143
});
123144

124145
it('looks like the latest snapshot', async () => {

0 commit comments

Comments
 (0)