Skip to content

Commit dc9df2c

Browse files
odeimaizmrnicegyu11
authored andcommitted
🎨 [Frontend] Show default product thumbnail if resource's thumbnail is invalid (ITISFoundation#7341)
1 parent 0eeaffe commit dc9df2c

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ qx.Class.define("osparc.dashboard.GridButtonBase", {
285285
_applyThumbnail: function(value, old) {
286286
if (value.includes("@FontAwesome5Solid/")) {
287287
value += this.self().THUMBNAIL_SIZE;
288-
const image = this.getChildControl("thumbnail").getChildControl("image");
289-
image.set({
288+
const image = this.getChildControl("thumbnail").set({
290289
source: value,
291290
});
292291

@@ -297,13 +296,22 @@ qx.Class.define("osparc.dashboard.GridButtonBase", {
297296
image.addListener(eventName, () => this.__fitThumbnailHeight(), this);
298297
});
299298
} else {
300-
this.getContentElement().setStyles({
301-
"background-image": `url(${value})`,
302-
"background-repeat": "no-repeat",
303-
"background-size": "cover", // auto width, 85% height
304-
"background-position": "center center",
305-
"background-origin": "border-box"
306-
});
299+
let source = osparc.product.Utils.getThumbnailUrl();
300+
fetch(value, { method: "HEAD" })
301+
.then(response => {
302+
if (response.ok) {
303+
source = value;
304+
}
305+
})
306+
.finally(() => {
307+
this.getContentElement().setStyles({
308+
"background-image": `url(${source})`,
309+
"background-repeat": "no-repeat",
310+
"background-size": "cover", // auto width, 85% height
311+
"background-position": "center center",
312+
"background-origin": "border-box"
313+
});
314+
});
307315
}
308316
},
309317

‎services/static-webserver/client/source/class/osparc/ui/basic/Thumbnail.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ qx.Class.define("osparc.ui.basic.Thumbnail", {
8383
__applySource: function(val) {
8484
const image = this.getChildControl("image");
8585
if (val) {
86-
image.setSource(val);
86+
if (osparc.utils.Utils.isValidHttpUrl(val)) {
87+
osparc.utils.Utils.setUrlSourceToImage(image, val);
88+
} else {
89+
image.setSource(val);
90+
}
8791
}
8892
},
8993

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ qx.Class.define("osparc.utils.Utils", {
9191

9292
FLOATING_Z_INDEX: 1000001 + 1,
9393

94+
setUrlSourceToImage: function(image, imgSrc) {
95+
let source = osparc.product.Utils.getThumbnailUrl();
96+
fetch(imgSrc, { method: "HEAD" })
97+
.then(response => {
98+
if (response.ok) {
99+
source = imgSrc;
100+
}
101+
})
102+
.finally(() => image.setSource(source));
103+
},
104+
94105
addWhiteSpaces: function(integer) {
95106
return new Intl.NumberFormat("fr-FR").format(integer); // french will add white spaces every 3 digits
96107
},

‎services/static-webserver/client/source/resource/osparc/ui_config.json‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,32 @@
2121
"expectedTemplateLabel": "mcTI Planning Tool",
2222
"title": "Multichannel TI",
2323
"newStudyLabel": "Multichannel TI",
24-
"category": "precomputed",
25-
"idToWidget": "newMTIPlanButton"
24+
"category": "precomputed"
2625
}, {
2726
"resourceType": "template",
2827
"expectedTemplateLabel": "pmTI Planning Tool",
2928
"title": "Phase-modulation TI",
3029
"newStudyLabel": "Phase-modulation TI",
31-
"category": "precomputed",
32-
"idToWidget": "newPMTIPlanButton"
30+
"category": "precomputed"
3331
}, {
3432
"resourceType": "template",
3533
"expectedTemplateLabel": "personalized TI Planning Tool",
3634
"title": "Personalized<br>Classic TI",
3735
"newStudyLabel": "Personalized Classic TI",
3836
"category": "personalized",
39-
"idToWidget": "personalizationNewTIPlanButton"
37+
"idToWidget": "newPTIPlanButton"
4038
}, {
4139
"resourceType": "template",
4240
"expectedTemplateLabel": "personalized mcTI Planning Tool",
4341
"title": "Personalized<br>Multichannel TI",
4442
"newStudyLabel": "Personalized Multichannel TI",
45-
"category": "personalized",
46-
"idToWidget": "personalizationNewMTIPlanButton"
43+
"category": "personalized"
4744
}, {
4845
"resourceType": "template",
4946
"expectedTemplateLabel": "personalized pmTI Planning Tool",
5047
"title": "Personalized<br>Phase-modulation TI",
5148
"newStudyLabel": "Personalized Phase-modulation TI",
52-
"category": "personalized",
53-
"idToWidget": "personalizationNewPMTIPlanButton"
49+
"category": "personalized"
5450
}]
5551
}
5652
},
@@ -86,7 +82,7 @@
8682
"reason": "Not available in ${replace_me_product_name}",
8783
"title": "Personalized<br>Classic TI",
8884
"category": "personalized",
89-
"idToWidget": "personalizationNewTIPlanButton"
85+
"idToWidget": "newPTIPlanButton"
9086
}, {
9187
"showDisabled": true,
9288
"reason": "Not available in ${replace_me_product_name}",

‎tests/e2e/tests/tags.tes.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ describe('tags testing', () => {
4848
await page.goto(url);
4949
await auto.register(page, user, pass);
5050
// Create new study
51-
await waitAndClick(page, '[osparc-test-id="newPlusBtn"]');
51+
const uiConfig = await page.evaluate(async () => await osparc.store.Products.getInstance().fetchUiConfig());
52+
if ("plusButton" in uiConfig) {
53+
await waitAndClick(page, '[osparc-test-id="newPlusBtn"]');
54+
}
5255
await waitAndClick(page, '[osparc-test-id="emptyStudyBtn"]');
5356
// Wait until project is created and Dashboard button is enabled
5457
await utils.sleep(4000);

‎tests/e2e/utils/auto.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,24 @@ async function __dashboardServicesBrowser(page) {
107107
async function dashboardNewTIPlan(page) {
108108
console.log("Creating New Plan");
109109

110-
await utils.waitAndClick(page, '[osparc-test-id="newPlansBtn"]');
110+
const uiConfig = await page.evaluate(async () => await osparc.store.Products.getInstance().fetchUiConfig());
111+
if ("newStudies" in uiConfig) {
112+
await utils.waitAndClick(page, '[osparc-test-id="newPlansBtn"]');
113+
} else if ("plusButton" in uiConfig) {
114+
await utils.waitAndClick(page, '[osparc-test-id="newPlusBtn"]');
115+
}
116+
111117
await utils.waitAndClick(page, '[osparc-test-id="newTIPlanButton"]');
112118
}
113119

114120
async function dashboardStartSim4LifeLite(page) {
115-
console.log("Start Sim4Lite from + button");
121+
console.log("Start Sim4Life-Lite from + button");
122+
123+
const uiConfig = await page.evaluate(async () => await osparc.store.Products.getInstance().fetchUiConfig());
124+
if ("plusButton" in uiConfig) {
125+
await utils.waitAndClick(page, '[osparc-test-id="newPlusBtn"]');
126+
}
116127

117-
await utils.waitAndClick(page, '[osparc-test-id="newPlansBtn"]');
118128
await utils.waitAndClick(page, '[osparc-test-id="startS4LButton"]');
119129
}
120130

0 commit comments

Comments
 (0)