Simon Hunt

GUI -- Added VeilService.lostServer() function to only invoke the veil if the ca…

…lling controller is the current controller.
- removed test code from rest.js

Change-Id: I2e05b42a10a1e66a7a26210e347c584c6fbd5bf2
......@@ -24,7 +24,7 @@
'use strict';
// injected references
var $log, fs, ks;
var $log, $route, fs, ks;
var veil, pdiv, svg;
......@@ -46,12 +46,23 @@
ks.enableKeys(true);
}
// function that only invokes the veil if the caller is the current view
function lostServer(ctrlName, msg) {
if ($route.current.$$route.controller === ctrlName) {
$log.debug('VEIL-service: ', ctrlName);
show(msg)
} else {
$log.debug('VEIL-service: IGNORING ', ctrlName);
}
}
angular.module('onosLayer')
.factory('VeilService',
['$log', 'FnService', 'KeyService', 'GlyphService',
['$log', '$route', 'FnService', 'KeyService', 'GlyphService',
function (_$log_, _fs_, _ks_, gs) {
function (_$log_, _$route_, _fs_, _ks_, gs) {
$log = _$log_;
$route = _$route_;
fs = _fs_;
ks = _ks_;
......@@ -76,7 +87,8 @@
return {
show: show,
hide: hide
hide: hide,
lostServer: lostServer
};
}]);
......
......@@ -22,100 +22,14 @@
var $log;
// TODO: remove temporary test code
var fakeData = {
'1': {
"devices": [{
"id": "of:0000000000000001",
"available": true,
"_iconid_available": "deviceOnline",
"role": "MASTER",
"mfr": "Nicira, Inc.",
"hw": "Open vSwitch",
"sw": "2.0.1",
"serial": "None",
"annotations": {
"protocol": "OF_10"
}
},
{
"id": "of:0000000000000004",
"available": false,
"_iconid_available": "deviceOffline",
"role": "MASTER",
"mfr": "Nicira, Inc.",
"hw": "Open vSwitch",
"sw": "2.0.1",
"serial": "None",
"annotations": {
"protocol": "OF_10"
}
},
{
"id": "of:0000000000000092",
"available": false,
"_iconid_available": "deviceOffline",
"role": "MASTER",
"mfr": "Nicira, Inc.",
"hw": "Open vSwitch",
"sw": "2.0.1",
"serial": "None",
"annotations": {
"protocol": "OF_10"
}
}]
},
'2': {
"devices": [{
"id": "of:0000000000000002",
"available": true,
"_iconid_available": "deviceOnline",
"role": "MASTER",
"mfr": "Nicira, Inc.",
"hw": "Open vSwitch",
"sw": "2.0.0",
"serial": "None",
"annotations": {
"protocol": "OF_10"
}
},
{
"id": "of:0000000000000006",
"available": true,
"_iconid_available": "deviceOnline",
"role": "MASTER",
"mfr": "Nicira, Inc.",
"hw": "Open vSwitch",
"sw": "2.1.1",
"serial": "None",
"annotations": {
"protocol": "OF_10"
}
}]
},
'empty': {
devices: []
}
};
function getFakeData(url) {
var id = url.slice(5);
return fakeData[id] || fakeData.empty;
}
angular.module('onosRemote')
.factory('RestService', ['$log', '$http', 'UrlFnService',
.factory('RestService',
['$log', '$http', 'UrlFnService',
function (_$log_, $http, ufs) {
$log = _$log_;
function get(url, callback) {
// TODO: remove temporary test code
if (url.match(/^test\//)) {
callback(getFakeData(url));
return;
}
function get(url, callback, errorCb) {
var fullUrl = ufs.rsUrl(url);
$http.get(fullUrl).then(function (response) {
......@@ -123,8 +37,11 @@
callback(response.data);
}, function (response) {
// error
$log.warn('Failed to retrieve JSON data: ' + fullUrl,
response.status, response.data);
var emsg = 'Failed to retrieve JSON data: ' + fullUrl;
$log.warn(emsg, response.status, response.data);
if (errorCb) {
errorCb(emsg);
}
});
}
......@@ -132,5 +49,4 @@
get: get
};
}]);
}());
......
......@@ -23,9 +23,9 @@
angular.module('ovDevice', [])
.controller('OvDeviceCtrl',
['$log', '$scope', '$location', 'RestService',
['$log', '$scope', '$location', 'RestService', 'VeilService',
function ($log, $scope, $location, rs) {
function ($log, $scope, $location, rs, vs) {
var self = this;
self.deviceData = [];
......@@ -36,6 +36,8 @@
var url = 'device' + urlSuffix;
rs.get(url, function (data) {
self.deviceData = data.devices;
}, function (errMsg) {
vs.lostServer('OvDeviceCtrl', errMsg);
});
};
$scope.sortCallback();
......
......@@ -99,7 +99,7 @@
function onWsClose(reason) {
$log.log('web socket closed; reason=', reason);
wsock = null;
vs.show([
vs.lostServer('OvTopoCtrl', [
'Oops!',
'Web-socket connection to server closed...',
'Try refreshing the page.'
......