1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 19:42:01 +02:00

-Scope is applied now.

This commit is contained in:
Gunther Brunner 2014-03-25 19:29:37 +09:00
parent dd38b478de
commit ec1a488b4f
3 changed files with 48 additions and 12 deletions

View file

@ -1,4 +1,5 @@
module.exports = angular.module('stf/common-ui', [ module.exports = angular.module('stf/common-ui', [
require('./safe-apply').name,
require('./clear-button').name, require('./clear-button').name,
require('./filter-button').name, require('./filter-button').name,
require('./nothing-to-show').name, require('./nothing-to-show').name,

View file

@ -1,6 +1,26 @@
module.exports = angular.module('stf/socket/socket-state', [ module.exports = angular.module('stf/socket/socket-state', [
require('stf/socket').name, require('stf/socket').name,
require('stf/common-ui/safe-apply').name,
require('stf/common-ui/notifications').name require('stf/common-ui/notifications').name
]) ])
.directive('socketState', require('./socket-state-directive')) .directive('socketState', require('./socket-state-directive'))
.controller('SocketStateCtrl', require('./socket-state-controller')) .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
}
])
}
])

View file

@ -2,45 +2,60 @@ module.exports = function ($scope, $element, $attrs, $transclude, socket, growl,
var hasFailedOnce = false var hasFailedOnce = false
socket.on('connect', function () { socket.on('connect', function () {
$scope.$apply(function () {
$scope.socketState = 'connect' $scope.socketState = 'connect'
}) })
})
socket.on('connecting', function () { socket.on('connecting', function () {
$scope.$apply(function () {
$scope.socketState = 'connecting' $scope.socketState = 'connecting'
}) })
})
socket.on('disconnect', function () { socket.on('disconnect', function () {
$scope.$apply(function () {
$scope.socketState = 'disconnect' $scope.socketState = 'disconnect'
})
hasFailedOnce = true hasFailedOnce = true
}) })
socket.on('connect_failed', function () { socket.on('connect_failed', function () {
$scope.$apply(function () {
$scope.socketState = 'connect_failed' $scope.socketState = 'connect_failed'
})
hasFailedOnce = true hasFailedOnce = true
}) })
socket.on('error', function () { socket.on('error', function () {
$scope.$apply(function () {
$scope.socketState = 'error' $scope.socketState = 'error'
})
hasFailedOnce = true hasFailedOnce = true
}) })
socket.on('reconnect_failed', function () { socket.on('reconnect_failed', function () {
$scope.$apply(function () {
$scope.socketState = 'reconnect_failed' $scope.socketState = 'reconnect_failed'
})
hasFailedOnce = true hasFailedOnce = true
}) })
socket.on('reconnect', function () { socket.on('reconnect', function () {
$scope.$apply(function () {
$scope.socketState = 'reconnect' $scope.socketState = 'reconnect'
})
hasFailedOnce = true hasFailedOnce = true
}) })
socket.on('reconnecting', function () { socket.on('reconnecting', function () {
$scope.$apply(function () {
$scope.socketState = 'reconnecting' $scope.socketState = 'reconnecting'
})
hasFailedOnce = true hasFailedOnce = true
}) })
$scope.$watch('socketState', function (newValue, oldValue) { $scope.$watch('socketState', function (newValue, oldValue) {
console.log(newValue)
if (newValue) { if (newValue) {
if (newValue === 'connecting' && oldValue) { if (newValue === 'connecting' && oldValue) {
growl.info(gettext('<h4>WebSocket</h4> Connecting...'), {ttl: 1000}) growl.info(gettext('<h4>WebSocket</h4> Connecting...'), {ttl: 1000})
@ -51,7 +66,7 @@ module.exports = function ($scope, $element, $attrs, $transclude, socket, growl,
} else { } else {
switch (newValue) { switch (newValue) {
case 'disconnect': case 'disconnect':
growl.info(gettext('<h4>WebSocket</h4> Disconnected.'), {ttl: 2000}) growl.error(gettext('<h4>WebSocket</h4> Disconnected.'), {ttl: 2000})
break; break;
case 'connect_failed': case 'connect_failed':
growl.error(gettext('<h4>WebSocket</h4> Error while connecting.'), {ttl: 2000}) growl.error(gettext('<h4>WebSocket</h4> Error while connecting.'), {ttl: 2000})
@ -63,10 +78,10 @@ module.exports = function ($scope, $element, $attrs, $transclude, socket, growl,
growl.error(gettext('<h4>WebSocket</h4> Error while reconnecting.'), {ttl: 2000}) growl.error(gettext('<h4>WebSocket</h4> Error while reconnecting.'), {ttl: 2000})
break; break;
case 'reconnect': case 'reconnect':
growl.success(gettext('<h4>WebSocket</h4> Reconnected successfully.'), {ttl: 2000}) growl.success(gettext('<h4>WebSocket</h4> Reconnected successfully.'), {ttl: 10000})
break; break;
case 'reconnecting': case 'reconnecting':
growl.info(gettext('<h4>WebSocket</h4> Reconnecting...'), {ttl: 1000}) growl.info(gettext('<h4>WebSocket</h4> Reconnecting...'), {ttl: 10000})
break; break;
} }
} }