|
@@ -13,12 +13,25 @@ import App from '../base'
|
|
|
const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
|
|
const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
|
|
|
// Controller for messages (array)
|
|
// Controller for messages (array)
|
|
|
App.controller('SystemMessagesController', ($http, $scope) => {
|
|
App.controller('SystemMessagesController', ($http, $scope) => {
|
|
|
- $scope.messages = window.systemMessages
|
|
|
|
|
|
|
+ $scope.messages = []
|
|
|
var pollSystemMessages = function() {
|
|
var pollSystemMessages = function() {
|
|
|
|
|
+ // Ignore polling if tab is hidden or browser is offline
|
|
|
|
|
+ if (document.hidden || !navigator.onLine) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$http
|
|
$http
|
|
|
.get('/system/messages')
|
|
.get('/system/messages')
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
- $scope.messages = response.data
|
|
|
|
|
|
|
+ // Ignore if content-type is anything but JSON, prevents a bug where
|
|
|
|
|
+ // the user logs out in another tab, then a 302 redirect was returned,
|
|
|
|
|
+ // which is transparently resolved by the browser to the login (HTML)
|
|
|
|
|
+ // page.
|
|
|
|
|
+ // This then caused an Angular error where it was attempting to loop
|
|
|
|
|
+ // through the HTML as a string
|
|
|
|
|
+ if (response.headers('content-type').includes('json')) {
|
|
|
|
|
+ $scope.messages = response.data
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
.catch(() => {
|
|
.catch(() => {
|
|
|
// ignore errors
|
|
// ignore errors
|