Skip to content

Commit 467a45d

Browse files
authored
✨ Check new UI version (ITISFoundation#5548)
1 parent aa2d64d commit 467a45d

File tree

7 files changed

+146
-36
lines changed

7 files changed

+146
-36
lines changed

services/static-webserver/client/source/class/osparc/Application.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,17 @@ qx.Class.define("osparc.Application", {
231231
}
232232
},
233233

234-
__checkNewRelease: function() {
235-
const lastCommit = osparc.utils.Utils.localCache.getLastCommitVcsRefUI();
236-
const thisCommit = osparc.utils.LibVersions.getVcsRef();
237-
if (lastCommit) {
238-
if (lastCommit !== thisCommit) {
239-
const newRelease = new osparc.NewRelease();
240-
const title = this.tr("New Release");
241-
const win = osparc.ui.window.Window.popUpInWindow(newRelease, title, 350, 170).set({
242-
clickAwayClose: false,
243-
resizable: false,
244-
showClose: true
245-
});
246-
const closeBtn = win.getChildControl("close-button");
247-
osparc.utils.Utils.setIdToWidget(closeBtn, "newReleaseCloseBtn");
248-
}
249-
} else {
250-
osparc.utils.Utils.localCache.setLastCommitVcsRefUI(thisCommit);
234+
__checkNewRelease: async function() {
235+
if (osparc.NewRelease.firstTimeISeeThisFrontend()) {
236+
const newRelease = new osparc.NewRelease();
237+
const title = this.tr("New Release");
238+
const win = osparc.ui.window.Window.popUpInWindow(newRelease, title, 350, 130).set({
239+
clickAwayClose: false,
240+
resizable: false,
241+
showClose: true
242+
});
243+
const closeBtn = win.getChildControl("close-button");
244+
osparc.utils.Utils.setIdToWidget(closeBtn, "newReleaseCloseBtn");
251245
}
252246
},
253247

@@ -431,6 +425,7 @@ qx.Class.define("osparc.Application", {
431425
osparc.data.PollTasks.getInstance().removeTasks();
432426
osparc.MaintenanceTracker.getInstance().stopTracker();
433427
osparc.CookieExpirationTracker.getInstance().stopTracker();
428+
osparc.NewUITracker.getInstance().stopTracker();
434429
osparc.announcement.Tracker.getInstance().stopTracker();
435430
osparc.auth.Manager.getInstance().logout();
436431
if ("closeEditor" in this.__mainPage) {

services/static-webserver/client/source/class/osparc/NewRelease.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,37 @@ qx.Class.define("osparc.NewRelease", {
2626
this.__buildLayout();
2727
},
2828

29+
statics: {
30+
/**
31+
* Compare the version logged in the cache with the one being shown
32+
*/
33+
firstTimeISeeThisFrontend: function() {
34+
let isIt = false;
35+
const lastUICommit = osparc.utils.Utils.localCache.getLastCommitVcsRefUI();
36+
const thisUICommit = osparc.utils.LibVersions.getVcsRefUI();
37+
if (lastUICommit && thisUICommit) {
38+
isIt = lastUICommit !== thisUICommit;
39+
}
40+
osparc.utils.Utils.localCache.setLastCommitVcsRefUI(thisUICommit);
41+
return isIt;
42+
},
43+
44+
/**
45+
* Compare the latest version provided by the backend with the one loaded in the browser (might be an old cached one)
46+
*/
47+
isMyFrontendOld: async function() {
48+
const lastUICommit = await osparc.store.AppSummary.getLatestUIFromBE();
49+
const thisUICommit = osparc.utils.LibVersions.getVcsRefUI();
50+
if (lastUICommit && thisUICommit) {
51+
return lastUICommit !== thisUICommit;
52+
}
53+
return false;
54+
}
55+
},
56+
2957
members: {
3058
__buildLayout: function() {
31-
const introText = this.tr("We are pleased to announce that some new features were deployed for you!");
59+
const introText = qx.locale.Manager.tr("We are pleased to announce that some new features were deployed for you!");
3260
const introLabel = new qx.ui.basic.Label(introText).set({
3361
rich: true,
3462
wrap: true
@@ -37,7 +65,7 @@ qx.Class.define("osparc.NewRelease", {
3765

3866
const detailsText = this.tr("What's new");
3967
// old commit link
40-
let link = osparc.utils.LibVersions.getVcsRefUrl();
68+
const link = osparc.utils.LibVersions.getVcsRefUrl();
4169
const linkLabel = new osparc.ui.basic.LinkLabel(detailsText, link);
4270
this._add(linkLabel);
4371
const rData = osparc.store.StaticInfo.getInstance().getReleaseData();
@@ -47,22 +75,6 @@ qx.Class.define("osparc.NewRelease", {
4775
linkLabel.setUrl(releaseUrl);
4876
}
4977
}
50-
51-
const hardRefreshText = this.tr("You might need to hard refresh the browser to get the latest version.");
52-
const hardRefreshLabel = new qx.ui.basic.Label(hardRefreshText).set({
53-
rich: true,
54-
wrap: true
55-
});
56-
this._add(hardRefreshLabel, {
57-
flex: 1
58-
});
59-
60-
this.__saveCommitVcsRef();
61-
},
62-
63-
__saveCommitVcsRef: function() {
64-
const thisCommit = osparc.utils.LibVersions.getVcsRef();
65-
osparc.utils.Utils.localCache.setLastCommitVcsRefUI(thisCommit);
6678
}
6779
}
6880
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.NewUITracker", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
statics: {
23+
CHECK_INTERVAL: 60*60*1000 // Check every 60'
24+
},
25+
26+
members: {
27+
__checkInterval: null,
28+
29+
startTracker: function() {
30+
const checkNewUI = async () => {
31+
const newReleaseAvailable = await osparc.NewRelease.isMyFrontendOld();
32+
if (newReleaseAvailable) {
33+
let msg = "";
34+
msg += qx.locale.Manager.tr("A new version of the application is now available.");
35+
msg += "<br>";
36+
msg += qx.locale.Manager.tr("Reload to get the latest features.");
37+
// permanent message
38+
osparc.FlashMessenger.getInstance().logAs(msg, "INFO", 0);
39+
this.stopTracker();
40+
}
41+
};
42+
checkNewUI();
43+
this.__checkInterval = setInterval(checkNewUI, this.self().CHECK_INTERVAL);
44+
},
45+
46+
stopTracker: function() {
47+
if (this.__checkInterval) {
48+
clearInterval(this.__checkInterval);
49+
}
50+
}
51+
}
52+
});

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ qx.Class.define("osparc.data.Resources", {
9393
}
9494
},
9595

96+
/*
97+
* APP SUMMARY
98+
* Gets the json file built by the qx compiler with some extra env variables
99+
* added by oSPARC as compilation vars
100+
*/
101+
"appSummary": {
102+
endpoints: {
103+
get: {
104+
method: "GET",
105+
url: "/{productName}/app-summary.json",
106+
isJsonFile: true
107+
}
108+
}
109+
},
110+
96111
/*
97112
* STUDIES
98113
*/

services/static-webserver/client/source/class/osparc/desktop/MainPage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ qx.Class.define("osparc.desktop.MainPage", {
5757
osparc.WindowSizeTracker.getInstance().startTracker();
5858
osparc.MaintenanceTracker.getInstance().startTracker();
5959
osparc.CookieExpirationTracker.getInstance().startTracker();
60+
osparc.NewUITracker.getInstance().startTracker();
6061

6162
const store = osparc.store.Store.getInstance();
6263
const preloadPromises = [];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.store.AppSummary", {
19+
type: "static",
20+
21+
statics: {
22+
getLatestUIFromBE: async function() {
23+
const params = {
24+
url: {
25+
productName: osparc.product.Utils.getProductName()
26+
}
27+
};
28+
const appSummary = await osparc.data.Resources.fetch("appSummary", "get", params);
29+
if (appSummary && "environment" in appSummary && "osparc.vcsRefClient" in appSummary["environment"]) {
30+
return appSummary["environment"]["osparc.vcsRefClient"];
31+
}
32+
return null;
33+
}
34+
}
35+
});

services/static-webserver/client/source/class/osparc/utils/LibVersions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ qx.Class.define("osparc.utils.LibVersions", {
6767

6868
return {
6969
name: name,
70-
version: commitId ? commitId.substring(0, 7) : "",
70+
version: commitId ? commitId : "",
7171
url: remoteUrl
7272
};
7373
},

0 commit comments

Comments
 (0)