Simon Hunt

ONOS-4217: WebUI -- fix broken preferences / querystring precedence.

Change-Id: I9205e344c3b7dfa751ccb033d595715579913c3b
...@@ -26,9 +26,19 @@ ...@@ -26,9 +26,19 @@
26 // internal state 26 // internal state
27 var cache = {}, listeners = []; 27 var cache = {}, listeners = [];
28 28
29 - // returns the preference by the specified name 29 + // returns the preference settings for the specified key
30 - function getPrefs(name, defaults) { 30 + function getPrefs(name, defaults, qparams) {
31 - return cache[name] || defaults; 31 + var obj = angular.extend({}, defaults || {}, cache[name] || {});
32 +
33 + // if query params are specified, they override...
34 + if (fs.isO(qparams)) {
35 + angular.forEach(obj, function (v, k) {
36 + if (qparams.hasOwnProperty(k)) {
37 + obj[k] = qparams[k];
38 + }
39 + });
40 + }
41 + return obj;
32 } 42 }
33 43
34 // converts string values to numbers for selected (or all) keys 44 // converts string values to numbers for selected (or all) keys
...@@ -57,7 +67,7 @@ ...@@ -57,7 +67,7 @@
57 function updatePrefs(data) { 67 function updatePrefs(data) {
58 $log.info('User properties updated'); 68 $log.info('User properties updated');
59 cache = data; 69 cache = data;
60 - listeners.forEach(function (l) { l(); }); 70 + listeners.forEach(function (lsnr) { lsnr(); });
61 } 71 }
62 72
63 function addListener(listener) { 73 function addListener(listener) {
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
30 30
31 // references to injected services 31 // references to injected services
32 var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps, th, 32 var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps, th,
33 - tds, t3s, tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, tspr, ttip, tov; 33 + tds, t3s, tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, tspr,
34 + ttip, tov;
34 35
35 // DOM elements 36 // DOM elements
36 var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; 37 var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer;
...@@ -368,15 +369,14 @@ ...@@ -368,15 +369,14 @@
368 } 369 }
369 370
370 function setUpMap($loc) { 371 function setUpMap($loc) {
371 - var qp = $loc.search(), 372 + var prefs = ps.getPrefs(
372 - pr = ps.getPrefs('topo_mapid', { 373 + 'topo_mapid',
373 - id: qp.mapid || 'usa', 374 + { mapid: 'usa', mapscale: 1, tint: 'off'},
374 - scale: qp.mapscale || 1, 375 + $loc.search()
375 - tint: qp.tint || 'off' 376 + ),
376 - }), 377 + mapId = prefs.mapid,
377 - mapId = pr.id, 378 + mapScale = prefs.mapscale,
378 - mapScale = pr.scale, 379 + tint = prefs.tint,
379 - tint = pr.tint,
380 promise, 380 promise,
381 cfilter; 381 cfilter;
382 382
...@@ -415,7 +415,7 @@ ...@@ -415,7 +415,7 @@
415 shading: shading() 415 shading: shading()
416 }); 416 });
417 } 417 }
418 - ps.setPrefs('topo_mapid', { id: mapId, scale: mapScale, tint: tint }); 418 + ps.setPrefs('topo_mapid', prefs);
419 return promise; 419 return promise;
420 } 420 }
421 421
...@@ -438,13 +438,12 @@ ...@@ -438,13 +438,12 @@
438 } 438 }
439 439
440 function setUpSprites($loc, tspr) { 440 function setUpSprites($loc, tspr) {
441 - var s1 = $loc.search().sprites, 441 + var prefs = ps.getPrefs('topo_sprites', { sprites: '' }, $loc.search()),
442 - s2 = ps.getPrefs('topo_sprites', { id: s1 }), 442 + sprId = prefs.sprites;
443 - sprId = s2.id;
444 443
445 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites'); 444 spriteG = zoomLayer.append ('g').attr('id', 'topo-sprites');
446 if (sprId) { 445 if (sprId) {
447 - ps.setPrefs('topo_sprites', {id:sprId}); 446 + ps.setPrefs('topo_sprites', prefs);
448 tspr.loadSprites(spriteG, defs, sprId); 447 tspr.loadSprites(spriteG, defs, sprId);
449 } 448 }
450 } 449 }
......