|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2025 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.jobs.JobsButton", { |
| 19 | + extend: qx.ui.core.Widget, |
| 20 | + |
| 21 | + construct: function() { |
| 22 | + this.base(arguments); |
| 23 | + |
| 24 | + this._setLayout(new qx.ui.layout.Canvas()); |
| 25 | + |
| 26 | + this.set({ |
| 27 | + width: 30, |
| 28 | + alignX: "center", |
| 29 | + cursor: "pointer", |
| 30 | + visibility: "excluded", |
| 31 | + toolTipText: this.tr("Jobs"), |
| 32 | + }); |
| 33 | + |
| 34 | + const jobsStore = osparc.store.Jobs.getInstance(); |
| 35 | + jobsStore.getJobs().addListener("change", e => this.__updateJobsButton(), this); |
| 36 | + this.addListener("tap", () => console.log("Pop up jobs table"), this); |
| 37 | + }, |
| 38 | + |
| 39 | + members: { |
| 40 | + _createChildControlImpl: function(id) { |
| 41 | + let control; |
| 42 | + switch (id) { |
| 43 | + case "icon": { |
| 44 | + control = new qx.ui.basic.Image("@FontAwesome5Solid/cog/24"); |
| 45 | + osparc.utils.Utils.addClass(control.getContentElement(), "rotate"); |
| 46 | + |
| 47 | + const logoContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({ |
| 48 | + alignY: "middle" |
| 49 | + })); |
| 50 | + logoContainer.add(control); |
| 51 | + |
| 52 | + this._add(logoContainer, { |
| 53 | + height: "100%" |
| 54 | + }); |
| 55 | + break; |
| 56 | + } |
| 57 | + case "number": |
| 58 | + control = new qx.ui.basic.Label().set({ |
| 59 | + backgroundColor: "background-main-1", |
| 60 | + font: "text-12" |
| 61 | + }); |
| 62 | + control.getContentElement().setStyles({ |
| 63 | + "border-radius": "4px" |
| 64 | + }); |
| 65 | + this._add(control, { |
| 66 | + bottom: 8, |
| 67 | + right: 4 |
| 68 | + }); |
| 69 | + break; |
| 70 | + } |
| 71 | + return control || this.base(arguments, id); |
| 72 | + }, |
| 73 | + |
| 74 | + __updateJobsButton: function() { |
| 75 | + this._createChildControlImpl("icon"); |
| 76 | + const number = this.getChildControl("number"); |
| 77 | + |
| 78 | + const jobsStore = osparc.store.Jobs.getInstance(); |
| 79 | + const nJobs = jobsStore.getJobs().length; |
| 80 | + number.setValue(nJobs.toString()); |
| 81 | + nJobs ? this.show() : this.exclude(); |
| 82 | + }, |
| 83 | + } |
| 84 | +}); |
0 commit comments