Skip to content

Commit 283e6b5

Browse files
authored
✨ Allow a user to select from default project thumbnails (#5334)
1 parent a5a0a44 commit 283e6b5

File tree

9 files changed

+125
-27
lines changed

9 files changed

+125
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ qx.Class.define("osparc.dashboard.StudyThumbnailExplorer", {
7979
__getThumbnailSuggestions: function() {
8080
const thumbnailSuggestions = new osparc.editor.ThumbnailSuggestions().set({
8181
minHeight: this.self().THUMBNAIL_SLIDER_HEIGHT,
82-
maxHeight: this.self().THUMBNAIL_SLIDER_HEIGHT,
82+
maxHeight: this.self().THUMBNAIL_SLIDER_HEIGHT + 2,
8383
backgroundColor: "transparent",
84-
padding: [3, 0]
84+
padding: 3
8585
});
8686
return thumbnailSuggestions;
8787
},

services/static-webserver/client/source/class/osparc/desktop/preferences/pages/TagsPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ qx.Class.define("osparc.desktop.preferences.pages.TagsPage", {
4343

4444
__createComponents: function() {
4545
this.__addTagButton = new qx.ui.form.Button().set({
46-
appearance: "strong-button",
46+
appearance: "form-button-outlined",
4747
label: this.tr("New Tag"),
4848
icon: "@FontAwesome5Solid/plus/14"
4949
});

services/static-webserver/client/source/class/osparc/editor/ThumbnailEditor.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,15 @@ qx.Class.define("osparc.editor.ThumbnailEditor", {
7878
switch (id) {
7979
case "url-field":
8080
control = new qx.ui.form.TextField().set({
81-
font: "text-14",
82-
backgroundColor: "background-main",
81+
appearance: "form-input",
8382
placeholder: this.tr("url")
8483
});
8584
this.bind("url", control, "value");
8685
this._add(control);
8786
break;
8887
case "thumbnails-layout": {
8988
control = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
90-
const label = new qx.ui.basic.Label(this.tr("or pick one from the list of services:"));
89+
const label = new qx.ui.basic.Label(this.tr("or pick one from the list below:"));
9190
control.add(label);
9291
this._add(control, {
9392
flex: 1
@@ -96,6 +95,10 @@ qx.Class.define("osparc.editor.ThumbnailEditor", {
9695
}
9796
case "scroll-thumbnails": {
9897
control = new osparc.editor.ThumbnailSuggestions();
98+
control.set({
99+
padding: 2,
100+
backgroundColor: "transparent"
101+
})
99102
const thumbnailsLayout = this.getChildControl("thumbnails-layout");
100103
thumbnailsLayout.add(control);
101104
break;
@@ -109,13 +112,19 @@ qx.Class.define("osparc.editor.ThumbnailEditor", {
109112
case "cancel-btn": {
110113
const buttons = this.getChildControl("buttons-layout");
111114
control = new qx.ui.form.Button(this.tr("Cancel"));
115+
control.set({
116+
appearance: "form-button-text"
117+
});
112118
control.addListener("execute", () => this.fireEvent("cancel"), this);
113119
buttons.add(control);
114120
break;
115121
}
116122
case "save-btn": {
117123
const buttons = this.getChildControl("buttons-layout");
118124
control = new qx.ui.form.Button(this.tr("Save"));
125+
control.set({
126+
appearance: "form-button"
127+
});
119128
control.addListener("execute", () => {
120129
const urlField = this.getChildControl("url-field");
121130
const validUrl = this.self().sanitizeUrl(urlField.getValue());
@@ -136,7 +145,7 @@ qx.Class.define("osparc.editor.ThumbnailEditor", {
136145
thumbnailSuggestions.setSuggestions(suggestions);
137146
thumbnailSuggestions.addListener("thumbnailTapped", e => {
138147
const thumbnailData = e.getData();
139-
this.setUrl(thumbnailData["source"]);
148+
this.setUrl(thumbnailData.source);
140149
});
141150
this.getChildControl("thumbnails-layout").setVisibility(suggestions.length ? "visible" : "excluded");
142151
}

services/static-webserver/client/source/class/osparc/editor/ThumbnailSuggestions.js

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ qx.Class.define("osparc.editor.ThumbnailSuggestions", {
2323

2424
this.set({
2525
alignX: "center",
26-
maxHeight: 170
26+
height: 118,
27+
maxHeight: 118
2728
});
2829
this.setButtonsWidth(30);
2930

@@ -49,17 +50,31 @@ qx.Class.define("osparc.editor.ThumbnailSuggestions", {
4950
},
5051

5152
statics: {
53+
defaultTemplates: [
54+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/Thumbnail.png",
55+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/bright_coulomb.png",
56+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/dynamic_hertz.png",
57+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/electric_heaviside.png",
58+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/energetic_ampere.png",
59+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/glowing_tesla.png",
60+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/illuminated_volta.png",
61+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/luminous_ohm.png",
62+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/magnetic_lorentz.png",
63+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/radiant_maxwell.png",
64+
"https://raw.githubusercontent.com/ZurichMedTech/s4l-assets/main/app/full/project_thumbnails/vibrant_faraday.png"
65+
],
5266
extractThumbnailSuggestions: function(study) {
5367
const suggestions = new Set([]);
5468
const wb = study.getWorkbench();
5569
const nodes = wb.getWorkbenchInitData() ? wb.getWorkbenchInitData() : wb.getNodes();
5670
Object.values(nodes).forEach(node => {
57-
const srvMetadata = osparc.service.Utils.getMetaData(node["key"], node["version"]);
71+
const srvMetadata = osparc.service.Utils.getMetaData(node.getKey(), node.getVersion());
5872
if (srvMetadata && srvMetadata["thumbnail"] && !osparc.data.model.Node.isFrontend(node)) {
5973
suggestions.add(srvMetadata["thumbnail"]);
6074
}
6175
});
62-
return Array.from(suggestions);
76+
const amendedArray = [...suggestions, ...this.defaultTemplates]
77+
return Array.from(amendedArray);
6378
}
6479
},
6580

@@ -122,25 +137,34 @@ qx.Class.define("osparc.editor.ThumbnailSuggestions", {
122137
},
123138

124139
thumbnailTapped: function(thumbnail) {
125-
this.getChildren().forEach(thumbnailImg => osparc.utils.Utils.hideBorder(thumbnailImg));
140+
this.getChildren().forEach(thumbnailImg => {
141+
osparc.utils.Utils.updateBorderColor(thumbnailImg, qx.theme.manager.Color.getInstance().resolve("box-shadow"));
142+
osparc.utils.Utils.addBackground(thumbnailImg, qx.theme.manager.Color.getInstance().resolve("fab-background"));
143+
});
126144
const color = qx.theme.manager.Color.getInstance().resolve("background-selected-dark");
127-
osparc.utils.Utils.addBorder(thumbnail, 1, color);
145+
const bgColor = qx.theme.manager.Color.getInstance().resolve("background-selected");
146+
osparc.utils.Utils.updateBorderColor(thumbnail, color);
147+
osparc.utils.Utils.addBackground(thumbnail, bgColor);
128148
this.fireDataEvent("thumbnailTapped", {
129-
type: thumbnail.thumbnailType,
130-
source: thumbnail.thumbnailFileUrl
149+
type: thumbnail.thumbnailType || "templateThumbnail",
150+
source: thumbnail.thumbnailFileUrl || thumbnail.getSource()
131151
});
132152
},
133153

134154
setSuggestions: function(suggestions) {
135155
this.removeAll();
136156
suggestions.forEach(suggestion => {
137157
const maxHeight = this.getMaxHeight();
138-
const thumbnail = new osparc.ui.basic.Thumbnail(suggestion["thumbnailUrl"], maxHeight, parseInt(maxHeight*2/3));
139-
thumbnail.thumbnailType = suggestion["type"];
140-
thumbnail.thumbnailFileUrl = suggestion["fileUrl"];
141-
thumbnail.setMarginLeft(1); // give some extra space to the selection border
142-
thumbnail.addListener("mouseover", () => thumbnail.set({decorator: "selected-light"}), this);
143-
thumbnail.addListener("mouseout", () => thumbnail.set({decorator: "fab-button"}), this);
158+
const thumbnail = new osparc.ui.basic.Thumbnail(suggestion.thumbnailUrl || suggestion, maxHeight, parseInt(maxHeight*2/3));
159+
thumbnail.set({
160+
minWidth: 97,
161+
margin: 0,
162+
decorator: "thumbnail"
163+
});
164+
thumbnail.thumbnailType = suggestion.type || "templateThumbnail";
165+
thumbnail.thumbnailFileUrl = suggestion.fileUrl || suggestion;
166+
thumbnail.addListener("mouseover", () => thumbnail.set({decorator: "thumbnail-selected"}), this);
167+
thumbnail.addListener("mouseout", () => thumbnail.set({decorator: "thumbnail"}), this);
144168
thumbnail.addListener("tap", () => {
145169
this.thumbnailTapped(thumbnail);
146170
}, this);

services/static-webserver/client/source/class/osparc/form/tag/TagManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ qx.Class.define("osparc.form.tag.TagManager", {
7575
});
7676

7777
const addTagButton = this.__addTagButton = new qx.ui.form.Button().set({
78-
appearance: "strong-button",
78+
appearance: "form-button-outlined",
7979
label: this.tr("New Tag"),
8080
icon: "@FontAwesome5Solid/plus/14",
8181
alignX: "center",

services/static-webserver/client/source/class/osparc/theme/Appearance.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ qx.Theme.define("osparc.theme.Appearance", {
1919
extend: osparc.theme.common.Appearance,
2020

2121
appearances: {
22+
"material-button-invalid": {},
2223
"pb-list": {
2324
include: "list",
2425
alias: "list",
@@ -616,6 +617,37 @@ qx.Theme.define("osparc.theme.Appearance", {
616617
}
617618
},
618619

620+
"thumbnail": {
621+
include: "form-button",
622+
style: function(states) {
623+
const style = {
624+
decorator: "thumbnail",
625+
cursor: "pointer",
626+
padding: 5,
627+
textColor: "fab_text",
628+
backgroundColor: "fab-background",
629+
center: true
630+
};
631+
if (states.hovered) {
632+
style.decorator = "form-button-hovered";
633+
}
634+
if (states.focused) {
635+
style.decorator = "form-button-focused";
636+
}
637+
if (states.active) {
638+
style.decorator = "form-button-active";
639+
}
640+
if (states.disabled) {
641+
style.cursor = "not-allowed";
642+
style.decorator = "form-button-disabled";
643+
}
644+
if (states.checked || states.selected) {
645+
style.decorator = "form-button-checked";
646+
}
647+
return style;
648+
}
649+
},
650+
619651
"form-button-text": {
620652
style: function(states) {
621653
const style = {

services/static-webserver/client/source/class/osparc/theme/Decoration.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ qx.Theme.define("osparc.theme.Decoration", {
2020
extend: osparc.theme.common.Decoration,
2121

2222
decorations: {
23+
"material-button-invalid": {},
2324
"material-button": {
2425
style: {
2526
radius: 4,
@@ -555,6 +556,26 @@ qx.Theme.define("osparc.theme.Decoration", {
555556
}
556557
},
557558

559+
"thumbnail": {
560+
include: "material-button",
561+
style: {
562+
style: "solid",
563+
width: 1,
564+
color: "box-shadow",
565+
backgroundColor: "fab-background",
566+
}
567+
},
568+
569+
"thumbnail-selected": {
570+
include: "thumbnail",
571+
style: {
572+
style: "solid",
573+
width: 1,
574+
color: "background-selected-dark",
575+
backgroundColor: "background-selected"
576+
}
577+
},
578+
558579
/*
559580
---------------------------------------------------------------------------
560581
Appmotion

services/static-webserver/client/source/class/osparc/theme/mixin/Color.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ qx.Theme.define("osparc.theme.mixin.Color", {
1919
"error_bg": "rgba(255, 108, 108, 0.1)", // #FF6C6C1A
2020

2121
"pb-new": "rgba(10, 182, 255, 0.25)",
22-
"pb-study": "rgba(10, 182, 255, 0.5)",
23-
"pb-template": "rgba(9, 89, 122, 0.5)",
24-
"pb-service": "rgba(248, 219, 31, 0.5)",
25-
"pb-computational": "rgba(255, 165, 0, 0.5)",
26-
"pb-dynamic": "rgba(248, 219, 31, 0.5)",
27-
"pb-locked": "rgba(113, 157, 181, 0.5)",
22+
"pb-study": "rgba(10, 182, 255, 0.4)",
23+
"pb-template": "rgba(9, 89, 122, 0.4)",
24+
"pb-service": "rgba(248, 219, 31, 0.4)",
25+
"pb-computational": "rgba(255, 165, 0, 0.4)",
26+
"pb-dynamic": "rgba(248, 219, 31, 0.4)",
27+
"pb-locked": "rgba(113, 157, 181, 0.4)",
2828

2929
// button
3030
"default-button-text": "rgba(255, 255, 255, 1)",

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ qx.Class.define("osparc.utils.Utils", {
428428
widget.getContentElement().setStyle("border", width+"px solid " + color);
429429
},
430430

431+
updateBorderColor: function(widget, color = "inherit") {
432+
widget.getContentElement().setStyle("border-color", color);
433+
},
434+
435+
addBackground: function(widget, color = "transparent") {
436+
widget.getContentElement().setStyle("background-color", color);
437+
},
438+
439+
removeBackground: function(widget) {
440+
widget.getContentElement().setStyle("background-color", "transparent");
441+
},
442+
431443
removeBorder: function(widget) {
432444
widget.getContentElement().setStyle("border", "0px solid");
433445
},

0 commit comments

Comments
 (0)