Skip to content

Commit 24036ac

Browse files
committed
[skip ci] more refactoring
1 parent 38f1d6f commit 24036ac

File tree

2 files changed

+49
-107
lines changed

2 files changed

+49
-107
lines changed

services/static-webserver/client/source/class/osparc/metadata/ServicesInStudyUpdate.js

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ qx.Class.define("osparc.metadata.ServicesInStudyUpdate", {
2727
UPDATE_BUTTON: Object.keys(osparc.metadata.ServicesInStudy.GRID_POS).length+2
2828
},
2929

30-
anyServiceDeprecated: function(studyData) {
31-
if ("workbench" in studyData) {
32-
return osparc.study.Utils.isWorkbenchDeprecated(studyData["workbench"]);
33-
}
34-
return false;
35-
},
36-
37-
anyServiceRetired: function(studyData) {
38-
if ("workbench" in studyData) {
39-
return osparc.study.Utils.isWorkbenchRetired(studyData["workbench"]);
40-
}
41-
return false;
42-
},
43-
44-
anyServiceInaccessible: function(studyData) {
45-
if ("workbench" in studyData) {
46-
const inaccessibles = osparc.study.Utils.getInaccessibleServices(studyData["workbench"]);
47-
return inaccessibles.length;
48-
}
49-
return false;
50-
},
51-
5230
updatableNodeIds: function(workbench) {
5331
const nodeIds = [];
5432
for (const nodeId in workbench) {
@@ -84,53 +62,54 @@ qx.Class.define("osparc.metadata.ServicesInStudyUpdate", {
8462

8563
_populateIntroText: async function() {
8664
const canIWrite = osparc.data.model.Study.canIWrite(this._studyData["accessRights"]);
87-
const labels = [];
88-
if (this.self().anyServiceInaccessible(this._studyData)) {
89-
const inaccessibleText = this.tr("Some services' information is not accessible. Please contact service owner:");
90-
const inaccessibleLabel = new qx.ui.basic.Label(inaccessibleText);
91-
labels.push(inaccessibleLabel);
92-
}
93-
if (this.self().anyServiceRetired(this._studyData)) {
94-
let retiredText = this.tr("Services marked in red are retired: you cannot use them anymore.");
95-
if (canIWrite) {
96-
retiredText += "<br>" + this.tr("If the Update button is disabled, they might require manual intervention to be updated:");
97-
retiredText += "<br>- " + this.tr("Open the study");
98-
retiredText += "<br>- " + this.tr("Click on the retired service, download the data");
99-
retiredText += "<br>- " + this.tr("Upload the data to an updated version");
100-
}
101-
const retiredLabel = new qx.ui.basic.Label(retiredText);
102-
labels.push(retiredLabel);
103-
}
104-
if (this.self().anyServiceDeprecated(this._studyData)) {
105-
let deprecatedText = this.tr("Services marked in yellow are deprecated, they will be retired soon.");
106-
if (canIWrite) {
107-
deprecatedText += " " + this.tr("They can be updated by pressing the Update button.");
65+
const introText = new qx.ui.basic.Label().set({
66+
font: "text-14",
67+
rich: true
68+
});
69+
this._introText.add(introText);
70+
let msg = "";
71+
const params = {
72+
url: {
73+
studyId: this._studyData["uuid"]
10874
}
109-
const deprecatedLabel = new qx.ui.basic.Label(deprecatedText);
110-
labels.push(deprecatedLabel);
111-
}
112-
const updatableServices = this.self().updatableNodeIds(this._studyData["workbench"]);
113-
if (updatableServices.length === 0) {
114-
const upToDateText = this.tr("All services are up to date to their latest compatible version.");
115-
const upToDateLabel = new qx.ui.basic.Label(upToDateText);
116-
labels.push(upToDateLabel);
117-
} else if (canIWrite) {
118-
const useUpdateButtonText = this.tr("Use the Update buttons to bring the services to their latest compatible version.");
119-
const useUpdateButtonLabel = new qx.ui.basic.Label(useUpdateButtonText);
120-
labels.push(useUpdateButtonLabel);
121-
} else {
122-
const notUpToDateText = this.tr("Some services are not up to date.");
123-
const notUpToDateLabel = new qx.ui.basic.Label(notUpToDateText);
124-
labels.push(notUpToDateLabel);
125-
}
75+
};
76+
osparc.data.Resources.fetch("studies", "getServices", params)
77+
.then(resp => {
78+
const services = resp["services"];
79+
if (osparc.study.Utils.getInaccessibleServices2(services)) {
80+
msg += this.tr("Some services' are not accessible. Please contact service owner:");
81+
msg += "<br><br>";
82+
}
83+
if (osparc.study.Utils.anyServiceRetired(services)) {
84+
msg += this.tr("Services marked in red are retired: you cannot use them anymore.");
85+
if (canIWrite) {
86+
msg += "<br>" + this.tr("If the Update button is disabled, they might require manual intervention to be updated:");
87+
msg += "<br>- " + this.tr("Open the study");
88+
msg += "<br>- " + this.tr("Click on the retired service, download the data");
89+
msg += "<br>- " + this.tr("Upload the data to an updated version");
90+
}
91+
msg += "<br><br>";
92+
}
93+
if (osparc.study.Utils.anyServiceDeprecated(services)) {
94+
msg += this.tr("Services marked in yellow are deprecated, they will be retired soon.");
95+
if (canIWrite) {
96+
msg += " " + this.tr("They can be updated by pressing the Update button.");
97+
}
98+
msg += "<br><br>";
99+
}
100+
const anyServiceUpdatable = osparc.study.Utils.anyServiceUpdatable(services);
101+
if (anyServiceUpdatable === false && msg === "") {
102+
msg += this.tr("All services are up to date to their latest compatible version.");
103+
msg += "<br>";
104+
} else if (canIWrite) {
105+
msg += this.tr("Use the Update buttons to bring the services to their latest compatible version.");
106+
msg += "<br>";
107+
} else {
108+
msg += this.tr("Some services are not up to date.");
109+
}
126110

127-
labels.forEach(label => {
128-
label.set({
129-
font: "text-14",
130-
rich: true
111+
introText.setValue(msg);
131112
});
132-
this._introText.add(label);
133-
});
134113
},
135114

136115
__updateService: async function(nodeId, key, version, button) {

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

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ qx.Class.define("osparc.study.Utils", {
7474
return msg;
7575
},
7676

77+
getInaccessibleServices2: function(studyServices) {
78+
return studyServices.filter(service => service["execute"] === false);
79+
},
80+
7781
anyServiceRetired: function(studyServices) {
7882
const isRetired = studyServices.some(service => {
7983
if (service["release"] && service["release"]["retired"]) {
@@ -108,47 +112,6 @@ qx.Class.define("osparc.study.Utils", {
108112
return isUpdatable;
109113
},
110114

111-
isWorkbenchUpdatable: function(workbench) {
112-
const services = new Set(this.extractUniqueServices(workbench));
113-
const isUpdatable = Array.from(services).some(srv => osparc.service.Utils.isUpdatable(srv));
114-
return isUpdatable;
115-
},
116-
117-
isWorkbenchRetired: function(workbench) {
118-
const allServices = osparc.store.Services.servicesCached;
119-
const services = new Set(this.extractUniqueServices(workbench));
120-
const isRetired = Array.from(services).some(srv => {
121-
if (srv.key in allServices && srv.version in allServices[srv.key]) {
122-
const serviceMD = allServices[srv.key][srv.version];
123-
if (serviceMD["retired"]) {
124-
const retirementDate = new Date(serviceMD["retired"]);
125-
const currentDate = new Date();
126-
return retirementDate < currentDate;
127-
}
128-
return false;
129-
}
130-
return false;
131-
});
132-
return isRetired;
133-
},
134-
135-
isWorkbenchDeprecated: function(workbench) {
136-
const allServices = osparc.store.Services.servicesCached;
137-
const services = new Set(this.extractUniqueServices(workbench));
138-
const isRetired = Array.from(services).some(srv => {
139-
if (srv.key in allServices && srv.version in allServices[srv.key]) {
140-
const serviceMD = allServices[srv.key][srv.version];
141-
if ("retired" in serviceMD && serviceMD["retired"]) {
142-
const retirementDate = new Date(serviceMD["retired"]);
143-
const currentDate = new Date();
144-
return retirementDate > currentDate;
145-
}
146-
return false;
147-
}
148-
return false;
149-
});
150-
return isRetired;
151-
},
152115

153116
createStudyFromService: function(key, version, existingStudies, newStudyLabel, contextProps = {}) {
154117
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)