diff options
Diffstat (limited to 'WebInterface/NodeJSServer/src/modules/ui/notification-banner.js')
-rw-r--r-- | WebInterface/NodeJSServer/src/modules/ui/notification-banner.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js b/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js index 395db94..7e6b8cb 100644 --- a/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js +++ b/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js @@ -7,11 +7,14 @@ export default class BannerController { * @param {string} bannerId ID of Notification Banner * @param {string} textP ID of Notification Banner text field * @param {string} dismissBtn ID of dismiss button + * @param {string} notificationBadge ID of badge (# of notifications) */ - constructor(bannerId, textP, dismissBtn) { + constructor(bannerId, textP, dismissBtn, notificationBadge) { + this.ids = {bannerId, textP, dismissBtn, notificationBadge}; this.banner = document.getElementById(bannerId); this.bannerText = document.getElementById(textP); this.dismissBtn = document.getElementById(dismissBtn); + this.notificationBadge = document.getElementById(notificationBadge); this.bannerMsgs = []; // Hide Banner after JS loading finished @@ -28,6 +31,21 @@ export default class BannerController { } /** + * Reloads the object + */ + refresh() { + this.banner = document.getElementById(this.ids.bannerId); + this.bannerText = document.getElementById(this.ids.textP); + this.dismissBtn = document.getElementById(this.ids.dismissBtn); + this.notificationBadge = document.getElementById( + this.ids.notificationBadge); + this.bannerMsgs = []; + + // Hide Banner after JS loading finished + this.banner.classList.add('hidden'); + } + + /** * Pushes a new message to the notification banner and shows it * @param {string} name Name to register notification (referenced in hide) * @param {string} text Notification text @@ -69,7 +87,6 @@ export default class BannerController { * Updates the notification banner with the most recent message */ update() { - // TODO: Show if multiple messages are there if (this.bannerMsgs.length === 0) { this.banner.classList.add('hidden'); return; @@ -85,5 +102,16 @@ export default class BannerController { else this.bannerText.innerText = text; this.current = name; + + // Update notification badge + if (this.bannerMsgs.length < 2) { + this.notificationBadge.classList.add('hidden'); + } else if (this.bannerMsgs.length > 9) { + this.notificationBadge.classList.remove('hidden'); + this.notificationBadge.textContent = '∞'; + } else { + this.notificationBadge.classList.remove('hidden'); + this.notificationBadge.textContent = this.bannerMsgs.length.toString(); + } } } |