Bri Prebilic Cole

GUI -- Strange Device View Table layout fixed in Safari.

(cherry-picks from master 55ee09b1)

Change-Id: Icfb3d80654a2ab009ca12b64f35a20ba98f37681
...@@ -122,6 +122,28 @@ ...@@ -122,6 +122,28 @@
122 return patt.test(ua); 122 return patt.test(ua);
123 } 123 }
124 124
125 + // Returns true if the current browser determined to be Chrome
126 + function isChrome() {
127 + var isChromium = $window.chrome,
128 + vendorName = $window.navigator.vendor,
129 + isOpera = $window.navigator.userAgent.indexOf("OPR") > -1;
130 + return (isChromium !== null &&
131 + isChromium !== undefined &&
132 + vendorName === "Google Inc." &&
133 + isOpera == false);
134 + }
135 +
136 + // Returns true if the current browser determined to be Safari
137 + function isSafari() {
138 + return ($window.navigator.userAgent.indexOf('Safari') !== -1 &&
139 + $window.navigator.userAgent.indexOf('Chrome') === -1);
140 + }
141 +
142 + // Returns true if the current browser determined to be Firefox
143 + function isFirefox() {
144 + return typeof InstallTrigger !== 'undefined';
145 + }
146 +
125 // search through an array of objects, looking for the one with the 147 // search through an array of objects, looking for the one with the
126 // tagged property matching the given key. tag defaults to 'id'. 148 // tagged property matching the given key. tag defaults to 'id'.
127 // returns the index of the matching object, or -1 for no match. 149 // returns the index of the matching object, or -1 for no match.
...@@ -222,6 +244,9 @@ ...@@ -222,6 +244,9 @@
222 areFunctionsNonStrict: areFunctionsNonStrict, 244 areFunctionsNonStrict: areFunctionsNonStrict,
223 windowSize: windowSize, 245 windowSize: windowSize,
224 isMobile: isMobile, 246 isMobile: isMobile,
247 + isChrome: isChrome,
248 + isSafari: isSafari,
249 + isFirefox: isFirefox,
225 debugOn: debugOn, 250 debugOn: debugOn,
226 find: find, 251 find: find,
227 inArray: inArray, 252 inArray: inArray,
......
...@@ -267,9 +267,10 @@ ...@@ -267,9 +267,10 @@
267 $log.log('OvDeviceCtrl has been created'); 267 $log.log('OvDeviceCtrl has been created');
268 }]) 268 }])
269 269
270 - .directive('deviceDetailsPanel', ['$rootScope', '$window', 270 + .directive('deviceDetailsPanel', ['$rootScope', '$window', '$timeout',
271 - function ($rootScope, $window) { 271 + function ($rootScope, $window, $timeout) {
272 return function (scope) { 272 return function (scope) {
273 + var unbindWatch;
273 274
274 function heightCalc() { 275 function heightCalc() {
275 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height') 276 pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
...@@ -277,10 +278,21 @@ ...@@ -277,10 +278,21 @@
277 wSize = fs.windowSize(pStartY); 278 wSize = fs.windowSize(pStartY);
278 pHeight = wSize.height; 279 pHeight = wSize.height;
279 } 280 }
280 - heightCalc();
281 281
282 + function initPanel() {
283 + heightCalc();
282 createDetailsPane(); 284 createDetailsPane();
285 + }
286 +
287 + // Safari has a bug where it renders the fixed-layout table wrong
288 + // if you ask for the window's size too early
289 + if (scope.onos.browser === 'safari') {
290 + $timeout(initPanel);
291 + } else {
292 + initPanel();
293 + }
283 294
295 + // if the panelData changes
284 scope.$watch('panelData', function () { 296 scope.$watch('panelData', function () {
285 if (!fs.isEmptyObject(scope.panelData)) { 297 if (!fs.isEmptyObject(scope.panelData)) {
286 populateDetails(scope.panelData); 298 populateDetails(scope.panelData);
...@@ -288,12 +300,13 @@ ...@@ -288,12 +300,13 @@
288 } 300 }
289 }); 301 });
290 302
291 - $rootScope.$watchCollection( 303 + // if the window size changes
304 + unbindWatch = $rootScope.$watchCollection(
292 function () { 305 function () {
293 return { 306 return {
294 h: $window.innerHeight, 307 h: $window.innerHeight,
295 w: $window.innerWidth 308 w: $window.innerWidth
296 - } 309 + };
297 }, function () { 310 }, function () {
298 if (!fs.isEmptyObject(scope.panelData)) { 311 if (!fs.isEmptyObject(scope.panelData)) {
299 heightCalc(); 312 heightCalc();
...@@ -303,6 +316,7 @@ ...@@ -303,6 +316,7 @@
303 ); 316 );
304 317
305 scope.$on('$destroy', function () { 318 scope.$on('$destroy', function () {
319 + unbindWatch();
306 ps.destroyPanel(pName); 320 ps.destroyPanel(pName);
307 }); 321 });
308 }; 322 };
......
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
143 143
144 </head> 144 </head>
145 <body class="light" ng-app="onosApp"> 145 <body class="light" ng-app="onosApp">
146 -<div id="frame" ng-controller="OnosCtrl as onosCtrl"> 146 +<div id="frame" ng-controller="OnosCtrl as onosCtrl" detect-browser>
147 <div id="mast" 147 <div id="mast"
148 ng-controller="MastCtrl as mastCtrl" 148 ng-controller="MastCtrl as mastCtrl"
149 ng-include="'app/fw/mast/mast.html'"></div> 149 ng-include="'app/fw/mast/mast.html'"></div>
......
...@@ -69,12 +69,12 @@ ...@@ -69,12 +69,12 @@
69 angular.module('onosApp', moduleDependencies) 69 angular.module('onosApp', moduleDependencies)
70 70
71 .controller('OnosCtrl', [ 71 .controller('OnosCtrl', [
72 - '$log', '$route', '$routeParams', '$location', 72 + '$log', '$scope', '$route', '$routeParams', '$location',
73 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', 73 'KeyService', 'ThemeService', 'GlyphService', 'VeilService',
74 'PanelService', 'FlashService', 'QuickHelpService', 74 'PanelService', 'FlashService', 'QuickHelpService',
75 'WebSocketService', 75 'WebSocketService',
76 76
77 - function ($log, $route, $routeParams, $location, 77 + function ($log, $scope, $route, $routeParams, $location,
78 ks, ts, gs, vs, ps, flash, qhs, wss) { 78 ks, ts, gs, vs, ps, flash, qhs, wss) {
79 var self = this; 79 var self = this;
80 80
...@@ -83,6 +83,9 @@ ...@@ -83,6 +83,9 @@
83 self.$location = $location; 83 self.$location = $location;
84 self.version = '1.2.0'; 84 self.version = '1.2.0';
85 85
86 + // shared object inherited by all views:
87 + $scope.onos = {};
88 +
86 // initialize services... 89 // initialize services...
87 ts.init(); 90 ts.init();
88 ks.installOn(d3.select('body')); 91 ks.installOn(d3.select('body'));
...@@ -131,5 +134,29 @@ ...@@ -131,5 +134,29 @@
131 }); 134 });
132 } 135 }
133 }); 136 });
137 + }])
138 +
139 + .directive('detectBrowser', ['$log', 'FnService',
140 + function ($log, fs) {
141 + return function (scope) {
142 + var body = d3.select('body'),
143 + browser = '';
144 + if (fs.isChrome()) {
145 + browser = 'chrome';
146 + } else if (fs.isSafari()) {
147 + browser = 'safari';
148 + } else if (fs.isFirefox()) {
149 + browser = 'firefox';
150 + }
151 + body.classed(browser, true);
152 + scope.onos.browser = browser;
153 +
154 + if (fs.isMobile()) {
155 + body.classed('mobile', true);
156 + scope.onos.mobile = true;
157 + }
158 +
159 + $log.debug('Detected browser is', fs.cap(browser));
160 + };
134 }]); 161 }]);
135 }()); 162 }());
......