-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Frontend: Student competition announcement (#4404)
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
services/static-webserver/client/source/class/osparc/AnnouncementTracker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* ************************************************************************ | ||
osparc - the simcore frontend | ||
https://osparc.io | ||
Copyright: | ||
2023 IT'IS Foundation, https://itis.swiss | ||
License: | ||
MIT: https://opensource.org/licenses/MIT | ||
Authors: | ||
* Odei Maiz (odeimaiz) | ||
************************************************************************ */ | ||
|
||
qx.Class.define("osparc.AnnouncementTracker", { | ||
extend: qx.core.Object, | ||
type: "singleton", | ||
|
||
properties: { | ||
start: { | ||
check: "Date", | ||
init: null, | ||
nullable: true | ||
}, | ||
|
||
end: { | ||
check: "Date", | ||
init: null, | ||
nullable: true | ||
}, | ||
|
||
title: { | ||
check: "String", | ||
init: null, | ||
nullable: true | ||
}, | ||
|
||
description: { | ||
check: "String", | ||
init: null, | ||
nullable: true | ||
}, | ||
|
||
link: { | ||
check: "String", | ||
init: null, | ||
nullable: true | ||
} | ||
}, | ||
|
||
members: { | ||
__loginAnnouncement: null, | ||
__userMenuAnnouncement: null, | ||
|
||
startTracker: function() { | ||
if (osparc.product.Utils.isProduct("s4llite")) { | ||
const announcementData = { | ||
start: "2023-06-22T15:00:00.000Z", | ||
end: "2023-11-01T02:00:00.000Z", | ||
title: "Student Competition 2023", | ||
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>", | ||
link: "https://zmt.swiss/news-and-events/news/sim4life/s4llite-student-competition-2023/" | ||
}; | ||
this.__setAnnouncement(announcementData); | ||
} | ||
}, | ||
|
||
getLoginAnnouncement: function() { | ||
if (this.__isValid() && this.__loginAnnouncement) { | ||
return this.__loginAnnouncement; | ||
} | ||
return null; | ||
}, | ||
|
||
getUserMenuAnnouncement: function() { | ||
if (this.__isValid() && this.__userMenuAnnouncement) { | ||
return this.__userMenuAnnouncement; | ||
} | ||
return null; | ||
}, | ||
|
||
__isValid: function() { | ||
const now = new Date(); | ||
if ( | ||
this.getStart() && | ||
this.getEnd() && | ||
this.getStart() > now && | ||
now < this.getEnd() | ||
) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
|
||
__setAnnouncement: function(announcementData) { | ||
this.setStart(announcementData && "start" in announcementData ? new Date(announcementData.start) : null); | ||
this.setEnd(announcementData && "end" in announcementData ? new Date(announcementData.end) : null); | ||
this.setTitle(announcementData && "title" in announcementData ? announcementData.title : null); | ||
this.setDescription(announcementData && "description" in announcementData ? announcementData.description : null); | ||
this.setLink(announcementData && "link" in announcementData ? announcementData.link : null); | ||
|
||
this.__buildAnnouncementUIs(); | ||
}, | ||
|
||
__buildAnnouncementUIs: function() { | ||
this.__buildLoginAnnouncement(); | ||
this.__buildUserMenuAnnouncement(); | ||
}, | ||
|
||
__buildLoginAnnouncement: function() { | ||
const announcmentLayout = this.__loginAnnouncement = new qx.ui.container.Composite(new qx.ui.layout.VBox(5)).set({ | ||
backgroundColor: "strong-main", | ||
alignX: "center", | ||
padding: 12, | ||
allowGrowX: true, | ||
maxWidth: 300 | ||
}); | ||
announcmentLayout.getContentElement().setStyles({ | ||
"border-radius": "8px" | ||
}); | ||
|
||
const titleLabel = new qx.ui.basic.Label().set({ | ||
value: this.getTitle(), | ||
font: "text-16", | ||
textColor: "white", | ||
alignX: "center", | ||
rich: true, | ||
wrap: true | ||
}); | ||
announcmentLayout.add(titleLabel); | ||
|
||
const descriptionLabel = new qx.ui.basic.Label().set({ | ||
value: this.getDescription(), | ||
font: "text-14", | ||
textColor: "white", | ||
alignX: "center", | ||
rich: true, | ||
wrap: true | ||
}); | ||
announcmentLayout.add(descriptionLabel); | ||
}, | ||
|
||
__buildUserMenuAnnouncement: function() { | ||
const link = this.getLink(); | ||
if (link) { | ||
const button = this.__userMenuAnnouncement = new qx.ui.menu.Button(this.getTitle() + "..."); | ||
button.addListener("execute", () => window.open(link)); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters