Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Frontend: Simpler credits workflow #4846

Merged
merged 18 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1225,54 +1225,6 @@ qx.Class.define("osparc.data.Resources", {
return this.getInstance().get(resource, params, useCache);
},

dummy: {
newWalletData: function() {
return {
"walletId": Math.floor(Math.random() * 1000),
name: "New Wallet",
description: "",
thumbnail: null,
owner: null,
"availableCredits": 0,
status: "ACTIVE",
accessRights: []
};
},

getUsageDetailed: function() {
return new Promise(resolve => {
resolve([{
"studyName": "Prj_1",
"jobType": "MESH",
"start": "2023-06-05T09:35:29.026Z",
"end": "2023-06-05T09:40:29.026Z",
"duration": 277233,
"computingTime": 1200000,
"numberOfCores": 4,
"status": "FINISHED"
}, {
"studyName": "Prj_1",
"jobType": "SIMULATION",
"start": "2023-06-06T09:35:29.026Z",
"end": "2023-06-06T09:40:29.026Z",
"duration": 1429861,
"computingTime": 11520000,
"numberOfCores": 8,
"status": "FINISHED"
}, {
"studyName": "Prj_2",
"jobType": "SIMULATION",
"start": "2023-06-06T10:37:29.026Z",
"end": "2023-06-06T10:42:29.026Z",
"duration": 1182460,
"computingTime": 9600000,
"numberOfCores": 8,
"status": "CANCELED"
}]);
});
}
},

getServiceUrl: function(key, version) {
return {
"key": encodeURIComponent(key),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@ qx.Class.define("osparc.data.model.Wallet", {
}
},

members: {
getMyAccessRights: function() {
statics: {
getMyAccessRights: function(accessRights) {
const myGid = osparc.auth.Data.getInstance().getGroupId();
if (myGid && this.getAccessRights()) {
return this.getAccessRights().find(accessRight => accessRight["gid"] === myGid);
if (myGid && accessRights) {
return accessRights.find(aR => aR["gid"] === myGid);
}
return null;
}
},

members: {
getMyAccessRights: function() {
return this.self().getMyAccessRights(this.getAccessRights());
},

serialize: function() {
return JSON.parse(qx.util.Serializer.toJson(this));
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ qx.Class.define("osparc.desktop.credits.Overview", {
height: 25
});
const myAccessRights = wallet.getMyAccessRights();
buyButton.setVisibility(myAccessRights && myAccessRights["write"] ? "visible" : "excluded");
buyButton.setEnabled(Boolean(myAccessRights && myAccessRights["write"]));
buyButton.addListener("execute", () => this.fireDataEvent("buyCredits", {
walletId: wallet.getWalletId()
}), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
allowGrowX: false
});
addMemberBtn.addListener("execute", () => {
const collaboratorsManager = new osparc.share.NewCollaboratorsManager(this._serializedData);
const serializedData = this.__currentModel.serialize();
serializedData["resourceType"] = "wallet";
const showOrganizations = false;
const collaboratorsManager = new osparc.share.NewCollaboratorsManager(serializedData, showOrganizations);
collaboratorsManager.addListener("addCollaborators", e => {
const cb = () => collaboratorsManager.close();
this.__addMembers(e.getData(), cb);
Expand Down Expand Up @@ -207,6 +210,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
return;
}

const myGroupId = osparc.auth.Data.getInstance().getGroupId();
const membersList = [];
const potentialCollaborators = await osparc.store.Store.getInstance().getPotentialCollaborators(true);
const canIWrite = wallet.getMyAccessRights()["write"];
Expand All @@ -224,16 +228,19 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
let options = [];
if (canIWrite) {
// accountant...
if (collaborator["accessRights"]["write"]) {
if (gid === myGroupId) {
// it's me
options = [];
} else if (collaborator["accessRights"]["write"]) {
// ...on accountant
options = [
"demoteToMember",
// "demoteToMember", // only allow one Accountant per Wallet, we shouldn't get here
"removeMember"
];
} else if (collaborator["accessRights"]["read"]) {
// ...on member
options = [
"promoteToAccountant",
// "promoteToAccountant", // only allow one Accountant per Wallet
"removeMember"
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ qx.Class.define("osparc.desktop.wallets.WalletListItem", {
alignY: "middle",
visibility: "hidden"
});
this.bind("accessRights", control, "enabled", {
converter: accessRights => {
const myAr = osparc.data.model.Wallet.getMyAccessRights(accessRights);
return Boolean(myAr && myAr["write"]);
}
});
control.addListener("execute", () => this.fireDataEvent("buyCredits", {
walletId: this.getKey()
}), this);
Expand Down Expand Up @@ -260,20 +266,22 @@ qx.Class.define("osparc.desktop.wallets.WalletListItem", {

__applyPreferredWallet: function(isPreferredWallet) {
const favouriteButton = this.getChildControl("favourite-button");
favouriteButton.setBackgroundColor("transparent");
const favouriteButtonIcon = favouriteButton.getChildControl("icon");
if (isPreferredWallet) {
this.setToolTipText(this.tr("Default Credit Account"));
favouriteButton.set({
label: this.tr("Primary"),
icon: "@FontAwesome5Solid/toggle-on/20",
backgroundColor: "strong-main"
toolTipText: this.tr("Default Credit Account"),
odeimaiz marked this conversation as resolved.
Show resolved Hide resolved
icon: "@FontAwesome5Solid/toggle-on/20"
});
favouriteButtonIcon.setTextColor("strong-main");
} else {
this.setToolTipText(this.tr("Make it Default Credit Account"));
favouriteButton.set({
label: this.tr("Secondary"),
icon: "@FontAwesome5Solid/toggle-off/20",
backgroundColor: null
toolTipText: this.tr("Make it Default Credit Account"),
icon: "@FontAwesome5Solid/toggle-off/20"
});
favouriteButtonIcon.setTextColor("text");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", {
flex: 1
});

// Disabled until create a New Wallet is enabled
/*
const newWalletButton = this.__getCreateWalletSection();
newWalletButton.setVisibility(osparc.data.Permissions.getInstance().canDo("user.wallets.create") ? "visible" : "excluded");
this._add(newWalletButton);
*/

this.loadWallets();
},
Expand Down Expand Up @@ -109,7 +112,7 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", {
__getCreateWalletSection: function() {
const createWalletBtn = new qx.ui.form.Button().set({
appearance: "strong-button",
label: this.tr("New Wallet"),
label: this.tr("New Credit Account"),
odeimaiz marked this conversation as resolved.
Show resolved Hide resolved
alignX: "center",
icon: "@FontAwesome5Solid/plus/14",
allowGrowX: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Elements in the tree also accept Drag and/or Drop mechanisms which are implemented here.
* "osparc-file-link" type is used for the Drag&Drop.
*
* If a file is dropped into a folder, this class will start the copying proccess fireing
* If a file is dropped into a folder, this class will start the copying process firing
* "fileCopied" event if successful
*
* Also provides two static methods for checking whether en entry in the tree is File/Directory
Expand Down Expand Up @@ -68,7 +68,7 @@ qx.Class.define("osparc.file.FilesTree", {
init: false
},

dropMechnism: {
dropMechanism: {
check: "Boolean",
init: false
}
Expand Down Expand Up @@ -217,11 +217,11 @@ qx.Class.define("osparc.file.FilesTree", {
},

__resetTree: function(treeName) {
// FIXME: It is not reseting the model
// FIXME: It is not resetting the model
this.resetModel();
const rootData = {
label: treeName,
itemId: treeName.replace(/\s/g, ""), // remove all whitespaces
itemId: treeName.replace(/\s/g, ""), // remove all white spaces
location: null,
path: null,
pathLabel: [treeName],
Expand Down Expand Up @@ -609,7 +609,7 @@ qx.Class.define("osparc.file.FilesTree", {
this.__createDragMechanism(item);
}

if (this.isDropMechnism()) {
if (this.isDropMechanism()) {
this.__createDropMechanism(item);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
let existingCollabs = [];
if (this.__resourceData) {
if (this.__resourceData["accessRights"]) {
// study/template
existingCollabs = Object.keys(this.__resourceData["accessRights"]);
// study/template/wallet
if (this.__resourceData["resourceType"] === "wallet") {
// array of objects
existingCollabs = this.__resourceData["accessRights"].map(collab => collab["gid"]);
} else {
// object
existingCollabs = Object.keys(this.__resourceData["accessRights"]);
}
} else if (this.__resourceData["access_rights"]) {
// service
// object
existingCollabs = Object.keys(this.__resourceData["access_rights"]);
}
}
Expand Down