Skip to content

Commit fda4dab

Browse files
committed
Conversations and Conversation
1 parent 9a6d71c commit fda4dab

File tree

3 files changed

+173
-99
lines changed

3 files changed

+173
-99
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ qx.Class.define("osparc.data.Resources", {
319319
}
320320
}
321321
},
322+
"conversations": {
323+
useCache: false,
324+
endpoints: {
325+
get: {
326+
method: "GET",
327+
url: statics.API + "/projects/{studyId}/conversations?offset={offset}&limit={limit}"
328+
},
329+
}
330+
},
322331
"jobs": {
323332
useCache: false, // handled in osparc.store.Jobs
324333
endpoints: {
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2023 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+
19+
qx.Class.define("osparc.info.Conversation", {
20+
extend: qx.ui.tabview.Page,
21+
22+
/**
23+
* @param studyData {String} Study Data
24+
* @param conversationId {int} Conversation Id
25+
*/
26+
construct: function(studyData, conversationId = null) {
27+
this.base(arguments);
28+
29+
this.__studyData = studyData;
30+
this.__conversationId = conversationId;
31+
32+
this._setLayout(new qx.ui.layout.VBox(10));
33+
34+
this.set({
35+
padding: 10,
36+
showCloseButton: false,
37+
});
38+
39+
this.__buildLayout();
40+
41+
this.fetchComments();
42+
},
43+
44+
members: {
45+
__studyData: null,
46+
__conversationId: null,
47+
__nextRequestParams: null,
48+
__commentsTitle: null,
49+
__commentsList: null,
50+
__loadMoreComments: null,
51+
52+
__buildLayout: function() {
53+
this.__commentsTitle = new qx.ui.basic.Label();
54+
this._add(this.__commentsTitle);
55+
56+
this.__commentsList = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
57+
alignY: "middle"
58+
});
59+
this._add(this.__commentsList, {
60+
flex: 1
61+
});
62+
63+
this.__loadMoreComments = new osparc.ui.form.FetchButton(this.tr("Load more comments..."));
64+
this.__loadMoreComments.addListener("execute", () => this.fetchComments(false));
65+
this._add(this.__loadMoreComments);
66+
67+
if (osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])) {
68+
const addComments = new osparc.info.CommentAdd(this.__studyData["uuid"]);
69+
addComments.setPaddingLeft(10);
70+
addComments.addListener("commentAdded", () => this.fetchComments());
71+
this._add(addComments);
72+
}
73+
},
74+
75+
fetchComments: function(removeComments = true) {
76+
if (this.__conversationId === null) {
77+
this.__commentsList.hide();
78+
this.__loadMoreComments.hide();
79+
return;
80+
}
81+
82+
this.__loadMoreComments.show();
83+
this.__loadMoreComments.setFetching(true);
84+
85+
if (removeComments) {
86+
this.__commentsList.removeAll();
87+
}
88+
89+
this.__getNextRequest()
90+
.then(resp => {
91+
const comments = resp["data"];
92+
this.__addComments(comments);
93+
this.__nextRequestParams = resp["_links"]["next"];
94+
if (this.__nextRequestParams === null) {
95+
this.__loadMoreComments.exclude();
96+
}
97+
})
98+
.finally(() => this.__loadMoreComments.setFetching(false));
99+
},
100+
101+
__getNextRequest: function() {
102+
const params = {
103+
url: {
104+
studyId: this.__studyData["uuid"],
105+
offset: 0,
106+
limit: 20
107+
}
108+
};
109+
const nextRequestParams = this.__nextRequestParams;
110+
if (nextRequestParams) {
111+
params.url.offset = nextRequestParams.offset;
112+
params.url.limit = nextRequestParams.limit;
113+
}
114+
const options = {
115+
resolveWResponse: true
116+
};
117+
return osparc.data.Resources.fetch("studyComments", "getPage", params, options);
118+
},
119+
120+
__addComments: function(comments) {
121+
if (comments.length === 1) {
122+
this.__commentsTitle.setValue(this.tr("1 Comment"));
123+
} else if (comments.length > 1) {
124+
this.__commentsTitle.setValue(comments.length + this.tr(" Comments"));
125+
}
126+
127+
comments.forEach(comment => {
128+
const commentUi = new osparc.info.CommentUI(comment);
129+
this.__commentsList.add(commentUi);
130+
});
131+
}
132+
}
133+
});

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

Lines changed: 31 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -25,130 +25,62 @@ qx.Class.define("osparc.study.Conversations", {
2525
construct: function(studyData) {
2626
this.base(arguments);
2727

28-
this.__studyData = studyData;
28+
this._setLayout(new qx.ui.layout.VBox());
2929

30-
this._setLayout(new qx.ui.layout.VBox(10));
31-
32-
this.__buildLayout();
33-
34-
// this.fetchConversations();
35-
this.fetchComments();
36-
},
37-
38-
statics: {
39-
popUpInWindow: function(studyData) {
40-
const conversations = new osparc.study.Conversations(studyData);
41-
const title = qx.locale.Manager.tr("Conversations");
42-
const viewWidth = 600;
43-
const viewHeight = 700;
44-
const win = osparc.ui.window.Window.popUpInWindow(conversations, title, viewWidth, viewHeight);
45-
return win;
46-
},
30+
this.fetchConversations(studyData);
4731
},
4832

4933
members: {
50-
__studyData: null,
51-
__nextRequestParams: null,
52-
5334
_createChildControlImpl: function(id) {
5435
let control;
5536
switch (id) {
56-
case "title":
57-
control = new qx.ui.basic.Label().set({
58-
value: this.tr("0 Comments")
59-
});
37+
case "loading-button":
38+
control = new osparc.ui.form.FetchButton();
6039
this._add(control);
6140
break;
62-
case "comments-list":
63-
control = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
64-
alignY: "middle"
65-
});
41+
case "conversations-layout":
42+
control = new qx.ui.tabview.TabView();
6643
this._add(control, {
6744
flex: 1
6845
});
6946
break;
70-
case "load-more-button":
71-
control = new osparc.ui.form.FetchButton(this.tr("Load more comments..."));
72-
control.addListener("execute", () => this.fetchComments(false));
73-
this._add(control);
74-
break;
75-
case "add-comment":
76-
if (osparc.data.model.Study.canIWrite(this.__studyData["accessRights"])) {
77-
control = new osparc.info.CommentAdd(this.__studyData["uuid"]);
78-
control.setPaddingLeft(10);
79-
control.addListener("commentAdded", () => this.fetchComments());
80-
this._add(control);
81-
}
82-
break;
8347
}
8448

8549
return control || this.base(arguments, id);
8650
},
8751

88-
__buildLayout: function() {
89-
this.getChildControl("title");
90-
this.getChildControl("comments-list");
91-
this.getChildControl("load-more-button");
92-
this.getChildControl("add-comment");
93-
},
94-
95-
fetchConversations: function() {
96-
},
97-
98-
fetchComments: function(removeComments = true) {
99-
const loadMoreButton = this.getChildControl("load-more-button");
100-
loadMoreButton.show();
52+
fetchConversations: function(studyData) {
53+
const loadMoreButton = this.getChildControl("loading-button");
10154
loadMoreButton.setFetching(true);
10255

103-
if (removeComments) {
104-
this.getChildControl("comments-list").removeAll();
105-
}
106-
107-
this.__getNextRequest()
108-
.then(resp => {
109-
const comments = resp["data"];
110-
this.__addComments(comments);
111-
this.__nextRequestParams = resp["_links"]["next"];
112-
if (this.__nextRequestParams === null) {
113-
loadMoreButton.exclude();
114-
}
115-
})
116-
.finally(() => loadMoreButton.setFetching(false));
117-
},
118-
119-
__getNextRequest: function() {
12056
const params = {
12157
url: {
122-
studyId: this.__studyData["uuid"],
123-
conversationId: this.__studyData["uuid"],
58+
studyId: studyData["uuid"],
12459
offset: 0,
125-
limit: 40
60+
limit: 42,
12661
}
12762
};
128-
const nextRequestParams = this.__nextRequestParams;
129-
if (nextRequestParams) {
130-
params.url.offset = nextRequestParams.offset;
131-
params.url.limit = nextRequestParams.limit;
132-
}
133-
const options = {
134-
resolveWResponse: true
135-
};
136-
return osparc.data.Resources.fetch("studyComments", "getPage", params, options);
63+
osparc.data.Resources.fetch("conversations", "get", params)
64+
.then(conversations => {
65+
const conversationsLayout = this.getChildControl("conversations-layout");
66+
console.log("Conversations fetched", conversations);
67+
if (conversations.length === 0) {
68+
const noConversationTab = new osparc.info.Conversation(studyData);
69+
noConversationTab.setLabel(this.tr("new 1"));
70+
conversationsLayout.add(noConversationTab);
71+
} else {
72+
conversations.forEach(conversation => {
73+
const conversationId = conversation["id"];
74+
const conversationTab = new osparc.info.Conversation(studyData, conversationId);
75+
conversationTab.setLabel(conversation["name"]);
76+
conversationsLayout.add(conversationTab);
77+
});
78+
}
79+
})
80+
.finally(() => {
81+
loadMoreButton.setFetching(false);
82+
loadMoreButton.exclude();
83+
});
13784
},
138-
139-
__addComments: function(comments) {
140-
const commentsTitle = this.getChildControl("title");
141-
if (comments.length === 1) {
142-
commentsTitle.setValue(this.tr("1 Comment"));
143-
} else if (comments.length > 1) {
144-
commentsTitle.setValue(comments.length + this.tr(" Comments"));
145-
}
146-
147-
const commentsList = this.getChildControl("comments-list");
148-
comments.forEach(comment => {
149-
const commentUi = new osparc.info.CommentUI(comment);
150-
commentsList.add(commentUi);
151-
});
152-
}
15385
}
15486
});

0 commit comments

Comments
 (0)