|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2020 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 | +/** |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +qx.Class.define("osparc.component.widget.BreadcrumbNavigation", { |
| 23 | + extend: qx.ui.core.Widget, |
| 24 | + |
| 25 | + construct: function() { |
| 26 | + this.base(arguments); |
| 27 | + |
| 28 | + this._setLayout(new qx.ui.layout.HBox(0).set({ |
| 29 | + alignY: "middle" |
| 30 | + })); |
| 31 | + }, |
| 32 | + |
| 33 | + events: { |
| 34 | + "nodeSelected": "qx.event.type.Data" |
| 35 | + }, |
| 36 | + |
| 37 | + statics: { |
| 38 | + BUTTON_OPTIONS: { |
| 39 | + font: "text-14", |
| 40 | + allowGrowY: false, |
| 41 | + minWidth: 32, |
| 42 | + minHeight: 32 |
| 43 | + } |
| 44 | + }, |
| 45 | + |
| 46 | + members: { |
| 47 | + populateButtons: function(nodesIds = [], shape = "slash") { |
| 48 | + const btns = []; |
| 49 | + if (shape === "slash") { |
| 50 | + for (let i=0; i<nodesIds.length; i++) { |
| 51 | + const nodeId = nodesIds[i]; |
| 52 | + const btn = this.__createNodePathBtn(nodeId); |
| 53 | + if (i === nodesIds.length-1) { |
| 54 | + btn.setValue(true); |
| 55 | + } |
| 56 | + btns.push(btn); |
| 57 | + } |
| 58 | + } else if (shape === "arrow") { |
| 59 | + const study = osparc.store.Store.getInstance().getCurrentStudy(); |
| 60 | + const currentNodeId = study.getUi().getCurrentNodeId(); |
| 61 | + for (let i=0; i<nodesIds.length; i++) { |
| 62 | + const nodeId = nodesIds[i]; |
| 63 | + const btn = this.__createNodeSlideBtn(nodeId); |
| 64 | + if (nodeId === currentNodeId) { |
| 65 | + btn.setValue(true); |
| 66 | + } |
| 67 | + btns.push(btn); |
| 68 | + } |
| 69 | + } |
| 70 | + this.__buttonsToBreadcrumb(btns, shape); |
| 71 | + }, |
| 72 | + |
| 73 | + __createNodeBtn: function(nodeId) { |
| 74 | + const btn = new qx.ui.form.ToggleButton().set({ |
| 75 | + ...this.self().BUTTON_OPTIONS, |
| 76 | + maxWidth: 200 |
| 77 | + }); |
| 78 | + btn.addListener("execute", () => { |
| 79 | + this.fireDataEvent("nodeSelected", nodeId); |
| 80 | + }, this); |
| 81 | + return btn; |
| 82 | + }, |
| 83 | + |
| 84 | + __createNodePathBtn: function(nodeId) { |
| 85 | + const btn = this.__createNodeBtn(nodeId); |
| 86 | + const study = osparc.store.Store.getInstance().getCurrentStudy(); |
| 87 | + if (nodeId === study.getUuid()) { |
| 88 | + study.bind("name", btn, "label"); |
| 89 | + study.bind("name", btn, "toolTipText"); |
| 90 | + } else { |
| 91 | + const node = study.getWorkbench().getNode(nodeId); |
| 92 | + if (node) { |
| 93 | + node.bind("label", btn, "label"); |
| 94 | + node.bind("label", btn, "toolTipText"); |
| 95 | + } |
| 96 | + } |
| 97 | + return btn; |
| 98 | + }, |
| 99 | + |
| 100 | + __createNodeSlideBtn: function(nodeId) { |
| 101 | + const btn = this.__createNodeBtn(nodeId); |
| 102 | + const study = osparc.store.Store.getInstance().getCurrentStudy(); |
| 103 | + const slideShow = study.getUi().getSlideshow(); |
| 104 | + const node = study.getWorkbench().getNode(nodeId); |
| 105 | + if (node && nodeId in slideShow) { |
| 106 | + const pos = slideShow[nodeId].position; |
| 107 | + node.bind("label", btn, "label", { |
| 108 | + converter: val => (pos+1).toString() + "- " + val |
| 109 | + }); |
| 110 | + node.bind("label", btn, "toolTipText"); |
| 111 | + } |
| 112 | + return btn; |
| 113 | + }, |
| 114 | + |
| 115 | + __buttonsToBreadcrumb: function(btns, shape = "slash") { |
| 116 | + this._removeAll(); |
| 117 | + for (let i=0; i<btns.length; i++) { |
| 118 | + const thisBtn = btns[i]; |
| 119 | + let nextBtn = null; |
| 120 | + if (i+1<btns.length) { |
| 121 | + nextBtn = btns[i+1]; |
| 122 | + } |
| 123 | + |
| 124 | + this._add(thisBtn); |
| 125 | + |
| 126 | + const breadcrumbSplitter = new osparc.component.widget.BreadcrumbSplitter(16, 32).set({ |
| 127 | + shape, |
| 128 | + marginLeft: -1, |
| 129 | + marginRight: -1 |
| 130 | + }); |
| 131 | + if (breadcrumbSplitter.getReady()) { |
| 132 | + breadcrumbSplitter.setLeftWidget(thisBtn); |
| 133 | + if (nextBtn) { |
| 134 | + breadcrumbSplitter.setRightWidget(nextBtn); |
| 135 | + } |
| 136 | + } else { |
| 137 | + breadcrumbSplitter.addListenerOnce("SvgWidgetReady", () => { |
| 138 | + breadcrumbSplitter.setLeftWidget(thisBtn); |
| 139 | + if (nextBtn) { |
| 140 | + breadcrumbSplitter.setRightWidget(nextBtn); |
| 141 | + } |
| 142 | + }, this); |
| 143 | + } |
| 144 | + this._add(breadcrumbSplitter); |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | +}); |
0 commit comments