Skip to content

Commit

Permalink
✨ Frontend: Announcements (#4489)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored and pcrespov committed Jul 13, 2023
1 parent 0b9b0c3 commit c7fdefe
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 203 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* ************************************************************************
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.AnnouncementsTracker", {
extend: qx.core.Object,
type: "singleton",

statics: {
CHECK_INTERVAL: 60*60*1000 // Check every 60'
},

members: {
__checkInternval: null,
__announcements: null,

startTracker: function() {
const checkAnnouncements = () => {
osparc.data.Resources.get("announcements")
.then(announcements => {
if (announcements && announcements.length) {
this.__setAnnouncements(announcements);
} else {
this.__setAnnouncements(null);
}
})
.catch(err => console.error(err));
};
checkAnnouncements();
this.__checkInternval = setInterval(checkAnnouncements, this.self().CHECK_INTERVAL);
},

stopTracker: function() {
if (this.__checkInternval) {
clearInterval(this.__checkInternval);
}
},

__setAnnouncements: function(announcementsData) {
this.__announcements = {};
if (announcementsData) {
announcementsData.forEach(announcementData => {
const announcement = new osparc.component.announcement.Announcement(announcementData);
osparc.component.announcement.AnnouncementUIFactory.getInstance().setAnnouncement(announcement);
});
}
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ qx.Class.define("osparc.Application", {
const threejs = osparc.wrapper.Three.getInstance();
threejs.init();

const announcementsTracker = osparc.AnnouncementsTracker.getInstance();
announcementsTracker.startTracker();

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 Expand Up @@ -433,6 +436,7 @@ qx.Class.define("osparc.Application", {

osparc.data.PollTasks.getInstance().removeTasks();
osparc.MaintenanceTracker.getInstance().stopTracker();
osparc.AnnouncementsTracker.getInstance().stopTracker();
osparc.auth.Manager.getInstance().logout();
if (this.__mainPage) {
this.__mainPage.closeEditor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ qx.Class.define("osparc.auth.LoginPageS4L", {
const image = this._getLogoWPlatform();
loginLayout.add(image);

const announcementTracker = osparc.AnnouncementTracker.getInstance();
announcementTracker.startTracker();
const loginAnnouncement = announcementTracker.getLoginAnnouncement();
if (loginAnnouncement) {
loginLayout.add(loginAnnouncement);
}

const pages = this._getLoginStack();
loginLayout.add(pages);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ qx.Class.define("osparc.auth.ui.LoginView", {
__loginBtn: null,

_buildPage: function() {
const announcementUIFactory = osparc.component.announcement.AnnouncementUIFactory.getInstance();
if (announcementUIFactory.hasLoginAnnouncement()) {
this.add(announcementUIFactory.createLoginAnnouncement());
}

this.__form = new qx.ui.form.Form();

const email = new qx.ui.form.TextField().set({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2018 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

qx.Class.define("osparc.component.announcement.Announcement", {
extend: qx.core.Object,

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

this.set({
id: announcementData.id,
products: announcementData.products,
start: new Date(announcementData.start),
end: new Date(announcementData.end),
title: announcementData.title,
description: announcementData.description,
link: announcementData.link,
widgets: announcementData.widgets
});
},

properties: {
id: {
check: "String",
init: null,
nullable: false
},

products: {
check: "Array",
init: [],
nullable: false
},

start: {
check: "Date",
init: null,
nullable: false
},

end: {
check: "Date",
init: null,
nullable: false
},

title: {
check: "String",
init: null,
nullable: true
},

description: {
check: "String",
init: null,
nullable: true
},

link: {
check: "String",
init: null,
nullable: true
},

widgets: {
check: "Array",
init: [],
nullable: true
}
}
});
Loading

0 comments on commit c7fdefe

Please sign in to comment.