GUI -- Added theme listeners, so the instance panel can update the instances on a theme change.
Change-Id: If26d5a6ce9fadc02c7184c5ad4d252fc168300a8
Showing
9 changed files
with
128 additions
and
14 deletions
... | @@ -140,8 +140,9 @@ | ... | @@ -140,8 +140,9 @@ |
140 | var lightNorm = ['#3E5780', '#78533B', '#CB4D28', '#018D61', '#8A2979', '#006D73', '#56AF00'], | 140 | var lightNorm = ['#3E5780', '#78533B', '#CB4D28', '#018D61', '#8A2979', '#006D73', '#56AF00'], |
141 | lightMute = ['#A8B8CC', '#CCB3A8', '#FFC2BD', '#96D6BF', '#D19FCE', '#8FCCCA', '#CAEAA4'], | 141 | lightMute = ['#A8B8CC', '#CCB3A8', '#FFC2BD', '#96D6BF', '#D19FCE', '#8FCCCA', '#CAEAA4'], |
142 | 142 | ||
143 | - darkNorm = ['#3E5780', '#78533B', '#CB4D28', '#018D61', '#8A2979', '#006D73', '#56AF00'], | 143 | + // let's try slightly brigher colors for dark normal.. |
144 | - darkMute = ['#A8B8CC', '#CCB3A8', '#FFC2BD', '#96D6BF', '#D19FCE', '#8FCCCA', '#CAEAA4']; | 144 | + darkNorm = ['#364D7F', '#7F5236', '#A93114', '#018D61', '#7E116D', '#02747A', '#378300'], |
145 | + darkMute = ['#1B2645', '#432B1C', '#76220E', '#035433', '#560B4A', '#013A3E', '#2D6D00']; | ||
145 | 146 | ||
146 | var colors= { | 147 | var colors= { |
147 | light: { | 148 | light: { | ... | ... |
... | @@ -20,11 +20,13 @@ | ... | @@ -20,11 +20,13 @@ |
20 | (function () { | 20 | (function () { |
21 | 'use strict'; | 21 | 'use strict'; |
22 | 22 | ||
23 | - var $log; | 23 | + var $log, fs; |
24 | 24 | ||
25 | var themes = ['light', 'dark'], | 25 | var themes = ['light', 'dark'], |
26 | themeStr = themes.join(' '), | 26 | themeStr = themes.join(' '), |
27 | - thidx; | 27 | + thidx, |
28 | + listeners = {}, | ||
29 | + nextListenerId = 1; | ||
28 | 30 | ||
29 | function init() { | 31 | function init() { |
30 | thidx = 0; | 32 | thidx = 0; |
... | @@ -59,16 +61,46 @@ | ... | @@ -59,16 +61,46 @@ |
59 | } | 61 | } |
60 | 62 | ||
61 | function themeEvent(w) { | 63 | function themeEvent(w) { |
62 | - // TODO: emit a theme-changed event | 64 | + var t = getTheme(), |
63 | - var m = 'Theme-Change-('+w+'): ' + getTheme(); | 65 | + m = 'Theme-Change-('+w+'): ' + t; |
64 | $log.debug(m); | 66 | $log.debug(m); |
67 | + angular.forEach(listeners, function(value) { | ||
68 | + value.cb( | ||
69 | + { | ||
70 | + event: 'themeChange', | ||
71 | + value: t | ||
72 | + } | ||
73 | + ); | ||
74 | + }); | ||
65 | } | 75 | } |
66 | 76 | ||
67 | - // TODO: add hook for theme-change listener | 77 | + function addListener(callback) { |
78 | + var id = nextListenerId++, | ||
79 | + cb = fs.isF(callback), | ||
80 | + o = { id: id, cb: cb }; | ||
81 | + | ||
82 | + if (cb) { | ||
83 | + listeners[id] = o; | ||
84 | + } else { | ||
85 | + $log.error('ThemeService.addListener(): callback not a function'); | ||
86 | + o.error = 'No callback defined'; | ||
87 | + } | ||
88 | + return o; | ||
89 | + } | ||
90 | + | ||
91 | + function removeListener(lsnr) { | ||
92 | + var id = lsnr && lsnr.id, | ||
93 | + o = listeners[id]; | ||
94 | + if (o) { | ||
95 | + delete listeners[id]; | ||
96 | + } | ||
97 | + } | ||
68 | 98 | ||
69 | angular.module('onosUtil') | 99 | angular.module('onosUtil') |
70 | - .factory('ThemeService', ['$log', function (_$log_) { | 100 | + .factory('ThemeService', ['$log', 'FnService', |
101 | + function (_$log_, _fs_) { | ||
71 | $log = _$log_; | 102 | $log = _$log_; |
103 | + fs = _fs_; | ||
72 | thidx = 0; | 104 | thidx = 0; |
73 | 105 | ||
74 | return { | 106 | return { |
... | @@ -80,7 +112,9 @@ | ... | @@ -80,7 +112,9 @@ |
80 | setTheme(x); | 112 | setTheme(x); |
81 | } | 113 | } |
82 | }, | 114 | }, |
83 | - toggleTheme: toggleTheme | 115 | + toggleTheme: toggleTheme, |
116 | + addListener: addListener, | ||
117 | + removeListener: removeListener | ||
84 | }; | 118 | }; |
85 | }]); | 119 | }]); |
86 | 120 | ... | ... |
... | @@ -50,7 +50,8 @@ | ... | @@ -50,7 +50,8 @@ |
50 | var onosInstances, | 50 | var onosInstances, |
51 | onosOrder, | 51 | onosOrder, |
52 | oiShowMaster, | 52 | oiShowMaster, |
53 | - oiBox; | 53 | + oiBox, |
54 | + themeListener; | ||
54 | 55 | ||
55 | 56 | ||
56 | // ========================== | 57 | // ========================== |
... | @@ -291,9 +292,15 @@ | ... | @@ -291,9 +292,15 @@ |
291 | onosInstances = {}; | 292 | onosInstances = {}; |
292 | onosOrder = []; | 293 | onosOrder = []; |
293 | oiShowMaster = false; | 294 | oiShowMaster = false; |
295 | + | ||
296 | + // we want to update the instances, each time the theme changes | ||
297 | + themeListener = ts.addListener(updateInstances); | ||
294 | } | 298 | } |
295 | 299 | ||
296 | function destroyInst() { | 300 | function destroyInst() { |
301 | + ts.removeListener(themeListener); | ||
302 | + themeListener = null; | ||
303 | + | ||
297 | ps.destroyPanel(idIns); | 304 | ps.destroyPanel(idIns); |
298 | oiBox = null; | 305 | oiBox = null; |
299 | } | 306 | } | ... | ... |
... | @@ -70,11 +70,11 @@ describe('factory: fw/svg/svgUtil.js', function() { | ... | @@ -70,11 +70,11 @@ describe('factory: fw/svg/svgUtil.js', function() { |
70 | 70 | ||
71 | 71 | ||
72 | it('should provide an alternate (dark) shade of blue', function () { | 72 | it('should provide an alternate (dark) shade of blue', function () { |
73 | - expect(sus.cat7().getColor('foo', false, 'dark')).toEqual('#3E5780'); | 73 | + expect(sus.cat7().getColor('foo', false, 'dark')).toEqual('#364D7F'); |
74 | }); | 74 | }); |
75 | 75 | ||
76 | it('should provide an alternate (dark) shade of blue for muted', function () { | 76 | it('should provide an alternate (dark) shade of blue for muted', function () { |
77 | - expect(sus.cat7().getColor('foo', true, 'dark')).toEqual('#A8B8CC'); | 77 | + expect(sus.cat7().getColor('foo', true, 'dark')).toEqual('#1B2645'); |
78 | }); | 78 | }); |
79 | 79 | ||
80 | it('should iterate across the colors', function () { | 80 | it('should iterate across the colors', function () { | ... | ... |
... | @@ -18,16 +18,28 @@ | ... | @@ -18,16 +18,28 @@ |
18 | ONOS GUI -- Util -- Theme Service - Unit Tests | 18 | ONOS GUI -- Util -- Theme Service - Unit Tests |
19 | */ | 19 | */ |
20 | describe('factory: fw/util/theme.js', function() { | 20 | describe('factory: fw/util/theme.js', function() { |
21 | - var ts, $log; | 21 | + var ts, $log, fs; |
22 | 22 | ||
23 | beforeEach(module('onosUtil')); | 23 | beforeEach(module('onosUtil')); |
24 | 24 | ||
25 | - beforeEach(inject(function (ThemeService, _$log_) { | 25 | + beforeEach(inject(function (ThemeService, _$log_, FnService) { |
26 | ts = ThemeService; | 26 | ts = ThemeService; |
27 | $log = _$log_; | 27 | $log = _$log_; |
28 | + fs = FnService; | ||
28 | ts.init(); | 29 | ts.init(); |
29 | })); | 30 | })); |
30 | 31 | ||
32 | + it('should define MapService', function () { | ||
33 | + expect(ts).toBeDefined(); | ||
34 | + }); | ||
35 | + | ||
36 | + it('should define api functions', function () { | ||
37 | + expect(fs.areFunctions(ts, [ | ||
38 | + 'init', 'theme', 'toggleTheme', 'addListener', 'removeListener' | ||
39 | + ])).toBeTruthy(); | ||
40 | + }); | ||
41 | + | ||
42 | + | ||
31 | function verifyBodyClass(yes, no) { | 43 | function verifyBodyClass(yes, no) { |
32 | function bodyHasClass(c) { | 44 | function bodyHasClass(c) { |
33 | return d3.select('body').classed(c); | 45 | return d3.select('body').classed(c); |
... | @@ -78,4 +90,8 @@ describe('factory: fw/util/theme.js', function() { | ... | @@ -78,4 +90,8 @@ describe('factory: fw/util/theme.js', function() { |
78 | expect($log.debug).not.toHaveBeenCalled(); | 90 | expect($log.debug).not.toHaveBeenCalled(); |
79 | verifyBodyClass('light', 'dark'); | 91 | verifyBodyClass('light', 'dark'); |
80 | }); | 92 | }); |
93 | + | ||
94 | + | ||
95 | + // TODO : Unit tests for listeners... | ||
96 | + | ||
81 | }); | 97 | }); | ... | ... |
-
Please register or login to post a comment