From 09e8456e9dc08e3043224d84a17dbeb9ba083bc4 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 27 Sep 2022 15:36:15 +0200 Subject: [PATCH 1/3] expirationDate is only date, no time --- .../client/source/class/osparc/Application.js | 13 +++++++++++-- .../osparc/desktop/preferences/pages/ProfilePage.js | 6 +++--- .../client/source/class/osparc/utils/Utils.js | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/Application.js b/services/static-webserver/client/source/class/osparc/Application.js index a9284a201a5..3c0214f68e4 100644 --- a/services/static-webserver/client/source/class/osparc/Application.js +++ b/services/static-webserver/client/source/class/osparc/Application.js @@ -354,9 +354,18 @@ qx.Class.define("osparc.Application", { .then(profile => { if ("expirationDate" in profile) { const now = new Date(); - const daysToExpiration = osparc.utils.Utils.daysBetween(now, new Date(profile["expirationDate"])); + const today = new Date(now.toISOString().slice(0, 10)); + const expirationDay = new Date(profile["expirationDate"]); + const daysToExpiration = osparc.utils.Utils.daysBetween(today, expirationDay); if (daysToExpiration < 7) { - let msg = this.tr("This account will expire in ") + daysToExpiration + (daysToExpiration < 2 ? this.tr(" day") : this.tr(" days")); + let msg = ""; + if (daysToExpiration === 0) { + msg = this.tr("This account will expire Today."); + } else if (daysToExpiration === 1) { + msg = this.tr("This account will expire Tomorrow."); + } else { + msg = this.tr("This account will expire in ") + daysToExpiration + this.tr(" days."); + } msg += "
"; msg += this.tr("Please, contact us by email:"); msg += "
"; diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ProfilePage.js index 64bcc55b479..4ebfbf23d82 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ProfilePage.js @@ -137,10 +137,10 @@ qx.Class.define("osparc.desktop.preferences.pages.ProfilePage", { controller.addTarget(lastName, "value", "lastName", true); controller.addTarget(role, "value", "role", false); controller.addTarget(expirationDate, "value", "expirationDate", false, { - converter: data => { - if (data) { + converter: expirationDay => { + if (expirationDay) { expirationLayout.show(); - return osparc.utils.Utils.formatDateAndTime(new Date(data)); + return osparc.utils.Utils.formatDate(new Date(expirationDay)); } return ""; } diff --git a/services/static-webserver/client/source/class/osparc/utils/Utils.js b/services/static-webserver/client/source/class/osparc/utils/Utils.js index 01cbdc8453c..ee498d78013 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Utils.js +++ b/services/static-webserver/client/source/class/osparc/utils/Utils.js @@ -274,11 +274,11 @@ qx.Class.define("osparc.utils.Utils", { return osparc.utils.Utils.formatDate(value) + " " + osparc.utils.Utils.formatTime(value); }, - daysBetween: function(date1, date2) { + daysBetween: function(day1, day2) { // The number of milliseconds in one day const ONE_DAY = 1000 * 60 * 60 * 24; // Calculate the difference in milliseconds - const differenceMs = date2 - date1; + const differenceMs = day2 - day1; // Convert back to days and return return Math.round(differenceMs / ONE_DAY); }, From 3c2db8d0f690c93234348176c4fb2f120eb934d7 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 27 Sep 2022 16:20:30 +0200 Subject: [PATCH 2/3] finshed --- .../client/source/class/osparc/Application.js | 15 ++--------- .../client/source/class/osparc/auth/Data.js | 7 ++++++ .../source/class/osparc/auth/Manager.js | 7 +++--- .../class/osparc/navigation/NavigationBar.js | 25 +++++++++++++++++++ .../client/source/class/osparc/utils/Utils.js | 25 ++++++++++++++++++- 5 files changed, 62 insertions(+), 17 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/Application.js b/services/static-webserver/client/source/class/osparc/Application.js index 3c0214f68e4..3ef38018aeb 100644 --- a/services/static-webserver/client/source/class/osparc/Application.js +++ b/services/static-webserver/client/source/class/osparc/Application.js @@ -358,19 +358,8 @@ qx.Class.define("osparc.Application", { const expirationDay = new Date(profile["expirationDate"]); const daysToExpiration = osparc.utils.Utils.daysBetween(today, expirationDay); if (daysToExpiration < 7) { - let msg = ""; - if (daysToExpiration === 0) { - msg = this.tr("This account will expire Today."); - } else if (daysToExpiration === 1) { - msg = this.tr("This account will expire Tomorrow."); - } else { - msg = this.tr("This account will expire in ") + daysToExpiration + this.tr(" days."); - } - msg += "
"; - msg += this.tr("Please, contact us by email:"); - msg += "
"; - osparc.store.StaticInfo.getInstance().getSupportEmail() - .then(supportEmail => osparc.component.message.FlashMessenger.getInstance().logAs(msg + supportEmail, "WARNING")); + osparc.utils.Utils.expirationMessage(daysToExpiration) + .then(msg => osparc.component.message.FlashMessenger.getInstance().logAs(msg, "WARNING")); } } if (studyId) { diff --git a/services/static-webserver/client/source/class/osparc/auth/Data.js b/services/static-webserver/client/source/class/osparc/auth/Data.js index b8725d356f2..ac132202ff5 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Data.js +++ b/services/static-webserver/client/source/class/osparc/auth/Data.js @@ -81,6 +81,13 @@ qx.Class.define("osparc.auth.Data", { init: "", nullable: true, check: "String" + }, + + expirationDate: { + init: null, + nullable: true, + check: "Date", + event: "changeExpirationDate" } }, diff --git a/services/static-webserver/client/source/class/osparc/auth/Manager.js b/services/static-webserver/client/source/class/osparc/auth/Manager.js index 7f7e5e14333..3bc6037a404 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Manager.js +++ b/services/static-webserver/client/source/class/osparc/auth/Manager.js @@ -216,9 +216,10 @@ qx.Class.define("osparc.auth.Manager", { updateProfile: function(profile) { const authData = osparc.auth.Data.getInstance(); authData.set({ - email: profile.login, - firstName: profile.first_name, - lastName: profile.last_name + email: profile["login"], + firstName: profile["first_name"], + lastName: profile["last_name"], + expirationDate: "expirationDate" in profile ? new Date(profile["expirationDate"]) : null }); }, diff --git a/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js b/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js index 5b7a63620b1..909a266818a 100644 --- a/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js +++ b/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js @@ -114,6 +114,7 @@ qx.Class.define("osparc.navigation.NavigationBar", { this.getChildControl("manual"); this.getChildControl("feedback"); this.getChildControl("theme-switch"); + this.getChildControl("expiration-icon"); this.getChildControl("user-menu"); this.setPageContext("dashboard"); @@ -197,6 +198,30 @@ qx.Class.define("osparc.navigation.NavigationBar", { control = new osparc.component.task.TasksButton(); this.getChildControl("right-items").add(control); break; + case "expiration-icon": + control = new qx.ui.basic.Image("@FontAwesome5Solid/hourglass-end/22").set({ + visibility: "excluded", + textColor: "danger-red", + cursor: "pointer" + }); + control.addListener("tap", () => osparc.navigation.UserMenuButton.openPreferences(), this); + osparc.auth.Data.getInstance().bind("expirationDate", control, "visibility", { + converter: expirationDay => { + if (expirationDay) { + const now = new Date(); + const today = new Date(now.toISOString().slice(0, 10)); + const daysToExpiration = osparc.utils.Utils.daysBetween(today, expirationDay); + if (daysToExpiration < 7) { + osparc.utils.Utils.expirationMessage(daysToExpiration) + .then(msg => control.setToolTipText(msg)); + return "visible"; + } + } + return "excluded"; + } + }); + this.getChildControl("right-items").add(control); + break; case "manual": control = this.__createManualMenuBtn(); control.set(this.self().BUTTON_OPTIONS); diff --git a/services/static-webserver/client/source/class/osparc/utils/Utils.js b/services/static-webserver/client/source/class/osparc/utils/Utils.js index ee498d78013..60ddfd3339f 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Utils.js +++ b/services/static-webserver/client/source/class/osparc/utils/Utils.js @@ -246,10 +246,14 @@ qx.Class.define("osparc.utils.Utils", { const today = new Date(); const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); if (today.toDateString() === value.toDateString()) { dateStr = qx.locale.Manager.tr("Today"); } else if (yesterday.toDateString() === value.toDateString()) { dateStr = qx.locale.Manager.tr("Yesterday"); + } else if (tomorrow.toDateString() === value.toDateString()) { + dateStr = qx.locale.Manager.tr("Tomorrow"); } else { dateStr = dateFormat.format(value); } @@ -280,7 +284,26 @@ qx.Class.define("osparc.utils.Utils", { // Calculate the difference in milliseconds const differenceMs = day2 - day1; // Convert back to days and return - return Math.round(differenceMs / ONE_DAY); + const daysBetween = Math.round(differenceMs / ONE_DAY); + return daysBetween; + }, + + expirationMessage: function(daysToExpiration) { + let msg = ""; + if (daysToExpiration === 0) { + msg = qx.locale.Manager.tr("This account will expire Today."); + } else if (daysToExpiration === 1) { + msg = qx.locale.Manager.tr("This account will expire Tomorrow."); + } else { + msg = qx.locale.Manager.tr("This account will expire in ") + daysToExpiration + qx.locale.Manager.tr(" days."); + } + msg += "
"; + msg += qx.locale.Manager.tr("Please, contact us by email:"); + msg += "
"; + return new Promise(resolve => { + osparc.store.StaticInfo.getInstance().getSupportEmail() + .then(supportEmail => resolve(msg + supportEmail)); + }); }, getNameFromEmail: function(email) { From 92db53f27b1c04764107bd85f4ba1325791caca5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 27 Sep 2022 16:21:00 +0200 Subject: [PATCH 3/3] minor --- .../client/source/class/osparc/navigation/NavigationBar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js b/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js index 909a266818a..d8a9ab9ad08 100644 --- a/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js +++ b/services/static-webserver/client/source/class/osparc/navigation/NavigationBar.js @@ -111,10 +111,10 @@ qx.Class.define("osparc.navigation.NavigationBar", { this.getChildControl("read-only-icon"); this.getChildControl("tasks-button"); + this.getChildControl("expiration-icon"); this.getChildControl("manual"); this.getChildControl("feedback"); this.getChildControl("theme-switch"); - this.getChildControl("expiration-icon"); this.getChildControl("user-menu"); this.setPageContext("dashboard");