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 @@ ...@@ -24,7 +24,7 @@
24 'use strict'; 24 'use strict';
25 25
26 // injected references 26 // injected references
27 - var $log, fs, ks; 27 + var $log, $route, fs, ks;
28 28
29 var veil, pdiv, svg; 29 var veil, pdiv, svg;
30 30
...@@ -46,12 +46,23 @@ ...@@ -46,12 +46,23 @@
46 ks.enableKeys(true); 46 ks.enableKeys(true);
47 } 47 }
48 48
49 + // function that only invokes the veil if the caller is the current view
50 + function lostServer(ctrlName, msg) {
51 + if ($route.current.$$route.controller === ctrlName) {
52 + $log.debug('VEIL-service: ', ctrlName);
53 + show(msg)
54 + } else {
55 + $log.debug('VEIL-service: IGNORING ', ctrlName);
56 + }
57 + }
58 +
49 angular.module('onosLayer') 59 angular.module('onosLayer')
50 .factory('VeilService', 60 .factory('VeilService',
51 - ['$log', 'FnService', 'KeyService', 'GlyphService', 61 + ['$log', '$route', 'FnService', 'KeyService', 'GlyphService',
52 62
53 - function (_$log_, _fs_, _ks_, gs) { 63 + function (_$log_, _$route_, _fs_, _ks_, gs) {
54 $log = _$log_; 64 $log = _$log_;
65 + $route = _$route_;
55 fs = _fs_; 66 fs = _fs_;
56 ks = _ks_; 67 ks = _ks_;
57 68
...@@ -76,7 +87,8 @@ ...@@ -76,7 +87,8 @@
76 87
77 return { 88 return {
78 show: show, 89 show: show,
79 - hide: hide 90 + hide: hide,
91 + lostServer: lostServer
80 }; 92 };
81 }]); 93 }]);
82 94
......
...@@ -22,100 +22,14 @@ ...@@ -22,100 +22,14 @@
22 22
23 var $log; 23 var $log;
24 24
25 -
26 - // TODO: remove temporary test code
27 - var fakeData = {
28 - '1': {
29 - "devices": [{
30 - "id": "of:0000000000000001",
31 - "available": true,
32 - "_iconid_available": "deviceOnline",
33 - "role": "MASTER",
34 - "mfr": "Nicira, Inc.",
35 - "hw": "Open vSwitch",
36 - "sw": "2.0.1",
37 - "serial": "None",
38 - "annotations": {
39 - "protocol": "OF_10"
40 - }
41 - },
42 - {
43 - "id": "of:0000000000000004",
44 - "available": false,
45 - "_iconid_available": "deviceOffline",
46 - "role": "MASTER",
47 - "mfr": "Nicira, Inc.",
48 - "hw": "Open vSwitch",
49 - "sw": "2.0.1",
50 - "serial": "None",
51 - "annotations": {
52 - "protocol": "OF_10"
53 - }
54 - },
55 - {
56 - "id": "of:0000000000000092",
57 - "available": false,
58 - "_iconid_available": "deviceOffline",
59 - "role": "MASTER",
60 - "mfr": "Nicira, Inc.",
61 - "hw": "Open vSwitch",
62 - "sw": "2.0.1",
63 - "serial": "None",
64 - "annotations": {
65 - "protocol": "OF_10"
66 - }
67 - }]
68 - },
69 - '2': {
70 - "devices": [{
71 - "id": "of:0000000000000002",
72 - "available": true,
73 - "_iconid_available": "deviceOnline",
74 - "role": "MASTER",
75 - "mfr": "Nicira, Inc.",
76 - "hw": "Open vSwitch",
77 - "sw": "2.0.0",
78 - "serial": "None",
79 - "annotations": {
80 - "protocol": "OF_10"
81 - }
82 - },
83 - {
84 - "id": "of:0000000000000006",
85 - "available": true,
86 - "_iconid_available": "deviceOnline",
87 - "role": "MASTER",
88 - "mfr": "Nicira, Inc.",
89 - "hw": "Open vSwitch",
90 - "sw": "2.1.1",
91 - "serial": "None",
92 - "annotations": {
93 - "protocol": "OF_10"
94 - }
95 - }]
96 - },
97 - 'empty': {
98 - devices: []
99 - }
100 - };
101 -
102 - function getFakeData(url) {
103 - var id = url.slice(5);
104 -
105 - return fakeData[id] || fakeData.empty;
106 - }
107 -
108 angular.module('onosRemote') 25 angular.module('onosRemote')
109 - .factory('RestService', ['$log', '$http', 'UrlFnService', 26 + .factory('RestService',
27 + ['$log', '$http', 'UrlFnService',
28 +
110 function (_$log_, $http, ufs) { 29 function (_$log_, $http, ufs) {
111 $log = _$log_; 30 $log = _$log_;
112 31
113 - function get(url, callback) { 32 + function get(url, callback, errorCb) {
114 - // TODO: remove temporary test code
115 - if (url.match(/^test\//)) {
116 - callback(getFakeData(url));
117 - return;
118 - }
119 var fullUrl = ufs.rsUrl(url); 33 var fullUrl = ufs.rsUrl(url);
120 34
121 $http.get(fullUrl).then(function (response) { 35 $http.get(fullUrl).then(function (response) {
...@@ -123,8 +37,11 @@ ...@@ -123,8 +37,11 @@
123 callback(response.data); 37 callback(response.data);
124 }, function (response) { 38 }, function (response) {
125 // error 39 // error
126 - $log.warn('Failed to retrieve JSON data: ' + fullUrl, 40 + var emsg = 'Failed to retrieve JSON data: ' + fullUrl;
127 - response.status, response.data); 41 + $log.warn(emsg, response.status, response.data);
42 + if (errorCb) {
43 + errorCb(emsg);
44 + }
128 }); 45 });
129 } 46 }
130 47
...@@ -132,5 +49,4 @@ ...@@ -132,5 +49,4 @@
132 get: get 49 get: get
133 }; 50 };
134 }]); 51 }]);
135 -
136 }()); 52 }());
......
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
23 23
24 angular.module('ovDevice', []) 24 angular.module('ovDevice', [])
25 .controller('OvDeviceCtrl', 25 .controller('OvDeviceCtrl',
26 - ['$log', '$scope', '$location', 'RestService', 26 + ['$log', '$scope', '$location', 'RestService', 'VeilService',
27 27
28 - function ($log, $scope, $location, rs) { 28 + function ($log, $scope, $location, rs, vs) {
29 var self = this; 29 var self = this;
30 self.deviceData = []; 30 self.deviceData = [];
31 31
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
36 var url = 'device' + urlSuffix; 36 var url = 'device' + urlSuffix;
37 rs.get(url, function (data) { 37 rs.get(url, function (data) {
38 self.deviceData = data.devices; 38 self.deviceData = data.devices;
39 + }, function (errMsg) {
40 + vs.lostServer('OvDeviceCtrl', errMsg);
39 }); 41 });
40 }; 42 };
41 $scope.sortCallback(); 43 $scope.sortCallback();
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
99 function onWsClose(reason) { 99 function onWsClose(reason) {
100 $log.log('web socket closed; reason=', reason); 100 $log.log('web socket closed; reason=', reason);
101 wsock = null; 101 wsock = null;
102 - vs.show([ 102 + vs.lostServer('OvTopoCtrl', [
103 'Oops!', 103 'Oops!',
104 'Web-socket connection to server closed...', 104 'Web-socket connection to server closed...',
105 'Try refreshing the page.' 105 'Try refreshing the page.'
......