Skip to content

Commit 21b9009

Browse files
committed
Check if conversation still exists, if not, ask to remove annotation
1 parent 2c1c051 commit 21b9009

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ qx.Class.define("osparc.data.Resources", {
320320
method: "GET",
321321
url: statics.API + "/projects/{studyId}/conversations?offset={offset}&limit={limit}"
322322
},
323+
getConversation: {
324+
method: "GET",
325+
url: statics.API + "/projects/{studyId}/conversations/{conversationId}"
326+
},
323327
renameConversation: {
324328
method: "PUT",
325329
url: statics.API + "/projects/{studyId}/conversations/{conversationId}"

services/static-webserver/client/source/class/osparc/store/Conversations.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ qx.Class.define("osparc.store.Conversations", {
5151
conversationId,
5252
}
5353
};
54-
return osparc.data.Resources.fetch("conversations", "getConversation", params)
55-
.catch(err => osparc.FlashMessenger.logError(err));
54+
return osparc.data.Resources.fetch("conversations", "getConversation", params);
5655
},
5756

5857
addConversation: function(studyId, name = "new 1", type = osparc.study.Conversations.TYPES.PROJECT_STATIC) {

services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
12381238
this.__setSelectedAnnotations([annotation]);
12391239
switch (annotation.getType()) {
12401240
case osparc.workbench.Annotation.TYPES.CONVERSATION: {
1241-
this.__popUpConversation(annotation.getAttributes()["conversationId"]);
1241+
this.__popUpConversation(annotation.getAttributes()["conversationId"], annotation.getId());
12421242
break;
12431243
}
12441244
default: {
@@ -1992,8 +1992,8 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
19921992
.then(conversationData => {
19931993
serializeData.attributes.conversationId = conversationData["conversationId"];
19941994
serializeData.attributes.text = conversationData["name"];
1995-
this.__addAnnotation(serializeData);
1996-
this.__popUpConversation(conversationData["conversationId"]);
1995+
const annotation = this.__addAnnotation(serializeData);
1996+
this.__popUpConversation(conversationData["conversationId"], annotation.getId());
19971997
});
19981998
break;
19991999
}
@@ -2008,6 +2008,8 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
20082008
this.getStudy().getUi().addAnnotation(annotation);
20092009

20102010
this.__renderAnnotation(annotation);
2011+
2012+
return annotation;
20112013
},
20122014

20132015
__renderAnnotation: function(annotation) {
@@ -2034,8 +2036,26 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
20342036
}
20352037
},
20362038

2037-
__popUpConversation: function(conversationId) {
2039+
__popUpConversation: function(conversationId, annotationId) {
20382040
osparc.study.Conversations.popUpInWindow(this.getStudy().serialize(), conversationId);
2041+
2042+
// Check if conversation still exists, if not, ask to remove annotation
2043+
osparc.store.Conversations.getInstance().getConversation(this.getStudy().getUuid(), conversationId)
2044+
.catch(err => {
2045+
if ("status" in err && err.status === 404) {
2046+
const win = new osparc.ui.window.Confirmation(this.tr("Do you want to remove the annotation?")).set({
2047+
caption: this.tr("Conversation not found"),
2048+
confirmText: this.tr("Delete"),
2049+
confirmAction: "delete",
2050+
});
2051+
win.open();
2052+
win.addListener("close", () => {
2053+
if (win.getConfirmed()) {
2054+
this.__removeAnnotation(annotationId);
2055+
}
2056+
});
2057+
}
2058+
});
20392059
},
20402060

20412061
__dropFile: async function(e) {

0 commit comments

Comments
 (0)