From 84b667d77c57c2e2d40222baf5f4ab96f602c39f Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:01:10 +0200 Subject: [PATCH 1/7] handles error with json parsing --- .../client/source/class/osparc/po/PreRegistration.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index 2234de28c19..4b72f8a1f4c 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -78,8 +78,14 @@ qx.Class.define("osparc.po.PreRegistration", { submitBtn.setFetching(true); const findingStatus = this.getChildControl("finding-status"); findingStatus.setValue(this.tr("Searching Pre-Registered users...")); + try { + const preData = JSON.parse(requestAccountData.getValue()) + } catch (error) { + console.error(`Cannot parse pre-registration JSON data: ${preData}:`, error) + osparc.FlashMessenger.logAs("Invalid JSON in Pre-Registration input", "ERROR"); + } const params = { - data: JSON.parse(requestAccountData.getValue()) + data: preData }; osparc.data.Resources.fetch("users", "preRegister", params) .then(data => { From 69dbdfeb58fde62f4e56625d13409bdd917c556d Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:11:49 +0200 Subject: [PATCH 2/7] cleanup --- .../source/class/osparc/po/PreRegistration.js | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index 4b72f8a1f4c..532b90f5f83 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -78,30 +78,32 @@ qx.Class.define("osparc.po.PreRegistration", { submitBtn.setFetching(true); const findingStatus = this.getChildControl("finding-status"); findingStatus.setValue(this.tr("Searching Pre-Registered users...")); + const preData = requestAccountData.getValue() try { - const preData = JSON.parse(requestAccountData.getValue()) + const params = { + data: JSON.parse(preData) + }; + + osparc.data.Resources.fetch("users", "preRegister", params) + .then(data => { + if (data.length) { + findingStatus.setValue(this.tr("Pre-Registered as:")); + } else { + findingStatus.setValue(this.tr("No Pre-Registered user found")); + } + this.__populatePreRegistrationLayout(data); + }) + .catch(err => { + findingStatus.setValue(this.tr("Error searching Pre-Registered users")); + console.error(err); + osparc.FlashMessenger.logAs(err.message, "ERROR"); + }) + .finally(() => submitBtn.setFetching(false)); + } catch (error) { - console.error(`Cannot parse pre-registration JSON data: ${preData}:`, error) - osparc.FlashMessenger.logAs("Invalid JSON in Pre-Registration input", "ERROR"); + console.error(`Cannot parse pre-registration JSON data: ${preData}:`, error) + osparc.FlashMessenger.logAs("Invalid JSON in Pre-Registration input", "ERROR"); } - const params = { - data: preData - }; - osparc.data.Resources.fetch("users", "preRegister", params) - .then(data => { - if (data.length) { - findingStatus.setValue(this.tr("Pre-Registered as:")); - } else { - findingStatus.setValue(this.tr("No Pre-Registered user found")); - } - this.__populatePreRegistrationLayout(data); - }) - .catch(err => { - findingStatus.setValue(this.tr("Error searching Pre-Registered users")); - console.error(err); - osparc.FlashMessenger.logAs(err.message, "ERROR"); - }) - .finally(() => submitBtn.setFetching(false)); } }, this); form.addButton(submitBtn); From 6725932160a77a36fe8b50e07bb1e508b8ec50ba Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:54:50 +0200 Subject: [PATCH 3/7] refactor --- .../source/class/osparc/po/PreRegistration.js | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index 532b90f5f83..c55c7a21b64 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -76,34 +76,44 @@ qx.Class.define("osparc.po.PreRegistration", { } if (form.validate()) { submitBtn.setFetching(true); + + const flashErrorMsg = "Failed to Pre-Registration. See details below"; const findingStatus = this.getChildControl("finding-status"); findingStatus.setValue(this.tr("Searching Pre-Registered users...")); - const preData = requestAccountData.getValue() + + let params; try { - const params = { - data: JSON.parse(preData) + params = { + data: JSON.parse(requestAccountData.getValue()) }; + } catch (err) { + console.error(err); + + const detailErrorMsg = this.tr(`Error parsing JSON Pre-Registered users: ${err}`); + findingStatus.setValue(detailErrorMsg); - osparc.data.Resources.fetch("users", "preRegister", params) - .then(data => { - if (data.length) { - findingStatus.setValue(this.tr("Pre-Registered as:")); - } else { - findingStatus.setValue(this.tr("No Pre-Registered user found")); - } - this.__populatePreRegistrationLayout(data); - }) - .catch(err => { - findingStatus.setValue(this.tr("Error searching Pre-Registered users")); - console.error(err); - osparc.FlashMessenger.logAs(err.message, "ERROR"); - }) - .finally(() => submitBtn.setFetching(false)); - - } catch (error) { - console.error(`Cannot parse pre-registration JSON data: ${preData}:`, error) - osparc.FlashMessenger.logAs("Invalid JSON in Pre-Registration input", "ERROR"); + osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); + submitBtn.setFetching(false); + return } + + osparc.data.Resources.fetch("users", "preRegister", params) + .then(data => { + if (data.length) { + findingStatus.setValue(this.tr("Pre-Registered as:")); + } else { + findingStatus.setValue(this.tr("No Pre-Registered user found")); + } + this.__populatePreRegistrationLayout(data); + }) + .catch(err => { + const detail_msg = this.tr(`Error during Pre-Registeristration: ${err.message}`) + findingStatus.setValue(detail_msg); + console.error(err); + osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); + }) + .finally(() => submitBtn.setFetching(false)); + } }, this); form.addButton(submitBtn); From 92a3c83a1234c7da9102ee2e4bb4fbc6b52e87a6 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:08:54 +0200 Subject: [PATCH 4/7] cleanup msg --- .../client/source/class/osparc/po/PreRegistration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index c55c7a21b64..d3fccb27ffd 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -77,7 +77,7 @@ qx.Class.define("osparc.po.PreRegistration", { if (form.validate()) { submitBtn.setFetching(true); - const flashErrorMsg = "Failed to Pre-Registration. See details below"; + const flashErrorMsg = this.tr("Pre-Registration Failed. See details below"); const findingStatus = this.getChildControl("finding-status"); findingStatus.setValue(this.tr("Searching Pre-Registered users...")); @@ -89,7 +89,7 @@ qx.Class.define("osparc.po.PreRegistration", { } catch (err) { console.error(err); - const detailErrorMsg = this.tr(`Error parsing JSON Pre-Registered users: ${err}`); + const detailErrorMsg = `Error parsing Request Form JSON. ${err}`; findingStatus.setValue(detailErrorMsg); osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); From 5de7458be5ef9ed31802ef87704853a991cc0d36 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:23:53 +0200 Subject: [PATCH 5/7] formatting --- .../source/class/osparc/po/PreRegistration.js | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index d3fccb27ffd..1ff033623d0 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -87,33 +87,32 @@ qx.Class.define("osparc.po.PreRegistration", { data: JSON.parse(requestAccountData.getValue()) }; } catch (err) { - console.error(err); + console.error(err); - const detailErrorMsg = `Error parsing Request Form JSON. ${err}`; - findingStatus.setValue(detailErrorMsg); + const detailErrorMsg = `Error parsing Request Form JSON. ${err}`; + findingStatus.setValue(detailErrorMsg); - osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); - submitBtn.setFetching(false); - return + osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); + submitBtn.setFetching(false); + return } osparc.data.Resources.fetch("users", "preRegister", params) - .then(data => { - if (data.length) { - findingStatus.setValue(this.tr("Pre-Registered as:")); - } else { - findingStatus.setValue(this.tr("No Pre-Registered user found")); - } - this.__populatePreRegistrationLayout(data); + .then(data => { + if (data.length) { + findingStatus.setValue(this.tr("Pre-Registered as:")); + } else { + findingStatus.setValue(this.tr("No Pre-Registered user found")); + } + this.__populatePreRegistrationLayout(data); }) - .catch(err => { - const detail_msg = this.tr(`Error during Pre-Registeristration: ${err.message}`) - findingStatus.setValue(detail_msg); - console.error(err); - osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); + .catch(err => { + const detailErrorMsg = this.tr(`Error during Pre-Registeristration: ${err.message}`) + findingStatus.setValue(detailErrorMsg); + console.error(err); + osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); }) - .finally(() => submitBtn.setFetching(false)); - + .finally(() => submitBtn.setFetching(false)); } }, this); form.addButton(submitBtn); From 00ec5e12b70ffdbbedc0ad6dd9a4e91b64040884 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:46:20 +0200 Subject: [PATCH 6/7] linter --- .../client/source/class/osparc/po/PreRegistration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index 1ff033623d0..4e132c1c715 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -105,13 +105,13 @@ qx.Class.define("osparc.po.PreRegistration", { findingStatus.setValue(this.tr("No Pre-Registered user found")); } this.__populatePreRegistrationLayout(data); - }) + }) .catch(err => { const detailErrorMsg = this.tr(`Error during Pre-Registeristration: ${err.message}`) findingStatus.setValue(detailErrorMsg); console.error(err); osparc.FlashMessenger.logAs(flashErrorMsg, "ERROR"); - }) + }) .finally(() => submitBtn.setFetching(false)); } }, this); From 0d96f4f183e24c9eedf830f45e80374dc384552a Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:56:23 +0200 Subject: [PATCH 7/7] @odeimaiz review: rich control --- .../client/source/class/osparc/po/PreRegistration.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js index 4e132c1c715..e9fb2cdb434 100644 --- a/services/static-webserver/client/source/class/osparc/po/PreRegistration.js +++ b/services/static-webserver/client/source/class/osparc/po/PreRegistration.js @@ -29,7 +29,9 @@ qx.Class.define("osparc.po.PreRegistration", { break; case "finding-status": control = new qx.ui.basic.Label(); - this._add(control); + this._add(control, { + rich: true + }); break; case "pre-registration-container": control = new qx.ui.container.Scroll();