|
| 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 | + * Pedro Crespo-Valero (pcrespov) |
| 15 | + * Odei Maiz (odeimaiz) |
| 16 | +
|
| 17 | +************************************************************************ */ |
| 18 | + |
| 19 | +qx.Class.define("osparc.po.UsersPending", { |
| 20 | + extend: osparc.po.BaseView, |
| 21 | + |
| 22 | + statics: { |
| 23 | + getPendingUsers: function() { |
| 24 | + return new Promise(resolve => { |
| 25 | + resolve({ |
| 26 | + data: [{ |
| 27 | + name: "John Doe", |
| 28 | + |
| 29 | + date: "2025-01-01 00:00:00.702394", |
| 30 | + status: "PENDING", |
| 31 | + info: { |
| 32 | + "institution": "ETH Zurich", |
| 33 | + "department": "Department of Physics", |
| 34 | + "position": "PhD Student", |
| 35 | + "country": "Switzerland", |
| 36 | + "city": "Zurich", |
| 37 | + }, |
| 38 | + }, { |
| 39 | + name: "Jane Doe", |
| 40 | + |
| 41 | + date: "2025-01-01 00:01:00.702394", |
| 42 | + status: "REJECTED", |
| 43 | + info: { |
| 44 | + "institution": "ETH Zurich", |
| 45 | + "department": "Department of Physics", |
| 46 | + "position": "PhD Student", |
| 47 | + "country": "Switzerland", |
| 48 | + "city": "Zurich", |
| 49 | + }, |
| 50 | + }, { |
| 51 | + name: "Alice Smith", |
| 52 | + |
| 53 | + date: "2025-01-01 00:02:00.702394", |
| 54 | + status: "APPROVED", |
| 55 | + info: { |
| 56 | + "institution": "ETH Zurich", |
| 57 | + "department": "Department of Physics", |
| 58 | + "position": "PhD Student", |
| 59 | + "country": "Switzerland", |
| 60 | + "city": "Zurich", |
| 61 | + }, |
| 62 | + }] |
| 63 | + }); |
| 64 | + }); |
| 65 | + }, |
| 66 | + |
| 67 | + createApproveButton: function(email) { |
| 68 | + const button = new osparc.ui.form.FetchButton(qx.locale.Manager.tr("Approve")); |
| 69 | + button.addListener("execute", () => { |
| 70 | + button.setFetching(true); |
| 71 | + const params = { |
| 72 | + data: { |
| 73 | + email, |
| 74 | + }, |
| 75 | + }; |
| 76 | + osparc.data.Resources.fetch("poUsers", "approveUser", params) |
| 77 | + .then(() => { |
| 78 | + osparc.FlashMessenger.logAs(qx.locale.Manager.tr("User approved"), "INFO"); |
| 79 | + }) |
| 80 | + .catch(err => osparc.FlashMessenger.logError(err)) |
| 81 | + .finally(() => button.setFetching(false)); |
| 82 | + }); |
| 83 | + return button; |
| 84 | + }, |
| 85 | + |
| 86 | + createRejectButton: function(email) { |
| 87 | + const button = new osparc.ui.form.FetchButton(qx.locale.Manager.tr("Reject")); |
| 88 | + button.addListener("execute", () => { |
| 89 | + button.setFetching(true); |
| 90 | + const params = { |
| 91 | + data: { |
| 92 | + email, |
| 93 | + }, |
| 94 | + }; |
| 95 | + osparc.data.Resources.fetch("poUsers", "rejectUser", params) |
| 96 | + .then(() => { |
| 97 | + osparc.FlashMessenger.logAs(qx.locale.Manager.tr("User denied"), "INFO"); |
| 98 | + }) |
| 99 | + .catch(err => osparc.FlashMessenger.logError(err)) |
| 100 | + .finally(() => button.setFetching(false)); |
| 101 | + }); |
| 102 | + return button; |
| 103 | + }, |
| 104 | + |
| 105 | + createResendEmailButton: function(email) { |
| 106 | + const button = new osparc.ui.form.FetchButton(qx.locale.Manager.tr("Resend Email")); |
| 107 | + button.addListener("execute", () => { |
| 108 | + button.setFetching(true); |
| 109 | + const params = { |
| 110 | + data: { |
| 111 | + email, |
| 112 | + }, |
| 113 | + }; |
| 114 | + osparc.data.Resources.fetch("poUsers", "resendConfirmationEmail", params) |
| 115 | + .then(() => { |
| 116 | + osparc.FlashMessenger.logAs(qx.locale.Manager.tr("Email sent"), "INFO"); |
| 117 | + }) |
| 118 | + .catch(err => osparc.FlashMessenger.logError(err)) |
| 119 | + .finally(() => button.setFetching(false)); |
| 120 | + }); |
| 121 | + return button; |
| 122 | + }, |
| 123 | + |
| 124 | + createInfoButton: function(infoMetadata) { |
| 125 | + const infoButton = new qx.ui.form.Button(null, "@MaterialIcons/info_outline/16"); |
| 126 | + infoButton.addListener("execute", () => { |
| 127 | + const container = new qx.ui.container.Scroll(); |
| 128 | + container.add(new osparc.ui.basic.JsonTreeWidget(infoMetadata, "pendingUserInfo")); |
| 129 | + osparc.ui.window.Window.popUpInWindow(container, qx.locale.Manager.tr("User Info")); |
| 130 | + }); |
| 131 | + return infoButton; |
| 132 | + }, |
| 133 | + }, |
| 134 | + |
| 135 | + members: { |
| 136 | + _createChildControlImpl: function(id) { |
| 137 | + let control; |
| 138 | + switch (id) { |
| 139 | + case "pending-users-container": |
| 140 | + control = new qx.ui.container.Scroll(); |
| 141 | + this._add(control, { |
| 142 | + flex: 1 |
| 143 | + }); |
| 144 | + break; |
| 145 | + case "pending-users-layout": { |
| 146 | + const grid = new qx.ui.layout.Grid(15, 5); |
| 147 | + control = new qx.ui.container.Composite(grid); |
| 148 | + this.getChildControl("pending-users-container").add(control); |
| 149 | + break; |
| 150 | + } |
| 151 | + } |
| 152 | + return control || this.base(arguments, id); |
| 153 | + }, |
| 154 | + |
| 155 | + _buildLayout: function() { |
| 156 | + this.getChildControl("pending-users-container"); |
| 157 | + |
| 158 | + this.__populatePendingUsersLayout(); |
| 159 | + }, |
| 160 | + |
| 161 | + __addHeader: function() { |
| 162 | + const pendingUsersLayout = this.getChildControl("pending-users-layout"); |
| 163 | + |
| 164 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Name")).set({ |
| 165 | + font: "text-14" |
| 166 | + }), { |
| 167 | + row: 0, |
| 168 | + column: 0, |
| 169 | + }); |
| 170 | + |
| 171 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Email")).set({ |
| 172 | + font: "text-14" |
| 173 | + }), { |
| 174 | + row: 0, |
| 175 | + column: 1, |
| 176 | + }); |
| 177 | + |
| 178 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Date")).set({ |
| 179 | + font: "text-14" |
| 180 | + }), { |
| 181 | + row: 0, |
| 182 | + column: 2, |
| 183 | + }); |
| 184 | + |
| 185 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Info")).set({ |
| 186 | + font: "text-14" |
| 187 | + }), { |
| 188 | + row: 0, |
| 189 | + column: 3, |
| 190 | + }); |
| 191 | + |
| 192 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Status")).set({ |
| 193 | + font: "text-14" |
| 194 | + }), { |
| 195 | + row: 0, |
| 196 | + column: 4, |
| 197 | + }); |
| 198 | + |
| 199 | + pendingUsersLayout.add(new qx.ui.basic.Label(this.tr("Action")).set({ |
| 200 | + font: "text-14" |
| 201 | + }), { |
| 202 | + row: 0, |
| 203 | + column: 5, |
| 204 | + }); |
| 205 | + }, |
| 206 | + |
| 207 | + __addRows: function(pendingUsers) { |
| 208 | + const pendingUsersLayout = this.getChildControl("pending-users-layout"); |
| 209 | + |
| 210 | + let row = 1; |
| 211 | + pendingUsers.forEach(pendingUser => { |
| 212 | + pendingUsersLayout.add(new qx.ui.basic.Label(pendingUser.name), { |
| 213 | + row, |
| 214 | + column: 0, |
| 215 | + }); |
| 216 | + pendingUsersLayout.add(new qx.ui.basic.Label(pendingUser.email), { |
| 217 | + row, |
| 218 | + column: 1, |
| 219 | + }); |
| 220 | + pendingUsersLayout.add(new qx.ui.basic.Label(osparc.utils.Utils.formatDateAndTime(new Date(pendingUser.date))), { |
| 221 | + row, |
| 222 | + column: 2, |
| 223 | + }); |
| 224 | + const infoButton = this.self().createInfoButton(pendingUser.info); |
| 225 | + pendingUsersLayout.add(infoButton, { |
| 226 | + row, |
| 227 | + column: 3, |
| 228 | + }); |
| 229 | + pendingUsersLayout.add(new qx.ui.basic.Label(pendingUser.status.toLowerCase()), { |
| 230 | + row, |
| 231 | + column: 4, |
| 232 | + }); |
| 233 | + const buttonsLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)); |
| 234 | + pendingUsersLayout.add(buttonsLayout, { |
| 235 | + row, |
| 236 | + column: 5, |
| 237 | + }); |
| 238 | + |
| 239 | + switch (pendingUser.status) { |
| 240 | + case "PENDING": { |
| 241 | + const approveButton = this.self().createApproveButton(pendingUser.email); |
| 242 | + buttonsLayout.add(approveButton); |
| 243 | + const rejectButton = this.self().createRejectButton(pendingUser.email); |
| 244 | + buttonsLayout.add(rejectButton); |
| 245 | + break; |
| 246 | + } |
| 247 | + case "REJECTED": { |
| 248 | + const approveButton = this.self().createApproveButton(pendingUser.email); |
| 249 | + buttonsLayout.add(approveButton); |
| 250 | + break; |
| 251 | + } |
| 252 | + case "APPROVED": { |
| 253 | + const resendEmailButton = this.self().createResendEmailButton(pendingUser.email); |
| 254 | + buttonsLayout.add(resendEmailButton); |
| 255 | + break; |
| 256 | + } |
| 257 | + } |
| 258 | + row++; |
| 259 | + }); |
| 260 | + }, |
| 261 | + |
| 262 | + __populatePendingUsersLayout: function() { |
| 263 | + // osparc.data.Resources.fetch("poUsers", "getPendingUsers", params) |
| 264 | + this.self().getPendingUsers() |
| 265 | + .then(pendingUsers => { |
| 266 | + const pendingUsersLayout = this.getChildControl("pending-users-layout"); |
| 267 | + pendingUsersLayout.removeAll(); |
| 268 | + this.__addHeader(); |
| 269 | + this.__addRows(pendingUsers["data"]); |
| 270 | + }) |
| 271 | + .catch(err => osparc.FlashMessenger.logError(err)); |
| 272 | + } |
| 273 | + } |
| 274 | +}); |
0 commit comments