Skip to content

Commit 89d6628

Browse files
authored
✨ [Frontend] Patch service icon (#7209)
1 parent b478207 commit 89d6628

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

services/static-webserver/client/source/class/osparc/dashboard/CardBase.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,24 @@ qx.Class.define("osparc.dashboard.CardBase", {
461461
let owner = null;
462462
let workbench = null;
463463
let defaultHits = null;
464+
let icon = null;
464465
switch (resourceData["resourceType"]) {
465466
case "study":
466467
uuid = resourceData.uuid ? resourceData.uuid : null;
467468
owner = resourceData.prjOwner ? resourceData.prjOwner : "";
468469
workbench = resourceData.workbench ? resourceData.workbench : {};
470+
icon = osparc.study.Utils.guessIcon(resourceData);
469471
break;
470472
case "template":
471473
uuid = resourceData.uuid ? resourceData.uuid : null;
472474
owner = resourceData.prjOwner ? resourceData.prjOwner : "";
473475
workbench = resourceData.workbench ? resourceData.workbench : {};
476+
icon = osparc.study.Utils.guessIcon(resourceData);
474477
break;
475478
case "service":
476479
uuid = resourceData.key ? resourceData.key : null;
477480
owner = resourceData.owner ? resourceData.owner : resourceData.contact;
481+
icon = resourceData["icon"] || osparc.dashboard.CardBase.PRODUCT_ICON;
478482
defaultHits = 0;
479483
break;
480484
}
@@ -489,7 +493,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
489493
lastChangeDate: resourceData.lastChangeDate ? new Date(resourceData.lastChangeDate) : null,
490494
trashedAt: resourceData.trashedAt ? new Date(resourceData.trashedAt) : null,
491495
trashedBy: resourceData.trashedBy || null,
492-
icon: ["study", "template"].includes(resourceData.resourceType) ? osparc.study.Utils.guessIcon(resourceData) : osparc.dashboard.CardBase.PRODUCT_ICON,
496+
icon,
493497
thumbnail: resourceData.thumbnail || this.self().PRODUCT_THUMBNAIL,
494498
state: resourceData.state ? resourceData.state : {},
495499
classifiers: resourceData.classifiers && resourceData.classifiers ? resourceData.classifiers : [],

services/static-webserver/client/source/class/osparc/info/ServiceLarge.js

+34-5
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ qx.Class.define("osparc.info.ServiceLarge", {
143143
// Show description only
144144
vBox.add(description.getChildren()[1]);
145145
} else {
146-
const title = this.__createTitle();
146+
const hBox = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
147+
const icon = this.__createIcon();
148+
const iconLayout = this.__createViewWithEdit(icon, this.__openIconEditor);
149+
hBox.add(iconLayout);
150+
const title = this.__createName();
147151
const titleLayout = this.__createViewWithEdit(title, this.__openTitleEditor);
148-
vBox.add(titleLayout);
152+
hBox.add(titleLayout);
153+
vBox.add(hBox);
149154

150155
const extraInfo = this.__extraInfo();
151156
const extraInfoLayout = this.__createExtraInfo(extraInfo);
@@ -218,7 +223,21 @@ qx.Class.define("osparc.info.ServiceLarge", {
218223
return null;
219224
},
220225

221-
__createTitle: function() {
226+
__createIcon: function() {
227+
const serviceIcon = this.getService()["icon"] || "osparc/no_photography_black_24dp.svg";
228+
const iconSize = osparc.dashboard.GridButtonBase.ICON_SIZE;
229+
const icon = new osparc.ui.basic.Thumbnail(serviceIcon, iconSize, iconSize).set({
230+
minHeight: iconSize,
231+
minWidth: iconSize,
232+
});
233+
icon.getChildControl("image").set({
234+
minWidth: iconSize,
235+
minHeight: iconSize,
236+
});
237+
return icon;
238+
},
239+
240+
__createName: function() {
222241
const serviceName = this.getService()["name"];
223242
let text = "";
224243
if (this.getInstanceLabel()) {
@@ -443,9 +462,19 @@ qx.Class.define("osparc.info.ServiceLarge", {
443462
return container;
444463
},
445464

465+
__openIconEditor: function() {
466+
const iconEditor = new osparc.widget.Renamer(this.getService()["icon"], null, this.tr("Edit Icon"));
467+
iconEditor.addListener("labelChanged", e => {
468+
iconEditor.close();
469+
const newIcon = e.getData()["newLabel"];
470+
this.__patchService("icon", newIcon);
471+
}, this);
472+
iconEditor.center();
473+
iconEditor.open();
474+
},
475+
446476
__openTitleEditor: function() {
447-
const title = this.tr("Edit Title");
448-
const titleEditor = new osparc.widget.Renamer(this.getService()["name"], null, title);
477+
const titleEditor = new osparc.widget.Renamer(this.getService()["name"], null, this.tr("Edit Name"));
449478
titleEditor.addListener("labelChanged", e => {
450479
titleEditor.close();
451480
const newLabel = e.getData()["newLabel"];

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

+17-26
Original file line numberDiff line numberDiff line change
@@ -358,42 +358,33 @@ qx.Class.define("osparc.study.Utils", {
358358
return ["UNKNOWN_SERVICES", false].includes(blocked);
359359
},
360360

361+
getNonFrontendNodes: function(studyData) {
362+
return Object.values(studyData["workbench"]).filter(node => !osparc.data.model.Node.isFrontend(node));
363+
},
364+
361365
guessIcon: function(studyData) {
362-
if (osparc.product.Utils.isProduct("osparc")) {
363-
return this.__guessOsparcIcon(studyData);
364-
}
365-
if (osparc.product.Utils.isS4LProduct() || osparc.product.Utils.isProduct("s4llite")) {
366-
return this.__guessS4LIcon(studyData);
367-
}
368366
if (osparc.product.Utils.isProduct("tis") || osparc.product.Utils.isProduct("tiplite")) {
369367
return this.__guessTIPIcon(studyData);
370368
}
371-
return osparc.dashboard.CardBase.PRODUCT_ICON;
372-
},
373-
374-
__guessOsparcIcon: function(studyData) {
375-
// the was to guess the TI type is to check the boot mode of the ti-postpro in the pipeline
376-
const wbServices = Object.values(studyData["workbench"]);
377-
if (wbServices.length > 1) {
378-
return "osparc/icons/diagram.png";
379-
}
380-
return osparc.dashboard.CardBase.PRODUCT_ICON;
369+
return this.__guessIcon(studyData);
381370
},
382371

383-
__guessS4LIcon: function(studyData) {
372+
__guessIcon: function(studyData) {
384373
// the was to guess the TI type is to check the boot mode of the ti-postpro in the pipeline
385-
const wbServices = Object.values(studyData["workbench"]);
374+
const wbServices = this.self().getNonFrontendNodes(studyData);
386375
if (wbServices.length === 1) {
387-
if (wbServices[0]["key"].includes("iseg")) {
388-
return "https://raw.githubusercontent.com/ITISFoundation/osparc-iseg/master/iSeg/images/isegicon.png";
389-
}
390-
if (wbServices[0]["key"].includes("jupyter")) {
391-
return "https://images.seeklogo.com/logo-png/35/1/jupyter-logo-png_seeklogo-354673.png";
392-
}
393-
if (wbServices[0]["key"].includes("s4l-ui")) {
394-
return "https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/refs/heads/main/app/icons/s4l/Sim4Life.png";
376+
const wbService = wbServices[0];
377+
const allServices = osparc.store.Services.servicesCached;
378+
if (wbService.key in allServices && wbService.version in allServices[wbService.key]) {
379+
const serviceMetadata = allServices[wbService.key][wbService.version];
380+
if (serviceMetadata["icon"]) {
381+
return serviceMetadata["icon"];
382+
}
395383
}
396384
}
385+
if (wbServices.length > 1) {
386+
return "osparc/icons/diagram.png";
387+
}
397388
return osparc.dashboard.CardBase.PRODUCT_ICON;
398389
},
399390

Loading

0 commit comments

Comments
 (0)