Skip to content

Commit cc5d2cd

Browse files
Merge branch 'master' into maintenance/small-refactor-of-projects-comments
2 parents 098a44e + 384e9f1 commit cc5d2cd

File tree

12 files changed

+471
-28
lines changed

12 files changed

+471
-28
lines changed

services/static-webserver/client/source/class/osparc/component/editor/TextEditor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ qx.Class.define("osparc.component.editor.TextEditor", {
8383
const writePage = new qx.ui.tabview.Page(this.tr("Write")).set({
8484
layout: new qx.ui.layout.VBox(5)
8585
});
86+
writePage.getChildControl("button").getChildControl("label").set({
87+
font: "text-13"
88+
});
8689
writePage.add(control, {
8790
flex: 1
8891
});
@@ -104,6 +107,9 @@ qx.Class.define("osparc.component.editor.TextEditor", {
104107
const previewPage = new qx.ui.tabview.Page(this.tr("Preview")).set({
105108
layout: new qx.ui.layout.VBox(5)
106109
});
110+
previewPage.getChildControl("button").getChildControl("label").set({
111+
font: "text-13"
112+
});
107113
const scrollContainer = new qx.ui.container.Scroll();
108114
scrollContainer.add(control);
109115
previewPage.add(scrollContainer, {

services/static-webserver/client/source/class/osparc/dashboard/ResourceMoreOptions.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
2626
this._setLayout(new qx.ui.layout.VBox(10));
2727

2828
this.__addToolbar();
29-
this.__addDetailsView();
29+
this.__addTabPagesView();
3030
},
3131

3232
events: {
@@ -64,12 +64,16 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
6464
osparc.utils.Utils.centerTabIcon(tabPage);
6565

6666
// Page title
67-
tabPage.add(new qx.ui.basic.Label(title).set({
68-
font: "text-15"
69-
}));
67+
if (title) {
68+
tabPage.add(new qx.ui.basic.Label(title).set({
69+
font: "text-15"
70+
}));
71+
}
7072

7173
// Page content
72-
tabPage.add(widget, {
74+
const scrollContainer = new qx.ui.container.Scroll();
75+
scrollContainer.add(widget);
76+
tabPage.add(scrollContainer, {
7377
flex: 1
7478
});
7579

@@ -89,7 +93,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
8993
members: {
9094
__resourceData: null,
9195
__toolbar: null,
92-
__detailsView: null,
96+
__tabsView: null,
9397
__dataPage: null,
9498
__permissionsPage: null,
9599
__tagsPage: null,
@@ -155,8 +159,8 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
155159
this._add(toolbar);
156160
},
157161

158-
__addDetailsView: function() {
159-
const detailsView = this.__detailsView = new qx.ui.tabview.TabView().set({
162+
__addTabPagesView: function() {
163+
const detailsView = this.__tabsView = new qx.ui.tabview.TabView().set({
160164
barPosition: "left",
161165
contentPadding: 0
162166
});
@@ -169,7 +173,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
169173

170174
__openPage: function(page) {
171175
if (page) {
172-
this.__detailsView.setSelection([page]);
176+
this.__tabsView.setSelection([page]);
173177
}
174178
},
175179

@@ -244,7 +248,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
244248
},
245249

246250
__addPages: function() {
247-
const detailsView = this.__detailsView;
251+
const detailsView = this.__tabsView;
248252

249253
// keep selected page
250254
const selection = detailsView.getSelection();
@@ -259,7 +263,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
259263
// add Open service button
260264
[
261265
this.__getInfoPage,
262-
this.__getPreviewPage,
266+
this.__getCommentsPage,
263267
this.__getDataPage,
264268
this.__getPermissionsPage,
265269
this.__getTagsPage,
@@ -287,7 +291,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
287291

288292
__getInfoPage: function() {
289293
const id = "Information";
290-
const title = this.tr("Information");
294+
const title = "";
291295
const icon = "@FontAwesome5Solid/info";
292296
const resourceData = this.__resourceData;
293297
const infoCard = osparc.utils.Resources.isService(resourceData) ? new osparc.info.ServiceLarge(resourceData, null, false) : new osparc.info.StudyLarge(resourceData, false);
@@ -322,18 +326,27 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
322326
return page;
323327
},
324328

325-
__getPreviewPage: function() {
326-
if (!osparc.product.Utils.showStudyPreview()) {
329+
__getCommentsPage: function() {
330+
const resourceData = this.__resourceData;
331+
if (osparc.utils.Resources.isService(resourceData)) {
327332
return null;
328333
}
329334

330-
const id = "Preview";
331-
const title = this.tr("Preview");
332-
const icon = "@FontAwesome5Solid/search-plus";
333-
const resourceData = this.__resourceData;
334-
const studyThumbnailExplorer = new osparc.dashboard.StudyThumbnailExplorer(resourceData);
335+
const id = "Comments";
336+
const title = this.tr("Comments");
337+
const icon = "@FontAwesome5Solid/comments";
338+
339+
const commentsLayout = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
340+
const commentsList = new osparc.info.CommentsList(resourceData["uuid"]);
341+
commentsLayout.add(commentsList);
342+
if (osparc.data.model.Study.canIWrite(resourceData["accessRights"])) {
343+
const addComment = new osparc.info.CommentAdd(resourceData["uuid"]);
344+
addComment.setPaddingLeft(10);
345+
addComment.addListener("commentAdded", () => commentsList.fetchComments());
346+
commentsLayout.add(addComment);
347+
}
335348

336-
const page = this.self().createPage(title, studyThumbnailExplorer, icon, id);
349+
const page = this.self().createPage(title, commentsLayout, icon, id);
337350
return page;
338351
},
339352

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ qx.Class.define("osparc.data.Resources", {
185185
}
186186
}
187187
},
188+
"studyComments": {
189+
useCache: true,
190+
idField: "uuid",
191+
endpoints: {
192+
getPage: {
193+
method: "GET",
194+
url: statics.API + "/projects/{studyId}/comments?offset={offset}&limit={limit}"
195+
},
196+
addComment: {
197+
method: "POST",
198+
url: statics.API + "/projects/{studyId}/comments"
199+
}
200+
}
201+
},
188202
/*
189203
* NODES
190204
*/

services/static-webserver/client/source/class/osparc/info/CardLarge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ qx.Class.define("osparc.info.CardLarge", {
2727
minHeight: 350,
2828
padding: this.self().PADDING
2929
});
30-
this._setLayout(new qx.ui.layout.VBox(8));
30+
this._setLayout(new qx.ui.layout.VBox(15));
3131
},
3232

3333
events: {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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.CommentAdd", {
20+
extend: qx.ui.core.Widget,
21+
22+
/**
23+
* @param studyId {String} Study Id
24+
*/
25+
construct: function(studyId) {
26+
this.base(arguments);
27+
28+
this.__studyId = studyId;
29+
30+
this._setLayout(new qx.ui.layout.VBox(5));
31+
32+
this.__buildLayout();
33+
},
34+
35+
events: {
36+
"commentAdded": "qx.event.type.Event"
37+
},
38+
39+
members: {
40+
_createChildControlImpl: function(id) {
41+
let control;
42+
switch (id) {
43+
case "add-comment-label":
44+
control = new qx.ui.basic.Label().set({
45+
value: this.tr("Add comment")
46+
});
47+
this._add(control);
48+
break;
49+
case "add-comment-layout": {
50+
const grid = new qx.ui.layout.Grid(8, 5);
51+
grid.setColumnWidth(0, 32);
52+
grid.setColumnFlex(1, 1);
53+
control = new qx.ui.container.Composite(grid);
54+
this._add(control, {
55+
flex: 1
56+
});
57+
break;
58+
}
59+
case "thumbnail": {
60+
control = new qx.ui.basic.Image().set({
61+
alignY: "middle",
62+
scale: true,
63+
allowGrowX: true,
64+
allowGrowY: true,
65+
allowShrinkX: true,
66+
allowShrinkY: true,
67+
maxWidth: 32,
68+
maxHeight: 32
69+
});
70+
const userEmail = osparc.auth.Data.getInstance().getEmail();
71+
control.set({
72+
source: osparc.utils.Avatar.getUrl(userEmail, 32)
73+
});
74+
control.getContentElement().setStyles({
75+
"border-radius": "8px"
76+
});
77+
const layout = this.getChildControl("add-comment-layout");
78+
layout.add(control, {
79+
row: 0,
80+
column: 0
81+
});
82+
break;
83+
}
84+
case "comment-field": {
85+
control = new osparc.component.editor.TextEditor();
86+
control.getChildControl("buttons").exclude();
87+
const layout = this.getChildControl("add-comment-layout");
88+
layout.add(control, {
89+
row: 0,
90+
column: 1
91+
});
92+
break;
93+
}
94+
case "add-comment-button": {
95+
control = new qx.ui.form.Button(this.tr("Add")).set({
96+
allowGrowX: false,
97+
alignX: "right"
98+
});
99+
this._add(control);
100+
break;
101+
}
102+
}
103+
104+
return control || this.base(arguments, id);
105+
},
106+
107+
__buildLayout: function() {
108+
this.getChildControl("thumbnail");
109+
const commentField = this.getChildControl("comment-field");
110+
const addButton = this.getChildControl("add-comment-button");
111+
addButton.addListener("execute", () => {
112+
const commentText = commentField.getChildControl("text-area").getValue();
113+
if (commentText) {
114+
const params = {
115+
url: {
116+
studyId: this.__studyId
117+
},
118+
data: {
119+
"contents": commentText
120+
}
121+
};
122+
osparc.data.Resources.fetch("studyComments", "addComment", params)
123+
.then(() => {
124+
this.fireEvent("commentAdded");
125+
commentField.getChildControl("text-area").setValue("");
126+
})
127+
.catch(err => {
128+
console.error(err);
129+
osparc.component.message.FlashMessenger.logAs(err.message, "ERROR");
130+
});
131+
}
132+
});
133+
}
134+
}
135+
});

0 commit comments

Comments
 (0)