|
| 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.vipMarket.AnatomicalModelDetails", { |
| 19 | + extend: qx.ui.core.Widget, |
| 20 | + |
| 21 | + construct: function() { |
| 22 | + this.base(arguments); |
| 23 | + |
| 24 | + const layout = new qx.ui.layout.Grow(); |
| 25 | + this._setLayout(layout); |
| 26 | + |
| 27 | + this.__poplulateLayout(); |
| 28 | + }, |
| 29 | + |
| 30 | + events: { |
| 31 | + "modelLeased": "qx.event.type.Event", |
| 32 | + }, |
| 33 | + |
| 34 | + properties: { |
| 35 | + anatomicalModelsData: { |
| 36 | + check: "Object", |
| 37 | + init: null, |
| 38 | + nullable: true, |
| 39 | + apply: "__poplulateLayout" |
| 40 | + }, |
| 41 | + }, |
| 42 | + |
| 43 | + members: { |
| 44 | + __poplulateLayout: function() { |
| 45 | + this._removeAll(); |
| 46 | + |
| 47 | + const anatomicalModelsData = this.getAnatomicalModelsData(); |
| 48 | + if (anatomicalModelsData) { |
| 49 | + const card = this.__createcCard(anatomicalModelsData); |
| 50 | + this._add(card); |
| 51 | + } else { |
| 52 | + const selectModelLabel = new qx.ui.basic.Label().set({ |
| 53 | + value: this.tr("Select a model for more details"), |
| 54 | + font: "text-16", |
| 55 | + alignX: "center", |
| 56 | + alignY: "middle", |
| 57 | + allowGrowX: true, |
| 58 | + allowGrowY: true, |
| 59 | + }); |
| 60 | + this._add(selectModelLabel); |
| 61 | + } |
| 62 | + }, |
| 63 | + |
| 64 | + __createcCard: function(anatomicalModelsData) { |
| 65 | + console.log(anatomicalModelsData); |
| 66 | + |
| 67 | + const cardGrid = new qx.ui.layout.Grid(16, 16); |
| 68 | + const cardLayout = new qx.ui.container.Composite(cardGrid); |
| 69 | + |
| 70 | + const description = anatomicalModelsData["Description"]; |
| 71 | + description.split(" - ").forEach((desc, idx) => { |
| 72 | + const titleLabel = new qx.ui.basic.Label().set({ |
| 73 | + value: desc, |
| 74 | + font: "text-16", |
| 75 | + alignX: "center", |
| 76 | + alignY: "middle", |
| 77 | + allowGrowX: true, |
| 78 | + allowGrowY: true, |
| 79 | + }); |
| 80 | + cardLayout.add(titleLabel, { |
| 81 | + column: 0, |
| 82 | + row: idx, |
| 83 | + colSpan: 2, |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + const thumbnail = new qx.ui.basic.Image().set({ |
| 88 | + source: anatomicalModelsData["Thumbnail"], |
| 89 | + alignY: "middle", |
| 90 | + scale: true, |
| 91 | + allowGrowX: true, |
| 92 | + allowGrowY: true, |
| 93 | + allowShrinkX: true, |
| 94 | + allowShrinkY: true, |
| 95 | + maxWidth: 256, |
| 96 | + maxHeight: 256, |
| 97 | + }); |
| 98 | + cardLayout.add(thumbnail, { |
| 99 | + column: 0, |
| 100 | + row: 2, |
| 101 | + }); |
| 102 | + |
| 103 | + const features = anatomicalModelsData["Features"]; |
| 104 | + const featuresGrid = new qx.ui.layout.Grid(8, 8); |
| 105 | + const featuresLayout = new qx.ui.container.Composite(featuresGrid); |
| 106 | + let idx = 0; |
| 107 | + [ |
| 108 | + "Name", |
| 109 | + "Version", |
| 110 | + "Sex", |
| 111 | + "Age", |
| 112 | + "Weight", |
| 113 | + "Height", |
| 114 | + "Date", |
| 115 | + "Ethnicity", |
| 116 | + "Functionality", |
| 117 | + ].forEach(key => { |
| 118 | + if (key.toLowerCase() in features) { |
| 119 | + const titleLabel = new qx.ui.basic.Label().set({ |
| 120 | + value: key, |
| 121 | + font: "text-14", |
| 122 | + alignX: "right", |
| 123 | + }); |
| 124 | + featuresLayout.add(titleLabel, { |
| 125 | + column: 0, |
| 126 | + row: idx, |
| 127 | + }); |
| 128 | + |
| 129 | + const nameLabel = new qx.ui.basic.Label().set({ |
| 130 | + value: features[key.toLowerCase()], |
| 131 | + font: "text-14", |
| 132 | + alignX: "left", |
| 133 | + }); |
| 134 | + featuresLayout.add(nameLabel, { |
| 135 | + column: 1, |
| 136 | + row: idx, |
| 137 | + }); |
| 138 | + |
| 139 | + idx++; |
| 140 | + } |
| 141 | + }); |
| 142 | + |
| 143 | + const doiTitle = new qx.ui.basic.Label().set({ |
| 144 | + value: "DOI", |
| 145 | + font: "text-14", |
| 146 | + alignX: "right", |
| 147 | + marginTop: 16, |
| 148 | + }); |
| 149 | + featuresLayout.add(doiTitle, { |
| 150 | + column: 0, |
| 151 | + row: idx, |
| 152 | + }); |
| 153 | + |
| 154 | + const doiValue = new qx.ui.basic.Label().set({ |
| 155 | + value: anatomicalModelsData["DOI"] ? anatomicalModelsData["DOI"] : "-", |
| 156 | + font: "text-14", |
| 157 | + alignX: "left", |
| 158 | + marginTop: 16, |
| 159 | + }); |
| 160 | + featuresLayout.add(doiValue, { |
| 161 | + column: 1, |
| 162 | + row: idx, |
| 163 | + }); |
| 164 | + |
| 165 | + cardLayout.add(featuresLayout, { |
| 166 | + column: 1, |
| 167 | + row: 2, |
| 168 | + }); |
| 169 | + |
| 170 | + const buttonsLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)); |
| 171 | + if (anatomicalModelsData["leased"]) { |
| 172 | + const leaseModelButton = new qx.ui.form.Button().set({ |
| 173 | + label: this.tr("3 seats Leased (27 days left)"), |
| 174 | + appearance: "strong-button", |
| 175 | + center: true, |
| 176 | + enabled: false, |
| 177 | + }); |
| 178 | + buttonsLayout.add(leaseModelButton, { |
| 179 | + flex: 1 |
| 180 | + }); |
| 181 | + } |
| 182 | + const leaseModelButton = new osparc.ui.form.FetchButton().set({ |
| 183 | + label: this.tr("Lease model (2 for months)"), |
| 184 | + appearance: "strong-button", |
| 185 | + center: true, |
| 186 | + }); |
| 187 | + leaseModelButton.addListener("execute", () => { |
| 188 | + leaseModelButton.setFetching(true); |
| 189 | + setTimeout(() => { |
| 190 | + leaseModelButton.setFetching(false); |
| 191 | + this.fireDataEvent("modelLeased", this.getAnatomicalModelsData()["ID"]); |
| 192 | + }, 2000); |
| 193 | + }); |
| 194 | + buttonsLayout.add(leaseModelButton, { |
| 195 | + flex: 1 |
| 196 | + }); |
| 197 | + cardLayout.add(buttonsLayout, { |
| 198 | + column: 0, |
| 199 | + row: 3, |
| 200 | + colSpan: 2, |
| 201 | + }); |
| 202 | + |
| 203 | + return cardLayout; |
| 204 | + }, |
| 205 | + } |
| 206 | +}); |
0 commit comments