diff --git a/res/app/components/stf/common-ui/index.js b/res/app/components/stf/common-ui/index.js index 6221f074..9f8c3d2a 100644 --- a/res/app/components/stf/common-ui/index.js +++ b/res/app/components/stf/common-ui/index.js @@ -1,4 +1,5 @@ module.exports = angular.module('stf/common-ui', [ + require('./safe-apply').name, require('./clear-button').name, require('./filter-button').name, require('./nothing-to-show').name, diff --git a/res/app/components/stf/socket/socket-state/index.js b/res/app/components/stf/socket/socket-state/index.js index 2a49361a..117be91a 100644 --- a/res/app/components/stf/socket/socket-state/index.js +++ b/res/app/components/stf/socket/socket-state/index.js @@ -1,6 +1,26 @@ module.exports = angular.module('stf/socket/socket-state', [ require('stf/socket').name, + require('stf/common-ui/safe-apply').name, require('stf/common-ui/notifications').name ]) .directive('socketState', require('./socket-state-directive')) .controller('SocketStateCtrl', require('./socket-state-controller')) + .config([ + '$provide', function ($provide) { + return $provide.decorator('$rootScope', [ + '$delegate', function ($delegate) { + $delegate.safeApply = function (fn) { + var phase = $delegate.$$phase + if (phase === "$apply" || phase === "$digest") { + if (fn && typeof fn === 'function') { + fn() + } + } else { + $delegate.$apply(fn) + } + } + return $delegate + } + ]) + } + ]) diff --git a/res/app/components/stf/socket/socket-state/socket-state-controller.js b/res/app/components/stf/socket/socket-state/socket-state-controller.js index 8d72b7ca..a2b8604e 100644 --- a/res/app/components/stf/socket/socket-state/socket-state-controller.js +++ b/res/app/components/stf/socket/socket-state/socket-state-controller.js @@ -2,45 +2,60 @@ module.exports = function ($scope, $element, $attrs, $transclude, socket, growl, var hasFailedOnce = false socket.on('connect', function () { - $scope.socketState = 'connect' + $scope.$apply(function () { + $scope.socketState = 'connect' + }) }) socket.on('connecting', function () { - $scope.socketState = 'connecting' + $scope.$apply(function () { + $scope.socketState = 'connecting' + }) }) socket.on('disconnect', function () { - $scope.socketState = 'disconnect' + $scope.$apply(function () { + $scope.socketState = 'disconnect' + }) hasFailedOnce = true }) socket.on('connect_failed', function () { - $scope.socketState = 'connect_failed' + $scope.$apply(function () { + $scope.socketState = 'connect_failed' + }) hasFailedOnce = true }) socket.on('error', function () { - $scope.socketState = 'error' + $scope.$apply(function () { + $scope.socketState = 'error' + }) hasFailedOnce = true }) socket.on('reconnect_failed', function () { - $scope.socketState = 'reconnect_failed' + $scope.$apply(function () { + $scope.socketState = 'reconnect_failed' + }) hasFailedOnce = true }) socket.on('reconnect', function () { - $scope.socketState = 'reconnect' + $scope.$apply(function () { + $scope.socketState = 'reconnect' + }) hasFailedOnce = true }) socket.on('reconnecting', function () { - $scope.socketState = 'reconnecting' + $scope.$apply(function () { + $scope.socketState = 'reconnecting' + }) hasFailedOnce = true }) $scope.$watch('socketState', function (newValue, oldValue) { - console.log(newValue) if (newValue) { if (newValue === 'connecting' && oldValue) { growl.info(gettext('