Bri Prebilic Cole
Committed by Gerrit Code Review

GUI -- Modified Toolbar service to have multiple rows of buttons. Added more but…

…tons in topoToolbar - WIP.

Change-Id: Ibc749b4ecdcb07ecf63d50817f8af3d455b4cde0
...@@ -171,7 +171,31 @@ ...@@ -171,7 +171,31 @@
171 "-3.5,3.9-7.4,8.9-11.7,15.1c0,0-3.1,3.4-5.2,0.9C52.9,51.5,61," + 171 "-3.5,3.9-7.4,8.9-11.7,15.1c0,0-3.1,3.4-5.2,0.9C52.9,51.5,61," +
172 "39.3,61,39.3s2.2-3.1,5.6-7c-2.9-3-5.9-6.3-6.6-7.3c0,0-3.7-5-1.3" + 172 "39.3,61,39.3s2.2-3.1,5.6-7c-2.9-3-5.9-6.3-6.6-7.3c0,0-3.7-5-1.3" +
173 "-6.6c3.2-2.1,6.3,0.8,6.3,0.8s3.1,3.3,7,7.2c4.7-4.7,10.1-9.2," + 173 "-6.6c3.2-2.1,6.3,0.8,6.3,0.8s3.1,3.3,7,7.2c4.7-4.7,10.1-9.2," +
174 - "14.7-10c0,0,3.3-1,5.2,1.7C92.5,18.8,92.4,19.6,91.9,20.4z" 174 + "14.7-10c0,0,3.3-1,5.2,1.7C92.5,18.8,92.4,19.6,91.9,20.4z",
175 +
176 + resetZoom: "M86.4,81.6L60.3,54.2c1.9-3.1,3-6.8,3.1-10.7c0.3-12" +
177 + "-9.2-22.1-21.2-22.4c-12-0.3-22.1,9.2-22.4,21.2c-0.3,12,9.2," +
178 + "22.1,21.2,22.4c4.3,0.1,9.6-0.9,12.8-3.9l25.5,26.8c1.6,1.7,4.3," +
179 + "2.4,5.7,1.1l1.8-1.7C88.2,85.8,88,83.3,86.4,81.6z M27.8," +
180 + "42.5C28,34.8,34.4,28.8,42,29c7.7,0.2,13.7,6.6,13.5,14.2c" +
181 + "-0.2,7.7-6.6,13.7-14.2,13.5C33.6,56.5,27.6,50.2,27.8,42.5z " +
182 + "M10.4,27.2c-1.7,0-3-1.3-3-3V7.1h16.2c1.7,0,3,1.3,3,3s-1.3,3-3," +
183 + "3H13.4v11.2C13.4,25.9,12.1,27.2,10.4,27.2z M23.7,102.3H7.5" +
184 + "V85.2c0-1.7,1.3-3,3-3s3,1.3,3,3v11.2h10.2c1.7,0,3,1.3,3,3S25.3," +
185 + "102.3,23.7,102.3z M102.6,103.4H86.4c-1.7,0-3-1.3-3-3c0-1.7,1.3" +
186 + "-3,3-3h10.2V86.2c0-1.7,1.3-3,3-3c1.7,0,3,1.3,3,3V103.4z M99.6," +
187 + "27.2c-1.7,0-3-1.3-3-3V13.1H86.4c-1.7,0-3-1.3-3-3s1.3-3,3" +
188 + "-3h16.2v17.2C102.6,25.9,101.3,27.2,99.6,27.2z",
189 +
190 + nextIntent: "M88.1,55.7L34.6,13.1c0,0-1.6-0.5-2.1-0.2c-1.9,1.2" +
191 + "-6.5,13.8-3.1,17.2c7,6.9,30.6,24.5,32.4,25.9c-1.8,1.4-25.4,19" +
192 + "-32.4,25.9c-3.4,3.4,1.2,16,3.1,17.2c0.6,0.4,2.1-0.2,2.1-0.2" +
193 + "s53.1-42.4,53.5-42.7C88.5,56,88.1,55.7,88.1,55.7z",
194 +
195 + prevIntent: "M22.5,55.6L76,12.9c0,0,1.6-0.5,2.2-0.2c1.9,1.2," +
196 + "6.5,13.8,3.1,17.2c-7,6.9-30.6,24.5-32.4,25.9c1.8,1.4,25.4,19," +
197 + "32.4,25.9c3.4,3.4-1.2,16-3.1,17.2c-0.6,0.4-2.2-0.2-2.2-0.2" +
198 + "S22.9,56.3,22.5,56C22.2,55.8,22.5,55.6,22.5,55.6z"
175 }, 199 },
176 200
177 badgeViewBox = '0 0 10 10', 201 badgeViewBox = '0 0 10 10',
......
...@@ -37,6 +37,15 @@ ...@@ -37,6 +37,15 @@
37 } 37 }
38 38
39 39
40 +.toolbar {
41 + line-height: 125%;
42 +}
43 +.tbar-row {
44 + display: inline-block;
45 +}
46 +
47 +
48 +
40 .separator { 49 .separator {
41 border: 1px solid; 50 border: 1px solid;
42 margin: 0 4px 0 4px; 51 margin: 0 4px 0 4px;
......
...@@ -75,6 +75,10 @@ ...@@ -75,6 +75,10 @@
75 return null; 75 return null;
76 } 76 }
77 77
78 + function noPxWidth(elem) {
79 + return Number(elem.style('width').replace(/px$/, ''));
80 + }
81 +
78 82
79 // ================================== 83 // ==================================
80 84
...@@ -87,8 +91,9 @@ ...@@ -87,8 +91,9 @@
87 tbid = 'toolbar-' + id, 91 tbid = 'toolbar-' + id,
88 panel = ps.createPanel(tbid, settings), 92 panel = ps.createPanel(tbid, settings),
89 arrowDiv = createArrow(panel), 93 arrowDiv = createArrow(panel),
90 - tbWidth = arrowSize + 2; // empty toolbar width 94 + currentRow = panel.append('div').classed('tbar-row', true),
91 - 95 + tbWidth = arrowSize + 2, // empty toolbar width
96 + maxWidth = panel.width();
92 97
93 arrowDiv.on('click', toggle); 98 arrowDiv.on('click', toggle);
94 99
...@@ -103,6 +108,7 @@ ...@@ -103,6 +108,7 @@
103 panel.classed('toolbar', true) 108 panel.classed('toolbar', true)
104 .style('top', settings.top); 109 .style('top', settings.top);
105 110
111 + // Helper functions
106 112
107 function dupId(id, caller) { 113 function dupId(id, caller) {
108 if (items[id]) { 114 if (items[id]) {
...@@ -112,17 +118,25 @@ ...@@ -112,17 +118,25 @@
112 return false; 118 return false;
113 } 119 }
114 120
121 + function adjustWidth(btnWidth) {
122 + if (noPxWidth(currentRow) >= maxWidth) {
123 + tbWidth += btnWidth;
124 + maxWidth = tbWidth;
125 + }
126 + panel.width(tbWidth);
127 + }
128 +
115 // API functions 129 // API functions
116 130
117 function addButton(id, gid, cb, tooltip) { 131 function addButton(id, gid, cb, tooltip) {
118 if (dupId(id, 'addButton')) return null; 132 if (dupId(id, 'addButton')) return null;
119 133
120 var bid = tbid + '-' + id, 134 var bid = tbid + '-' + id,
121 - btn = bns.button(panel, bid, gid, cb, tooltip); 135 + btn = bns.button(currentRow, bid, gid, cb, tooltip);
122 136
123 items[id] = btn; 137 items[id] = btn;
124 - tbWidth += btn.width(); 138 + $log.debug('adding button');
125 - panel.width(tbWidth); 139 + adjustWidth(btn.width());
126 return btn; 140 return btn;
127 } 141 }
128 142
...@@ -130,11 +144,10 @@ ...@@ -130,11 +144,10 @@
130 if (dupId(id, 'addToggle')) return null; 144 if (dupId(id, 'addToggle')) return null;
131 145
132 var tid = tbid + '-' + id, 146 var tid = tbid + '-' + id,
133 - tog = bns.toggle(panel, tid, gid, initState, cb, tooltip); 147 + tog = bns.toggle(currentRow, tid, gid, initState, cb, tooltip);
134 148
135 items[id] = tog; 149 items[id] = tog;
136 - tbWidth += tog.width(); 150 + adjustWidth(tog.width());
137 - panel.width(tbWidth);
138 return tog; 151 return tog;
139 } 152 }
140 153
...@@ -142,23 +155,33 @@ ...@@ -142,23 +155,33 @@
142 if (dupId(id, 'addRadioSet')) return null; 155 if (dupId(id, 'addRadioSet')) return null;
143 156
144 var rid = tbid + '-' + id, 157 var rid = tbid + '-' + id,
145 - rad = bns.radioSet(panel, rid, rset); 158 + rad = bns.radioSet(currentRow, rid, rset);
146 159
147 items[id] = rad; 160 items[id] = rad;
148 - tbWidth += rad.width(); 161 + adjustWidth(rad.width());
149 - panel.width(tbWidth);
150 return rad; 162 return rad;
151 } 163 }
152 164
153 function addSeparator() { 165 function addSeparator() {
154 - panel.append('div') 166 + currentRow.append('div')
155 .classed('separator', true); 167 .classed('separator', true);
156 tbWidth += sepWidth; 168 tbWidth += sepWidth;
157 } 169 }
158 170
171 + function addRow() {
172 + if (currentRow.select('div').empty()) { return null; }
173 + else {
174 + panel.append('br');
175 + currentRow = panel.append('div').classed('tbar-row', true);
176 + }
177 + }
178 +
159 function show(cb) { 179 function show(cb) {
160 rotateArrowLeft(arrowDiv); 180 rotateArrowLeft(arrowDiv);
161 panel.show(cb); 181 panel.show(cb);
182 + $log.debug('tbar width', tbWidth);
183 + $log.debug('maxwidth', maxWidth);
184 + $log.debug('panel width', panel.width());
162 } 185 }
163 186
164 function hide(cb) { 187 function hide(cb) {
...@@ -179,6 +202,7 @@ ...@@ -179,6 +202,7 @@
179 addToggle: addToggle, 202 addToggle: addToggle,
180 addRadioSet: addRadioSet, 203 addRadioSet: addRadioSet,
181 addSeparator: addSeparator, 204 addSeparator: addSeparator,
205 + addRow: addRow,
182 206
183 show: show, 207 show: show,
184 hide: hide, 208 hide: hide,
......
...@@ -40,7 +40,21 @@ ...@@ -40,7 +40,21 @@
40 H: { id: 'hosts-tog', gid: 'endstation', isel: false }, 40 H: { id: 'hosts-tog', gid: 'endstation', isel: false },
41 M: { id: 'offline-tog', gid: 'switch', isel: true }, 41 M: { id: 'offline-tog', gid: 'switch', isel: true },
42 P: { id: 'ports-tog', gid: 'ports', isel: true }, 42 P: { id: 'ports-tog', gid: 'ports', isel: true },
43 - B: { id: 'bkgrnd-tog', gid: 'map', isel: true } 43 + B: { id: 'bkgrnd-tog', gid: 'map', isel: true },
44 +
45 + //X: { id: 'nodelock-tog', gid: 'lock', isel: false },
46 + Z: { id: 'oblique-tog', gid: 'oblique', isel: false },
47 + L: { id: 'cycleLabels-btn', gid: 'cycleLabels' },
48 + R: { id: 'resetZoom-btn', gid: 'resetZoom' },
49 +
50 + V: { id: 'allIntents-btn', gid: 'allIntents' },
51 + leftArrow: { id: 'prevIntent-btn', gid: 'prevIntent' },
52 + rightArrow: { id: 'nextIntent-btn', gid: 'nextIntent' },
53 + W: { id: 'intentTraffic-btn', gid: 'intentTraffic' },
54 + A: { id: 'allTraffic-btn', gid: 'allTraffic' },
55 + F: { id: 'flows-btn', gid: 'flows' },
56 +
57 + E: { id: 'eqMaster-btn', gid: 'eqMaster' }
44 }; 58 };
45 59
46 function init(_api_) { 60 function init(_api_) {
...@@ -56,6 +70,10 @@ ...@@ -56,6 +70,10 @@
56 }); 70 });
57 } 71 }
58 72
73 + function addButton(key) {
74 + var v = keyData.get(key);
75 + v.btn = toolbar.addButton(v.id, v.gid, v.cb, v.tt);
76 + }
59 function addToggle(key) { 77 function addToggle(key) {
60 var v = keyData.get(key); 78 var v = keyData.get(key);
61 v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt); 79 v.tog = toolbar.addToggle(v.id, v.gid, v.isel, v.cb, v.tt);
...@@ -72,11 +90,30 @@ ...@@ -72,11 +90,30 @@
72 addToggle('P'); 90 addToggle('P');
73 addToggle('B'); 91 addToggle('B');
74 } 92 }
93 + function addSecondRow() {
94 + addToggle('Z');
95 + addButton('L');
96 + addButton('R');
97 + }
98 + function addThirdRow() {
99 + addButton('V');
100 + addButton('leftArrow');
101 + addButton('rightArrow');
102 + addButton('W');
103 + addButton('A');
104 + addButton('F');
105 + toolbar.addSeparator();
106 + addButton('E');
107 + }
75 108
76 function createToolbar() { 109 function createToolbar() {
77 initKeyData(); 110 initKeyData();
78 toolbar = tbs.createToolbar(name); 111 toolbar = tbs.createToolbar(name);
79 addFirstRow(); 112 addFirstRow();
113 + toolbar.addRow();
114 + addSecondRow();
115 + toolbar.addRow();
116 + addThirdRow();
80 toolbar.show(); 117 toolbar.show();
81 } 118 }
82 119
......
...@@ -141,8 +141,8 @@ describe('factory: fw/widget/toolbar.js', function () { ...@@ -141,8 +141,8 @@ describe('factory: fw/widget/toolbar.js', function () {
141 141
142 it('should create a separator div', function () { 142 it('should create a separator div', function () {
143 spyOn($log, 'warn'); 143 spyOn($log, 'warn');
144 - var toolbar = tbs.createToolbar('foo'); 144 + var toolbar = tbs.createToolbar('foo'),
145 - var tbar = d3.select('#toolbar-foo'); 145 + tbar = d3.select('#toolbar-foo');
146 146
147 toolbar.addSeparator(); 147 toolbar.addSeparator();
148 expect($log.warn).not.toHaveBeenCalled(); 148 expect($log.warn).not.toHaveBeenCalled();
...@@ -150,4 +150,31 @@ describe('factory: fw/widget/toolbar.js', function () { ...@@ -150,4 +150,31 @@ describe('factory: fw/widget/toolbar.js', function () {
150 expect(tbar.select('.separator').size()).toBe(1); 150 expect(tbar.select('.separator').size()).toBe(1);
151 }); 151 });
152 152
153 + it('should add another row of buttons', function () {
154 + var toolbar = tbs.createToolbar('foo'),
155 + tbar = d3.select('#toolbar-foo'),
156 + rows;
157 + toolbar.addButton('btn0', 'gid');
158 + toolbar.addRow();
159 + toolbar.addButton('btn1', 'gid');
160 +
161 + rows = tbar.selectAll('.tbar-row');
162 + expect(rows.size()).toBe(2);
163 + rows.each(function (d, i) {
164 + expect(d3.select(this)
165 + .select('div')
166 + .attr('id','toolbar-foo-btn' + i)
167 + .empty())
168 + .toBe(false);
169 + });
170 + });
171 +
172 + it('should not add a row if current row is empty', function () {
173 + var toolbar = tbs.createToolbar('foo');
174 + expect(toolbar.addRow()).toBeNull();
175 + toolbar.addButton('btn0', 'gid');
176 + expect(toolbar.addRow()).not.toBeNull();
177 + expect(toolbar.addRow()).toBeNull();
178 + });
179 +
153 }); 180 });
......