Skip to content

Commit

Permalink
✨ Feature: Shared Credits notification (ITISFoundation#4809)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Oct 2, 2023
1 parent 61faf41 commit a13e39c
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ qx.Class.define("osparc.data.Roles", {
return this.__createIntoFromRoles(osparc.data.Roles.ORG);
},

createRolesWalleltInfo: function() {
createRolesWalletInfo: function() {
return this.__createIntoFromRoles(osparc.data.Roles.WALLET);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ qx.Class.define("osparc.desktop.MainPage", {
const preferenceSettings = osparc.Preferences.getInstance();
const preferenceWalletId = preferenceSettings.getPreferredWalletId();
const wallets = store.getWallets();
if (preferenceWalletId === null && wallets && wallets.length) {
// Select one by default: according to the use case, the one larger number of accessRights
wallets.sort((a, b) => b.getAccessRights().length - a.getAccessRights().length);
if (wallets.length === 1 && (preferenceWalletId === null || osparc.desktop.credits.Utils.getWallet(preferenceWalletId) === null)) {
// If there is only one wallet available, make it default
preferenceSettings.requestChangePreferredWalletId(wallets[0].getWalletId());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ qx.Class.define("osparc.desktop.credits.Overview", {

__createWalletsView: function() {
const activeWallet = osparc.store.Store.getInstance().getActiveWallet();
const preferredWallet = osparc.desktop.credits.Utils.getFavouriteWallet();
const preferredWallet = osparc.desktop.credits.Utils.getPreferredWallet();
const oneWallet = activeWallet ? activeWallet : preferredWallet;
if (oneWallet) {
// show one wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,27 @@ qx.Class.define("osparc.desktop.credits.UserCenter", {
__openPage: function(page) {
if (page) {
this.__tabsView.setSelection([page]);
return true;
}
return false;
},

openOverview: function() {
if (this.__overviewPage) {
this.__openPage(this.__overviewPage);
} else {
// fallback
this.__openPage(this.__profilePage);
return this.__openPage(this.__overviewPage);
}
// fallback
this.__openPage(this.__profilePage);
return false;
},

openWallets: function() {
if (this.__walletsPage) {
this.__openPage(this.__walletsPage);
} else {
// fallback
this.__openPage(this.__profilePage);
return this.__openPage(this.__walletsPage);
}
// fallback
this.__openPage(this.__profilePage);
return false;
},

__openBuyCredits: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ qx.Class.define("osparc.desktop.credits.UserCenterWindow", {
__userCenter: null,

openOverview: function() {
this.__userCenter.openOverview();
return this.__userCenter.openOverview();
},

openWallets: function() {
this.__userCenter.openWallets();
return this.__userCenter.openWallets();
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ qx.Class.define("osparc.desktop.credits.Utils", {
getWallet: function(walletId) {
const store = osparc.store.Store.getInstance();
const wallets = store.getWallets();
const favouriteWallet = wallets.find(wallet => wallet.getWalletId() === walletId);
if (favouriteWallet) {
return favouriteWallet;
const foundWallet = wallets.find(wallet => wallet.getWalletId() === walletId);
if (foundWallet) {
return foundWallet;
}
return null;
},

getFavouriteWallet: function() {
getPreferredWallet: function() {
const store = osparc.store.Store.getInstance();
const wallets = store.getWallets();
const favouriteWallet = wallets.find(wallet => wallet.isPreferredWallet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ qx.Class.define("osparc.desktop.credits.WalletsMiniViewer", {
this.__walletListeners = [];

this.__buildLayout();

this.addListener("tap", () => {
osparc.desktop.credits.Utils.areWalletsEnabled()
.then(walletsEnabled => {
const creditsWindow = osparc.desktop.credits.UserCenterWindow.openWindow(walletsEnabled);
creditsWindow.openOverview();
});
}, this);
},

properties: {
Expand All @@ -76,15 +68,22 @@ qx.Class.define("osparc.desktop.credits.WalletsMiniViewer", {

__reloadLayout: function() {
const activeWallet = this.getActiveWallet();
const preferredWallet = osparc.desktop.credits.Utils.getFavouriteWallet();
const preferredWallet = osparc.desktop.credits.Utils.getPreferredWallet();
const oneWallet = activeWallet ? activeWallet : preferredWallet;
if (oneWallet) {
this.__showOneWallet(oneWallet);
} else if (osparc.store.Store.getInstance().getWallets().length) {
this.__showAllWallets();
} else {
this.__showNoWallets();
this.__showSelectWallet();
}

const store = osparc.store.Store.getInstance();
store.getWallets().forEach(wallet => {
const preferredWalletId = wallet.addListener("changePreferredWallet", () => this.__reloadLayout());
this.__walletListeners.push({
walletId: wallet.getWalletId(),
listenerId: preferredWalletId
});
});
},

__removeWallets: function() {
Expand All @@ -99,93 +98,51 @@ qx.Class.define("osparc.desktop.credits.WalletsMiniViewer", {
this._removeAll();
},

__showNoWallets: function() {
__showSelectWallet: function() {
this.__removeWallets();

this._add(new qx.ui.core.Spacer(), {
flex: 1
});

const iconSrc = "@MaterialIcons/account_balance_wallet/26";
const walletsButton = new qx.ui.form.Button(null, iconSrc).set({
toolTipText: this.tr("No Wallets"),
backgroundColor: "transparent",
const walletsButton = new qx.ui.basic.Image(iconSrc).set({
toolTipText: this.tr("Select Wallet"),
textColor: "danger-red"
});
walletsButton.addListener("tap", () => {
osparc.desktop.credits.Utils.areWalletsEnabled()
.then(walletsEnabled => {
const creditsWindow = osparc.desktop.credits.UserCenterWindow.openWindow(walletsEnabled);
creditsWindow.openWallets();
const userCenterWindow = osparc.desktop.credits.UserCenterWindow.openWindow(walletsEnabled);
userCenterWindow.openWallets();
});
}, this);
this._add(walletsButton, {
flex: 1
});

this._add(new qx.ui.core.Spacer(), {
flex: 1
});
},

__showOneWallet: function(wallet) {
this.__removeWallets();

this._add(new qx.ui.core.Spacer(), {
flex: 1
});

this.__addWallet(wallet);
this.__addWalletListener(wallet);

this._add(new qx.ui.core.Spacer(), {
flex: 1
});
},

__showAllWallets: function() {
this.__removeWallets();

this._add(new qx.ui.core.Spacer(), {
flex: 1
});

const wallets = osparc.store.Store.getInstance().getWallets();
const maxIndicators = 3;
for (let i=0; i<wallets.length && i<maxIndicators; i++) {
const wallet = wallets[i];
if (wallet.getStatus() === "ACTIVE") {
this.__addWallet(wallet);
}
this.__addWalletListener(wallet);
}

this._add(new qx.ui.core.Spacer(), {
flex: 1
const changeStatusId = wallet.addListener("changeStatus", () => this.__reloadLayout());
this.__walletListeners.push({
walletId: wallet.getWalletId(),
listenerId: changeStatusId
});
},

__addWallet: function(wallet) {
const creditsLabel = new osparc.desktop.credits.CreditsLabel(wallet, true).set({
alignX: "right"
});
creditsLabel.addListener("tap", () => {
osparc.desktop.credits.Utils.areWalletsEnabled()
.then(walletsEnabled => {
const creditsWindow = osparc.desktop.credits.UserCenterWindow.openWindow(walletsEnabled);
creditsWindow.openOverview();
});
}, this);
this._add(creditsLabel, {
flex: 1
});
},

__addWalletListener: function(wallet) {
const changeStatusId = wallet.addListener("changeStatus", () => this.__reloadLayout());
this.__walletListeners.push({
walletId: wallet.getWalletId(),
listenerId: changeStatusId
});

const preferredWalletId = wallet.addListener("changePreferredWallet", () => this.__reloadLayout());
this.__walletListeners.push({
walletId: wallet.getWalletId(),
listenerId: preferredWalletId
});
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
__canIWrite: function() {
const wallet = this.__currentModel;
if (wallet) {
const myAcessRights = wallet.getMyAccessRights();
if (myAcessRights) {
return myAcessRights["write"];
const myAccessRights = wallet.getMyAccessRights();
if (myAccessRights) {
return myAccessRights["write"];
}
}
return false;
Expand Down Expand Up @@ -140,7 +140,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
},

__getRolesToolbar: function() {
return osparc.data.Roles.createRolesWalleltInfo();
return osparc.data.Roles.createRolesWalletInfo();
},

__getMembersFilter: function() {
Expand All @@ -152,15 +152,15 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
},

__getMembersList: function() {
const memebersUIList = new qx.ui.form.List().set({
const membersUIList = new qx.ui.form.List().set({
decorator: "no-border",
spacing: 3,
width: 150,
backgroundColor: "background-main-2"
});

const membersModel = this.__membersModel = new qx.data.Array();
const membersCtrl = new qx.data.controller.List(membersModel, memebersUIList, "name");
const membersCtrl = new qx.data.controller.List(membersModel, membersUIList, "name");
membersCtrl.setDelegate({
createItem: () => new osparc.desktop.wallets.MemberListItem(),
bindItem: (ctrl, item, id) => {
Expand Down Expand Up @@ -195,7 +195,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
}
});

return memebersUIList;
return membersUIList;
},

__reloadWalletMembers: async function() {
Expand Down Expand Up @@ -276,6 +276,19 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
cb();
}
});

// push 'WALLET_SHARED' notification
osparc.store.Store.getInstance().getPotentialCollaborators()
.then(potentialCollaborators => {
gids.forEach(gid => {
if (gid in potentialCollaborators && "id" in potentialCollaborators[gid]) {
// it's a user, not an organization
const collab = potentialCollaborators[gid];
const uid = collab["id"];
osparc.notification.Notifications.postNewWallet(uid, wallet.getWalletId());
}
});
});
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ qx.Class.define("osparc.notification.Notification", {
"NEW_ORGANIZATION",
"STUDY_SHARED",
"TEMPLATE_SHARED",
"ANNOTATION_NOTE"
"ANNOTATION_NOTE",
"WALLET_SHARED"
],
init: null,
nullable: false,
Expand Down
Loading

0 comments on commit a13e39c

Please sign in to comment.