Disabling UI when offline.

This commit is contained in:
Ben Vanik 2013-12-25 06:43:08 -08:00
parent 062610c596
commit 20249c2290
6 changed files with 60 additions and 2 deletions

View File

@ -48,6 +48,10 @@ body {
right: 0; right: 0;
bottom: 0; bottom: 0;
} }
.disconnected .app-body {
opacity: 0.25;
pointer-events: none;
}
.tab-pane { .tab-pane {
position: absolute; position: absolute;
left: 0; left: 0;

View File

@ -13,7 +13,7 @@
</style> </style>
</head> </head>
<body ng-controller="AppController"> <body ng-controller="AppController">
<div class="app-main"> <div class="app-main" ng-class="{disconnected: !app.session.dataSource || !app.session.dataSource.online}">
<div class="app-header" ng-include="'assets/ui/navbar.html'"></div> <div class="app-header" ng-include="'assets/ui/navbar.html'"></div>
<div class="app-body tab-content" ui-view></div> <div class="app-body tab-content" ui-view></div>
<div class="app-console navbar-default" ng-include="'assets/ui/console/console.html'"></div> <div class="app-console navbar-default" ng-include="'assets/ui/console/console.html'"></div>

View File

@ -17,3 +17,45 @@ function inherits(childCtor, parentCtor) {
childCtor.prototype = new tempCtor(); childCtor.prototype = new tempCtor();
childCtor.prototype.constructor = childCtor; childCtor.prototype.constructor = childCtor;
}; };
var EventEmitter = function() {
this.events_ = {};
};
EventEmitter.prototype.dispose = function() {
this.events_ = {};
};
EventEmitter.prototype.on = function(name, listener, opt_scope) {
var listeners = this.events_[name];
if (!listeners) {
listeners = this.events_[name] = [];
}
listeners.push({
callback: listener,
scope: opt_scope || null
});
};
EventEmitter.prototype.off = function(name, listener, opt_scope) {
var listeners = this.events_[name];
if (!listeners) {
return;
}
for (var n = 0; n < listeners.length; n++) {
if (listeners[n].callback == listener) {
listeners.splice(n, 1);
if (!listeners.length) {
delete this.events_[name];
}
return;
}
}
}
EventEmitter.prototype.emit = function(name, args) {
var listeners = this.events_[name];
if (!listeners) {
return;
}
for (var n = 0; n < listeners.length; n++) {
var listener = listeners[n];
listener.callback.apply(listener.scope, args);
}
};

View File

@ -56,11 +56,13 @@ module.service('Breakpoint', function() {
module.service('DataSource', function($q) { module.service('DataSource', function($q) {
var DataSource = function(source, delegate) { var DataSource = function(source, delegate) {
EventEmitter.call(this);
this.source = source; this.source = source;
this.delegate = delegate; this.delegate = delegate;
this.online = false; this.online = false;
this.status = 'disconnected'; this.status = 'disconnected';
}; };
inherits(DataSource, EventEmitter);
DataSource.prototype.open = function() {}; DataSource.prototype.open = function() {};
DataSource.prototype.dispose = function() {}; DataSource.prototype.dispose = function() {};
DataSource.prototype.issue = function(command) {}; DataSource.prototype.issue = function(command) {};
@ -181,6 +183,7 @@ module.service('RemoteDataSource', function(
this.online = true; this.online = true;
this.status = 'connected'; this.status = 'connected';
this.emit('online');
d.resolve(); d.resolve();
}).bind(this)); }).bind(this));
}).bind(this); }).bind(this);
@ -194,6 +197,7 @@ module.service('RemoteDataSource', function(
} else { } else {
this.status = 'disconnected'; this.status = 'disconnected';
log.info('Disconnected'); log.info('Disconnected');
this.emit('offline');
} }
}).bind(this)); }).bind(this));
}).bind(this); }).bind(this);

View File

@ -146,6 +146,12 @@ module.service('Session', function(
} }
this.dataSource = dataSource; this.dataSource = dataSource;
this.dataSource.on('online', function() {
//
}, this);
this.dataSource.on('offline', function() {
this.setDataSource(null);
}, this);
var ps = []; var ps = [];

View File

@ -508,7 +508,9 @@ json_t* WSClient::HandleMessage(const char* command, json_t* request,
// Check debugger meta commands. // Check debugger meta commands.
if (xestrcmpa(target_name, "debug") == 0) { if (xestrcmpa(target_name, "debug") == 0) {
succeeded = true; succeeded = true;
if (xestrcmpa(sub_command, "make_ready") == 0) { if (xestrcmpa(sub_command, "ping") == 0) {
return json_true();
} else if (xestrcmpa(sub_command, "make_ready") == 0) {
MakeReady(); MakeReady();
return json_true(); return json_true();
} else { } else {