Skip to content

Commit 493be5b

Browse files
authored
Fixed cached classifiers (#1755)
* fixed replicated classifiers cache
1 parent bc60e03 commit 493be5b

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
lines changed

services/web/client/source/class/osparc/component/export/Permissions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ qx.Class.define("osparc.component.export.Permissions", {
3737
statics: {
3838
canDelete: function(accessRights) {
3939
let canDelete = accessRights.getDelete ? accessRights.getDelete() : false;
40-
canDelete = !canDelete && accessRights.getWrite_access ? accessRights.getWrite_access() : false;
40+
canDelete = canDelete || (accessRights.getWrite_access ? accessRights.getWrite_access() : false);
4141
return canDelete;
4242
},
4343

4444
canWrite: function(accessRights) {
4545
let canWrite = accessRights.getWrite ? accessRights.getWrite() : false;
46-
canWrite = !canWrite && accessRights.getWrite_access ? accessRights.getWrite_access() : false;
46+
canWrite = canWrite || (accessRights.getWrite_access ? accessRights.getWrite_access() : false);
4747
return canWrite;
4848
},
4949

5050
canView: function(accessRights) {
5151
let canView = accessRights.getRead ? accessRights.getRead() : false;
52-
canView = !canView && accessRights.getExecute_access ? accessRights.getExecute_access() : false;
52+
canView = canView || (accessRights.getExecute_access ? accessRights.getExecute_access() : false);
5353
return canView;
5454
}
5555
},

services/web/client/source/class/osparc/data/Resources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ qx.Class.define("osparc.data.Resources", {
192192
* GROUPS/DAGS
193193
*/
194194
"dags": {
195-
usesCache: true,
195+
useCache: true,
196196
idField: "key",
197197
endpoints: {
198198
post: {
@@ -342,7 +342,7 @@ qx.Class.define("osparc.data.Resources", {
342342
* Gets the json object containing sample classifiers
343343
*/
344344
"classifiers": {
345-
useCache: true,
345+
useCache: false,
346346
idField: "classifiers",
347347
endpoints: {
348348
get: {

services/web/client/source/class/osparc/store/Store.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ qx.Class.define("osparc.store.Store", {
115115
init: {}
116116
},
117117
classifiers: {
118-
check: "Object",
119-
init: {}
118+
check: "Array",
119+
init: []
120120
}
121121
},
122122

@@ -460,6 +460,55 @@ qx.Class.define("osparc.store.Store", {
460460
});
461461
},
462462

463+
__getOrgClassifiers: function(orgId) {
464+
const params = {
465+
url: {
466+
"gid": orgId
467+
}
468+
};
469+
return osparc.data.Resources.get("classifiers", params);
470+
},
471+
472+
getAllClassifiers: function(reload = false) {
473+
return new Promise((resolve, reject) => {
474+
const oldClassifiers = this.getClassifiers();
475+
if (!reload && oldClassifiers.length) {
476+
resolve(oldClassifiers);
477+
return;
478+
}
479+
osparc.store.Store.getInstance().getGroupsOrganizations()
480+
.then(orgs => {
481+
const allClassifiers = [];
482+
if (orgs.length === 0) {
483+
this.setClassifiers(allClassifiers);
484+
resolve(allClassifiers);
485+
return;
486+
}
487+
const classifierPromises = [];
488+
orgs.forEach(org => {
489+
classifierPromises.push(this.__getOrgClassifiers(org["gid"]));
490+
});
491+
Promise.all(classifierPromises)
492+
.then(classifierss => {
493+
if (classifierss.length === 0) {
494+
this.setClassifiers(allClassifiers);
495+
resolve(allClassifiers);
496+
return;
497+
}
498+
classifierss.forEach(({classifiers}) => {
499+
if (classifiers) {
500+
Object.keys(classifiers).forEach(key => {
501+
allClassifiers.push(classifiers[key]);
502+
});
503+
}
504+
});
505+
this.setClassifiers(allClassifiers);
506+
resolve(allClassifiers);
507+
});
508+
});
509+
});
510+
},
511+
463512
_applyStudy: function(newStudy) {
464513
if (newStudy) {
465514
this.setCurrentStudyId(newStudy.getStudyId());

services/web/client/source/class/osparc/utils/Classifiers.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,16 @@ qx.Class.define("osparc.utils.Classifiers", {
3030
label: "root",
3131
children: []
3232
};
33-
osparc.store.Store.getInstance().getGroupsOrganizations()
34-
.then(orgs => {
35-
if (orgs.length === 0) {
36-
reject();
37-
return;
33+
osparc.store.Store.getInstance().getAllClassifiers()
34+
.then(classifiers => {
35+
const keys = Object.keys(classifiers);
36+
if (keys.length) {
37+
// Tree-ify
38+
const tree = {};
39+
keys.forEach(key => this.__buildTree(classifiers, key, classifiers[key].classifier.split("::"), tree));
40+
rootData.children.push(...this.__virtualTree(tree));
3841
}
39-
const classifierPromises = [];
40-
orgs.forEach(org => {
41-
const params = {
42-
url: {
43-
"gid": org["gid"]
44-
}
45-
};
46-
classifierPromises.push(osparc.data.Resources.get("classifiers", params));
47-
});
48-
Promise.all(classifierPromises)
49-
.then(classifierss => {
50-
if (classifierss.length === 0) {
51-
reject();
52-
return;
53-
}
54-
classifierss.forEach(({classifiers}) => {
55-
const keys = Object.keys(classifiers);
56-
if (keys.length) {
57-
// Tree-ify
58-
const tree = {};
59-
keys.forEach(key => this.__buildTree(classifiers, key, classifiers[key].classifier.split("::"), tree));
60-
rootData.children.push(...this.__virtualTree(tree));
61-
}
62-
});
63-
resolve(rootData);
64-
});
42+
resolve(rootData);
6543
});
6644
});
6745
},

0 commit comments

Comments
 (0)