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

Added support for Websocket to Data Service, including error handling #204

Merged
merged 5 commits into from
Nov 16, 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
117 changes: 77 additions & 40 deletions src/compas-editors/CompasVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,40 @@ export default class CompasVersionsPlugin extends LitElement {

private confirmRestoreVersionWizard(version: string): Wizard {
function openScl(plugin: CompasVersionsPlugin) {
return function () {
const type = getTypeFromDocName(plugin.docName);

CompasSclDataService()
.getSclDocumentVersion(type, plugin.docId, version)
.then(sclDocument => {
updateDocumentInOpenSCD(plugin, sclDocument);
function updateDocument(sclDocument: Document): void {
updateDocumentInOpenSCD(plugin, sclDocument);

plugin.dispatchEvent(
newLogEvent({
kind: 'info',
title: get('compas.versions.restoreVersionSuccess', {
version: version,
}),
})
);
plugin.dispatchEvent(
newLogEvent({
kind: 'info',
title: get('compas.versions.restoreVersionSuccess', {
version: version,
}),
})
.catch(reason => createLogEvent(plugin, reason));
);
}

return function () {
const type = getTypeFromDocName(plugin.docName);

const service = CompasSclDataService();
if (service.useWebsocket()) {
service.getSclDocumentVersionUsingWebsockets(
plugin,
type,
plugin.docId,
version,
(sclDocument) => {
updateDocument(sclDocument);
})
} else {
service
.getSclDocumentVersionUsingRest(type, plugin.docId, version)
.then(sclDocument => {
updateDocument(sclDocument);
})
.catch(reason => createLogEvent(plugin, reason));
}
// Close the Restore Dialog.
plugin.dispatchEvent(newWizardEvent());

Expand Down Expand Up @@ -285,15 +300,17 @@ export default class CompasVersionsPlugin extends LitElement {
const oldScl = await this.getVersion(oldVersion);
const newScl = this.doc.documentElement;

this.dispatchEvent(
newWizardEvent(
compareWizard(this, oldScl, newScl, {
title: get('compas.compare.titleCurrent', {
oldVersion: oldVersion,
}),
})
)
);
if (oldScl && newScl) {
this.dispatchEvent(
newWizardEvent(
compareWizard(this, oldScl, newScl, {
title: get('compas.compare.titleCurrent', {
oldVersion: oldVersion,
}),
})
)
);
}
} else {
this.dispatchEvent(
newWizardEvent(
Expand All @@ -318,16 +335,18 @@ export default class CompasVersionsPlugin extends LitElement {
const oldScl = await this.getVersion(oldVersion);
const newScl = await this.getVersion(newVersion);

this.dispatchEvent(
newWizardEvent(
compareWizard(this, oldScl, newScl, {
title: get('compas.compare.title', {
oldVersion: oldVersion,
newVersion: newVersion,
}),
})
)
);
if (oldScl && newScl) {
this.dispatchEvent(
newWizardEvent(
compareWizard(this, oldScl, newScl, {
title: get('compas.compare.title', {
oldVersion: oldVersion,
newVersion: newVersion,
}),
})
)
);
}
} else {
this.dispatchEvent(
newWizardEvent(
Expand All @@ -351,13 +370,31 @@ export default class CompasVersionsPlugin extends LitElement {
];
}

private async getVersion(version: string) {
private async getVersion(version: string): Promise<void | Element> {
const type = getTypeFromDocName(this.docName);
return CompasSclDataService()
.getSclDocumentVersion(type, this.docId, version)
.then(sclDocument => {
return Promise.resolve(sclDocument.documentElement);
const service = CompasSclDataService();

if (service.useWebsocket()) {
return new Promise((resolve) => {
service.getSclDocumentVersionUsingWebsockets(
this,
type,
this.docId,
version,
(sclDocument) => {
resolve(sclDocument.documentElement);
})
});
} else {
return service
.getSclDocumentVersionUsingRest(type, this.docId, version)
.then(sclDocument => {
return Promise.resolve(<Element>sclDocument.documentElement);
})
.catch(reason => {
createLogEvent(this, reason)
});
}
}

private openEditWizard(): void {
Expand Down
Loading