GUI -- Refactored Toolbar Service.
Change-Id: I758d0da30438eb7257350480024d3bd99624509c
Showing
4 changed files
with
133 additions
and
140 deletions
... | @@ -18,16 +18,6 @@ | ... | @@ -18,16 +18,6 @@ |
18 | ONOS GUI -- Button Service -- CSS file | 18 | ONOS GUI -- Button Service -- CSS file |
19 | */ | 19 | */ |
20 | 20 | ||
21 | -.tbarArrow { | ||
22 | - padding: 0 10px 0 10px; | ||
23 | -} | ||
24 | -.light .tbarArrow svg.embeddedIcon .icon.tableColSortAsc .glyph { | ||
25 | - fill: #838383; | ||
26 | -} | ||
27 | -.dark .tbarArrow svg.embeddedIcon .icon.tableColSortAsc .glyph { | ||
28 | - fill: #B2B2B2; | ||
29 | -} | ||
30 | - | ||
31 | .button, | 21 | .button, |
32 | .toggleButton, | 22 | .toggleButton, |
33 | .radioSet { | 23 | .radioSet { | ... | ... |
... | @@ -18,16 +18,35 @@ | ... | @@ -18,16 +18,35 @@ |
18 | ONOS GUI -- Toolbar Service -- CSS file | 18 | ONOS GUI -- Toolbar Service -- CSS file |
19 | */ | 19 | */ |
20 | 20 | ||
21 | +.light .tbarArrow svg.embeddedIcon .icon .glyph { | ||
22 | + fill: #838383; | ||
23 | +} | ||
24 | +.dark .tbarArrow svg.embeddedIcon .icon .glyph { | ||
25 | + fill: #B2B2B2; | ||
26 | +} | ||
27 | + | ||
28 | + | ||
29 | +.tbarArrow svg.embeddedIcon .icon rect { | ||
30 | + stroke: none; | ||
31 | +} | ||
32 | +.light .tbarArrow svg.embeddedIcon .icon rect { | ||
33 | + fill: none; | ||
34 | +} | ||
35 | +.dark .tbarArrow svg.embeddedIcon .icon rect { | ||
36 | + fill: none; | ||
37 | +} | ||
38 | + | ||
39 | + | ||
21 | .separator { | 40 | .separator { |
22 | border: 1px solid; | 41 | border: 1px solid; |
23 | margin: 0 4px 0 4px; | 42 | margin: 0 4px 0 4px; |
24 | display: inline-block; | 43 | display: inline-block; |
44 | + height: 23px; | ||
45 | + width: 0; | ||
25 | } | 46 | } |
26 | .light .separator { | 47 | .light .separator { |
27 | border-color: #ddd; | 48 | border-color: #ddd; |
28 | } | 49 | } |
29 | - | ||
30 | .dark .separator { | 50 | .dark .separator { |
31 | border-color: #1A1A1A; | 51 | border-color: #1A1A1A; |
32 | - | ||
33 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
52 | +} | ... | ... |
... | @@ -17,12 +17,18 @@ | ... | @@ -17,12 +17,18 @@ |
17 | /* | 17 | /* |
18 | ONOS GUI -- Widget -- Toolbar Service | 18 | ONOS GUI -- Widget -- Toolbar Service |
19 | */ | 19 | */ |
20 | +// TODO: Augment service to allow toolbars to exist on right edge of screen | ||
21 | + | ||
22 | + | ||
20 | (function () { | 23 | (function () { |
21 | 'use strict'; | 24 | 'use strict'; |
22 | 25 | ||
26 | + // injected refs | ||
23 | var $log, fs, ps, bns, is; | 27 | var $log, fs, ps, bns, is; |
24 | 28 | ||
25 | - var ids = [], | 29 | + // configuration |
30 | + var arrowSize = 10, | ||
31 | + sepWidth = 6, | ||
26 | defaultSettings = { | 32 | defaultSettings = { |
27 | edge: 'left', | 33 | edge: 'left', |
28 | width: 20, | 34 | width: 20, |
... | @@ -31,122 +37,120 @@ | ... | @@ -31,122 +37,120 @@ |
31 | top: '80%', | 37 | top: '80%', |
32 | fade: false, | 38 | fade: false, |
33 | shown: false | 39 | shown: false |
34 | - }, | 40 | + }; |
35 | - settings, | ||
36 | - arrowSize = 10, | ||
37 | - btnPadding = 4, | ||
38 | - tbarId, | ||
39 | - tbarPanel, | ||
40 | - tbarDiv, | ||
41 | - tbarArrowDiv; | ||
42 | - | ||
43 | - // this function is only used in testing | ||
44 | - function init() { | ||
45 | - ids = []; | ||
46 | - } | ||
47 | 41 | ||
48 | - // === Helper functions -------------------------------------- | 42 | + // internal state |
43 | + var tbars = {}; | ||
49 | 44 | ||
50 | - function validId(id, caller) { | ||
51 | - if (fs.inArray(id, ids) !== -1) { | ||
52 | - $log.warn(caller + ': ID already exists'); | ||
53 | - return false; | ||
54 | - } | ||
55 | - return true; | ||
56 | - } | ||
57 | 45 | ||
58 | - // TODO: Allow toolbar to be on right edge of screen | 46 | + // === Helper functions -------------------------------------- |
47 | + | ||
59 | // translate uses 50 because the svg viewbox is 50 | 48 | // translate uses 50 because the svg viewbox is 50 |
60 | - function rotateArrowLeft() { | 49 | + function rotateArrowLeft(adiv) { |
61 | - tbarArrowDiv.select('g') | 50 | + adiv.select('g') |
62 | .attr('transform', 'translate(0 50) rotate(-90)'); | 51 | .attr('transform', 'translate(0 50) rotate(-90)'); |
63 | } | 52 | } |
64 | - function rotateArrowRight() { | 53 | + function rotateArrowRight(adiv) { |
65 | - tbarArrowDiv.select('g') | 54 | + adiv.select('g') |
66 | .attr('transform', 'translate(50 0) rotate(90)'); | 55 | .attr('transform', 'translate(50 0) rotate(90)'); |
67 | } | 56 | } |
68 | - function createArrow() { | 57 | + |
69 | - tbarArrowDiv = tbarDiv.append('div') | 58 | + function createArrow(panel) { |
59 | + var arrowDiv = panel.append('div') | ||
70 | .classed('tbarArrow', true) | 60 | .classed('tbarArrow', true) |
71 | - .style({'position': 'absolute', | 61 | + .style({ |
62 | + 'position': 'absolute', | ||
72 | 'top': '53%', | 63 | 'top': '53%', |
73 | 'left': '96%', | 64 | 'left': '96%', |
74 | 'margin-right': '-4%', | 65 | 'margin-right': '-4%', |
75 | 'transform': 'translate(-50%, -50%)', | 66 | 'transform': 'translate(-50%, -50%)', |
76 | - 'cursor': 'pointer'}); | 67 | + 'cursor': 'pointer' |
77 | - is.loadEmbeddedIcon(tbarArrowDiv, 'tableColSortAsc', arrowSize); | 68 | + }); |
78 | - | 69 | + is.loadIcon(arrowDiv, 'triangleUp', arrowSize, true); |
79 | - tbarArrowDiv.on('click', toggleTools); | 70 | + return arrowDiv; |
80 | } | 71 | } |
81 | 72 | ||
82 | - // === Adding to toolbar functions ---------------------------- | 73 | + function warn(msg, id) { |
83 | - | 74 | + $log.warn('createToolbar: ' + msg + ': [' + id + ']'); |
84 | - // TODO: these add functions look very similar -- combine them somehow? | 75 | + return null; |
85 | - function addButton(id, gid, cb, tooltip) { | ||
86 | - var btnId = tbarId + '-' + id, | ||
87 | - button; | ||
88 | - if (!validId(btnId, 'addButton')) { return null; } | ||
89 | - ids.push(btnId); | ||
90 | - button = bns.button(tbarDiv, btnId, gid, cb, tooltip); | ||
91 | - if (button) { addToWidth(button.width()); } | ||
92 | - displayTools(); | ||
93 | - return button; | ||
94 | } | 76 | } |
95 | 77 | ||
96 | - function addToggle(id, gid, initState, cb, tooltip) { | ||
97 | - var togId = tbarId + '-' + id, | ||
98 | - toggle; | ||
99 | - if (!validId(togId, 'addToggle')) { return null; } | ||
100 | - ids.push(togId); | ||
101 | - toggle = bns.toggle(tbarDiv, togId, gid, initState, cb, tooltip); | ||
102 | - if (toggle) { addToWidth(toggle.width()); } | ||
103 | - displayTools(); | ||
104 | - return toggle; | ||
105 | - } | ||
106 | 78 | ||
107 | - function addRadioSet(id, rset) { | 79 | + // ================================== |
108 | - var radId = tbarId + '-' + id, | ||
109 | - radios; | ||
110 | - if (!validId(radId, 'addRadioSet')) { return null; } | ||
111 | - ids.push(radId); | ||
112 | - radios = bns.radioSet(tbarDiv, radId, rset); | ||
113 | - if (radios) { addToWidth(radios.width()); } | ||
114 | - displayTools(); | ||
115 | - return radios; | ||
116 | - } | ||
117 | 80 | ||
118 | - function addSeparator() { | 81 | + function createToolbar(id, opts) { |
119 | - if (!tbarDiv) { | 82 | + if (!id) return warn('no ID given', id); |
120 | - $log.warn('Separator cannot append to div'); | 83 | + if (tbars[id]) return warn('duplicate ID given', id); |
121 | - return null; | 84 | + |
85 | + var settings = angular.extend({}, defaultSettings, fs.isO(opts)), | ||
86 | + tbid = 'toolbar-' + id, | ||
87 | + panel = ps.createPanel(tbid, settings), | ||
88 | + arrowDiv = createArrow(panel), | ||
89 | + tbWidth = arrowSize + 2; // empty toolbar width | ||
90 | + | ||
91 | + | ||
92 | + arrowDiv.on('click', toggle); | ||
93 | + | ||
94 | + // add a descriptor for this toolbar | ||
95 | + tbars[id] = { | ||
96 | + settings: settings, | ||
97 | + panel: panel, | ||
98 | + panelId: tbid | ||
99 | + }; | ||
100 | + | ||
101 | + panel.classed('toolbar', true) | ||
102 | + .style('top', settings.top); | ||
103 | + | ||
104 | + | ||
105 | + // API functions | ||
106 | + | ||
107 | + function addButton(id, gid, cb, tooltip) { | ||
108 | + var bid = tbid + '-' + id, | ||
109 | + btn = bns.button(panel, bid, gid, cb, tooltip); | ||
110 | + tbWidth += btn.width(); | ||
111 | + panel.width(tbWidth); | ||
112 | + return btn; | ||
122 | } | 113 | } |
123 | - addToWidth(2); | ||
124 | - displayTools(); | ||
125 | - return tbarDiv.append('div') | ||
126 | - .classed('separator', true) | ||
127 | - .style({'height': '23px', | ||
128 | - 'width': '0px'}); | ||
129 | - } | ||
130 | 114 | ||
131 | - // === Main toolbar API functions ---------------------------- | 115 | + function addToggle(id, gid, initState, cb, tooltip) { |
116 | + var tid = tbid + '-' + id, | ||
117 | + tog = bns.toggle(panel, tid, gid, initState, cb, tooltip); | ||
118 | + tbWidth += tog.width(); | ||
119 | + panel.width(tbWidth); | ||
120 | + return tog; | ||
121 | + } | ||
132 | 122 | ||
133 | - function createToolbar(id, opts) { | 123 | + function addRadioSet(id, rset) { |
134 | - if (!id) { | 124 | + var rid = tbid + '-' + id, |
135 | - $log.warn('createToolbar: no ID given'); | 125 | + rad = bns.radioSet(panel, rid, rset); |
136 | - return null; | 126 | + tbWidth += rad.width(); |
127 | + panel.width(tbWidth); | ||
128 | + return rad; | ||
129 | + } | ||
130 | + | ||
131 | + function addSeparator() { | ||
132 | + panel.append('div') | ||
133 | + .classed('separator', true); | ||
134 | + tbWidth += sepWidth; | ||
137 | } | 135 | } |
138 | - tbarId = 'tbar-' + id; | ||
139 | - settings = angular.extend({}, defaultSettings, fs.isO(opts)); | ||
140 | 136 | ||
141 | - if (!validId(tbarId, 'createToolbar')) { return null; } | 137 | + function show(cb) { |
142 | - ids.push(tbarId); | 138 | + rotateArrowLeft(arrowDiv); |
139 | + panel.show(cb); | ||
140 | + } | ||
143 | 141 | ||
144 | - tbarPanel = ps.createPanel(tbarId, settings); | 142 | + function hide(cb) { |
145 | - tbarDiv = tbarPanel.classed('toolbar', true) | 143 | + rotateArrowRight(arrowDiv); |
146 | - .style('top', settings.top); | 144 | + panel.hide(cb); |
145 | + } | ||
147 | 146 | ||
148 | - createArrow(); | 147 | + function toggle(cb) { |
149 | - displayTools(); | 148 | + if (panel.isVisible()) { |
149 | + hide(cb); | ||
150 | + } else { | ||
151 | + show(cb); | ||
152 | + } | ||
153 | + } | ||
150 | 154 | ||
151 | return { | 155 | return { |
152 | addButton: addButton, | 156 | addButton: addButton, |
... | @@ -156,49 +160,21 @@ | ... | @@ -156,49 +160,21 @@ |
156 | 160 | ||
157 | show: show, | 161 | show: show, |
158 | hide: hide, | 162 | hide: hide, |
159 | - toggleTools: toggleTools, | 163 | + toggle: toggle |
160 | - | 164 | + }; |
161 | - width: width | ||
162 | - } | ||
163 | } | 165 | } |
164 | 166 | ||
165 | function destroyToolbar(id) { | 167 | function destroyToolbar(id) { |
166 | - ps.destroyPanel(id); | 168 | + var tb = tbars[id]; |
167 | - tbarDiv = null; | 169 | + delete tbars[id]; |
168 | - } | ||
169 | 170 | ||
170 | - function show(cb) { | 171 | + if (tb) { |
171 | - tbarPanel.show(cb); | 172 | + ps.destroyPanel(tb.panelId); |
172 | - rotateArrowLeft(); | ||
173 | - } | ||
174 | - | ||
175 | - function hide(cb) { | ||
176 | - tbarPanel.hide(cb); | ||
177 | - rotateArrowRight(); | ||
178 | - } | ||
179 | - | ||
180 | - function toggleTools(cb) { | ||
181 | - if (tbarPanel.isVisible()) { hide(cb); } | ||
182 | - else { show(cb) } | ||
183 | - } | ||
184 | - | ||
185 | - function displayTools() { | ||
186 | - if (settings.shown) { show(); } | ||
187 | - else { hide(); } | ||
188 | - } | ||
189 | - | ||
190 | - function width(w) { | ||
191 | - if (w) { tbarPanel.width(w); } | ||
192 | - return tbarPanel.width(); | ||
193 | - } | ||
194 | - | ||
195 | - function addToWidth(size) { | ||
196 | - if (!(settings.width > (fs.windowSize(0, 500).width))) { | ||
197 | - settings.width = width() + size + btnPadding; | ||
198 | - tbarPanel.width(settings.width); | ||
199 | } | 173 | } |
200 | } | 174 | } |
201 | 175 | ||
176 | + // === Module Definition === | ||
177 | + | ||
202 | angular.module('onosWidget') | 178 | angular.module('onosWidget') |
203 | .factory('ToolbarService', | 179 | .factory('ToolbarService', |
204 | ['$log', 'FnService', 'PanelService', 'ButtonService', 'IconService', | 180 | ['$log', 'FnService', 'PanelService', 'ButtonService', 'IconService', |
... | @@ -210,6 +186,11 @@ | ... | @@ -210,6 +186,11 @@ |
210 | bns = _bns_; | 186 | bns = _bns_; |
211 | is = _is_; | 187 | is = _is_; |
212 | 188 | ||
189 | + // this function is only used in testing | ||
190 | + function init() { | ||
191 | + tbars = {}; | ||
192 | + } | ||
193 | + | ||
213 | return { | 194 | return { |
214 | init: init, | 195 | init: init, |
215 | createToolbar: createToolbar, | 196 | createToolbar: createToolbar, | ... | ... |
... | @@ -87,6 +87,9 @@ | ... | @@ -87,6 +87,9 @@ |
87 | toolbar.addToggle('demo-toggle', 'chain', false, togFn); | 87 | toolbar.addToggle('demo-toggle', 'chain', false, togFn); |
88 | toolbar.addSeparator(); | 88 | toolbar.addSeparator(); |
89 | toolbar.addRadioSet('demo-radio', rset); | 89 | toolbar.addRadioSet('demo-radio', rset); |
90 | + toolbar.hide(); | ||
91 | + | ||
92 | + checkFn(); | ||
90 | 93 | ||
91 | $log.log('OvSampleCtrl has been created'); | 94 | $log.log('OvSampleCtrl has been created'); |
92 | }]); | 95 | }]); | ... | ... |
-
Please register or login to post a comment