-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [Frontend] Connect folders to backend (#6151)
- Loading branch information
Showing
14 changed files
with
542 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
services/static-webserver/client/source/class/osparc/dashboard/FolderTreeItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* ************************************************************************ | ||
osparc - the simcore frontend | ||
https://osparc.io | ||
Copyright: | ||
2024 IT'IS Foundation, https://itis.swiss | ||
License: | ||
MIT: https://opensource.org/licenses/MIT | ||
Authors: | ||
* Odei Maiz (odeimaiz) | ||
************************************************************************ */ | ||
|
||
qx.Class.define("osparc.dashboard.FolderTreeItem", { | ||
extend: qx.ui.tree.VirtualTreeItem, | ||
|
||
members: { | ||
_addWidgets: function() { | ||
this.addSpacer(); | ||
// this.addOpenButton(); | ||
const openButton = this.getChildControl("open"); | ||
openButton.addListener("changeOpen", () => { | ||
console.log("changeOpen", this); | ||
}, this); | ||
openButton.addListener("changeVisibility", e => { | ||
// console.log("changeVisibility", this.getLabel() + e.getData(), this); | ||
openButton.show(); | ||
}, this); | ||
this._add(openButton); | ||
this.addIcon(); | ||
const label = this.getChildControl("label"); | ||
this._add(label, { | ||
flex: 1 | ||
}); | ||
} | ||
} | ||
}); |
131 changes: 131 additions & 0 deletions
131
services/static-webserver/client/source/class/osparc/dashboard/FoldersTree.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* ************************************************************************ | ||
osparc - the simcore frontend | ||
https://osparc.io | ||
Copyright: | ||
2024 IT'IS Foundation, https://itis.swiss | ||
License: | ||
MIT: https://opensource.org/licenses/MIT | ||
Authors: | ||
* Odei Maiz (odeimaiz) | ||
************************************************************************ */ | ||
|
||
qx.Class.define("osparc.dashboard.FoldersTree", { | ||
extend: qx.ui.tree.VirtualTree, | ||
|
||
construct: function() { | ||
const rootFolder = this.self().createNewEntry(null); | ||
const root = qx.data.marshal.Json.createModel(rootFolder, true); | ||
this.__fetchChildren(root); | ||
|
||
this.base(arguments, root, "label", "children"); | ||
|
||
this.set({ | ||
openMode: "dbltap", | ||
decorator: "no-border", | ||
font: "text-14", | ||
showLeafs: true, | ||
paddingLeft: -10, | ||
}); | ||
|
||
this.__initTree(); | ||
}, | ||
|
||
events: { | ||
"selectionChanged": "qx.event.type.Event" // tap | ||
}, | ||
|
||
statics: { | ||
createNewEntry: function(folder) { | ||
return { | ||
folderId: folder ? folder.getFolderId() : null, | ||
label: folder ? folder.getName() : "Home", | ||
children: [ | ||
this.self().getLoadingData() | ||
], | ||
loaded: false, | ||
}; | ||
}, | ||
|
||
getLoadingData: function() { | ||
return { | ||
folderId: -1, | ||
label: "Loading...", | ||
children: [], | ||
icon: "@FontAwesome5Solid/circle-notch/12", | ||
loaded: false, | ||
}; | ||
}, | ||
|
||
addLoadingChild: function(parentModel) { | ||
const loadingModel = qx.data.marshal.Json.createModel(this.self().getLoadingData(), true); | ||
parentModel.getChildren().append(loadingModel); | ||
}, | ||
|
||
removeLoadingChild: function(parent) { | ||
for (let i = parent.getChildren().getLength() - 1; i >= 0; i--) { | ||
if (parent.getChildren().toArray()[i].getLabel() === "Loading...") { | ||
parent.getChildren().splice(i, 1); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
members: { | ||
__initTree: function() { | ||
const that = this; | ||
this.setDelegate({ | ||
createItem: () => new osparc.dashboard.FolderTreeItem(), | ||
bindItem: (c, item, id) => { | ||
c.bindDefaultProperties(item, id); | ||
c.bindProperty("folderId", "model", null, item, id); | ||
c.bindProperty("", "open", { | ||
converter(value, _, __, target) { | ||
const isOpen = target.isOpen(); | ||
if (isOpen && !value.getLoaded()) { | ||
// eslint-disable-next-line no-underscore-dangle | ||
that.__fetchChildren(value); | ||
} | ||
return isOpen; | ||
} | ||
}, item, id); | ||
}, | ||
configureItem: item => { | ||
item.addListener("tap", () => this.fireDataEvent("selectionChanged", item.getModel()), this); | ||
}, | ||
sorter: (a, b) => { | ||
const aLabel = a.getLabel(); | ||
if (aLabel === -1) { | ||
return 1; | ||
} | ||
const bLabel = b.getLabel(); | ||
if (bLabel === -1) { | ||
return -1; | ||
} | ||
return aLabel - bLabel; | ||
} | ||
}); | ||
}, | ||
|
||
__fetchChildren: function(parentModel) { | ||
parentModel.setLoaded(true); | ||
|
||
const folderId = parentModel.getFolderId ? parentModel.getFolderId() : parentModel.getModel(); | ||
osparc.store.Folders.getInstance().fetchFolders(folderId) | ||
.then(folders => { | ||
this.self().removeLoadingChild(parentModel); | ||
folders.forEach(folder => { | ||
const folderData = this.self().createNewEntry(folder); | ||
const folderModel = qx.data.marshal.Json.createModel(folderData, true); | ||
parentModel.getChildren().append(folderModel); | ||
}); | ||
}) | ||
.catch(console.error); | ||
} | ||
} | ||
}); |
92 changes: 92 additions & 0 deletions
92
services/static-webserver/client/source/class/osparc/dashboard/MoveStudyToFolder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* ************************************************************************ | ||
osparc - the simcore frontend | ||
https://osparc.io | ||
Copyright: | ||
2024 IT'IS Foundation, https://itis.swiss | ||
License: | ||
MIT: https://opensource.org/licenses/MIT | ||
Authors: | ||
* Odei Maiz (odeimaiz) | ||
************************************************************************ */ | ||
|
||
qx.Class.define("osparc.dashboard.MoveStudyToFolder", { | ||
extend: qx.ui.core.Widget, | ||
|
||
construct: function(studyData, currentFolderId) { | ||
this.base(arguments); | ||
|
||
this.__studyData = studyData; | ||
this.__currentFolderId = currentFolderId; | ||
|
||
this._setLayout(new qx.ui.layout.VBox(10)); | ||
|
||
this.getChildControl("current-folder"); | ||
const foldersTree = this.getChildControl("folders-tree"); | ||
this.getChildControl("cancel-btn"); | ||
const moveButton = this.getChildControl("move-btn"); | ||
|
||
moveButton.setEnabled(false) | ||
foldersTree.addListener("selectionChanged", e => { | ||
const folderId = e.getData(); | ||
moveButton.setEnabled(this.__currentFolderId !== folderId); | ||
moveButton.addListenerOnce("execute", () => this.fireDataEvent("moveToFolder", folderId)); | ||
}); | ||
}, | ||
|
||
events: { | ||
"cancel": "qx.event.type.Event", | ||
"moveToFolder": "qx.event.type.Data" | ||
}, | ||
|
||
members: { | ||
__studyData: null, | ||
__currentFolderId: null, | ||
|
||
_createChildControlImpl: function(id) { | ||
let control; | ||
switch (id) { | ||
case "current-folder": { | ||
const folder = osparc.store.Folders.getInstance().getFolder(this.__currentFolderId); | ||
const currentFolderName = folder ? folder["name"] : "Home"; | ||
control = new qx.ui.basic.Label(this.tr("Current location: ") + currentFolderName); | ||
this._add(control); | ||
break; | ||
} | ||
case "folders-tree": | ||
control = new osparc.dashboard.FoldersTree(); | ||
this._add(control); | ||
break; | ||
case "buttons-layout": | ||
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(10).set({ | ||
alignX: "right" | ||
})); | ||
this._add(control); | ||
break; | ||
case "cancel-btn": { | ||
const buttons = this.getChildControl("buttons-layout"); | ||
control = new qx.ui.form.Button(this.tr("Cancel")).set({ | ||
appearance: "form-button-text" | ||
}); | ||
control.addListener("execute", () => this.fireEvent("cancel"), this); | ||
buttons.add(control); | ||
break; | ||
} | ||
case "move-btn": { | ||
const buttons = this.getChildControl("buttons-layout"); | ||
control = new qx.ui.form.Button(this.tr("Move")).set({ | ||
appearance: "form-button" | ||
}); | ||
buttons.add(control); | ||
break; | ||
} | ||
} | ||
return control || this.base(arguments, id); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.