Skip to content

Commit 78b3cfb

Browse files
committed
updateMessagesNumber
1 parent 2289736 commit 78b3cfb

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ qx.Class.define("osparc.conversation.Conversation", {
4646
},
4747
},
4848

49+
events: {
50+
"messagesChanged": "qx.event.type.Event",
51+
},
52+
4953
members: {
5054
_messages: null,
5155

@@ -141,9 +145,15 @@ qx.Class.define("osparc.conversation.Conversation", {
141145
return new osparc.conversation.MessageUI(message);
142146
},
143147

148+
getMessages: function() {
149+
return this._messages;
150+
},
151+
144152
clearAllMessages: function() {
145153
this._messages = [];
146154
this.getChildControl("messages-container").removeAll();
155+
156+
this.fireEvent("messagesChanged");
147157
},
148158

149159
addMessage: function(message) {
@@ -187,6 +197,8 @@ qx.Class.define("osparc.conversation.Conversation", {
187197
const messagesScroll = this.getChildControl("messages-container-scroll");
188198
messagesScroll.scrollToY(messagesScroll.getChildControl("pane").getScrollMaxY());
189199
}, 50);
200+
201+
this.fireEvent("messagesChanged");
190202
},
191203

192204
deleteMessage: function(message) {
@@ -206,6 +218,8 @@ qx.Class.define("osparc.conversation.Conversation", {
206218
if (controlIndex > -1) {
207219
messagesContainer.remove(children[controlIndex]);
208220
}
221+
222+
this.fireEvent("messagesChanged");
209223
},
210224

211225
updateMessage: function(message) {

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ qx.Class.define("osparc.study.ConversationPage", {
6666
members: {
6767
__studyData: null,
6868

69+
_createChildControlImpl: function(id) {
70+
let control;
71+
switch (id) {
72+
case "n-messages":
73+
control = new qx.ui.basic.Label();
74+
this._add(control);
75+
break;
76+
case "conversation":
77+
control = new osparc.study.Conversation(this.__studyData);
78+
this.bind("conversation", control, "conversation");
79+
control.addListener("messagesChanged", () => this.__updateMessagesNumber());
80+
this._add(control, {
81+
flex: 1,
82+
});
83+
break;
84+
}
85+
return control || this.base(arguments, id);
86+
},
87+
88+
__buildLayout: function() {
89+
this.getChildControl("n-messages");
90+
this.getChildControl("conversation");
91+
},
92+
6993
getConversationId: function() {
7094
if (this.getConversation()) {
7195
return this.getConversation().getConversationId();
@@ -119,8 +143,8 @@ qx.Class.define("osparc.study.ConversationPage", {
119143
visibility: osparc.data.model.Study.canIWrite(this.__studyData["accessRights"]) ? "visible" : "excluded",
120144
});
121145
closeButton.addListener("execute", () => {
122-
// if (this.__messagesList.getChildren().length === 0) {
123-
if (this._messages.length === 0) {
146+
const messages = this.getChildControl("conversation").getMessages();
147+
if (messages.length === 0) {
124148
osparc.store.ConversationsProject.getInstance().deleteConversation(this.__studyData["uuid"], this.getConversationId());
125149
} else {
126150
const msg = this.tr("Are you sure you want to delete the conversation?");
@@ -151,28 +175,16 @@ qx.Class.define("osparc.study.ConversationPage", {
151175
this.getChildControl("button").setLabel(newName);
152176
},
153177

154-
__buildLayout: function() {
155-
this.__messagesTitle = new qx.ui.basic.Label();
156-
this._add(this.__messagesTitle);
157-
158-
const conversation = new osparc.study.Conversation(this.__studyData);
159-
this.bind("conversation", conversation, "conversation");
160-
this._add(conversation, {
161-
flex: 1,
162-
});
163-
},
164-
165178
__updateMessagesNumber: function() {
166-
if (!this.__messagesTitle) {
167-
return;
168-
}
169-
const nMessages = this._messages.filter(msg => msg["type"] === "MESSAGE").length;
179+
const nMessagesLabel = this.getChildControl("n-messages");
180+
const messages = this.getChildControl("conversation").getMessages();
181+
const nMessages = messages.filter(msg => msg["type"] === "MESSAGE").length;
170182
if (nMessages === 0) {
171-
this.__messagesTitle.setValue(this.tr("No Messages yet"));
183+
nMessagesLabel.setValue(this.tr("No Messages yet"));
172184
} else if (nMessages === 1) {
173-
this.__messagesTitle.setValue(this.tr("1 Message"));
185+
nMessagesLabel.setValue(this.tr("1 Message"));
174186
} else if (nMessages > 1) {
175-
this.__messagesTitle.setValue(nMessages + this.tr(" Messages"));
187+
nMessagesLabel.setValue(nMessages + this.tr(" Messages"));
176188
}
177189
},
178190
}

0 commit comments

Comments
 (0)