Skip to content

Commit 0ef335a

Browse files
author
Dennis Labordus
committed
Refactor CoMPAS Versions Tab, added delete buttons.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent eadf9d7 commit 0ef335a

File tree

4 files changed

+142
-13
lines changed

4 files changed

+142
-13
lines changed

src/compas-editors/CompasVersions.ts

Lines changed: 114 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,39 @@ 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"></span>
93+
</mwc-list-item>`
94+
}
7595
return html`<mwc-list-item tabindex="0"
76-
@click=${() => {
77-
this.confirmRestoreCompas(version);
78-
}}>
96+
hasMeta
97+
graphic="control">
7998
${name} (${version})
99+
<span slot="graphic" style="width: 90px">
100+
<mwc-icon @click=${() => {
101+
this.confirmRestoreCompas(version);
102+
}}>restore</mwc-icon>
103+
<mwc-icon @click=${() => {
104+
this.confirmDeleteVersionCompas(version);
105+
}}>delete</mwc-icon>
106+
</span>
80107
</mwc-list-item>`
81108
})}
82109
</mwc-list>
@@ -123,8 +150,54 @@ function openScl(docName: string, docId: string, version: string) {
123150
const type = getTypeFromDocName(docName);
124151
fetchScl(type, docId, version);
125152

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

129202
return [];
130203
}
@@ -133,14 +206,46 @@ function openScl(docName: string, docId: string, version: string) {
133206
function confirmRestoreCompasWizard(docName: string, docId: string, version: string): Wizard {
134207
return [
135208
{
136-
title: get('compas.versions.confirmTitle'),
209+
title: get('compas.versions.confirmRestoreTitle'),
137210
primary: {
138211
icon: '',
139212
label: get('compas.versions.confirmButton'),
140213
action: openScl(docName, docId, version),
141214
},
142215
content: [
143-
html`<span>${translate('compas.versions.confirm')}</span>`,
216+
html`<span>${translate('compas.versions.confirmRestore', {version : version})}</span>`,
217+
],
218+
},
219+
];
220+
}
221+
222+
function confirmDeleteCompasWizard(docName: string, docId: string): Wizard {
223+
return [
224+
{
225+
title: get('compas.versions.confirmDeleteTitle'),
226+
primary: {
227+
icon: '',
228+
label: get('compas.versions.confirmButton'),
229+
action: deleteScl(docName, docId),
230+
},
231+
content: [
232+
html`<span>${translate('compas.versions.confirmDelete')}</span>`,
233+
],
234+
},
235+
];
236+
}
237+
238+
function confirmDeleteVersionCompasWizard(docName: string, docId: string, version: string): Wizard {
239+
return [
240+
{
241+
title: get('compas.versions.confirmDeleteVersionTitle'),
242+
primary: {
243+
icon: '',
244+
label: get('compas.versions.confirmButton'),
245+
action: deleteSclVersion(docName, docId, version),
246+
},
247+
content: [
248+
html`<span>${translate('compas.versions.confirmDeleteVersion', {version : version})}</span>`,
144249
],
145250
},
146251
];

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: {

0 commit comments

Comments
 (0)