Skip to content

Commit 39c3cc6

Browse files
committed
conversation as prop
1 parent 62d1e04 commit 39c3cc6

File tree

3 files changed

+72
-48
lines changed

3 files changed

+72
-48
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ qx.Class.define("osparc.support.Conversation", {
2020
extend: qx.ui.core.Widget,
2121

2222
/**
23-
* @param conversationId {String} Conversation Id
23+
* @param conversation {osparc.data.model.Conversation} Conversation
2424
*/
25-
construct: function(conversationId) {
25+
construct: function(conversation) {
2626
this.base(arguments);
2727

2828
this.__messages = [];
@@ -31,18 +31,18 @@ qx.Class.define("osparc.support.Conversation", {
3131

3232
this.__buildLayout();
3333

34-
if (conversationId) {
35-
this.setConversationId(conversationId);
34+
if (conversation) {
35+
this.setConversation(conversation);
3636
}
3737
},
3838

3939
properties: {
40-
conversationId: {
41-
check: "String",
40+
conversation: {
41+
check: "osparc.data.model.Conversation",
4242
init: null,
4343
nullable: true,
44-
event: "changeConversationId",
45-
apply: "__applyConversationId",
44+
event: "changeConversation",
45+
apply: "__applyConversation",
4646
},
4747

4848
studyId: {
@@ -88,7 +88,9 @@ qx.Class.define("osparc.support.Conversation", {
8888
control = new osparc.conversation.AddMessage().set({
8989
padding: 5,
9090
});
91-
this.bind("conversationId", control, "conversationId");
91+
this.bind("conversation", control, "conversationId", {
92+
converter: conversation => conversation ? conversation.getConversationId() : null
93+
});
9294
// make it more compact
9395
control.getChildControl("comment-field").getChildControl("tabs").getChildControl("bar").exclude();
9496
control.getChildControl("comment-field").getChildControl("subtitle").exclude();
@@ -128,22 +130,18 @@ qx.Class.define("osparc.support.Conversation", {
128130
});
129131
},
130132

131-
__applyConversationId: function(conversationId) {
133+
__applyConversation: function(conversation) {
132134
this.__reloadMessages(true);
133135

134-
if (conversationId === null && osparc.store.Store.getInstance().getCurrentStudy()) {
136+
if (conversation === null && osparc.store.Store.getInstance().getCurrentStudy()) {
135137
this.getChildControl("share-project-checkbox").show();
136138
}
137139
},
138140

139-
__applyStudyId: function(studyId) {
140-
141-
},
142-
143141
__getNextRequest: function() {
144142
const params = {
145143
url: {
146-
conversationId: this.getConversationId(),
144+
conversationId: this.getConversation().getConversationId(),
147145
offset: 0,
148146
limit: 42
149147
}
@@ -163,7 +161,7 @@ qx.Class.define("osparc.support.Conversation", {
163161
__reloadMessages: function(removeMessages = true) {
164162
const messagesContainer = this.getChildControl("messages-container");
165163
const loadMoreMessages = this.getChildControl("load-more-button");
166-
if (this.getConversationId() === null) {
164+
if (this.getConversation() === null) {
167165
messagesContainer.hide();
168166
loadMoreMessages.hide();
169167
return;

services/static-webserver/client/source/class/osparc/support/ConversationPage.js

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ qx.Class.define("osparc.support.ConversationPage", {
2828

2929
this.getChildControl("back-button");
3030

31-
const conversation = this.getChildControl("conversation");
32-
this.bind("conversationId", conversation, "conversationId");
33-
conversation.bind("conversationId", this, "conversationId");
31+
const conversation = this.getChildControl("conversation-content");
32+
this.bind("conversation", conversation, "conversation");
33+
conversation.bind("conversation", this, "conversation");
3434
},
3535

3636
properties: {
37-
conversationId: {
38-
check: "String",
37+
conversation: {
38+
check: "osparc.data.model.Conversation",
3939
init: null,
4040
nullable: true,
41-
event: "changeConversationId",
42-
apply: "__applyConversationId",
41+
event: "changeConversation",
42+
apply: "__applyConversation",
4343
},
4444
},
4545

@@ -94,17 +94,28 @@ qx.Class.define("osparc.support.ConversationPage", {
9494
});
9595
this.getChildControl("conversation-header-center-layout").addAt(control, 1);
9696
break;
97-
case "conversation-options":
97+
case "conversation-options": {
9898
control = new qx.ui.form.MenuButton().set({
9999
maxWidth: 22,
100100
maxHeight: 22,
101101
alignX: "center",
102102
alignY: "middle",
103103
icon: "@FontAwesome5Solid/ellipsis-v/14",
104104
});
105+
const menu = new qx.ui.menu.Menu().set({
106+
position: "bottom-right",
107+
});
108+
control.setMenu(menu);
109+
const renameButton = new qx.ui.menu.Button().set({
110+
label: this.tr("Rename"),
111+
icon: "@FontAwesome5Solid/i-cursor/10"
112+
});
113+
renameButton.addListener("execute", () => this.__renameConversation());
114+
menu.add(renameButton);
105115
this.getChildControl("conversation-header-layout").addAt(control, 2);
106116
break;
107-
case "conversation":
117+
}
118+
case "conversation-content":
108119
control = new osparc.support.Conversation();
109120
const scroll = new qx.ui.container.Scroll();
110121
scroll.add(control);
@@ -116,31 +127,43 @@ qx.Class.define("osparc.support.ConversationPage", {
116127
return control || this.base(arguments, id);
117128
},
118129

119-
__applyConversationId: function(conversationId) {
130+
__applyConversation: function(conversation) {
120131
const title = this.getChildControl("conversation-title");
121132
const options = this.getChildControl("conversation-options");
122-
if (conversationId) {
123-
osparc.store.ConversationsSupport.getInstance().getConversation(conversationId)
124-
.then(conversation => {
125-
conversation.bind("nameAlias", title, "value");
126-
const amISupporter = osparc.store.Products.getInstance().amIASupportUser();
127-
const extraContextLabel = this.getChildControl("conversation-extra-content");
128-
extraContextLabel.setVisibility(amISupporter ? "visible" : "excluded");
129-
const extraContext = conversation.getExtraContext();
130-
if (amISupporter && extraContext && Object.keys(extraContext).length) {
131-
let extraContextText = `Support ID: ${conversationId}`;
132-
const contextProjectId = conversation.getContextProjectId();
133-
if (contextProjectId) {
134-
extraContextText += `<br>Project ID: ${contextProjectId}`;
135-
}
136-
extraContextLabel.setValue(extraContextText);
137-
}
138-
options.show();
139-
});
133+
if (conversation) {
134+
conversation.bind("nameAlias", title, "value");
135+
const amISupporter = osparc.store.Products.getInstance().amIASupportUser();
136+
const extraContextLabel = this.getChildControl("conversation-extra-content");
137+
extraContextLabel.setVisibility(amISupporter ? "visible" : "excluded");
138+
const extraContext = conversation.getExtraContext();
139+
if (amISupporter && extraContext && Object.keys(extraContext).length) {
140+
let extraContextText = `Support ID: ${conversation}`;
141+
const contextProjectId = conversation.getContextProjectId();
142+
if (contextProjectId) {
143+
extraContextText += `<br>Project ID: ${contextProjectId}`;
144+
}
145+
extraContextLabel.setValue(extraContextText);
146+
}
147+
options.show();
140148
} else {
141149
title.setValue("");
142150
options.exclude();
143151
}
144152
},
153+
154+
__renameConversation: function() {
155+
let oldName = this.getConversation().getName();
156+
if (oldName === "null") {
157+
oldName = "";
158+
}
159+
const renamer = new osparc.widget.Renamer(oldName);
160+
renamer.addListener("labelChanged", e => {
161+
renamer.close();
162+
const newLabel = e.getData()["newLabel"];
163+
this.getConversation().setName(newLabel);
164+
}, this);
165+
renamer.center();
166+
renamer.open();
167+
},
145168
}
146169
});

services/static-webserver/client/source/class/osparc/support/SupportCenter.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ qx.Class.define("osparc.support.SupportCenter", {
143143
},
144144

145145
openConversation: function(conversationId) {
146-
const conversationContent = this.getChildControl("conversation-page");
147-
conversationContent.setConversationId(conversationId);
148-
this.__showConversation();
146+
const conversationPage = this.getChildControl("conversation-page");
147+
osparc.store.ConversationsSupport.getInstance().getConversation(conversationId)
148+
.then(conversation => {
149+
conversationPage.setConversation(conversation);
150+
this.__showConversation();
151+
});
149152
},
150153

151154
__createConversation: function() {

0 commit comments

Comments
 (0)