Skip to content

Commit d851641

Browse files
authored
✨ Frontend: Student competition announcement (#4404)
1 parent c20bf3e commit d851641

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2023 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.AnnouncementTracker", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
properties: {
23+
start: {
24+
check: "Date",
25+
init: null,
26+
nullable: true
27+
},
28+
29+
end: {
30+
check: "Date",
31+
init: null,
32+
nullable: true
33+
},
34+
35+
title: {
36+
check: "String",
37+
init: null,
38+
nullable: true
39+
},
40+
41+
description: {
42+
check: "String",
43+
init: null,
44+
nullable: true
45+
},
46+
47+
link: {
48+
check: "String",
49+
init: null,
50+
nullable: true
51+
}
52+
},
53+
54+
members: {
55+
__loginAnnouncement: null,
56+
__userMenuAnnouncement: null,
57+
58+
startTracker: function() {
59+
if (osparc.product.Utils.isProduct("s4llite")) {
60+
const announcementData = {
61+
start: "2023-06-22T15:00:00.000Z",
62+
end: "2023-11-01T02:00:00.000Z",
63+
title: "Student Competition 2023",
64+
description: "For more information click <a href='https://zmt.swiss/news-and-events/news/sim4life/s4llite-student-competition-2023/' style='color: white' target='_blank'>here</a>",
65+
link: "https://zmt.swiss/news-and-events/news/sim4life/s4llite-student-competition-2023/"
66+
};
67+
this.__setAnnouncement(announcementData);
68+
}
69+
},
70+
71+
getLoginAnnouncement: function() {
72+
if (this.__isValid() && this.__loginAnnouncement) {
73+
return this.__loginAnnouncement;
74+
}
75+
return null;
76+
},
77+
78+
getUserMenuAnnouncement: function() {
79+
if (this.__isValid() && this.__userMenuAnnouncement) {
80+
return this.__userMenuAnnouncement;
81+
}
82+
return null;
83+
},
84+
85+
__isValid: function() {
86+
const now = new Date();
87+
if (
88+
this.getStart() &&
89+
this.getEnd() &&
90+
this.getStart() > now &&
91+
now < this.getEnd()
92+
) {
93+
return true;
94+
}
95+
return false;
96+
},
97+
98+
__setAnnouncement: function(announcementData) {
99+
this.setStart(announcementData && "start" in announcementData ? new Date(announcementData.start) : null);
100+
this.setEnd(announcementData && "end" in announcementData ? new Date(announcementData.end) : null);
101+
this.setTitle(announcementData && "title" in announcementData ? announcementData.title : null);
102+
this.setDescription(announcementData && "description" in announcementData ? announcementData.description : null);
103+
this.setLink(announcementData && "link" in announcementData ? announcementData.link : null);
104+
105+
this.__buildAnnouncementUIs();
106+
},
107+
108+
__buildAnnouncementUIs: function() {
109+
this.__buildLoginAnnouncement();
110+
this.__buildUserMenuAnnouncement();
111+
},
112+
113+
__buildLoginAnnouncement: function() {
114+
const announcmentLayout = this.__loginAnnouncement = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({
115+
backgroundColor: "strong-main",
116+
alignX: "center",
117+
padding: 12,
118+
allowGrowX: true,
119+
maxWidth: 300
120+
});
121+
announcmentLayout.getContentElement().setStyles({
122+
"border-radius": "8px"
123+
});
124+
125+
const titleLabel = new qx.ui.basic.Label().set({
126+
value: this.getTitle(),
127+
font: "text-16",
128+
textColor: "white",
129+
alignX: "center",
130+
rich: true,
131+
wrap: true
132+
});
133+
announcmentLayout.add(titleLabel);
134+
135+
const descriptionLabel = new qx.ui.basic.Label().set({
136+
value: this.getDescription(),
137+
font: "text-14",
138+
textColor: "white",
139+
alignX: "center",
140+
rich: true,
141+
wrap: true
142+
});
143+
announcmentLayout.add(descriptionLabel);
144+
},
145+
146+
__buildUserMenuAnnouncement: function() {
147+
const link = this.getLink();
148+
if (link) {
149+
const button = this.__userMenuAnnouncement = new qx.ui.menu.Button(this.getTitle() + "...");
150+
button.addListener("execute", () => window.open(link));
151+
}
152+
}
153+
}
154+
});

services/static-webserver/client/source/class/osparc/auth/LoginPageS4L.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ qx.Class.define("osparc.auth.LoginPageS4L", {
6868
const image = this._getLogoWPlatform();
6969
loginLayout.add(image);
7070

71+
const announcementTracker = osparc.AnnouncementTracker.getInstance();
72+
announcementTracker.startTracker();
73+
const loginAnnouncement = announcementTracker.getLoginAnnouncement();
74+
if (loginAnnouncement) {
75+
loginLayout.add(loginAnnouncement);
76+
}
77+
7178
const pages = this._getLoginStack();
7279
loginLayout.add(pages);
7380

services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ qx.Class.define("osparc.navigation.UserMenuButton", {
163163
osparc.store.Support.addQuickStartToMenu(this.getMenu());
164164
osparc.store.Support.addPanddyToMenu(this.getMenu());
165165
}
166+
const announcementTracker = osparc.AnnouncementTracker.getInstance();
167+
announcementTracker.startTracker();
168+
const userMenuAnnouncement = announcementTracker.getUserMenuAnnouncement();
169+
if (userMenuAnnouncement) {
170+
this.getMenu().add(userMenuAnnouncement);
171+
}
166172
this.getMenu().addSeparator();
167173
this.getChildControl("about");
168174
if (osparc.product.Utils.showAboutProduct()) {

0 commit comments

Comments
 (0)