|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2024 IT'IS Foundation, https://itis.swiss |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | +
|
| 13 | + Authors: |
| 14 | + * Odei Maiz (odeimaiz) |
| 15 | +
|
| 16 | +************************************************************************ */ |
| 17 | + |
| 18 | +qx.Class.define("osparc.dashboard.MoveResourceTo", { |
| 19 | + extend: qx.ui.core.Widget, |
| 20 | + |
| 21 | + construct: function(currentWorkspaceId, currentFolderId) { |
| 22 | + this.base(arguments); |
| 23 | + |
| 24 | + this.__currentWorkspaceId = currentWorkspaceId; |
| 25 | + this.__currentFolderId = currentFolderId; |
| 26 | + |
| 27 | + this._setLayout(new qx.ui.layout.VBox(10)); |
| 28 | + |
| 29 | + this.getChildControl("current-location"); |
| 30 | + |
| 31 | + const workspacesAndFoldersTree = this.getChildControl("workspaces-and-folders-tree"); |
| 32 | + this.getChildControl("cancel-btn"); |
| 33 | + const moveButton = this.getChildControl("move-btn"); |
| 34 | + |
| 35 | + moveButton.setEnabled(false); |
| 36 | + workspacesAndFoldersTree.getSelection().addListener("change", () => { |
| 37 | + const selection = workspacesAndFoldersTree.getSelection(); |
| 38 | + if (selection.getLength() > 0) { |
| 39 | + const item = selection.getItem(0); |
| 40 | + this.__selectedWorkspaceId = item.getWorkspaceId(); |
| 41 | + this.__selectedFolderId = item.getFolderId(); |
| 42 | + moveButton.setEnabled(this.__currentWorkspaceId !== this.__selectedWorkspaceId || this.__currentFolderId !== this.__selectedFolderId); |
| 43 | + } |
| 44 | + }, this); |
| 45 | + moveButton.addListener("execute", () => { |
| 46 | + this.fireDataEvent("moveTo", { |
| 47 | + workspaceId: this.__selectedWorkspaceId, |
| 48 | + folderId: this.__selectedFolderId, |
| 49 | + }); |
| 50 | + }, this); |
| 51 | + }, |
| 52 | + |
| 53 | + events: { |
| 54 | + "cancel": "qx.event.type.Event", |
| 55 | + "moveTo": "qx.event.type.Data" |
| 56 | + }, |
| 57 | + |
| 58 | + members: { |
| 59 | + __currentWorkspaceId: null, |
| 60 | + __currentFolderId: null, |
| 61 | + __selectedWorkspaceId: null, |
| 62 | + __selectedFolderId: null, |
| 63 | + |
| 64 | + _createChildControlImpl: function(id) { |
| 65 | + let control; |
| 66 | + switch (id) { |
| 67 | + case "current-location": { |
| 68 | + control = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)); |
| 69 | + const intro = new qx.ui.basic.Label(this.tr("Current location")); |
| 70 | + control.add(intro); |
| 71 | + const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.__currentWorkspaceId); |
| 72 | + const workspaceText = workspace ? workspace.getName() : "My Workspace"; |
| 73 | + const workspaceLabel = new qx.ui.basic.Label(this.tr("- Workspace: ") + workspaceText); |
| 74 | + control.add(workspaceLabel); |
| 75 | + const folder = osparc.store.Folders.getInstance().getFolder(this.__currentFolderId); |
| 76 | + if (folder) { |
| 77 | + const folderText = folder.getName(); |
| 78 | + const folderLabel = new qx.ui.basic.Label(this.tr("- Folder: ") + folderText); |
| 79 | + control.add(folderLabel); |
| 80 | + } |
| 81 | + this._add(control); |
| 82 | + break; |
| 83 | + } |
| 84 | + case "workspaces-and-folders-tree": |
| 85 | + control = new osparc.dashboard.WorkspacesAndFoldersTree(); |
| 86 | + this._add(control, { |
| 87 | + flex: 1 |
| 88 | + }); |
| 89 | + break; |
| 90 | + case "buttons-layout": |
| 91 | + control = new qx.ui.container.Composite(new qx.ui.layout.HBox(10).set({ |
| 92 | + alignX: "right" |
| 93 | + })); |
| 94 | + this._add(control); |
| 95 | + break; |
| 96 | + case "cancel-btn": { |
| 97 | + const buttons = this.getChildControl("buttons-layout"); |
| 98 | + control = new qx.ui.form.Button(this.tr("Cancel")).set({ |
| 99 | + appearance: "form-button-text" |
| 100 | + }); |
| 101 | + control.addListener("execute", () => this.fireEvent("cancel"), this); |
| 102 | + buttons.add(control); |
| 103 | + break; |
| 104 | + } |
| 105 | + case "move-btn": { |
| 106 | + const buttons = this.getChildControl("buttons-layout"); |
| 107 | + control = new qx.ui.form.Button(this.tr("Move")).set({ |
| 108 | + appearance: "form-button" |
| 109 | + }); |
| 110 | + buttons.add(control); |
| 111 | + break; |
| 112 | + } |
| 113 | + } |
| 114 | + return control || this.base(arguments, id); |
| 115 | + }, |
| 116 | + |
| 117 | + __getUpstreamFolders: function(childFolder, folderIds = []) { |
| 118 | + if (childFolder) { |
| 119 | + folderIds.unshift(childFolder.getFolderId()); |
| 120 | + const parentFolder = osparc.store.Folders.getInstance().getFolder(childFolder.getParentFolderId()); |
| 121 | + this.__getUpstreamFolders(parentFolder, folderIds); |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | +}); |
0 commit comments