Skip to content

Commit 6671e1a

Browse files
authored
Service/Node resources in frontend (#2998)
1 parent 98d6049 commit 6671e1a

File tree

9 files changed

+151
-5
lines changed

9 files changed

+151
-5
lines changed

services/web/client/source/class/osparc/component/form/Auto.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,12 @@ qx.Class.define("osparc.component.form.Auto", {
529529
if (s.set.filter) {
530530
s.set.filter = RegExp(s.filter);
531531
}
532+
if ("minimum" in s.set) {
533+
control.setMinimum(s.set["minimum"]);
534+
}
535+
if ("maximum" in s.set) {
536+
control.setMaximum(s.set["maximum"]);
537+
}
532538
control.set(s.set);
533539
}
534540
control.key = key;

services/web/client/source/class/osparc/component/node/BaseNodeView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ qx.Class.define("osparc.component.node.BaseNodeView", {
180180
},
181181

182182
__openServiceDetails: function() {
183-
const serviceDetails = new osparc.servicecard.Large(this.getNode().getMetaData(), this.getNode().getNodeId());
183+
const serviceDetails = new osparc.servicecard.Large(this.getNode().getMetaData(), this.getNode().getNodeId(), this.getStudy());
184184
const title = this.tr("Service information");
185185
const width = 600;
186186
const height = 700;

services/web/client/source/class/osparc/component/widget/NodesTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ qx.Class.define("osparc.component.widget.NodesTree", {
244244
osparc.ui.window.Window.popUpInWindow(studyDetails, title, width, height);
245245
} else {
246246
const node = study.getWorkbench().getNode(nodeId);
247-
const serviceDetails = new osparc.servicecard.Large(node.getMetaData(), nodeId);
247+
const serviceDetails = new osparc.servicecard.Large(node.getMetaData(), nodeId, study);
248248
const title = this.tr("Service information");
249249
const width = 600;
250250
const height = 700;

services/web/client/source/class/osparc/component/workbench/WorkbenchUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ qx.Class.define("osparc.component.workbench.WorkbenchUI", {
16451645
__openNodeInfo: function(nodeId) {
16461646
if (nodeId) {
16471647
const node = this.getStudy().getWorkbench().getNode(nodeId);
1648-
const serviceDetails = new osparc.servicecard.Large(node.getMetaData(), nodeId);
1648+
const serviceDetails = new osparc.servicecard.Large(node.getMetaData(), nodeId, this.getStudy());
16491649
const title = this.tr("Service information");
16501650
const width = 600;
16511651
const height = 700;

services/web/client/source/class/osparc/dashboard/ResourceMoreOptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
200200
const title = this.tr("Information");
201201
const icon = "@FontAwesome5Solid/info";
202202
const resourceData = this.__resourceData;
203-
const infoCard = osparc.utils.Resources.isService(resourceData) ? new osparc.servicecard.Large(resourceData, null, false) : new osparc.studycard.Large(resourceData, false);
203+
const infoCard = osparc.utils.Resources.isService(resourceData) ? new osparc.servicecard.Large(resourceData, null, null, false) : new osparc.studycard.Large(resourceData, false);
204204
infoCard.addListener("openAccessRights", () => this.openAccessRights());
205205
infoCard.addListener("openClassifiers", () => this.openClassfiers());
206206
infoCard.addListener("openQuality", () => this.openQuality());

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,31 @@ qx.Class.define("osparc.data.Resources", {
154154
}
155155
}
156156
},
157+
/*
158+
* NODES
159+
*/
160+
"nodesInStudyResources": {
161+
idField: "nodeId",
162+
useCache: false,
163+
endpoints: {
164+
getResources: {
165+
useCache: false,
166+
method: "GET",
167+
url: statics.API + "/projects/{studyId}/nodes/{nodeId}/resources"
168+
}
169+
}
170+
},
171+
"serviceResources": {
172+
idField: ["key", "version"],
173+
useCache: false,
174+
endpoints: {
175+
getResources: {
176+
useCache: false,
177+
method: "GET",
178+
url: statics.API + "/catalog/services/{key}/{version}/resources"
179+
}
180+
}
181+
},
157182
/*
158183
* SNAPSHOTS
159184
*/

services/web/client/source/class/osparc/servicecard/Large.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ qx.Class.define("osparc.servicecard.Large", {
2424
* @param instanceUuid {String} uuid of the service instance
2525
* @param openOptions {Boolean} open edit options in new window or fire event
2626
*/
27-
construct: function(serviceData, instanceUuid = null, openOptions = true) {
27+
construct: function(serviceData, instanceUuid = null, study = null, openOptions = true) {
2828
this.base(arguments);
2929

3030
this.set({
@@ -39,6 +39,10 @@ qx.Class.define("osparc.servicecard.Large", {
3939
this.setInstanceUuid(instanceUuid);
4040
}
4141

42+
if (study) {
43+
this.setStudy(study);
44+
}
45+
4246
if (openOptions !== undefined) {
4347
this.setOpenOptions(openOptions);
4448
}
@@ -72,6 +76,12 @@ qx.Class.define("osparc.servicecard.Large", {
7276
nullable: true
7377
},
7478

79+
study: {
80+
check: "osparc.data.model.Study",
81+
init: null,
82+
nullable: true
83+
},
84+
7585
openOptions: {
7686
check: "Boolean",
7787
init: true,
@@ -127,6 +137,9 @@ qx.Class.define("osparc.servicecard.Large", {
127137
description.addAt(editInTitle, 0);
128138
this._add(description);
129139

140+
const resources = this.__createResources();
141+
this._add(resources);
142+
130143
const rawMetadata = this.__createRawMetadata();
131144
const more = new osparc.desktop.PanelView(this.tr("raw metadata"), rawMetadata).set({
132145
caretSize: 14
@@ -282,6 +295,36 @@ qx.Class.define("osparc.servicecard.Large", {
282295
return osparc.servicecard.Utils.createDescription(this.getService(), maxHeight);
283296
},
284297

298+
__createResources: function() {
299+
const resourcesLayout = osparc.servicecard.Utils.createResourcesInfo();
300+
resourcesLayout.exclude();
301+
let promise = null;
302+
if (this.getInstanceUuid()) {
303+
const params = {
304+
url: {
305+
studyId: this.getStudy().getUuid(),
306+
nodeId: this.getInstanceUuid()
307+
}
308+
};
309+
promise = osparc.data.Resources.fetch("nodesInStudyResources", "getResources", params);
310+
} else {
311+
const params = {
312+
url: osparc.data.Resources.getServiceUrl(
313+
this.getService()["key"],
314+
this.getService()["version"]
315+
)
316+
};
317+
promise = osparc.data.Resources.fetch("serviceResources", "getResources", params);
318+
}
319+
promise
320+
.then(serviceResources => {
321+
resourcesLayout.show();
322+
osparc.servicecard.Utils.resourcesToResourcesInfo(resourcesLayout, serviceResources);
323+
})
324+
.catch(err => console.error(err));
325+
return resourcesLayout;
326+
},
327+
285328
__createRawMetadata: function() {
286329
const container = new qx.ui.container.Scroll();
287330
container.add(new osparc.ui.basic.JsonTreeWidget(this.getService(), "serviceDescriptionSettings"));

services/web/client/source/class/osparc/servicecard/Utils.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,70 @@ qx.Class.define("osparc.servicecard.Utils", {
193193
return descriptionLayout;
194194
},
195195

196+
createResourcesInfo: function() {
197+
const resourcesLayout = new qx.ui.container.Composite(new qx.ui.layout.VBox(5).set({
198+
alignY: "middle"
199+
}));
200+
201+
const label = new qx.ui.basic.Label(qx.locale.Manager.tr("Resources")).set({
202+
font: "title-12"
203+
});
204+
resourcesLayout.add(label);
205+
206+
const grid = new qx.ui.layout.Grid(5, 3);
207+
grid.setColumnAlign(0, "right", "middle");
208+
grid.setColumnAlign(1, "left", "middle");
209+
const resourcesInfo = new qx.ui.container.Composite(grid).set({
210+
allowGrowX: false,
211+
alignX: "left",
212+
alignY: "middle"
213+
});
214+
resourcesLayout.add(resourcesInfo);
215+
216+
return resourcesLayout;
217+
},
218+
219+
resourcesToResourcesInfo: function(resourcesLayout, resourcesInfo) {
220+
const layout = resourcesLayout.getChildren()[1];
221+
let row = 0;
222+
Object.keys(resourcesInfo).forEach(resourceKey => {
223+
let column = 0;
224+
const resourceInfo = resourcesInfo[resourceKey];
225+
let label = resourceKey;
226+
if (resourceKey === "RAM") {
227+
label += " (GB)";
228+
}
229+
layout.add(new qx.ui.basic.Label(label).set({
230+
font: "title-12"
231+
}), {
232+
row,
233+
column
234+
});
235+
column++;
236+
Object.keys(resourceInfo).forEach(resourceInfoKey => {
237+
layout.add(new qx.ui.basic.Label(resourceInfoKey).set({
238+
font: "title-12"
239+
}), {
240+
row,
241+
column
242+
});
243+
column++;
244+
let value = resourceInfo[resourceInfoKey];
245+
if (resourceKey === "RAM") {
246+
value = osparc.utils.Utils.bytesToGB(value);
247+
}
248+
layout.add(new qx.ui.basic.Label(String(value)).set({
249+
font: "text-12"
250+
}), {
251+
row,
252+
column
253+
});
254+
column++;
255+
});
256+
row++;
257+
});
258+
},
259+
196260
createExtraInfo: function(extraInfos) {
197261
const grid = new qx.ui.layout.Grid(5, 3);
198262
grid.setColumnAlign(0, "right", "middle");

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ qx.Class.define("osparc.store.Store", {
6262
check: "Array",
6363
init: []
6464
},
65+
nodesInStudyResources: {
66+
check: "Array",
67+
init: []
68+
},
69+
serviceResources: {
70+
check: "Array",
71+
init: []
72+
},
6573
snapshots: {
6674
check: "Array",
6775
init: [],

0 commit comments

Comments
 (0)