Skip to content

Commit eff1787

Browse files
authored
Merge branch 'master' into pr-osparc-download-link-in-folder
2 parents 58df48f + 82edbc1 commit eff1787

File tree

17 files changed

+383
-290
lines changed

17 files changed

+383
-290
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,25 @@ qx.Class.define("osparc.component.study.ResourceSelector", {
340340

341341
const openButton = this.getChildControl("open-button");
342342
openButton.addListener("execute", () => {
343-
this.fireEvent("startStudy");
344-
345-
store.setActiveWallet(this.getWallet());
343+
const selection = this.getChildControl("wallet-selector").getSelection();
344+
if (selection.length) {
345+
const params = {
346+
url: {
347+
"studyId": this.__studyData["uuid"],
348+
"walletId": selection[0]["walletId"]
349+
}
350+
};
351+
osparc.data.Resources.fetch("studies", "selectWallet", params)
352+
.then(() => {
353+
store.setActiveWallet(this.getWallet());
354+
this.fireEvent("startStudy");
355+
})
356+
.catch(err => {
357+
console.error(err);
358+
const msg = err.message || this.tr("Error selecting Wallet");
359+
osparc.component.message.FlashMessenger.getInstance().logAs(msg, "ERROR");
360+
});
361+
}
346362
});
347363

348364
const cancelButton = this.getChildControl("cancel-button");

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 36 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ qx.Class.define("osparc.data.Resources", {
103103
method: "POST",
104104
url: statics.API + "/projects/{studyId}:open"
105105
},
106+
selectWallet: {
107+
method: "PUT",
108+
url: statics.API + "/projects/{studyId}/wallet/{walletId}"
109+
},
106110
openDisableAutoStart: {
107111
method: "POST",
108112
url: statics.API + "/projects/{studyId}:open?disable_service_auto_start={disableServiceAutoStart}"
@@ -597,17 +601,29 @@ qx.Class.define("osparc.data.Resources", {
597601
method: "GET",
598602
url: statics.API + "/wallets"
599603
},
600-
getOne: {
601-
method: "GET",
602-
url: statics.API + "/wallets/{walletId}"
603-
},
604604
post: {
605605
method: "POST",
606606
url: statics.API + "/wallets"
607607
},
608-
patch: {
609-
method: "PATCH",
608+
put: {
609+
method: "PUT",
610610
url: statics.API + "/wallets/{walletId}"
611+
},
612+
getAccessRights: {
613+
method: "GET",
614+
url: statics.API + "/wallets/{walletId}/groups"
615+
},
616+
putAccessRights: {
617+
method: "PUT",
618+
url: statics.API + "/wallets/{walletId}/groups/{groupId}"
619+
},
620+
postAccessRights: {
621+
method: "POST",
622+
url: statics.API + "/wallets/{walletId}/groups/{groupId}"
623+
},
624+
deleteAccessRights: {
625+
method: "DELETE",
626+
url: statics.API + "/wallets/{walletId}/groups/{groupId}"
611627
}
612628
}
613629
},
@@ -909,15 +925,17 @@ qx.Class.define("osparc.data.Resources", {
909925
osparc.component.metadata.Quality.attachQualityToObject(data);
910926
}
911927
}
912-
if (endpoint.includes("delete")) {
913-
this.__removeCached(resource, deleteId);
914-
} else if (useCache && endpointDef.method === "POST" && options.pollTask !== true) {
915-
this.__addCached(resource, data);
916-
} else if (useCache && endpointDef.method === "GET") {
917-
if (endpoint.includes("getPage")) {
928+
if (useCache) {
929+
if (endpoint.includes("delete")) {
930+
this.__removeCached(resource, deleteId);
931+
} else if (endpointDef.method === "POST" && options.pollTask !== true) {
918932
this.__addCached(resource, data);
919-
} else {
920-
this.__setCached(resource, data);
933+
} else if (endpointDef.method === "GET") {
934+
if (endpoint.includes("getPage")) {
935+
this.__addCached(resource, data);
936+
} else {
937+
this.__setCached(resource, data);
938+
}
921939
}
922940
}
923941
res.dispose();
@@ -1098,114 +1116,17 @@ qx.Class.define("osparc.data.Resources", {
10981116
dummy: {
10991117
newWalletData: function() {
11001118
return {
1101-
id: Math.floor(Math.random() * 1000),
1119+
"wallet_id": Math.floor(Math.random() * 1000),
11021120
name: "New Wallet",
11031121
description: "",
11041122
thumbnail: null,
1105-
type: "shared",
11061123
owner: null,
1107-
accessRights: {},
1108-
credits: {
1109-
left: 0
1110-
},
1111-
active: true
1124+
"available_credits": 0,
1125+
status: "ACTIVE",
1126+
accessRights: []
11121127
};
11131128
},
11141129

1115-
addWalletsToStore: function() {
1116-
const store = osparc.store.Store.getInstance();
1117-
osparc.data.Resources.dummy.getWallets()
1118-
.then(walletsData => {
1119-
if (walletsData && "wallets" in walletsData && walletsData["wallets"].length) {
1120-
const wallets = [];
1121-
walletsData["wallets"].forEach(walletData => {
1122-
const wallet = new osparc.data.model.Wallet(walletData);
1123-
wallets.push(wallet);
1124-
});
1125-
store.setWallets(wallets);
1126-
setInterval(() => {
1127-
store.getWallets().forEach(wallet => {
1128-
wallet.setCredits(wallet.getCredits()-1);
1129-
});
1130-
}, 30000);
1131-
}
1132-
})
1133-
.catch(err => console.error(err));
1134-
},
1135-
1136-
getWallets: function() {
1137-
const myGid = osparc.auth.Data.getInstance().getGroupId();
1138-
return new Promise(resolve => {
1139-
resolve({
1140-
wallets: [{
1141-
id: 1,
1142-
name: "My Wallet",
1143-
description: "Personal Wallet",
1144-
thumbnail: null,
1145-
type: "personal",
1146-
owner: myGid,
1147-
accessRights: {
1148-
[myGid]: {
1149-
delete: true,
1150-
write: true,
1151-
read: true
1152-
}
1153-
},
1154-
credits: {
1155-
left: 10
1156-
},
1157-
active: true
1158-
}, {
1159-
id: 2,
1160-
name: "Our Wallet",
1161-
description: "Organization wide Wallet",
1162-
thumbnail: null,
1163-
type: "shared",
1164-
owner: myGid,
1165-
accessRights: {
1166-
[myGid]: {
1167-
delete: false,
1168-
write: true,
1169-
read: true
1170-
},
1171-
417: {
1172-
delete: false,
1173-
write: false,
1174-
read: true
1175-
}
1176-
},
1177-
credits: {
1178-
left: 100
1179-
},
1180-
active: true
1181-
}, {
1182-
id: 3,
1183-
name: "Another Wallet",
1184-
description: "Organization wide Wallet 2",
1185-
thumbnail: null,
1186-
type: "shared",
1187-
owner: 417,
1188-
accessRights: {
1189-
417: {
1190-
delete: true,
1191-
write: true,
1192-
read: true
1193-
},
1194-
[myGid]: {
1195-
delete: false,
1196-
write: false,
1197-
read: true
1198-
}
1199-
},
1200-
credits: {
1201-
left: 1000
1202-
},
1203-
active: true
1204-
}]
1205-
});
1206-
});
1207-
},
1208-
12091130
getUsageDetailed: function() {
12101131
return new Promise(resolve => {
12111132
resolve([{

services/static-webserver/client/source/class/osparc/data/model/Wallet.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ qx.Class.define("osparc.data.model.Wallet", {
2222
this.base(arguments);
2323

2424
this.set({
25-
walletId: walletData["id"],
25+
walletId: walletData["wallet_id"],
2626
name: walletData["name"],
2727
description: walletData["description"] ? walletData["description"] : null,
2828
thumbnail: walletData["thumbnail"] ? walletData["thumbnail"] : null,
29-
walletType: walletData["type"] ? walletData["type"] : "personal",
30-
accessRights: walletData["accessRights"],
31-
credits: walletData["credits"] && walletData["credits"]["left"] ? walletData["credits"]["left"] : 0,
32-
active: walletData["active"] ? walletData["active"] : false
29+
owner: walletData["owner"] ? walletData["owner"] : null,
30+
status: walletData["status"] ? walletData["status"] : false,
31+
creditsAvailable: walletData["available_credits"] ? walletData["available_credits"] : 20,
32+
accessRights: walletData["accessRights"] ? walletData["accessRights"] : []
3333
});
3434
},
3535

@@ -51,7 +51,7 @@ qx.Class.define("osparc.data.model.Wallet", {
5151
description: {
5252
check: "String",
5353
init: "",
54-
nullable: false,
54+
nullable: true,
5555
event: "changeDescription"
5656
},
5757

@@ -62,32 +62,42 @@ qx.Class.define("osparc.data.model.Wallet", {
6262
event: "changeThumbnail"
6363
},
6464

65-
walletType: {
66-
check: ["personal", "shared"],
67-
init: "personal",
65+
owner: {
66+
check: "Number",
67+
init: null,
6868
nullable: false,
69-
event: "changeWalletType"
69+
event: "changeOwner"
7070
},
7171

72-
accessRights: {
73-
check: "Object",
74-
init: null,
72+
status: {
73+
check: ["ACTIVE", "INACTIVE"],
74+
init: false,
7575
nullable: false,
76-
event: "changeAccessRights"
76+
event: "changeStatus"
7777
},
7878

79-
credits: {
79+
creditsAvailable: {
8080
check: "Number",
8181
init: 0,
8282
nullable: false,
83-
event: "changeCredits"
83+
event: "changeCreditsAvailable"
8484
},
8585

86-
active: {
87-
check: "Boolean",
88-
init: false,
86+
accessRights: {
87+
check: "Array",
88+
init: null,
8989
nullable: false,
90-
event: "changeActive"
90+
event: "changeAccessRights"
91+
}
92+
},
93+
94+
members: {
95+
getMyAccessRights: function() {
96+
const myGid = osparc.auth.Data.getInstance().getGroupId();
97+
if (myGid && this.getAccessRights()) {
98+
return this.getAccessRights().find(accessRight => accessRight["gid"] === myGid);
99+
}
100+
return null;
91101
}
92102
}
93103
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ qx.Class.define("osparc.desktop.MainPage", {
5454
osparc.WindowSizeTracker.getInstance().startTracker();
5555
osparc.MaintenanceTracker.getInstance().startTracker();
5656

57-
osparc.data.Resources.dummy.addWalletsToStore();
58-
5957
const store = osparc.store.Store.getInstance();
58+
store.reloadWallets();
6059

6160
Promise.all([
6261
store.getAllClassifiers(true),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ qx.Class.define("osparc.desktop.credits.BuyCredits", {
436436
msg += "<br>";
437437
msg += "You now have " + nCredits + " more credits";
438438
osparc.component.message.FlashMessenger.getInstance().logAs(msg, "INFO", null, 10000);
439-
wallet.setCredits(wallet.getCredits() + nCredits);
439+
wallet.setCreditsAvailable(wallet.getCreditsAvailable() + nCredits);
440440
this.fireDataEvent("transactionSuccessful", {
441441
nCredits,
442442
totalPrice,

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ qx.Class.define("osparc.desktop.credits.CreditsIndicator", {
6565
apply: "__applyWallet"
6666
},
6767

68-
credits: {
68+
creditsAvailable: {
6969
check: "Number",
7070
init: 0,
7171
nullable: false,
7272
event: "changeCredits",
73-
apply: "__applyCredits"
73+
apply: "__applyCreditsAvailable"
7474
}
7575
},
7676

@@ -87,24 +87,24 @@ qx.Class.define("osparc.desktop.credits.CreditsIndicator", {
8787
members: {
8888
__applyWallet: function(wallet) {
8989
if (wallet) {
90-
wallet.bind("credits", this, "credits");
91-
wallet.bind("credits", this, "toolTipText", {
90+
wallet.bind("creditsAvailable", this, "creditsAvailable");
91+
wallet.bind("creditsAvailable", this, "toolTipText", {
9292
converter: val => wallet.getName() + ": " + val + " credits left"
9393
});
9494
}
9595
},
9696

97-
__applyCredits: function(credits) {
98-
if (credits !== null) {
99-
this.setValue(this.self().convertCreditsToIndicatorValue(credits));
97+
__applyCreditsAvailable: function(creditsAvailable) {
98+
if (creditsAvailable !== null) {
99+
this.setValue(this.self().convertCreditsToIndicatorValue(creditsAvailable));
100100

101-
if (credits <= 0) {
101+
if (creditsAvailable <= 0) {
102102
this.setBackgroundColor("danger-red");
103103
} else {
104104
this.resetBackgroundColor();
105105
}
106106

107-
let tttext = credits + " " + this.tr("credits left");
107+
let tttext = creditsAvailable + " " + this.tr("credits left");
108108
if (this.getWallet()) {
109109
tttext = this.getWallet().getName() + ": " + tttext;
110110
}

0 commit comments

Comments
 (0)