Skip to content

Commit 245036e

Browse files
authored
🎨 [Frontend] UX: Join project with assigned wallet (#8324)
1 parent c500c52 commit 245036e

File tree

5 files changed

+86
-36
lines changed

5 files changed

+86
-36
lines changed

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,20 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
121121

122122
const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
123123
if (walletsEnabled) {
124-
osparc.store.Study.getInstance().getWallet(studyId)
125-
.then(wallet => {
124+
Promise.all([
125+
osparc.store.Study.getInstance().getWallet(studyId),
126+
osparc.store.Study.getInstance().getOne(studyId),
127+
]).then(([wallet, latestStudyData]) => {
128+
const currentUserGroupIds = osparc.study.Utils.state.getCurrentGroupIds(latestStudyData["state"]);
126129
if (
127130
isStudyCreation ||
128131
wallet === null ||
129-
osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null
132+
(osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null && currentUserGroupIds.length === 0)
130133
) {
131-
// pop up study options if the study was just created or if it has no wallet assigned or user has no access to it
134+
// pop up StudyOptions if:
135+
// - the study was just created
136+
// - it has no wallet assigned
137+
// - I do not have access to it and the project is not being used
132138
const resourceSelector = new osparc.study.StudyOptions(studyId);
133139
if (isStudyCreation) {
134140
resourceSelector.getChildControl("open-button").setLabel(qx.locale.Manager.tr("New"));
@@ -157,7 +163,28 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
157163
}
158164
});
159165
} else {
160-
openStudy();
166+
const found = osparc.store.Store.getInstance().getWallets().find(w => w.getWalletId() === wallet["walletId"]);
167+
if (found) {
168+
// I have access to the wallet
169+
if (osparc.store.Store.getInstance().getContextWallet() !== found) {
170+
// switch to that wallet and inform the user that the context wallet has changed
171+
const text = qx.locale.Manager.tr("Switched to Credit Account") + " '" + found.getName() + "'";
172+
osparc.FlashMessenger.logAs(text);
173+
}
174+
osparc.store.Store.getInstance().setActiveWallet(found);
175+
openStudy();
176+
} else {
177+
// I do not have access to the wallet or it's being used
178+
// cancel and explain the user why
179+
const isRTCEnabled = osparc.utils.DisabledPlugins.isRTCEnabled();
180+
const msg = isRTCEnabled ?
181+
qx.locale.Manager.tr("You can't join the project because you don't have access to the Credit Account associated with it. Please contact the project owner.") :
182+
qx.locale.Manager.tr("You can't join the project because it's already open by another user.");
183+
osparc.FlashMessenger.logAs(msg, "ERROR");
184+
if (cancelCB) {
185+
cancelCB();
186+
}
187+
}
161188
}
162189
});
163190
} else {
@@ -196,7 +223,22 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
196223
osparc.utils.Utils.addBorderRightRadius(rButton);
197224
}
198225
return rButton;
199-
}
226+
},
227+
228+
getOpenText: function(resourceData) {
229+
const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
230+
let openText = qx.locale.Manager.tr("New") + " " + studyAlias;
231+
if (resourceData["resourceType"] === "study") {
232+
// if it's in use call it join
233+
const isRTCEnabled = osparc.utils.DisabledPlugins.isRTCEnabled();
234+
if (osparc.study.Utils.state.getCurrentGroupIds(resourceData["state"]).length && isRTCEnabled) {
235+
openText = qx.locale.Manager.tr("Join");
236+
} else {
237+
openText = qx.locale.Manager.tr("Open");
238+
}
239+
}
240+
return openText;
241+
},
200242
},
201243

202244
members: {
@@ -899,8 +941,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
899941
},
900942

901943
_getOpenMenuButton: function(resourceData) {
902-
const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
903-
const openText = (resourceData["resourceType"] === "study") ? this.tr("Open") : this.tr("New") + " " + studyAlias;
944+
const openText = osparc.dashboard.ResourceBrowserBase.getOpenText(resourceData);
904945
const openButton = new qx.ui.menu.Button(openText);
905946
openButton["openResourceButton"] = true;
906947
openButton.addListener("execute", () => {

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
157157
maxHeight: 40
158158
});
159159
return toolbar;
160-
}
160+
},
161+
162+
disableIfInUse: function(resourceData, widget) {
163+
if (resourceData["resourceType"] === "study") {
164+
// disable if it's being used
165+
widget.setEnabled(!osparc.study.Utils.state.getCurrentGroupIds(resourceData["state"]).length);
166+
}
167+
},
161168
},
162169

163170
properties: {
@@ -225,8 +232,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
225232
toolbar.add(serviceVersionSelector);
226233
}
227234

228-
const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
229-
const openText = (this.__resourceData["resourceType"] === "study") ? this.tr("Open") : this.tr("New") + " " + studyAlias;
235+
const openText = osparc.dashboard.ResourceBrowserBase.getOpenText(this.__resourceData);
230236
const openButton = new osparc.ui.form.FetchButton(openText).set({
231237
enabled: true
232238
});
@@ -536,6 +542,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
536542

537543
const lazyLoadContent = () => {
538544
const billingSettings = new osparc.study.BillingSettings(resourceData);
545+
this.self().disableIfInUse(resourceData, billingSettings);
539546
billingSettings.addListener("debtPayed", () => {
540547
page.payDebtButton.set({
541548
visibility: osparc.study.Utils.isInDebt(resourceData) ? "visible" : "excluded"
@@ -785,6 +792,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
785792

786793
const lazyLoadContent = () => {
787794
const servicesUpdate = new osparc.metadata.ServicesInStudyUpdate(resourceData);
795+
this.self().disableIfInUse(resourceData, servicesUpdate);
788796
servicesUpdate.addListener("updateService", e => {
789797
const updatedData = e.getData();
790798
this.__fireUpdateEvent(resourceData, updatedData);
@@ -818,6 +826,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
818826

819827
const lazyLoadContent = () => {
820828
const servicesBootOpts = new osparc.metadata.ServicesInStudyBootOpts(resourceData);
829+
this.self().disableIfInUse(resourceData, servicesBootOpts);
821830
servicesBootOpts.addListener("updateService", e => {
822831
const updatedData = e.getData();
823832
this.__fireUpdateEvent(resourceData, updatedData);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ qx.Class.define("osparc.desktop.wallets.WalletListItem", {
153153
rowSpan: 2
154154
});
155155
break;
156-
case "favourite-button":
156+
case "preferred-button":
157157
control = new qx.ui.form.Button().set({
158158
iconPosition: "right",
159159
width: 110, // make Primary and Secondary buttons same width
@@ -326,8 +326,11 @@ qx.Class.define("osparc.desktop.wallets.WalletListItem", {
326326
},
327327

328328
__applyPreferredWallet: function(isPreferredWallet) {
329-
const favouriteButton = this.getChildControl("favourite-button");
330-
favouriteButton.setBackgroundColor("transparent");
329+
const favouriteButton = this.getChildControl("preferred-button");
330+
favouriteButton.set({
331+
backgroundColor: "transparent",
332+
width: 60,
333+
});
331334
const favouriteButtonIcon = favouriteButton.getChildControl("icon");
332335
if (isPreferredWallet) {
333336
favouriteButton.set({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", {
229229
flex: 1
230230
});
231231
if (showCurrently) {
232-
const selectColumn = new qx.ui.basic.Label(this.tr("Currently in use")).set({
233-
marginRight: 18
232+
const selectColumn = new qx.ui.basic.Label(this.tr("Preferred")).set({
233+
marginRight: 8 // align it with the "preferred-button"
234234
});
235235
header.add(selectColumn)
236236
}

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -375,37 +375,34 @@ qx.Class.define("osparc.study.Utils", {
375375
},
376376

377377
state: {
378+
__getShareState: function(state) {
379+
if (state && "shareState" in state) {
380+
return state["shareState"];
381+
}
382+
return null;
383+
},
384+
378385
getProjectStatus: function(state) {
379-
if (
380-
state &&
381-
"shareState" in state &&
382-
"status" in state["shareState"]
383-
) {
384-
return state["shareState"]["status"];
386+
const shareState = this.__getShareState(state);
387+
if (shareState && "status" in shareState) {
388+
return shareState["status"];
385389
}
386390
return null;
387391
},
388392

389393
isProjectLocked: function(state) {
390-
if (
391-
state &&
392-
"shareState" in state &&
393-
"locked" in state["shareState"]
394-
) {
395-
return state["shareState"]["locked"];
394+
const shareState = this.__getShareState(state);
395+
if (shareState && "locked" in shareState) {
396+
return shareState["locked"];
396397
}
397398
return false;
398399
},
399400

400401
getCurrentGroupIds: function(state) {
401-
if (
402-
state &&
403-
"shareState" in state &&
404-
"currentUserGroupids" in state["shareState"]
405-
) {
406-
return state["shareState"]["currentUserGroupids"];
402+
const shareState = this.__getShareState(state);
403+
if (shareState && "currentUserGroupids" in shareState) {
404+
return shareState["currentUserGroupids"];
407405
}
408-
409406
return [];
410407
},
411408

@@ -449,7 +446,7 @@ qx.Class.define("osparc.study.Utils", {
449446
return "UNKNOWN_SERVICES";
450447
}
451448
}
452-
if (studyData["state"] && studyData["state"]["shareState"] && studyData["state"]["shareState"]["locked"]) {
449+
if (this.state.isProjectLocked(studyData["state"])) {
453450
return "IN_USE";
454451
}
455452
if (this.isInDebt(studyData)) {

0 commit comments

Comments
 (0)