Skip to content

Commit f9f13f7

Browse files
author
Dennis Labordus
authored
Merge pull request #161 from com-pas/show_history_data
On CoMPAS Version Tab show the information who/when/what per version
2 parents 9ecacf6 + de87245 commit f9f13f7

File tree

4 files changed

+83
-33
lines changed

4 files changed

+83
-33
lines changed

src/compas-editors/CompasVersions.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css, html, LitElement, property, TemplateResult } from 'lit-element';
22
import { get, translate } from 'lit-translate';
3+
import { nothing } from 'lit-html';
34

45
import '@material/mwc-fab';
56
import '@material/mwc-icon';
@@ -43,11 +44,11 @@ export default class CompasVersionsPlugin extends LitElement {
4344
docName!: string;
4445

4546
@property()
46-
scls!: Element[];
47+
historyItem!: Element[];
4748

4849
firstUpdated(): void {
4950
if (!this.docId) {
50-
this.scls = [];
51+
this.historyItem = [];
5152
} else {
5253
this.fetchData()
5354
}
@@ -57,10 +58,10 @@ export default class CompasVersionsPlugin extends LitElement {
5758
const type = getTypeFromDocName(this.docName);
5859
CompasSclDataService().listVersions(type, this.docId)
5960
.then(xmlResponse => {
60-
this.scls = Array.from(xmlResponse.querySelectorAll('Item') ?? []);
61+
this.historyItem = Array.from(xmlResponse.querySelectorAll('HistoryItem') ?? []);
6162
})
6263
.catch(() => {
63-
this.scls = [];
64+
this.historyItem = [];
6465
});
6566
}
6667

@@ -148,14 +149,33 @@ export default class CompasVersionsPlugin extends LitElement {
148149
return sclName!.textContent ?? 'unknown';
149150
}
150151

152+
private renderLineInfo(item: Element): TemplateResult {
153+
let element = getElementByName(item, SDS_NAMESPACE, "Name");
154+
if (element === null) {
155+
element = getElementByName(item, SDS_NAMESPACE, "Id");
156+
}
157+
const name = element!.textContent ?? '';
158+
const version = getElementByName(item, SDS_NAMESPACE, "Version")!.textContent ?? '';
159+
const who = getElementByName(item, SDS_NAMESPACE, "Who")!.textContent ?? '';
160+
const when = getElementByName(item, SDS_NAMESPACE, "When")!.textContent ?? '';
161+
const what = getElementByName(item, SDS_NAMESPACE, "What")!.textContent ?? '';
162+
163+
return html`<span>${name} (Version: ${version})</span>
164+
<span slot="secondary">
165+
Who: "${who ? who : '-'}",
166+
When: "${when ? when : '-'}",
167+
What: "${what ? what : '-'}"
168+
</span>`;
169+
}
170+
151171
render(): TemplateResult {
152-
if (!this.scls) {
172+
if (!this.historyItem) {
153173
return html `
154174
<compas-loading></compas-loading>
155175
`
156176
}
157177

158-
if (this.scls.length <= 0) {
178+
if (this.historyItem.length <= 0) {
159179
return html `
160180
<mwc-list>
161181
<mwc-list-item>
@@ -201,19 +221,15 @@ export default class CompasVersionsPlugin extends LitElement {
201221
@selected=${(evt: MultiSelectedEvent) => {
202222
selectedVersionsOnCompasVersionsEditor = evt.detail.index;
203223
}}>
204-
${this.scls.map( (item, index, items) => {
205-
let element = getElementByName(item, SDS_NAMESPACE, "Name");
206-
if (element === null) {
207-
element = getElementByName(item, SDS_NAMESPACE, "Id");
208-
}
209-
const name = element!.textContent ?? '';
224+
${this.historyItem.map( (item, index, items) => {
210225
const version = getElementByName(item, SDS_NAMESPACE, "Version")!.textContent ?? '';
211226
if (items.length - 1 === index) {
212227
return html`<mwc-check-list-item value="${version}"
213228
tabindex="0"
214229
graphic="icon"
230+
twoline
215231
.selected=${selectedVersionsOnCompasVersionsEditor.has(index)}>
216-
${name} (${version})
232+
${this.renderLineInfo(item)}
217233
<span slot="graphic">
218234
<mwc-icon @click=${() => {
219235
this.confirmRestoreVersionCompas(version);
@@ -224,8 +240,9 @@ export default class CompasVersionsPlugin extends LitElement {
224240
return html`<mwc-check-list-item value="${version}"
225241
tabindex="0"
226242
graphic="icon"
243+
twoline
227244
.selected=${selectedVersionsOnCompasVersionsEditor.has(index)}>
228-
${name} (${version})
245+
${this.renderLineInfo(item)}
229246
<span slot="graphic">
230247
<mwc-icon @click=${() => {
231248
this.confirmRestoreVersionCompas(version);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('compas-versions-plugin', () => {
4141
});
4242

4343
await element;
44-
await waitUntil(() => element.scls !== undefined);
44+
await waitUntil(() => element.historyItem !== undefined);
4545
});
4646

4747
afterEach(() => {
@@ -85,11 +85,11 @@ describe('compas-versions-plugin', () => {
8585

8686
stub = stubFetchResponseFunction(element, FETCH_FUNCTION, undefined, VERSION_ENTRY_ELEMENT_NAME,
8787
(result: Element[]) => {
88-
element.scls = result;
88+
element.historyItem = result;
8989
});
9090

9191
await element;
92-
await waitUntil(() => element.scls !== undefined);
92+
await waitUntil(() => element.historyItem !== undefined);
9393
});
9494

9595
afterEach(() => {
@@ -110,11 +110,11 @@ describe('compas-versions-plugin', () => {
110110

111111
stub = stubFetchResponseFunction(element, FETCH_FUNCTION, BASIC_VERSIONS_LIST_RESPONSE, VERSION_ENTRY_ELEMENT_NAME,
112112
(result: Element[]) => {
113-
element.scls = result;
113+
element.historyItem = result;
114114
});
115115

116116
await element;
117-
await waitUntil(() => element.scls !== undefined);
117+
await waitUntil(() => element.historyItem !== undefined);
118118
});
119119

120120
afterEach(() => {

test/integration/compas-editors/__snapshots__/CompasVersions.test.snap.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @web/test-runner snapshot v1 */
22
export const snapshots = {};
33

4-
snapshots["compas-versions-plugin no-compas-document looks like the latest snapshot"] =
4+
snapshots["compas-versions-plugin no-compas-document looks like the latest snapshot"] =
55
`<mwc-list>
66
<mwc-list-item
77
aria-disabled="false"
@@ -18,15 +18,15 @@ snapshots["compas-versions-plugin no-compas-document looks like the latest snaps
1818
`;
1919
/* end snapshot compas-versions-plugin no-compas-document looks like the latest snapshot */
2020

21-
snapshots["compas-versions-plugin show-loading looks like the latest snapshot"] =
21+
snapshots["compas-versions-plugin show-loading looks like the latest snapshot"] =
2222
`<compas-loading>
2323
</compas-loading>
2424
<wizard-dialog>
2525
</wizard-dialog>
2626
`;
2727
/* end snapshot compas-versions-plugin show-loading looks like the latest snapshot */
2828

29-
snapshots["compas-versions-plugin no-items-in-list looks like the latest snapshot"] =
29+
snapshots["compas-versions-plugin no-items-in-list looks like the latest snapshot"] =
3030
`<mwc-list>
3131
<mwc-list-item
3232
aria-disabled="false"
@@ -43,7 +43,7 @@ snapshots["compas-versions-plugin no-items-in-list looks like the latest snapsho
4343
`;
4444
/* end snapshot compas-versions-plugin no-items-in-list looks like the latest snapshot */
4545

46-
snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"] =
46+
snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"] =
4747
`<h1>
4848
[compas.versions.sclInfo]
4949
<nav>
@@ -76,9 +76,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
7676
graphic="icon"
7777
mwc-list-item=""
7878
tabindex="0"
79+
twoline=""
7980
value="1.0.0"
8081
>
81-
demo_station1 (1.0.0)
82+
<span>
83+
demo_station1 (Version: 1.0.0)
84+
</span>
85+
<span slot="secondary">
86+
Who: "Mr Editor",
87+
When: "2021-11-22T03:47:00+01:00",
88+
What: "SCL created, test configuration for station 0001"
89+
</span>
8290
<span slot="graphic">
8391
<mwc-icon>
8492
restore
@@ -93,9 +101,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
93101
graphic="icon"
94102
mwc-list-item=""
95103
tabindex="-1"
104+
twoline=""
96105
value="2.0.0"
97106
>
98-
demo_station1 (2.0.0)
107+
<span>
108+
demo_station1 (Version: 2.0.0)
109+
</span>
110+
<span slot="secondary">
111+
Who: "Mr Editor",
112+
When: "2021-11-22T03:47:16+01:00",
113+
What: "SCL updated, Updated the Station with breakers"
114+
</span>
99115
<span slot="graphic">
100116
<mwc-icon>
101117
restore
@@ -110,9 +126,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
110126
graphic="icon"
111127
mwc-list-item=""
112128
tabindex="-1"
129+
twoline=""
113130
value="2.1.0"
114131
>
115-
3b572a56-51cc-479b-97fd-e404ebf9ae67 (2.1.0)
132+
<span>
133+
3b572a56-51cc-479b-97fd-e404ebf9ae67 (Version: 2.1.0)
134+
</span>
135+
<span slot="secondary">
136+
Who: "Mr Editor",
137+
When: "2021-11-22T03:47:18+01:00",
138+
What: "SCL updated, Updated the Station with breakers"
139+
</span>
116140
<span slot="graphic">
117141
<mwc-icon>
118142
restore

test/unit/compas/CompasSclDataServiceResponses.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,32 @@ export const BASIC_ITEM_LIST_RESPONSE = `
2929
</Item>
3030
</ListResponse>`;
3131

32-
export const VERSION_ENTRY_ELEMENT_NAME = 'Item';
32+
export const VERSION_ENTRY_ELEMENT_NAME = 'HistoryItem';
3333
export const BASIC_VERSIONS_LIST_RESPONSE = `
3434
<ListResponse xmlns="${SDS_NAMESPACE}">
35-
<Item>
35+
<HistoryItem>
3636
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
3737
<Name>demo_station1</Name>
3838
<Version>1.0.0</Version>
39-
</Item>
40-
<Item>
39+
<Who>Mr Editor</Who>
40+
<When>2021-11-22T03:47:00+01:00</When>
41+
<What>SCL created, test configuration for station 0001</What>
42+
</HistoryItem>
43+
<HistoryItem>
4144
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
4245
<Name>demo_station1</Name>
4346
<Version>2.0.0</Version>
44-
</Item>
45-
<Item>
47+
<Who>Mr Editor</Who>
48+
<When>2021-11-22T03:47:16+01:00</When>
49+
<What>SCL updated, Updated the Station with breakers</What>
50+
</HistoryItem>
51+
<HistoryItem>
4652
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
4753
<Version>2.1.0</Version>
48-
</Item>
54+
<Who>Mr Editor</Who>
55+
<When>2021-11-22T03:47:18+01:00</When>
56+
<What>SCL updated, Updated the Station with breakers</What>
57+
</HistoryItem>
4958
</ListResponse>`;
5059

5160
export function stubFetchResponseFunction(element: any,

0 commit comments

Comments
 (0)