Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -1430,6 +1430,8 @@ qx.Class.define("osparc.data.Resources", {
},

members: {
__portsCompatibilityPromisesCached: null,

/**
* @param {String} resource Name of the resource as defined in the static property 'resources'.
* @param {String} endpoint Name of the endpoint. Several endpoints can be defined for each resource.
Expand Down Expand Up @@ -1722,56 +1724,65 @@ qx.Class.define("osparc.data.Resources", {
*/
__removeCached: function(resource, deleteId) {
osparc.store.Store.getInstance().remove(resource, this.self().resources[resource].idField || "uuid", deleteId);
}
},

statics: {
API: "/v0",
fetch: function(resource, endpoint, params, options = {}) {
return this.getInstance().fetch(resource, endpoint, params, options);
},
getOne: function(resource, params, id, useCache) {
return this.getInstance().getOne(resource, params, id, useCache);
},
get: function(resource, params, useCache, options) {
return this.getInstance().get(resource, params, useCache, options);
},

getServiceUrl: function(key, version) {
return {
"key": encodeURIComponent(key),
"version": version
};
},

getCompatibleInputs: function(node1, portId1, node2) {
const url = this.__getMatchInputsUrl(node1, portId1, node2);
const url = {
"serviceKey2": encodeURIComponent(node2.getKey()),
"serviceVersion2": node2.getVersion(),
"serviceKey1": encodeURIComponent(node1.getKey()),
"serviceVersion1": node1.getVersion(),
"portKey1": portId1
};

// eslint-disable-next-line no-underscore-dangle
const cachedCPs = this.getInstance().__getCached("portsCompatibility") || {};
const cachedCPs = this.__getCached("portsCompatibility") || {};
const strUrl = JSON.stringify(url);
if (strUrl in cachedCPs) {
return Promise.resolve(cachedCPs[strUrl]);
}

// avoid request deduplication
if (this.__portsCompatibilityPromisesCached === null) {
this.__portsCompatibilityPromisesCached = {};
}
if (strUrl in this.__portsCompatibilityPromisesCached) {
return this.__portsCompatibilityPromisesCached[strUrl];
}

const params = {
url
};
return this.fetch("portsCompatibility", "matchInputs", params)
this.__portsCompatibilityPromisesCached[strUrl] = this.fetch("portsCompatibility", "matchInputs", params)
.then(data => {
cachedCPs[strUrl] = data;
// eslint-disable-next-line no-underscore-dangle
this.getInstance().__setCached("portsCompatibility", cachedCPs);
this.__setCached("portsCompatibility", cachedCPs);
return data;
})
.finally(() => {
// Remove the promise from the cache
delete this.__portsCompatibilityPromisesCached[strUrl];
});

return this.__portsCompatibilityPromisesCached[strUrl];
},
},

__getMatchInputsUrl: function(node1, portId1, node2) {
statics: {
API: "/v0",
fetch: function(resource, endpoint, params, options = {}) {
return this.getInstance().fetch(resource, endpoint, params, options);
},
getOne: function(resource, params, id, useCache) {
return this.getInstance().getOne(resource, params, id, useCache);
},
get: function(resource, params, useCache, options) {
return this.getInstance().get(resource, params, useCache, options);
},

getServiceUrl: function(key, version) {
return {
"serviceKey2": encodeURIComponent(node2.getKey()),
"serviceVersion2": node2.getVersion(),
"serviceKey1": encodeURIComponent(node1.getKey()),
"serviceVersion1": node1.getVersion(),
"portKey1": portId1
"key": encodeURIComponent(key),
"version": version
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ qx.Class.define("osparc.form.renderer.PropForm", {
destinations[node2Id][portId] = "fetching";
}
});
osparc.data.Resources.getCompatibleInputs(node1, dragPortId, this.getNode())
osparc.data.Resources.getInstance().getCompatibleInputs(node1, dragPortId, this.getNode())
.then(compatiblePorts => {
this.getPortIds().forEach(portId => {
destinations[node2Id][portId] = compatiblePorts.includes(portId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ qx.Class.define("osparc.utils.Ports", {

statics: {
arePortsCompatible: function(node1, portId1, node2, portId2) {
return osparc.data.Resources.getCompatibleInputs(node1, portId1, node2)
return osparc.data.Resources.getInstance().getCompatibleInputs(node1, portId1, node2)
.then(compatiblePorts => compatiblePorts.includes(portId2));
},

Expand Down
Loading