From e01f2e202ef49f0c6a2cae7b6cecdfa051407123 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 27 Nov 2021 22:39:04 +0100 Subject: [PATCH] check if notifications are there regularly --- .../static/script/inventree/inventree.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index 078cb52924..5d95d0b618 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -1,6 +1,7 @@ /* globals ClipboardJS, inventreeFormDataUpload, + inventreeGet, launchModalForm, user_settings, */ @@ -216,6 +217,39 @@ function inventreeDocReady() { // Display any cached alert messages showCachedAlerts(); + + // Start notification background worker to check every 5 seconds if notifications are available + var notificationRunner = setInterval(notificationCheck, 5000); +} + + +/** + * The notification checker is initiated when the doc is loaded. It checks if there are unread notifications + * if unread messages exist the alert flag is raised by making it visible + **/ +var current_alert_state = false; +function notificationCheck() { + inventreeGet( + '/api/notifications/', + { + read: false, + }, + { + success: function(response) { + if (response.length == 0) { + if (current_alert_state == true){ + $("#notification-alert").addClass("d-none"); + current_alert_state = false; + } + } else { + if (current_alert_state == false){ + $("#notification-alert").removeClass("d-none"); + current_alert_state = true; + } + } + } + } + ); } function isFileTransfer(transfer) {