From eaa8944be6abdc979f363f0b91dd23f248bcf5d0 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:13:34 +0100 Subject: [PATCH 1/6] avatar with initials --- .../source/class/osparc/data/model/User.js | 2 +- .../class/osparc/desktop/account/MyAccount.js | 4 ++-- .../source/class/osparc/info/CommentAdd.js | 6 ++++-- .../source/class/osparc/info/CommentUI.js | 2 +- .../class/osparc/navigation/UserMenuButton.js | 3 ++- .../source/class/osparc/store/Groups.js | 2 +- .../source/class/osparc/utils/Avatar.js | 21 ++++++++++++------- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index f0c8a5dabb1..fbdc80c6adf 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -39,7 +39,7 @@ qx.Class.define("osparc.data.model.User", { if (userData["login"]) { description += userData["login"]; } - const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]); + const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"], userData["userName"]); this.set({ userId: parseInt(userData["id"]), groupId: parseInt(userData["gid"]), diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js index 2380a9745f3..40a3e5b5918 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js @@ -42,11 +42,11 @@ qx.Class.define("osparc.desktop.account.MyAccount", { }); const authData = osparc.auth.Data.getInstance(); - + const username = authData.getUsername(); const email = authData.getEmail(); const avatarSize = 80; const img = new qx.ui.basic.Image().set({ - source: osparc.utils.Avatar.getUrl(email, avatarSize), + source: osparc.utils.Avatar.emailToThumbnail(email, username, avatarSize), maxWidth: avatarSize, maxHeight: avatarSize, scale: true, diff --git a/services/static-webserver/client/source/class/osparc/info/CommentAdd.js b/services/static-webserver/client/source/class/osparc/info/CommentAdd.js index b8f36a839e6..53b26c23bad 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentAdd.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentAdd.js @@ -68,9 +68,11 @@ qx.Class.define("osparc.info.CommentAdd", { maxHeight: 32, decorator: "rounded", }); - const myEmail = osparc.auth.Data.getInstance().getEmail(); + const authData = osparc.auth.Data.getInstance(); + const myUsername = authData.getUsername(); + const myEmail = authData.getEmail(); control.set({ - source: osparc.utils.Avatar.getUrl(myEmail, 32) + source: osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32) }); const layout = this.getChildControl("add-comment-layout"); layout.add(control, { diff --git a/services/static-webserver/client/source/class/osparc/info/CommentUI.js b/services/static-webserver/client/source/class/osparc/info/CommentUI.js index ea6df760a08..94450f804b7 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentUI.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentUI.js @@ -104,7 +104,7 @@ qx.Class.define("osparc.info.CommentUI", { __buildLayout: function() { const thumbnail = this.getChildControl("thumbnail"); - thumbnail.setSource(osparc.utils.Avatar.getUrl("", 32)); + thumbnail.setSource(osparc.utils.Avatar.emailToThumbnail("", "", 32)); const userName = this.getChildControl("user-name"); userName.setValue("Unknown"); diff --git a/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js b/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js index e53fc4e7e1c..e1726533215 100644 --- a/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js +++ b/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js @@ -51,6 +51,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", { const preferencesSettings = osparc.Preferences.getInstance(); preferencesSettings.addListener("changeCreditsWarningThreshold", () => this.__updateHaloColor()); + const myUsername = authData.getUsername() || "Username"; const myEmail = authData.getEmail() || "bizzy@itis.ethz.ch"; const icon = this.getChildControl("icon"); authData.bind("role", this, "icon", { @@ -64,7 +65,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", { icon.getContentElement().setStyles({ "margin-left": "-4px" }); - return osparc.utils.Avatar.getUrl(myEmail, 32); + return osparc.utils.Avatar.emailToThumbnail(myEmail, myUsername, 32); } }); }, diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 21e2d4b2a29..e954de7aba6 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.store.Groups", { groupMe.set({ label: myAuthData.getUsername(), description: `${myAuthData.getFirstName()} ${myAuthData.getLastName()} - ${myAuthData.getEmail()}`, - thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail()), + thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail(), myAuthData.getUsername()), }) return orgs; }); diff --git a/services/static-webserver/client/source/class/osparc/utils/Avatar.js b/services/static-webserver/client/source/class/osparc/utils/Avatar.js index a2d40081bcb..9c36a58f4cd 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Avatar.js +++ b/services/static-webserver/client/source/class/osparc/utils/Avatar.js @@ -26,7 +26,7 @@ * Here is a little example of how to use the widget. * *
- *   let image = osparc.utils.Avatar.getUrl(userEmail);
+ *   let image = osparc.utils.Avatar.emailToThumbnail(userEmail);
  * 
*/ @@ -34,13 +34,16 @@ qx.Class.define("osparc.utils.Avatar", { type: "static", statics: { - emailToThumbnail: function(email) { - return this.getUrl(email, 32) + emailToThumbnail: function(email, username) { + return this.__getUrl(email, username, 32); }, - getUrl: function(email = "", size = 100, defIcon = "identicon", rating = "g") { + __getUrl: function(email, username, size = 100) { + if (email == null) { + return `https://ui-avatars.com/api/${username}/${size}`; + } // MD5 (Message-Digest Algorithm) by WebToolkit - let MD5 = function(s) { + const MD5 = function(s) { function L(k, d) { return (k << d) | (k >>> (32 - d)); } @@ -257,8 +260,10 @@ qx.Class.define("osparc.utils.Avatar", { return i.toLowerCase(); }; - return "https://secure.gravatar.com/avatar/" + MD5(email) + "?s=" + size + "&d=" + defIcon + "&r=" + rating; - } - + const emailHash = MD5(email); + const defaultImageUrl = `https://ui-avatars.com/api/${username}/${size}/`; + // return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}&r=g`; + return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}`; + }, } }); From 220d6b66f1dbeee9ce6035c1750baf5718dc9a43 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:14:59 +0100 Subject: [PATCH 2/6] minor --- .../client/source/class/osparc/utils/Avatar.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/utils/Avatar.js b/services/static-webserver/client/source/class/osparc/utils/Avatar.js index 9c36a58f4cd..13cf64a6eca 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Avatar.js +++ b/services/static-webserver/client/source/class/osparc/utils/Avatar.js @@ -40,7 +40,7 @@ qx.Class.define("osparc.utils.Avatar", { __getUrl: function(email, username, size = 100) { if (email == null) { - return `https://ui-avatars.com/api/${username}/${size}`; + email = ""; } // MD5 (Message-Digest Algorithm) by WebToolkit const MD5 = function(s) { @@ -261,9 +261,8 @@ qx.Class.define("osparc.utils.Avatar", { }; const emailHash = MD5(email); - const defaultImageUrl = `https://ui-avatars.com/api/${username}/${size}/`; - // return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}&r=g`; - return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}`; + const defaultImageUrl = `https://ui-avatars.com/api/${username}/${size}`; + return `https://www.gravatar.com/avatar/${emailHash}?d=${defaultImageUrl}&s=${size}&r=g`; }, } }); From fc07155133cb98f1695dccfe61d74a4025e2d05a Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:22:18 +0100 Subject: [PATCH 3/6] minor --- .../static-webserver/client/source/class/osparc/store/Store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index ea05e789754..978d299f061 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -618,7 +618,7 @@ qx.Class.define("osparc.store.Store", { __getOrgClassifiers: function(orgId, useCache = false) { const params = { url: { - "gid": orgId + "gid": parseInt(orgId) } }; return osparc.data.Resources.get("classifiers", params, useCache); From 5f2b0e747badc6b65a5fcd3ef13607d47e2f8737 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:27:42 +0100 Subject: [PATCH 4/6] fix --- .../static-webserver/client/source/class/osparc/store/Store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 978d299f061..044f2b9558b 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -222,7 +222,7 @@ qx.Class.define("osparc.store.Store", { check: "Array", init: [] }, - market: { + licensedItems: { check: "Array", init: [] }, From 9d67a358213ff5469878501bf150c348141ba6a3 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:30:47 +0100 Subject: [PATCH 5/6] minor --- .../client/source/class/osparc/utils/Avatar.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/utils/Avatar.js b/services/static-webserver/client/source/class/osparc/utils/Avatar.js index 13cf64a6eca..c108a661355 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Avatar.js +++ b/services/static-webserver/client/source/class/osparc/utils/Avatar.js @@ -39,9 +39,7 @@ qx.Class.define("osparc.utils.Avatar", { }, __getUrl: function(email, username, size = 100) { - if (email == null) { - email = ""; - } + email = email || ""; // MD5 (Message-Digest Algorithm) by WebToolkit const MD5 = function(s) { function L(k, d) { From d34078a18ebc4efcb0744603c1e08a07664b50fd Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 11 Dec 2024 17:48:50 +0100 Subject: [PATCH 6/6] fix issues --- .../static-webserver/client/source/class/osparc/store/Store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 044f2b9558b..e9146a1402f 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -640,7 +640,7 @@ qx.Class.define("osparc.store.Store", { } const classifierPromises = []; orgs.forEach(org => { - classifierPromises.push(this.__getOrgClassifiers(org["gid"], !reload)); + classifierPromises.push(this.__getOrgClassifiers(org.getGroupId(), !reload)); }); Promise.all(classifierPromises) .then(orgsClassifiersMD => {