Skip to content

Commit

Permalink
Merge branch 'master' into is3569/flaky-public-api-test
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Dec 2, 2022
2 parents 9dc50ec + 4b2db6c commit ae8b36a
Show file tree
Hide file tree
Showing 10 changed files with 1,675 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ qx.Class.define("osparc.Application", {
qx.log.appender.Native;
}

const intlTelInput = osparc.wrapper.IntlTelInput.getInstance();
intlTelInput.init();

const webSocket = osparc.wrapper.WebSocket.getInstance();
webSocket.addListener("connect", () => osparc.io.WatchDog.getInstance().setOnline(true));
webSocket.addListener("disconnect", () => osparc.io.WatchDog.getInstance().setOnline(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ qx.Class.define("osparc.auth.ui.VerifyPhoneNumberView", {
},

members: {
__phoneNumberTF: null,
__itiInput: null,
__verifyPhoneNumberBtn: null,
__validateCodeTF: null,
__validateCodeBtn: null,
Expand All @@ -71,22 +71,27 @@ qx.Class.define("osparc.auth.ui.VerifyPhoneNumberView", {
this.add(verificationInfoDesc);

const phoneNumberVerifyLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
const phoneNumber = this.__phoneNumberTF = new qx.ui.form.TextField().set({
required: true,
placeholder: this.tr("Type your phone number")
phoneNumberVerifyLayout.getContentElement().setStyles({
"overflow": "visible" // needed for countries dropdown menu
});
phoneNumberVerifyLayout.add(phoneNumber, {

const itiInput = this.__itiInput = new osparc.component.widget.IntlTelInput();
phoneNumberVerifyLayout.add(itiInput, {
flex: 1
});

const verifyPhoneNumberBtn = this.__verifyPhoneNumberBtn = new qx.ui.form.Button(this.tr("Send SMS")).set({
maxHeight: 23,
minWidth: 80
});
phoneNumberVerifyLayout.add(verifyPhoneNumberBtn);
this.add(phoneNumberVerifyLayout);
},

__buildValidationLayout: function() {
const smsValidationLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
const smsValidationLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({
zIndex: 1 // the contries list that goes on top has a z-index of 2
});
const validationCode = this.__validateCodeTF = new qx.ui.form.TextField().set({
placeholder: this.tr("Type the SMS code"),
enabled: false
Expand All @@ -108,20 +113,21 @@ qx.Class.define("osparc.auth.ui.VerifyPhoneNumberView", {
},

__verifyPhoneNumber: function() {
const isValid = osparc.auth.core.Utils.phoneNumberValidator(this.__phoneNumberTF.getValue(), this.__phoneNumberTF);
this.__itiInput.verifyPhoneNumber();
const isValid = this.__itiInput.isValidNumber();
if (isValid) {
this.__phoneNumberTF.setEnabled(false);
this.__itiInput.setEnabled(false);
this.__verifyPhoneNumberBtn.setEnabled(false);
this.self().restartResendTimer(this.__verifyPhoneNumberBtn, this.tr("Send SMS"));
osparc.auth.Manager.getInstance().verifyPhoneNumber(this.getUserEmail(), this.__phoneNumberTF.getValue())
osparc.auth.Manager.getInstance().verifyPhoneNumber(this.getUserEmail(), this.__itiInput.getNumber())
.then(data => {
osparc.component.message.FlashMessenger.logAs(data.message, "INFO");
this.__validateCodeTF.setEnabled(true);
this.__validateCodeBtn.setEnabled(true);
})
.catch(err => {
osparc.component.message.FlashMessenger.logAs(err.message, "ERROR");
this.__phoneNumberTF.setEnabled(true);
this.__itiInput.setEnabled(true);
});
}
},
Expand Down Expand Up @@ -150,7 +156,7 @@ qx.Class.define("osparc.auth.ui.VerifyPhoneNumberView", {
};

const manager = osparc.auth.Manager.getInstance();
manager.validateCodeRegister(this.getUserEmail(), this.__phoneNumberTF.getValue(), this.__validateCodeTF.getValue(), loginFun, failFun, this);
manager.validateCodeRegister(this.getUserEmail(), this.__itiInput.getNumber(), this.__validateCodeTF.getValue(), loginFun, failFun, this);
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2022 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

/* global intlTelInput */

/**
* @ignore(intlTelInput)
*/

qx.Class.define("osparc.component.widget.IntlTelInput", {
extend: qx.ui.core.Widget,

construct: function() {
this.base(arguments);

this._setLayout(new qx.ui.layout.HBox(5));

this.getContentElement().setStyles({
"overflow": "visible" // needed for countries dropdown menu
});

const randId = Math.floor(Math.random() * 100);
const html = `<input type='tel' id='phone-${randId}' name='phone' autocomplete='off'>`;
const phoneNumber = new qx.ui.embed.Html(html).set({
minWidth: 185,
maxHeight: 25
});
this._add(phoneNumber);
phoneNumber.addListenerOnce("appear", () => {
const convertInputToPhoneInput = () => {
const domElement = document.querySelector(`#phone-${randId}`);
this.__itiInput = this.__inputToPhoneInput(domElement);
phoneNumber.getContentElement().setStyles({
"overflow": "visible" // needed for countries dropdown menu
});
};
const intlTelInputLib = osparc.wrapper.IntlTelInput.getInstance();
if (intlTelInputLib.getLibReady()) {
convertInputToPhoneInput();
} else {
intlTelInputLib.addListenerOnce("changeLibReady", e => {
if (e.getData()) {
convertInputToPhoneInput();
}
});
}
});

const feedbackCheck = this.__feedbackCheck = new qx.ui.basic.Image().set({
paddingTop: 3
});
feedbackCheck.exclude();
this._add(feedbackCheck);
},

statics: {
updateStyle: function(itiInput, checkIcon) {
itiInput.a.style["width"] = checkIcon && checkIcon.isVisible() ? "185px" : "215px";
itiInput.a.style["height"] = "23px";
itiInput.a.style["borderWidth"] = "0px";
itiInput.a.style["backgroundColor"] = qx.theme.manager.Meta.getInstance().getTheme().name.includes("Light") ? "#eaedef" : "#202426";
itiInput.a.style["color"] = qx.theme.manager.Color.getInstance().resolve("text");
}
},

members: {
__itiInput: null,
__feedbackCheck: null,

getNumber: function() {
return this.__itiInput.getNumber();
},

isValidNumber: function() {
return this.__itiInput.isValidNumber();
},

verifyPhoneNumber: function() {
const isValid = this.isValidNumber();
this.__feedbackCheck.set({
toolTipText: "E.164: " + this.getNumber(),
source: isValid ? "@FontAwesome5Solid/check/18" : "@FontAwesome5Solid/exclamation-triangle/18",
textColor: isValid ? "text" : "failed-red"
});
this.__feedbackCheck.show();
if (!isValid) {
const validationError = this.__itiInput.getValidationError();
const errorMap = {
0: this.tr("Invalid number"),
1: this.tr("Invalid country code"),
2: this.tr("Number too short"),
3: this.tr("Number too long")
};
const errorMsg = validationError in errorMap ? errorMap[validationError] : "Invalid number";
this.__feedbackCheck.set({
toolTipText: errorMsg + ". " + this.__feedbackCheck.getToolTipText()
});
}
this.self().updateStyle(this.__itiInput, this.__feedbackCheck);
},

__inputToPhoneInput: function(input) {
const iti = intlTelInput(input, {
initialCountry: "ch", // auto: geoIpLookup. need to unlock https://ipinfo.io/,
preferredCountries: ["ch", "us"]
});
const themeManager = qx.theme.manager.Meta.getInstance();
themeManager.addListener("changeTheme", () => this.self().updateStyle(iti));
this.self().updateStyle(iti);
return iti;
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2022 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

/**
* @asset(intl-tel-input/js/intlTelInput.min.js)
* @asset(intl-tel-input/js/data.min.js)
* @asset(intl-tel-input/js/utils.js)
* @asset(intl-tel-input/css/intlTelInput.css)
* @asset(intl-tel-input/img/flags.png)
* @asset(intl-tel-input/img/[email protected])
*/

/**
* A qooxdoo wrapper for
* <a href='https://github.com/jackocnr/intl-tel-input' target='_blank'>IntlTelInput</a>
*/

qx.Class.define("osparc.wrapper.IntlTelInput", {
extend: qx.core.Object,
type: "singleton",

statics: {
NAME: "intlTelInput",
VERSION: "17.0.19",
URL: "https://github.com/jackocnr/intl-tel-input"
},

properties: {
libReady: {
check: "Boolean",
init: false,
nullable: false,
event: "changeLibReady"
}
},
members: {
init: function() {
// initialize the script loading
let intlTelInputPath = "intl-tel-input/js/intlTelInput.min.js";
let dataPath = "intl-tel-input/js/data.min.js";
let utilsPath = "intl-tel-input/js/utils.js";
let intlTelInputCss = "intl-tel-input/css/intlTelInput.css";
let intlTelInputCssUri = qx.util.ResourceManager.getInstance().toUri(intlTelInputCss);
qx.module.Css.includeStylesheet(intlTelInputCssUri);
let dynLoader = new qx.util.DynamicScriptLoader([
intlTelInputPath,
dataPath,
utilsPath
]);

dynLoader.addListenerOnce("ready", () => {
console.log(intlTelInputPath + " loaded");
this.setLibReady(true);
}, this);

dynLoader.addListener("failed", e => {
let data = e.getData();
console.error("failed to load " + data.script);
}, this);

dynLoader.start();
}
}
});
Loading

0 comments on commit ae8b36a

Please sign in to comment.