Skip to content

Commit d5a90d7

Browse files
authored
🎨 Frontend: Redesign File Picker in App Mode (#5893)
1 parent 632e5d6 commit d5a90d7

File tree

6 files changed

+167
-67
lines changed

6 files changed

+167
-67
lines changed

services/static-webserver/client/source/class/osparc/desktop/PanelView.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* Ignacio Pascual (ignapas)
1515
1616
************************************************************************ */
17-
/* eslint-disable no-use-before-define */
1817

1918
/**
2019
* Display widget with a title bar and collapsible content.
@@ -43,7 +42,7 @@ qx.Class.define("osparc.desktop.PanelView", {
4342
_applyContent: function(content, oldContent) {
4443
this.base(arguments, content, oldContent);
4544

46-
this._innerContainer.set({
45+
this.getInnerContainer().set({
4746
appearance: "panelview-content"
4847
});
4948
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2018 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (ignapas)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.desktop.RadioCollapsibleViews", {
19+
extend: qx.core.Object,
20+
21+
/**
22+
* @param {Array} collapsibleViews array of osparc.widget.CollapsibleView
23+
*/
24+
construct: function(collapsibleViews = []) {
25+
this.base(arguments);
26+
27+
this.__collapsibleViews = [];
28+
29+
collapsibleViews.forEach(cv => this.addCollapsibleView(cv));
30+
},
31+
32+
members: {
33+
__collapsibleViews: null,
34+
35+
/**
36+
* @param {osparc.widget.CollapsibleView | osparc.desktop.PanelView} collapsibleView
37+
*/
38+
addCollapsibleView: function(collapsibleView) {
39+
this.__collapsibleViews.push(collapsibleView);
40+
41+
collapsibleView.addListener("changeCollapsed", e => {
42+
const collapsed = e.getData();
43+
if (collapsed === false) {
44+
// close the other views
45+
const idx = this.__collapsibleViews.indexOf(collapsibleView);
46+
this.__collapsibleViews.forEach((cv, idx2) => {
47+
if (idx !== idx2) {
48+
cv.setCollapsed(true);
49+
}
50+
})
51+
}
52+
}, this);
53+
},
54+
55+
openCollapsibleView: function(idx = 0) {
56+
if (idx < this.__collapsibleViews.length) {
57+
this.__collapsibleViews[idx].setCollapsed(false);
58+
}
59+
}
60+
}
61+
});

services/static-webserver/client/source/class/osparc/file/FileDrop.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,16 @@ qx.Class.define("osparc.file.FileDrop", {
5151
}
5252
msg += "</center>";
5353

54-
const dropHere = this.__dropHere = new qx.ui.basic.Label(msg).set({
54+
const dropHereMessage = this.__dropHereMessage = new qx.ui.basic.Label(msg).set({
5555
font: "text-14",
5656
rich: true,
5757
alignX: "center",
5858
alignY: "middle"
5959
});
60-
this._add(dropHere, {
61-
top: 40,
62-
left: 40
63-
});
60+
this._add(dropHereMessage);
6461

65-
const centerDropHere = () => {
66-
// center it
67-
const dropHereBounds = dropHere.getBounds() || dropHere.getSizeHint();
68-
const fileDropBounds = this.getBounds() || this.getSizeHint();
69-
dropHere.setLayoutProperties({
70-
top: parseInt((fileDropBounds.height - dropHereBounds.height) / 2),
71-
left: parseInt((fileDropBounds.width - dropHereBounds.width) / 2)
72-
});
73-
};
74-
dropHere.addListener("appear", centerDropHere);
75-
this.addListener("resize", centerDropHere);
62+
dropHereMessage.addListener("appear", () => this.__centerDropHereMessage(), this);
63+
this.addListener("resize", () => this.__centerDropHereMessage(), this);
7664

7765
const svgLayer = this.__svgLayer = new osparc.workbench.SvgWidget();
7866
this._add(svgLayer, {
@@ -123,7 +111,7 @@ qx.Class.define("osparc.file.FileDrop", {
123111

124112
members: {
125113
__svgLayer: null,
126-
__dropHere: null,
114+
__dropHereMessage: null,
127115
__dropMe: null,
128116
__isDraggingFile: null,
129117
__isDraggingLink: null,
@@ -134,7 +122,25 @@ qx.Class.define("osparc.file.FileDrop", {
134122
},
135123

136124
__applyShowDropHere: function(value) {
137-
this.__dropHere.setVisibility(value ? "visible" : "excluded");
125+
this.__dropHereMessage.setVisibility(value ? "visible" : "excluded");
126+
},
127+
128+
__centerDropHereMessage: function() {
129+
const dropHere = this.__dropHereMessage;
130+
// center it
131+
const dropHereBounds = dropHere.getBounds() || dropHere.getSizeHint();
132+
const fileDropBounds = this.getBounds() || this.getSizeHint();
133+
dropHere.setLayoutProperties({
134+
top: parseInt((fileDropBounds.height - dropHereBounds.height) / 2),
135+
left: parseInt((fileDropBounds.width - dropHereBounds.width) / 2)
136+
});
137+
},
138+
139+
setDropHereMessage: function(msg) {
140+
this.__dropHereMessage.set({
141+
value: msg
142+
});
143+
this.__centerDropHereMessage();
138144
},
139145

140146
resetDropAction: function() {
@@ -212,11 +218,11 @@ qx.Class.define("osparc.file.FileDrop", {
212218

213219
__updateWidgets: function(dragging, posX, posY) {
214220
if (dragging) {
215-
this.__dropHere.exclude();
221+
this.__dropHereMessage.exclude();
216222
this.__updateDropMe(posX, posY);
217223
} else {
218224
if (this.getShowDropHere()) {
219-
this.__dropHere.show();
225+
this.__dropHereMessage.show();
220226
}
221227
this.__hideDropMe();
222228
}

services/static-webserver/client/source/class/osparc/file/FilePicker.js

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -284,26 +284,17 @@ qx.Class.define("osparc.file.FilePicker", {
284284

285285
__buildLayout: function() {
286286
this._removeAll();
287-
const isWorkbenchContext = this.getPageContext() === "workbench";
288287
const hasOutput = osparc.file.FilePicker.hasOutputAssigned(this.getNode().getOutputs());
289-
if (isWorkbenchContext) {
290-
if (hasOutput) {
291-
// WORKBENCH mode WITH output
292-
this.__buildInfoLayout();
293-
} else {
294-
// WORKBENCH mode WITHOUT output
295-
this.__addProgressBar();
296-
this.__buildNoFileWBLayout();
297-
}
288+
if (hasOutput) {
289+
this.__buildInfoLayout();
298290
} else {
299-
this.setMargin(10);
300-
if (hasOutput) {
301-
// APP mode WITH output
302-
this.__buildInfoLayout();
291+
this.__addProgressBar();
292+
const isWorkbenchContext = this.getPageContext() === "workbench";
293+
if (isWorkbenchContext) {
294+
this.__buildWorkbenchLayout();
303295
} else {
304-
// APP mode WITHOUT output
305-
this.__addProgressBar();
306-
this.__buildNoFileAppLayout();
296+
this.setMargin(10);
297+
this.__buildAppModeLayout();
307298
}
308299
}
309300
},
@@ -312,6 +303,7 @@ qx.Class.define("osparc.file.FilePicker", {
312303
const progressLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5).set({
313304
alignY: "middle"
314305
}));
306+
progressLayout.alwaysEnabled = true;
315307

316308
const progressBar = new qx.ui.indicator.ProgressBar();
317309
const nodeStatus = this.getNode().getStatus();
@@ -341,7 +333,7 @@ qx.Class.define("osparc.file.FilePicker", {
341333
const uploading = (validProgress > 0 && validProgress < 100);
342334
progressLayout.setVisibility(uploading ? "visible" : "excluded");
343335
this._getChildren().forEach(child => {
344-
if (child !== progressLayout) {
336+
if (!child.alwaysEnabled) {
345337
child.setEnabled(!uploading);
346338
}
347339
});
@@ -390,19 +382,6 @@ qx.Class.define("osparc.file.FilePicker", {
390382
return resetFileBtn;
391383
},
392384

393-
__buildNoFileWBLayout: function() {
394-
const uploadFileSection = this.__getUploadFileSection();
395-
this._add(uploadFileSection);
396-
397-
const fileDrop = this.__getFileDropSection();
398-
this._add(fileDrop, {
399-
flex: 1
400-
});
401-
402-
const downloadLinkSection = this.__getDownloadLinkSection();
403-
this._add(downloadLinkSection);
404-
},
405-
406385
__getUploadFileSection: function() {
407386
const uploadFileSection = new osparc.ui.form.FileInput();
408387
uploadFileSection.addListener("selectionChanged", () => {
@@ -453,9 +432,7 @@ qx.Class.define("osparc.file.FilePicker", {
453432
},
454433

455434
__getDownloadLinkSection: function() {
456-
const layout = new qx.ui.container.Composite(new qx.ui.layout.VBox(5).set({
457-
alignY: "middle"
458-
}));
435+
const layout = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
459436

460437
layout.add(new qx.ui.basic.Label(this.tr("Provide Link")));
461438

@@ -473,12 +450,25 @@ qx.Class.define("osparc.file.FilePicker", {
473450
return layout;
474451
},
475452

476-
__buildNoFileAppLayout: function() {
477-
let msg = this.tr("In order to Select a file you have three options:");
453+
__buildWorkbenchLayout: function() {
454+
const uploadFileSection = this.__getUploadFileSection();
455+
this._add(uploadFileSection);
456+
457+
const fileDrop = this.__getFileDropSection();
458+
this._add(fileDrop, {
459+
flex: 1
460+
});
461+
462+
const downloadLinkSection = this.__getDownloadLinkSection();
463+
this._add(downloadLinkSection);
464+
},
465+
466+
__buildAppModeLayout: function() {
467+
let msg = this.tr("In order to Select a File you have three options:");
478468
const options = [
479-
this.tr("- Upload a file"),
480-
this.tr("- Select a file from tree"),
481-
this.tr("- Provide Link")
469+
this.tr("- Upload a New File"),
470+
this.tr("- Provide a File Link"),
471+
this.tr("- Select a File from other ") + osparc.product.Utils.getStudyAlias()
482472
];
483473
for (let i=0; i<options.length; i++) {
484474
msg += "<br>" + options[i];
@@ -489,16 +479,52 @@ qx.Class.define("osparc.file.FilePicker", {
489479
});
490480
this._add(intro);
491481

492-
const uploadFileSection = this.__getUploadFileSection();
493-
this._add(uploadFileSection);
482+
const collapsibleViews = [];
483+
const contentMargin = 10;
494484

495-
const fileBrowserLayout = this.__getFileBrowserLayout();
496-
this._add(fileBrowserLayout, {
485+
const newFileSection = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
486+
const uploadFileSection = this.__getUploadFileSection();
487+
uploadFileSection.getButton().set({
488+
appearance: "strong-button",
489+
font: "text-14"
490+
});
491+
newFileSection.add(uploadFileSection);
492+
const fileDrop = this.__getFileDropSection();
493+
fileDrop.setDropHereMessage(this.tr("Drop file here"));
494+
newFileSection.add(fileDrop, {
497495
flex: 1
498496
});
497+
const newFilePView = new osparc.desktop.PanelView().set({
498+
title: this.tr("Select New File"),
499+
content: newFileSection
500+
});
501+
collapsibleViews.push(newFilePView);
499502

500503
const downloadLinkSection = this.__getDownloadLinkSection();
501-
this._add(downloadLinkSection);
504+
const downloadLinkPView = new osparc.desktop.PanelView().set({
505+
title: this.tr("Select Download Link"),
506+
content: downloadLinkSection
507+
});
508+
collapsibleViews.push(downloadLinkPView);
509+
510+
const fileBrowserLayout = this.__getFileBrowserLayout();
511+
const usedFilePView = new osparc.desktop.PanelView().set({
512+
title: this.tr("Select File from other ") + osparc.product.Utils.getStudyAlias(),
513+
content: fileBrowserLayout
514+
});
515+
collapsibleViews.push(usedFilePView);
516+
517+
const radioCollapsibleViews = new osparc.desktop.RadioCollapsibleViews();
518+
collapsibleViews.forEach(cv => {
519+
cv.getInnerContainer().set({
520+
margin: contentMargin
521+
});
522+
this._add(cv, {
523+
flex: 1
524+
});
525+
radioCollapsibleViews.addCollapsibleView(cv);
526+
});
527+
radioCollapsibleViews.openCollapsibleView(0);
502528
},
503529

504530
__getFileBrowserLayout: function() {

services/static-webserver/client/source/class/osparc/ui/form/FileInput.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ qx.Class.define("osparc.ui.form.FileInput", {
3434
});
3535
this.getContentElement().add(this.__input);
3636

37-
this.__selectBtn = new qx.ui.form.Button(this.tr("Select a file..."));
37+
this.__selectBtn = new qx.ui.form.Button(this.tr("Select File..."));
3838
this._add(this.__selectBtn);
3939

4040
this.__selectedFiles = new qx.ui.basic.Label();
@@ -63,6 +63,10 @@ qx.Class.define("osparc.ui.form.FileInput", {
6363
__selectBtn: null,
6464
__selectedFiles: null,
6565

66+
getButton: function() {
67+
return this.__selectBtn;
68+
},
69+
6670
__attachEventHandlers: function() {
6771
this.__input.addListener("change", () => {
6872
const fileNames = [];

services/static-webserver/client/source/class/osparc/widget/CollapsibleView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ qx.Class.define("osparc.widget.CollapsibleView", {
221221
}
222222
},
223223

224+
getInnerContainer: function() {
225+
return this._innerContainer;
226+
},
227+
224228
_applyCaretSize: function(size) {
225229
this.getChildControl("caret").setSource(this.__getCaretId(this.getCollapsed()));
226230
},

0 commit comments

Comments
 (0)