Skip to content

Commit

Permalink
show connection status in header
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Mar 20, 2015
1 parent 824d75e commit 10c325e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
@@ -0,0 +1,25 @@
class connectionstatus extends Directive('common')
constructor: (RecursionHelper) ->
return {
replace: true
restrict: 'E'
scope: {data:'='}
templateUrl: 'views/connectionstatus.html'
compile: RecursionHelper.compile
controller: '_connectionstatusController'
}

class _connectionstatus extends Controller('common')
constructor: ($scope, $timeout) ->
$scope.alertenabled = false
$scope.connectionlost = false
$scope.$on "mq.lost_connection", ->
$scope.connectionlost = true
$scope.alertenabled = true

$scope.$on "mq.restored_connection", ->
$scope.connectionlost = false
$scope.alertenabled = true
$timeout ->
$scope.alertenabled = false
, 4000
@@ -0,0 +1,13 @@
.connectionstatus
{
z-index: 1000;
width: 100%;
position: absolute;
top: 20px;
.alert {
margin-left: auto;
margin-right: auto;
width: 300px;
text-align: center;
}
}
@@ -0,0 +1,6 @@
.connectionstatus.anim-fade(ng-show="alertenabled")
.alert.alert-warning(ng-show="connectionlost")
i.fa.fa-spin.fa-spinner
| &nbsp;Connection Lost. Retrying...
.alert.alert-success(ng-hide="connectionlost")
| Connection restored!
10 changes: 5 additions & 5 deletions www/base/src/app/common/services/mq/mq.service.coffee
Expand Up @@ -5,7 +5,7 @@ class MqService extends Factory('common')
# ultra simple matcher used to route event back to the original subscriber
matcher = new RegExp("^"+matcher.replace(/\*/g, "[^/]+") + "$")
return matcher.test(value)

window.$rootScope = $rootScope
listeners = {}
ws = null
curid = 1
Expand Down Expand Up @@ -54,6 +54,7 @@ class MqService extends Factory('common')

# this is intended to be mocked in unittests
getWebSocket: (url) ->
# we use reconnecting websocket for automatic reconnection
return new ReconnectingWebSocket(url)

setBaseUrl: (url) ->
Expand All @@ -72,19 +73,18 @@ class MqService extends Factory('common')
listeners = {}

ws.onopen = (e) ->
# now we got our handshake, we can start consuming
# what was registered in between
# this is still racy, as we can have miss some events during this handshake time
pending_msgs = {}
allp = []
for k, v of listeners
allp.push(self.startConsuming(k))

$q.all(allp).then ->
deferred.resolve()
# this will trigger bound data to re fetch the full-data
if lostConnection
# this will trigger bound data to re fetch the full-data
$rootScope.$broadcast("mq.restored_connection", e)
else
$rootScope.$broadcast("mq.first_connection", e)

ws.onmessage = (e) ->
msg = JSON.parse(e.data)
Expand Down
1 change: 1 addition & 0 deletions www/base/src/app/index.jade
Expand Up @@ -4,4 +4,5 @@ block content
gl-topbar
gl-topbar-contextual-actions
loginbar
connectionstatus
ui-view
13 changes: 13 additions & 0 deletions www/base/src/styles/animations.less
Expand Up @@ -38,6 +38,19 @@ tl;dr is:
}
}

/* animation for */
.anim-fade {
-webkit-transition: .5s linear all;
transition: .5s linear all;
opacity: 1;
&.ng-hide-remove,
&.ng-hide-add,.list.ng-hide {
display:block!important;
}
&.ng-hide {
opacity: 0;
}
}
/* animation for validation tooltips in force forms */
.anim-popover {
&.ng-enter,
Expand Down

0 comments on commit 10c325e

Please sign in to comment.