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

On CoMPAS Version Tab show the information who/when/what per version #161

Merged
merged 2 commits into from
Jun 23, 2022
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
45 changes: 31 additions & 14 deletions src/compas-editors/CompasVersions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css, html, LitElement, property, TemplateResult } from 'lit-element';
import { get, translate } from 'lit-translate';
import { nothing } from 'lit-html';

import '@material/mwc-fab';
import '@material/mwc-icon';
Expand Down Expand Up @@ -43,11 +44,11 @@ export default class CompasVersionsPlugin extends LitElement {
docName!: string;

@property()
scls!: Element[];
historyItem!: Element[];

firstUpdated(): void {
if (!this.docId) {
this.scls = [];
this.historyItem = [];
} else {
this.fetchData()
}
Expand All @@ -57,10 +58,10 @@ export default class CompasVersionsPlugin extends LitElement {
const type = getTypeFromDocName(this.docName);
CompasSclDataService().listVersions(type, this.docId)
.then(xmlResponse => {
this.scls = Array.from(xmlResponse.querySelectorAll('Item') ?? []);
this.historyItem = Array.from(xmlResponse.querySelectorAll('HistoryItem') ?? []);
})
.catch(() => {
this.scls = [];
this.historyItem = [];
});
}

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

private renderLineInfo(item: Element): TemplateResult {
let element = getElementByName(item, SDS_NAMESPACE, "Name");
if (element === null) {
element = getElementByName(item, SDS_NAMESPACE, "Id");
}
const name = element!.textContent ?? '';
const version = getElementByName(item, SDS_NAMESPACE, "Version")!.textContent ?? '';
const who = getElementByName(item, SDS_NAMESPACE, "Who")!.textContent ?? '';
const when = getElementByName(item, SDS_NAMESPACE, "When")!.textContent ?? '';
const what = getElementByName(item, SDS_NAMESPACE, "What")!.textContent ?? '';

return html`<span>${name} (Version: ${version})</span>
<span slot="secondary">
Who: "${who ? who : '-'}",
When: "${when ? when : '-'}",
What: "${what ? what : '-'}"
</span>`;
}

render(): TemplateResult {
if (!this.scls) {
if (!this.historyItem) {
return html `
<compas-loading></compas-loading>
`
}

if (this.scls.length <= 0) {
if (this.historyItem.length <= 0) {
return html `
<mwc-list>
<mwc-list-item>
Expand Down Expand Up @@ -201,19 +221,15 @@ export default class CompasVersionsPlugin extends LitElement {
@selected=${(evt: MultiSelectedEvent) => {
selectedVersionsOnCompasVersionsEditor = evt.detail.index;
}}>
${this.scls.map( (item, index, items) => {
let element = getElementByName(item, SDS_NAMESPACE, "Name");
if (element === null) {
element = getElementByName(item, SDS_NAMESPACE, "Id");
}
const name = element!.textContent ?? '';
${this.historyItem.map( (item, index, items) => {
const version = getElementByName(item, SDS_NAMESPACE, "Version")!.textContent ?? '';
if (items.length - 1 === index) {
return html`<mwc-check-list-item value="${version}"
tabindex="0"
graphic="icon"
twoline
.selected=${selectedVersionsOnCompasVersionsEditor.has(index)}>
${name} (${version})
${this.renderLineInfo(item)}
<span slot="graphic">
<mwc-icon @click=${() => {
this.confirmRestoreVersionCompas(version);
Expand All @@ -224,8 +240,9 @@ export default class CompasVersionsPlugin extends LitElement {
return html`<mwc-check-list-item value="${version}"
tabindex="0"
graphic="icon"
twoline
.selected=${selectedVersionsOnCompasVersionsEditor.has(index)}>
${name} (${version})
${this.renderLineInfo(item)}
<span slot="graphic">
<mwc-icon @click=${() => {
this.confirmRestoreVersionCompas(version);
Expand Down
10 changes: 5 additions & 5 deletions test/integration/compas-editors/CompasVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('compas-versions-plugin', () => {
});

await element;
await waitUntil(() => element.scls !== undefined);
await waitUntil(() => element.historyItem !== undefined);
});

afterEach(() => {
Expand Down Expand Up @@ -85,11 +85,11 @@ describe('compas-versions-plugin', () => {

stub = stubFetchResponseFunction(element, FETCH_FUNCTION, undefined, VERSION_ENTRY_ELEMENT_NAME,
(result: Element[]) => {
element.scls = result;
element.historyItem = result;
});

await element;
await waitUntil(() => element.scls !== undefined);
await waitUntil(() => element.historyItem !== undefined);
});

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

stub = stubFetchResponseFunction(element, FETCH_FUNCTION, BASIC_VERSIONS_LIST_RESPONSE, VERSION_ENTRY_ELEMENT_NAME,
(result: Element[]) => {
element.scls = result;
element.historyItem = result;
});

await element;
await waitUntil(() => element.scls !== undefined);
await waitUntil(() => element.historyItem !== undefined);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["compas-versions-plugin no-compas-document looks like the latest snapshot"] =
snapshots["compas-versions-plugin no-compas-document looks like the latest snapshot"] =
`<mwc-list>
<mwc-list-item
aria-disabled="false"
Expand All @@ -18,15 +18,15 @@ snapshots["compas-versions-plugin no-compas-document looks like the latest snaps
`;
/* end snapshot compas-versions-plugin no-compas-document looks like the latest snapshot */

snapshots["compas-versions-plugin show-loading looks like the latest snapshot"] =
snapshots["compas-versions-plugin show-loading looks like the latest snapshot"] =
`<compas-loading>
</compas-loading>
<wizard-dialog>
</wizard-dialog>
`;
/* end snapshot compas-versions-plugin show-loading looks like the latest snapshot */

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

snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"] =
snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"] =
`<h1>
[compas.versions.sclInfo]
<nav>
Expand Down Expand Up @@ -76,9 +76,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
graphic="icon"
mwc-list-item=""
tabindex="0"
twoline=""
value="1.0.0"
>
demo_station1 (1.0.0)
<span>
demo_station1 (Version: 1.0.0)
</span>
<span slot="secondary">
Who: "Mr Editor",
When: "2021-11-22T03:47:00+01:00",
What: "SCL created, test configuration for station 0001"
</span>
<span slot="graphic">
<mwc-icon>
restore
Expand All @@ -93,9 +101,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
graphic="icon"
mwc-list-item=""
tabindex="-1"
twoline=""
value="2.0.0"
>
demo_station1 (2.0.0)
<span>
demo_station1 (Version: 2.0.0)
</span>
<span slot="secondary">
Who: "Mr Editor",
When: "2021-11-22T03:47:16+01:00",
What: "SCL updated, Updated the Station with breakers"
</span>
<span slot="graphic">
<mwc-icon>
restore
Expand All @@ -110,9 +126,17 @@ snapshots["compas-versions-plugin items-in-list looks like the latest snapshot"]
graphic="icon"
mwc-list-item=""
tabindex="-1"
twoline=""
value="2.1.0"
>
3b572a56-51cc-479b-97fd-e404ebf9ae67 (2.1.0)
<span>
3b572a56-51cc-479b-97fd-e404ebf9ae67 (Version: 2.1.0)
</span>
<span slot="secondary">
Who: "Mr Editor",
When: "2021-11-22T03:47:18+01:00",
What: "SCL updated, Updated the Station with breakers"
</span>
<span slot="graphic">
<mwc-icon>
restore
Expand Down
23 changes: 16 additions & 7 deletions test/unit/compas/CompasSclDataServiceResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,32 @@ export const BASIC_ITEM_LIST_RESPONSE = `
</Item>
</ListResponse>`;

export const VERSION_ENTRY_ELEMENT_NAME = 'Item';
export const VERSION_ENTRY_ELEMENT_NAME = 'HistoryItem';
export const BASIC_VERSIONS_LIST_RESPONSE = `
<ListResponse xmlns="${SDS_NAMESPACE}">
<Item>
<HistoryItem>
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
<Name>demo_station1</Name>
<Version>1.0.0</Version>
</Item>
<Item>
<Who>Mr Editor</Who>
<When>2021-11-22T03:47:00+01:00</When>
<What>SCL created, test configuration for station 0001</What>
</HistoryItem>
<HistoryItem>
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
<Name>demo_station1</Name>
<Version>2.0.0</Version>
</Item>
<Item>
<Who>Mr Editor</Who>
<When>2021-11-22T03:47:16+01:00</When>
<What>SCL updated, Updated the Station with breakers</What>
</HistoryItem>
<HistoryItem>
<Id>3b572a56-51cc-479b-97fd-e404ebf9ae67</Id>
<Version>2.1.0</Version>
</Item>
<Who>Mr Editor</Who>
<When>2021-11-22T03:47:18+01:00</When>
<What>SCL updated, Updated the Station with breakers</What>
</HistoryItem>
</ListResponse>`;

export function stubFetchResponseFunction(element: any,
Expand Down