Skip to content

Commit e963e6b

Browse files
committed
Conversations store
1 parent 98a3d79 commit e963e6b

File tree

6 files changed

+177
-107
lines changed

6 files changed

+177
-107
lines changed

services/static-webserver/client/source/class/osparc/conversation/AddMessage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
146146
this.__postMessage();
147147
} else {
148148
// create new conversation first
149-
osparc.study.Conversations.addConversation(this.__studyData["uuid"])
149+
osparc.store.Conversations.getInstance().addConversation(this.__studyData["uuid"])
150150
.then(data => {
151151
this.__conversationId = data["conversationId"];
152152
this.__postMessage();
@@ -213,7 +213,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
213213
this.__postNotify(userGid);
214214
} else {
215215
// create new conversation first
216-
osparc.study.Conversations.addConversation(this.__studyData["uuid"])
216+
osparc.store.Conversations.getInstance().addConversation(this.__studyData["uuid"])
217217
.then(data => {
218218
this.__conversationId = data["conversationId"];
219219
this.__postNotify(userGid);
@@ -225,7 +225,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
225225
const commentField = this.getChildControl("comment-field");
226226
const content = commentField.getChildControl("text-area").getValue();
227227
if (content) {
228-
osparc.study.Conversations.addMessage(this.__studyData["uuid"], this.__conversationId, content)
228+
osparc.store.Conversations.getInstance().addMessage(this.__studyData["uuid"], this.__conversationId, content)
229229
.then(data => {
230230
this.fireDataEvent("messageAdded", data);
231231
commentField.getChildControl("text-area").setValue("");
@@ -237,7 +237,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
237237
const commentField = this.getChildControl("comment-field");
238238
const content = commentField.getChildControl("text-area").getValue();
239239
if (content) {
240-
osparc.study.Conversations.editMessage(this.__studyData["uuid"], this.__conversationId, this.__message["messageId"], content)
240+
osparc.store.Conversations.getInstance().editMessage(this.__studyData["uuid"], this.__conversationId, this.__message["messageId"], content)
241241
.then(data => {
242242
this.fireDataEvent("messageUpdated", data);
243243
commentField.getChildControl("text-area").setValue("");
@@ -247,7 +247,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
247247

248248
__postNotify: function(userGid) {
249249
if (userGid) {
250-
osparc.study.Conversations.notifyUser(this.__studyData["uuid"], this.__conversationId, userGid)
250+
osparc.store.Conversations.getInstance().notifyUser(this.__studyData["uuid"], this.__conversationId, userGid)
251251
.then(data => {
252252
this.fireDataEvent("messageAdded", data);
253253
const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators();

services/static-webserver/client/source/class/osparc/conversation/Conversation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ qx.Class.define("osparc.conversation.Conversation", {
9090
titleEditor.close();
9191
const newLabel = e.getData()["newLabel"];
9292
if (this.getConversationId()) {
93-
osparc.study.Conversations.renameConversation(this.__studyData["uuid"], this.getConversationId(), newLabel)
93+
osparc.store.Conversations.getInstance().renameConversation(this.__studyData["uuid"], this.getConversationId(), newLabel)
9494
.then(() => this.renameConversation(newLabel));
9595
} else {
9696
// create new conversation first
97-
osparc.study.Conversations.addConversation(this.__studyData["uuid"], newLabel)
97+
osparc.store.Conversations.getInstance().addConversation(this.__studyData["uuid"], newLabel)
9898
.then(data => {
9999
this.setConversationId(data["conversationId"]);
100100
this.getChildControl("button").setLabel(newLabel);
@@ -117,7 +117,7 @@ qx.Class.define("osparc.conversation.Conversation", {
117117
});
118118
closeButton.addListener("execute", () => {
119119
const deleteConversation = () => {
120-
osparc.study.Conversations.deleteConversation(this.__studyData["uuid"], this.getConversationId())
120+
osparc.store.Conversations.getInstance().deleteConversation(this.__studyData["uuid"], this.getConversationId())
121121
.then(() => this.fireEvent("conversationDeleted"));
122122
}
123123
if (this.__messagesList.getChildren().length === 0) {

services/static-webserver/client/source/class/osparc/conversation/MessageUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ qx.Class.define("osparc.conversation.MessageUI", {
227227
win.open();
228228
win.addListener("close", () => {
229229
if (win.getConfirmed()) {
230-
osparc.study.Conversations.deleteMessage(message)
230+
osparc.store.Conversations.getInstance().deleteMessage(message)
231231
.then(() => this.fireDataEvent("messageDeleted", message))
232232
.catch(err => osparc.FlashMessenger.logError(err));
233233
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.Conversations", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
construct: function() {
23+
this.base(arguments);
24+
25+
this.__pricingPlansCached = [];
26+
},
27+
28+
members: {
29+
__pricingPlansCached: null,
30+
31+
addConversation: function(studyId, name = "new 1", type = this.TYPES.PROJECT_STATIC) {
32+
const params = {
33+
url: {
34+
studyId,
35+
},
36+
data: {
37+
name,
38+
type,
39+
}
40+
};
41+
return osparc.data.Resources.fetch("conversations", "addConversation", params)
42+
.catch(err => osparc.FlashMessenger.logError(err));
43+
},
44+
45+
deleteConversation: function(studyId, conversationId) {
46+
const params = {
47+
url: {
48+
studyId,
49+
conversationId,
50+
},
51+
};
52+
return osparc.data.Resources.fetch("conversations", "deleteConversation", params)
53+
.catch(err => osparc.FlashMessenger.logError(err));
54+
},
55+
56+
renameConversation: function(studyId, conversationId, name) {
57+
const params = {
58+
url: {
59+
studyId,
60+
conversationId,
61+
},
62+
data: {
63+
name,
64+
}
65+
};
66+
return osparc.data.Resources.fetch("conversations", "renameConversation", params)
67+
.catch(err => osparc.FlashMessenger.logError(err));
68+
},
69+
70+
addMessage: function(studyId, conversationId, message) {
71+
const params = {
72+
url: {
73+
studyId,
74+
conversationId,
75+
},
76+
data: {
77+
"content": message,
78+
"type": "MESSAGE",
79+
}
80+
};
81+
return osparc.data.Resources.fetch("conversations", "addMessage", params)
82+
.catch(err => osparc.FlashMessenger.logError(err));
83+
},
84+
85+
editMessage: function(studyId, conversationId, messageId, message) {
86+
const params = {
87+
url: {
88+
studyId,
89+
conversationId,
90+
messageId,
91+
},
92+
data: {
93+
"content": message,
94+
},
95+
};
96+
return osparc.data.Resources.fetch("conversations", "editMessage", params)
97+
.catch(err => osparc.FlashMessenger.logError(err));
98+
},
99+
100+
deleteMessage: function(message) {
101+
const params = {
102+
url: {
103+
studyId: message["projectId"],
104+
conversationId: message["conversationId"],
105+
messageId: message["messageId"],
106+
},
107+
};
108+
return osparc.data.Resources.fetch("conversations", "deleteMessage", params)
109+
.catch(err => osparc.FlashMessenger.logError(err));
110+
},
111+
112+
notifyUser: function(studyId, conversationId, userGroupId) {
113+
const params = {
114+
url: {
115+
studyId,
116+
conversationId,
117+
},
118+
data: {
119+
"content": userGroupId.toString(), // eventually the backend will accept integers
120+
"type": "NOTIFICATION",
121+
}
122+
};
123+
return osparc.data.Resources.fetch("conversations", "addMessage", params)
124+
.catch(err => osparc.FlashMessenger.logError(err));
125+
},
126+
127+
__addToCache: function(pricingPlanData) {
128+
let pricingPlan = this.__pricingPlansCached.find(f => f.getPricingPlanId() === pricingPlanData["pricingPlanId"]);
129+
if (pricingPlan) {
130+
// put
131+
pricingPlan.set({
132+
pricingPlanKey: pricingPlanData["pricingPlanKey"],
133+
name: pricingPlanData["displayName"],
134+
description: pricingPlanData["description"],
135+
classification: pricingPlanData["classification"],
136+
isActive: pricingPlanData["isActive"],
137+
});
138+
} else {
139+
// get and post
140+
pricingPlan = new osparc.data.model.PricingPlan(pricingPlanData);
141+
this.__pricingPlansCached.unshift(pricingPlan);
142+
}
143+
return pricingPlan;
144+
},
145+
146+
__addPricingUnitToCache: function(pricingPlan, pricingUnitData) {
147+
const pricingUnits = pricingPlan.getPricingUnits();
148+
let pricingUnit = pricingUnits ? pricingUnits.find(unit => ("getPricingUnitId" in unit) && unit.getPricingUnitId() === pricingUnitData["pricingUnitId"]) : null;
149+
if (pricingUnit) {
150+
const props = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.PricingPlan));
151+
// put
152+
Object.keys(pricingUnitData).forEach(key => {
153+
if (props.includes(key)) {
154+
pricingPlan.set(key, pricingUnitData[key]);
155+
}
156+
});
157+
} else {
158+
// get and post
159+
pricingUnit = new osparc.data.model.PricingUnit(pricingUnitData);
160+
pricingPlan.bind("classification", pricingUnit, "classification");
161+
pricingUnits.push(pricingUnit);
162+
}
163+
return pricingUnit;
164+
},
165+
}
166+
});

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

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -63,102 +63,6 @@ qx.Class.define("osparc.study.Conversations", {
6363
}, this);
6464
return win;
6565
},
66-
67-
addConversation: function(studyId, name = "new 1", type = this.TYPES.PROJECT_STATIC) {
68-
const params = {
69-
url: {
70-
studyId,
71-
},
72-
data: {
73-
name,
74-
type,
75-
}
76-
};
77-
return osparc.data.Resources.fetch("conversations", "addConversation", params)
78-
.catch(err => osparc.FlashMessenger.logError(err));
79-
},
80-
81-
deleteConversation: function(studyId, conversationId) {
82-
const params = {
83-
url: {
84-
studyId,
85-
conversationId,
86-
},
87-
};
88-
return osparc.data.Resources.fetch("conversations", "deleteConversation", params)
89-
.catch(err => osparc.FlashMessenger.logError(err));
90-
},
91-
92-
renameConversation: function(studyId, conversationId, name) {
93-
const params = {
94-
url: {
95-
studyId,
96-
conversationId,
97-
},
98-
data: {
99-
name,
100-
}
101-
};
102-
return osparc.data.Resources.fetch("conversations", "renameConversation", params)
103-
.catch(err => osparc.FlashMessenger.logError(err));
104-
},
105-
106-
addMessage: function(studyId, conversationId, message) {
107-
const params = {
108-
url: {
109-
studyId,
110-
conversationId,
111-
},
112-
data: {
113-
"content": message,
114-
"type": "MESSAGE",
115-
}
116-
};
117-
return osparc.data.Resources.fetch("conversations", "addMessage", params)
118-
.catch(err => osparc.FlashMessenger.logError(err));
119-
},
120-
121-
editMessage: function(studyId, conversationId, messageId, message) {
122-
const params = {
123-
url: {
124-
studyId,
125-
conversationId,
126-
messageId,
127-
},
128-
data: {
129-
"content": message,
130-
},
131-
};
132-
return osparc.data.Resources.fetch("conversations", "editMessage", params)
133-
.catch(err => osparc.FlashMessenger.logError(err));
134-
},
135-
136-
deleteMessage: function(message) {
137-
const params = {
138-
url: {
139-
studyId: message["projectId"],
140-
conversationId: message["conversationId"],
141-
messageId: message["messageId"],
142-
},
143-
};
144-
return osparc.data.Resources.fetch("conversations", "deleteMessage", params)
145-
.catch(err => osparc.FlashMessenger.logError(err));
146-
},
147-
148-
notifyUser: function(studyId, conversationId, userGroupId) {
149-
const params = {
150-
url: {
151-
studyId,
152-
conversationId,
153-
},
154-
data: {
155-
"content": userGroupId.toString(), // eventually the backend will accept integers
156-
"type": "NOTIFICATION",
157-
}
158-
};
159-
return osparc.data.Resources.fetch("conversations", "addMessage", params)
160-
.catch(err => osparc.FlashMessenger.logError(err));
161-
},
16266
},
16367

16468
members: {
@@ -335,7 +239,7 @@ qx.Class.define("osparc.study.Conversations", {
335239
enabled: osparc.data.model.Study.canIWrite(studyData["accessRights"]),
336240
});
337241
newConversationButton.addListener("execute", () => {
338-
osparc.study.Conversations.addConversation(studyData["uuid"], "new " + (this.__conversations.length + 1))
242+
osparc.store.Conversations.getInstance().addConversation(studyData["uuid"], "new " + (this.__conversations.length + 1))
339243
.then(conversationDt => {
340244
this.__addConversationPage(conversationDt);
341245
const newConversationPage = this.__getConversation(conversationDt["conversationId"]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
19941994
}
19951995
case annotationTypes.CONVERSATION: {
19961996
const conversationTitle = `${initPos.x}, ${initPos.y}`;
1997-
osparc.study.Conversations.addConversation(this.getStudy().getUuid(), conversationTitle, osparc.study.Conversations.TYPES.PROJECT_ANNOTATION)
1997+
osparc.store.Conversations.getInstance().addConversation(this.getStudy().getUuid(), conversationTitle, osparc.study.Conversations.TYPES.PROJECT_ANNOTATION)
19981998
.then(conversationData => {
19991999
serializeData.attributes.conversationId = conversationData["conversationId"];
20002000
serializeData.attributes.title = conversationData["name"];

0 commit comments

Comments
 (0)