Skip to content

Commit

Permalink
✨ [Frontend] Workspaces: Connect to backend (#6304)
Browse files Browse the repository at this point in the history
Co-authored-by: matusdrobuliak66 <[email protected]>
Co-authored-by: matusdrobuliak66 <[email protected]>
  • Loading branch information
3 people authored Sep 6, 2024
1 parent 99de33d commit 4d70330
Show file tree
Hide file tree
Showing 26 changed files with 778 additions and 466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ qx.Class.define("osparc.auth.ui.LoginView", {
this.fireEvent("toRegister");
} else if (createAccountAction === "REQUEST_ACCOUNT_FORM") {
this.fireEvent("toRequestAccount");
} else if (createAccountAction === "REQUEST_ACCOUNT_FORM") {
} else if (createAccountAction === "REQUEST_ACCOUNT_INSTRUCTIONS") {
osparc.store.Support.openInvitationRequiredDialog();
}
createAccountBtn.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
events: {
"folderSelected": "qx.event.type.Data",
"folderUpdated": "qx.event.type.Data",
"moveFolderToFolderRequested": "qx.event.type.Data",
"moveFolderToWorkspaceRequested": "qx.event.type.Data",
"deleteFolderRequested": "qx.event.type.Data"
},

Expand Down Expand Up @@ -73,12 +75,6 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
apply: "__applyTitle"
},

description: {
check: "String",
nullable: true,
apply: "__applyDescription"
},

lastModified: {
check: "Date",
nullable: true,
Expand Down Expand Up @@ -143,7 +139,6 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
folder.bind("folderId", this, "folderId");
folder.bind("parentId", this, "parentFolderId");
folder.bind("name", this, "title");
folder.bind("description", this, "description");
folder.bind("lastModified", this, "lastModified");

this.__addMenuButton();
Expand All @@ -152,11 +147,6 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
__applyTitle: function(value) {
const label = this.getChildControl("title");
label.setValue(value);
this.__updateTooltip();
},

__applyDescription: function() {
this.__updateTooltip();
},

__applyLastModified: function(value) {
Expand All @@ -175,58 +165,59 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
});

const editButton = new qx.ui.menu.Button(this.tr("Rename..."), "@FontAwesome5Solid/pencil-alt/12");
editButton.addListener("execute", () => {
const folder = this.getFolder();
const newFolder = false;
const folderEditor = new osparc.editor.FolderEditor(newFolder).set({
label: folder.getName(),
description: folder.getDescription()
});
const title = this.tr("Edit Folder");
const win = osparc.ui.window.Window.popUpInWindow(folderEditor, title, 300, 200);
folderEditor.addListener("updateFolder", () => {
const newName = folderEditor.getLabel();
const newDescription = folderEditor.getDescription();
const updateData = {
"name": newName,
"description": newDescription
};
osparc.data.model.Folder.putFolder(this.getFolderId(), updateData)
.then(() => {
folder.set({
name: newName,
description: newDescription
});
this.fireDataEvent("folderUpdated", folder.getFolderId());
})
.catch(err => console.error(err));
win.close();
});
folderEditor.addListener("cancel", () => win.close());
});
editButton.addListener("execute", () => this.__editFolder(), this);
menu.add(editButton);

const moveToFolderButton = new qx.ui.menu.Button(this.tr("Move to Folder..."), "@FontAwesome5Solid/folder/12");
moveToFolderButton.addListener("execute", () => this.fireDataEvent("moveFolderToFolderRequested", this.getFolderId()), this);
menu.add(moveToFolderButton);

const moveToWorkspaceButton = new qx.ui.menu.Button(this.tr("Move to Workspace..."), "");
moveToWorkspaceButton.addListener("execute", () => this.fireDataEvent("moveFolderToWorkspaceRequested", this.getFolderId()), this);
menu.add(moveToWorkspaceButton);

menu.addSeparator();

const deleteButton = new qx.ui.menu.Button(this.tr("Delete"), "@FontAwesome5Solid/trash/12");
deleteButton.addListener("execute", () => this.__deleteStudyRequested(), this);
menu.add(deleteButton);

menuButton.setMenu(menu);
},

__updateTooltip: function() {
const toolTipText = this.getTitle() + (this.getDescription() ? "<br>" + this.getDescription() : "");
this.set({
toolTipText
})
},

__itemSelected: function(newVal) {
if (newVal) {
this.fireDataEvent("folderSelected", this.getFolderId());
}
this.setValue(false);
},

__editFolder: function() {
const folder = this.getFolder();
const newFolder = false;
const folderEditor = new osparc.editor.FolderEditor(newFolder).set({
label: folder.getName(),
});
const title = this.tr("Edit Folder");
const win = osparc.ui.window.Window.popUpInWindow(folderEditor, title, 300, 150);
folderEditor.addListener("updateFolder", () => {
const newName = folderEditor.getLabel();
const updateData = {
"name": newName,
};
osparc.data.model.Folder.putFolder(this.getFolderId(), updateData)
.then(() => {
folder.set({
name: newName,
});
this.fireDataEvent("folderUpdated", folder.getFolderId());
})
.catch(err => console.error(err));
win.close();
});
folderEditor.addListener("cancel", () => win.close());
},

__deleteStudyRequested: function() {
const msg = this.tr("Are you sure you want to delete") + " <b>" + this.getTitle() + "</b>?";
const confirmationWin = new osparc.ui.window.Confirmation(msg).set({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ qx.Class.define("osparc.dashboard.FolderButtonNew", {
const newFolder = true;
const folderEditor = new osparc.editor.FolderEditor(newFolder);
const title = this.tr("New Folder");
const win = osparc.ui.window.Window.popUpInWindow(folderEditor, title, 300, 200);
const win = osparc.ui.window.Window.popUpInWindow(folderEditor, title, 300, 150);
folderEditor.addListener("createFolder", () => {
const name = folderEditor.getLabel();
const description = folderEditor.getDescription();
this.fireDataEvent("createFolder", {
name,
description
});
win.close();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
qx.Class.define("osparc.dashboard.FoldersTree", {
extend: qx.ui.tree.VirtualTree,

construct: function() {
const rootFolder = this.self().createNewEntry(null);
construct: function(currentWorkspaceId) {
this.__currentWorkspaceId = currentWorkspaceId;
const workspace = osparc.store.Workspaces.getWorkspace(currentWorkspaceId);
const rootLabel = workspace ? workspace.getName() : "My Workspace";
const rootFolder = this.self().createNewEntry(rootLabel, null);
const root = qx.data.marshal.Json.createModel(rootFolder, true);
this.__fetchChildren(root);

Expand All @@ -41,10 +44,10 @@ qx.Class.define("osparc.dashboard.FoldersTree", {
},

statics: {
createNewEntry: function(folder) {
createNewEntry: function(label, folderId) {
return {
folderId: folder ? folder.getFolderId() : null,
label: folder ? folder.getName() : "Home",
label,
folderId,
children: [
this.self().getLoadingData()
],
Expand Down Expand Up @@ -77,6 +80,8 @@ qx.Class.define("osparc.dashboard.FoldersTree", {
},

members: {
__currentWorkspaceId:null,

__initTree: function() {
const that = this;
this.setDelegate({
Expand Down Expand Up @@ -116,11 +121,11 @@ qx.Class.define("osparc.dashboard.FoldersTree", {
parentModel.setLoaded(true);

const folderId = parentModel.getFolderId ? parentModel.getFolderId() : parentModel.getModel();
osparc.store.Folders.getInstance().fetchFolders(folderId)
osparc.store.Folders.getInstance().fetchFolders(folderId, this.__currentWorkspaceId)
.then(folders => {
this.self().removeLoadingChild(parentModel);
folders.forEach(folder => {
const folderData = this.self().createNewEntry(folder);
const folderData = this.self().createNewEntry(folder.getName(), folder.getFolderId());
const folderModel = qx.data.marshal.Json.createModel(folderData, true);
parentModel.getChildren().append(folderModel);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
************************************************************************ */

qx.Class.define("osparc.dashboard.MoveStudyToFolder", {
qx.Class.define("osparc.dashboard.MoveResourceToFolder", {
extend: qx.ui.core.Widget,

construct: function(studyData, currentFolderId) {
construct: function(currentFolderId, currentWorkspaceId) {
this.base(arguments);

this.__studyData = studyData;
this.__currentFolderId = currentFolderId;
this.__currentWorkspaceId = currentWorkspaceId;

this._setLayout(new qx.ui.layout.VBox(10));

Expand All @@ -35,7 +35,10 @@ qx.Class.define("osparc.dashboard.MoveStudyToFolder", {
foldersTree.addListener("selectionChanged", e => {
const folderId = e.getData();
moveButton.setEnabled(this.__currentFolderId !== folderId);
moveButton.addListenerOnce("execute", () => this.fireDataEvent("moveToFolder", folderId));
this.__selectedFolderId = folderId;
});
moveButton.addListener("execute", () => {
this.fireDataEvent("moveToFolder", this.__selectedFolderId);
});
},

Expand All @@ -45,7 +48,6 @@ qx.Class.define("osparc.dashboard.MoveStudyToFolder", {
},

members: {
__studyData: null,
__currentFolderId: null,

_createChildControlImpl: function(id) {
Expand All @@ -59,7 +61,7 @@ qx.Class.define("osparc.dashboard.MoveStudyToFolder", {
break;
}
case "folders-tree":
control = new osparc.dashboard.FoldersTree();
control = new osparc.dashboard.FoldersTree(this.__currentWorkspaceId);
this._add(control);
break;
case "buttons-layout":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* ************************************************************************
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.MoveResourceToWorkspace", {
extend: qx.ui.core.Widget,

construct: function(currentWorkspaceId) {
this.base(arguments);

this.__currentWorkspaceId = currentWorkspaceId;

this._setLayout(new qx.ui.layout.VBox(10));

this.getChildControl("current-workspace");
const workspacesTree = this.getChildControl("workspaces-tree");
this.getChildControl("cancel-btn");
const moveButton = this.getChildControl("move-btn");

moveButton.setEnabled(false)
workspacesTree.addListener("selectionChanged", e => {
const workspaceId = e.getData();
moveButton.setEnabled(this.__currentWorkspaceId !== workspaceId);
this.__selectedWorkspaceId = workspaceId;
});
moveButton.addListener("execute", () => {
this.fireDataEvent("moveToWorkspace", this.__selectedWorkspaceId);
}, this);
},

events: {
"cancel": "qx.event.type.Event",
"moveToWorkspace": "qx.event.type.Data"
},

members: {
__currentWorkspaceId: null,

_createChildControlImpl: function(id) {
let control;
switch (id) {
case "current-workspace": {
const workspace = osparc.store.Workspaces.getWorkspace(this.__currentWorkspaceId);
const currentWorkspaceName = workspace ? workspace.getName() : "My Workspace";
control = new qx.ui.basic.Label(this.tr("Current location: ") + currentWorkspaceName);
this._add(control);
break;
}
case "workspaces-tree":
control = new osparc.dashboard.WorkspacesTree();
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);
}
}
});
Loading

0 comments on commit 4d70330

Please sign in to comment.