Skip to content

Commit b752f9b

Browse files
authored
Merge branch 'master' into pr-osparc-remove-zero-pull-rate
2 parents be8fac6 + db3aacf commit b752f9b

File tree

13 files changed

+246
-102
lines changed

13 files changed

+246
-102
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
115115
}
116116
// "Starting..." page
117117
this._hideLoadingPage();
118+
119+
// since all the resources (templates, users, orgs...) were already loaded, notifications can be built
120+
osparc.data.Resources.get("notifications")
121+
.then(notifications => {
122+
osparc.notification.Notifications.getInstance().addNotifications(notifications);
123+
});
118124
})
119125
.catch(err => {
120126
console.error(err);

services/static-webserver/client/source/class/osparc/desktop/MainPageDesktop.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,29 @@ qx.Class.define("osparc.desktop.MainPageDesktop", {
2626
this._add(osparc.notification.RibbonNotifications.getInstance());
2727

2828
const navBar = new osparc.navigation.NavigationBar();
29-
navBar.populateLayout()
30-
.then(() => {
31-
// exclude some items from the navigation bar
32-
navBar.getChildControl("dashboard-label").exclude();
33-
navBar.getChildControl("dashboard-button").exclude();
34-
navBar.getChildControl("notifications-button").exclude();
35-
navBar.getChildControl("help").exclude();
36-
37-
// exclude all the menu entries except "log-out" from user menu
38-
const userMenuButton = navBar.getChildControl("user-menu");
39-
const userMenu = userMenuButton.getMenu();
40-
// eslint-disable-next-line no-underscore-dangle
41-
const userMenuEntries = userMenu._getCreatedChildControls();
42-
Object.entries(userMenuEntries).forEach(([id, userMenuEntry]) => {
43-
if (!["mini-profile-view", "po-center", "log-out"].includes(id)) {
44-
userMenuEntry.exclude();
45-
}
46-
});
47-
// exclude also the separators
48-
userMenu.getChildren().forEach(child => {
49-
if (child.classname === "qx.ui.menu.Separator") {
50-
child.exclude();
51-
}
52-
});
53-
});
29+
navBar.populateLayout();
30+
// exclude some items from the navigation bar
31+
navBar.getChildControl("dashboard-label").exclude();
32+
navBar.getChildControl("dashboard-button").exclude();
33+
navBar.getChildControl("notifications-button").exclude();
34+
navBar.getChildControl("help").exclude();
35+
36+
// exclude all the menu entries except "log-out" from user menu
37+
const userMenuButton = navBar.getChildControl("user-menu");
38+
const userMenu = userMenuButton.getMenu();
39+
// eslint-disable-next-line no-underscore-dangle
40+
const userMenuEntries = userMenu._getCreatedChildControls();
41+
Object.entries(userMenuEntries).forEach(([id, userMenuEntry]) => {
42+
if (!["mini-profile-view", "po-center", "log-out"].includes(id)) {
43+
userMenuEntry.exclude();
44+
}
45+
});
46+
// exclude also the separators
47+
userMenu.getChildren().forEach(child => {
48+
if (child.classname === "qx.ui.menu.Separator") {
49+
child.exclude();
50+
}
51+
});
5452
this._add(navBar);
5553

5654
osparc.MaintenanceTracker.getInstance().startTracker();

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,12 @@ qx.Class.define("osparc.info.CommentUI", {
117117
const commentContent = this.getChildControl("comment-content");
118118
commentContent.setValue(this.__comment["contents"]);
119119

120-
osparc.store.Store.getInstance().getUser(this.__comment["user_id"])
121-
.then(user => {
122-
if (user) {
123-
const userSource = osparc.utils.Avatar.getUrl(user["login"], 32);
124-
thumbnail.setSource(userSource);
125-
userName.setValue(user["label"]);
126-
}
127-
});
120+
const user = osparc.store.Store.getInstance().getUser(this.__comment["user_id"])
121+
if (user) {
122+
const userSource = osparc.utils.Avatar.getUrl(user["login"], 32);
123+
thumbnail.setSource(userSource);
124+
userName.setValue(user["label"]);
125+
}
128126
}
129127
}
130128
});

services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,8 @@ qx.Class.define("osparc.navigation.NavigationBar", {
9292
__tabButtons: null,
9393

9494
populateLayout: function() {
95-
return new Promise(resolve => {
96-
osparc.data.Resources.get("notifications")
97-
.then(notifications => {
98-
osparc.notification.Notifications.getInstance().addNotifications(notifications);
99-
this.__buildLayout();
100-
osparc.WindowSizeTracker.getInstance().addListener("changeCompactVersion", () => this.__navBarResized(), this);
101-
resolve();
102-
})
103-
.catch(err => console.error(err));
104-
});
95+
this.__buildLayout();
96+
osparc.WindowSizeTracker.getInstance().addListener("changeCompactVersion", () => this.__navBarResized(), this);
10597
},
10698

10799
__buildLayout: function() {

services/static-webserver/client/source/class/osparc/notification/Notification.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ qx.Class.define("osparc.notification.Notification", {
2323

2424
this.set({
2525
id: notificationObj.id,
26+
resourceId: notificationObj.resource_id ? notificationObj.resource_id : null,
2627
category: notificationObj.category,
2728
actionablePath: notificationObj.actionable_path,
2829
title: notificationObj.title,
2930
text: notificationObj.text,
31+
userFromId: notificationObj.user_from_id ? notificationObj.user_from_id : null,
3032
date: new Date(notificationObj.date),
3133
read: ["true", "True", true].includes(notificationObj.read)
3234
});
@@ -40,6 +42,13 @@ qx.Class.define("osparc.notification.Notification", {
4042
event: "changeId"
4143
},
4244

45+
resourceId: {
46+
check: "String",
47+
init: null,
48+
nullable: true,
49+
event: "changeResourceId"
50+
},
51+
4352
category: {
4453
check: [
4554
"NEW_ORGANIZATION",
@@ -74,6 +83,13 @@ qx.Class.define("osparc.notification.Notification", {
7483
event: "changeText"
7584
},
7685

86+
userFromId: {
87+
check: "Number",
88+
init: null,
89+
nullable: true,
90+
event: "changeUserFromId"
91+
},
92+
7793
date: {
7894
check: "Date",
7995
init: null,

services/static-webserver/client/source/class/osparc/notification/NotificationUI.js

Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -112,37 +112,102 @@ qx.Class.define("osparc.notification.NotificationUI", {
112112
return control || this.base(arguments, id);
113113
},
114114

115-
__applyNotification: function(notification) {
116-
const icon = this.getChildControl("icon");
117-
notification.bind("category", icon, "source", {
118-
converter: value => {
119-
let source = "";
120-
switch (value) {
121-
case "NEW_ORGANIZATION":
122-
source = "@FontAwesome5Solid/users/14";
123-
break;
124-
case "STUDY_SHARED":
125-
source = "@FontAwesome5Solid/file/14";
126-
break;
127-
case "TEMPLATE_SHARED":
128-
source = "@FontAwesome5Solid/copy/14";
129-
break;
130-
case "ANNOTATION_NOTE":
131-
source = "@FontAwesome5Solid/file/14";
132-
break;
133-
case "WALLET_SHARED":
134-
source = "@MaterialIcons/account_balance_wallet/14";
135-
break;
115+
__applyNotification: async function(notification) {
116+
console.log("notification", notification);
117+
let resourceId = null;
118+
if (notification.getResourceId()) {
119+
resourceId = notification.getResourceId();
120+
} else if (notification.getActionablePath()) {
121+
// extract it from the actionable path
122+
const actionablePath = notification.getActionablePath();
123+
resourceId = actionablePath.split("/")[1];
124+
}
125+
const userFromId = notification.getUserFromId();
126+
127+
let source = "";
128+
let title = "";
129+
let description = "";
130+
switch (notification.getCategory()) {
131+
case "NEW_ORGANIZATION":
132+
source = "@FontAwesome5Solid/users/14";
133+
if (resourceId) {
134+
const group = await osparc.store.Store.getInstance().getGroup(resourceId);
135+
description = "You're now member of '" + group["name"] + "'";
136136
}
137-
return source;
138-
}
139-
});
137+
break;
138+
case "STUDY_SHARED":
139+
source = "@FontAwesome5Solid/file/14";
140+
if (resourceId) {
141+
const params = {
142+
url: {
143+
"studyId": resourceId
144+
}
145+
};
146+
const study = await osparc.data.Resources.getOne("studies", params);
147+
const studyAlias = osparc.product.Utils.getStudyAlias({
148+
firstUpperCase: true
149+
});
150+
if (study) {
151+
title = `${studyAlias} '${study["name"]}'`;
152+
}
153+
}
154+
if (userFromId) {
155+
const user = osparc.store.Store.getInstance().getUser(userFromId);
156+
if (user) {
157+
description = "was shared by " + user["label"];
158+
}
159+
}
160+
break;
161+
case "TEMPLATE_SHARED":
162+
source = "@FontAwesome5Solid/copy/14";
163+
if (resourceId) {
164+
const template = osparc.store.Store.getInstance().getTemplate(resourceId);
165+
const templateAlias = osparc.product.Utils.getTemplateAlias({
166+
firstUpperCase: true
167+
});
168+
if (template) {
169+
title = `${templateAlias} '${template["name"]}'`;
170+
}
171+
}
172+
if (userFromId) {
173+
const user = osparc.store.Store.getInstance().getUser(userFromId);
174+
if (user) {
175+
description = "was shared by " + user["label"];
176+
}
177+
}
178+
break;
179+
case "ANNOTATION_NOTE":
180+
source = "@FontAwesome5Solid/file/14";
181+
if (resourceId) {
182+
const params = {
183+
url: {
184+
"studyId": resourceId
185+
}
186+
};
187+
const study = await osparc.data.Resources.getOne("studies", params);
188+
if (study) {
189+
title = `Note added in '${study["name"]}'`;
190+
}
191+
}
192+
if (userFromId) {
193+
const user = osparc.store.Store.getInstance().getUser(userFromId);
194+
if (user) {
195+
description = "was added by " + user["label"];
196+
}
197+
}
198+
break;
199+
case "WALLET_SHARED":
200+
source = "@MaterialIcons/account_balance_wallet/14";
201+
break;
202+
}
203+
const icon = this.getChildControl("icon");
204+
icon.setSource(source);
140205

141-
const title = this.getChildControl("title");
142-
notification.bind("title", title, "value");
206+
const titleLabel = this.getChildControl("title");
207+
titleLabel.setValue(title ? title : notification.getTitle());
143208

144-
const text = this.getChildControl("text");
145-
notification.bind("text", text, "value");
209+
const descriptionLabel = this.getChildControl("text");
210+
descriptionLabel.setValue(description ? description : notification.getText());
146211

147212
const date = this.getChildControl("date");
148213
notification.bind("date", date, "value", {
@@ -166,23 +231,11 @@ qx.Class.define("osparc.notification.NotificationUI", {
166231
}
167232

168233
this.fireEvent("notificationTapped");
234+
osparc.notification.Notifications.markAsRead(notification);
235+
this.__openActionablePath(notification);
236+
},
169237

170-
if (notification.isRead() === false) {
171-
// set as read
172-
const params = {
173-
url: {
174-
notificationId: notification.getId()
175-
},
176-
data: {
177-
"read": true
178-
}
179-
};
180-
osparc.data.Resources.fetch("notifications", "patch", params)
181-
.then(() => notification.setRead(true))
182-
.catch(() => notification.setRead(false));
183-
}
184-
185-
// open actionable path
238+
__openActionablePath: function(notification) {
186239
const actionablePath = notification.getActionablePath();
187240
const items = actionablePath.split("/");
188241
const resourceId = items.pop();

0 commit comments

Comments
 (0)