Committed by
Gerrit Code Review
Added Key Commands to topo2
Change-Id: I83f596dfa7d906a2760cbcdc2fcd2d2aedb88832
Showing
8 changed files
with
182 additions
and
20 deletions
| ... | @@ -102,7 +102,7 @@ | ... | @@ -102,7 +102,7 @@ |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | function incDevLabIndex() { | 104 | function incDevLabIndex() { |
| 105 | - setDevLabIndex(deviceLabelIndex+1); | 105 | + setDevLabIndex(device3ndex+1); |
| 106 | switch(deviceLabelIndex) { | 106 | switch(deviceLabelIndex) { |
| 107 | case 0: return 'Hide device labels'; | 107 | case 0: return 'Hide device labels'; |
| 108 | case 1: return 'Show friendly device labels'; | 108 | case 1: return 'Show friendly device labels'; | ... | ... |
| ... | @@ -25,7 +25,7 @@ | ... | @@ -25,7 +25,7 @@ |
| 25 | 25 | ||
| 26 | // references to injected services | 26 | // references to injected services |
| 27 | var $scope, $log, fs, mast, ks, zs, | 27 | var $scope, $log, fs, mast, ks, zs, |
| 28 | - gs, sus, ps, t2es, t2fs, t2is, t2bcs; | 28 | + gs, sus, ps, t2es, t2fs, t2is, t2bcs, t2kcs; |
| 29 | 29 | ||
| 30 | // DOM elements | 30 | // DOM elements |
| 31 | var ovtopo2, svg, defs, zoomLayer, forceG; | 31 | var ovtopo2, svg, defs, zoomLayer, forceG; |
| ... | @@ -87,13 +87,13 @@ | ... | @@ -87,13 +87,13 @@ |
| 87 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', | 87 | 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', |
| 88 | 'WebSocketService', 'PrefsService', 'ThemeService', | 88 | 'WebSocketService', 'PrefsService', 'ThemeService', |
| 89 | 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', | 89 | 'Topo2EventService', 'Topo2ForceService', 'Topo2InstanceService', |
| 90 | - 'Topo2BreadcrumbService', | 90 | + 'Topo2BreadcrumbService', 'Topo2KeyCommandService', |
| 91 | 91 | ||
| 92 | function (_$scope_, _$log_, _$loc_, | 92 | function (_$scope_, _$log_, _$loc_, |
| 93 | _fs_, _mast_, _ks_, _zs_, | 93 | _fs_, _mast_, _ks_, _zs_, |
| 94 | _gs_, _ms_, _sus_, _flash_, | 94 | _gs_, _ms_, _sus_, _flash_, |
| 95 | _wss_, _ps_, _th_, | 95 | _wss_, _ps_, _th_, |
| 96 | - _t2es_, _t2fs_, _t2is_, _t2bcs_) { | 96 | + _t2es_, _t2fs_, _t2is_, _t2bcs_, _t2kcs_) { |
| 97 | 97 | ||
| 98 | var params = _$loc_.search(), | 98 | var params = _$loc_.search(), |
| 99 | dim, | 99 | dim, |
| ... | @@ -125,6 +125,9 @@ | ... | @@ -125,6 +125,9 @@ |
| 125 | t2fs = _t2fs_; | 125 | t2fs = _t2fs_; |
| 126 | t2is = _t2is_; | 126 | t2is = _t2is_; |
| 127 | t2bcs = _t2bcs_; | 127 | t2bcs = _t2bcs_; |
| 128 | + t2kcs = _t2kcs_; | ||
| 129 | + | ||
| 130 | + t2kcs.init(t2fs); | ||
| 128 | 131 | ||
| 129 | // capture selected intent parameters (if they are set in the | 132 | // capture selected intent parameters (if they are set in the |
| 130 | // query string) so that the traffic overlay can highlight | 133 | // query string) so that the traffic overlay can highlight | ... | ... |
| ... | @@ -61,15 +61,6 @@ | ... | @@ -61,15 +61,6 @@ |
| 61 | return remappedDeviceTypes[type] || type || 'unknown'; | 61 | return remappedDeviceTypes[type] || type || 'unknown'; |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | - function iconBox(dim, labelWidth) { | ||
| 65 | - return { | ||
| 66 | - x: -dim / 2, | ||
| 67 | - y: -dim / 2, | ||
| 68 | - width: dim + labelWidth, | ||
| 69 | - height: dim | ||
| 70 | - }; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | // note: these are the device icon colors without affinity (no master) | 64 | // note: these are the device icon colors without affinity (no master) |
| 74 | var dColTheme = { | 65 | var dColTheme = { |
| 75 | light: { | 66 | light: { |
| ... | @@ -130,11 +121,11 @@ | ... | @@ -130,11 +121,11 @@ |
| 130 | // Label | 121 | // Label |
| 131 | var labelElements = this.addLabelElements(label); | 122 | var labelElements = this.addLabelElements(label); |
| 132 | labelWidth = label ? this.computeLabelWidth(node) : 0; | 123 | labelWidth = label ? this.computeLabelWidth(node) : 0; |
| 133 | - labelElements.rect.attr(iconBox(devIconDim, labelWidth)); | 124 | + labelElements.rect.attr(this.iconBox(devIconDim, labelWidth)); |
| 134 | 125 | ||
| 135 | // Icon | 126 | // Icon |
| 136 | glyph = is.addDeviceIcon(node, glyphId, devIconDim); | 127 | glyph = is.addDeviceIcon(node, glyphId, devIconDim); |
| 137 | - glyph.attr(iconBox(devIconDim, 0)); | 128 | + glyph.attr(this.iconBox(devIconDim, 0)); |
| 138 | 129 | ||
| 139 | node.attr('transform', sus.translate(-halfDevIcon, -halfDevIcon)); | 130 | node.attr('transform', sus.translate(-halfDevIcon, -halfDevIcon)); |
| 140 | this.render(); | 131 | this.render(); | ... | ... |
| ... | @@ -190,6 +190,13 @@ | ... | @@ -190,6 +190,13 @@ |
| 190 | 190 | ||
| 191 | // ========================== Main Service Definition | 191 | // ========================== Main Service Definition |
| 192 | 192 | ||
| 193 | + function updateNodes() { | ||
| 194 | + var allNodes = t2rs.regionNodes(); | ||
| 195 | + angular.forEach(allNodes, function (node) { | ||
| 196 | + node.update(); | ||
| 197 | + }) | ||
| 198 | + } | ||
| 199 | + | ||
| 193 | angular.module('ovTopo2') | 200 | angular.module('ovTopo2') |
| 194 | .factory('Topo2ForceService', | 201 | .factory('Topo2ForceService', |
| 195 | ['$log', 'WebSocketService', 'Topo2InstanceService', 'Topo2RegionService', | 202 | ['$log', 'WebSocketService', 'Topo2InstanceService', 'Topo2RegionService', |
| ... | @@ -216,7 +223,9 @@ | ... | @@ -216,7 +223,9 @@ |
| 216 | topo2StartDone: startDone, | 223 | topo2StartDone: startDone, |
| 217 | 224 | ||
| 218 | showMastership: showMastership, | 225 | showMastership: showMastership, |
| 219 | - topo2PeerRegions: topo2PeerRegions | 226 | + topo2PeerRegions: topo2PeerRegions, |
| 227 | + | ||
| 228 | + updateNodes: updateNodes | ||
| 220 | }; | 229 | }; |
| 221 | }]); | 230 | }]); |
| 222 | })(); | 231 | })(); | ... | ... |
| 1 | +/* | ||
| 2 | +* Copyright 2016-present Open Networking Laboratory | ||
| 3 | +* | ||
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | +* you may not use this file except in compliance with the License. | ||
| 6 | +* You may obtain a copy of the License at | ||
| 7 | +* | ||
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | +* | ||
| 10 | +* Unless required by applicable law or agreed to in writing, software | ||
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | +* See the License for the specific language governing permissions and | ||
| 14 | +* limitations under the License. | ||
| 15 | +*/ | ||
| 16 | + | ||
| 17 | +(function () { | ||
| 18 | + | ||
| 19 | + // Injected Services | ||
| 20 | + var ks, t2ps; | ||
| 21 | + var topo2ForceService; | ||
| 22 | + | ||
| 23 | + // Commmands | ||
| 24 | + var actionMap = { | ||
| 25 | + L: [cycleDeviceLabels, 'Cycle device labels'] | ||
| 26 | + }; | ||
| 27 | + | ||
| 28 | + function init(t2fs) { | ||
| 29 | + topo2ForceService = t2fs; | ||
| 30 | + bindCommands(); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + function bindCommands() { | ||
| 34 | + | ||
| 35 | + ks.keyBindings(actionMap); | ||
| 36 | + | ||
| 37 | + ks.gestureNotes([ | ||
| 38 | + ['click', 'Select the item and show details'], | ||
| 39 | + ['shift-click', 'Toggle selection state'], | ||
| 40 | + ['drag', 'Reposition (and pin) device / host'], | ||
| 41 | + ['cmd-scroll', 'Zoom in / out'], | ||
| 42 | + ['cmd-drag', 'Pan'] | ||
| 43 | + ]); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + function cycleDeviceLabels() { | ||
| 47 | + var deviceLabelIndex = t2ps.get('dlbls') + 1; | ||
| 48 | + t2ps.set('dlbls', deviceLabelIndex % 3); | ||
| 49 | + topo2ForceService.updateNodes(); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + angular.module('ovTopo2') | ||
| 53 | + .factory('Topo2KeyCommandService', | ||
| 54 | + ['KeyService', 'Topo2PrefsService', | ||
| 55 | + | ||
| 56 | + function (_ks_, _t2ps_) { | ||
| 57 | + | ||
| 58 | + t2ps = _t2ps_; | ||
| 59 | + ks = _ks_; | ||
| 60 | + | ||
| 61 | + return { | ||
| 62 | + init: init, | ||
| 63 | + bindCommands: bindCommands | ||
| 64 | + }; | ||
| 65 | + } | ||
| 66 | + ]); | ||
| 67 | +})(); |
| ... | @@ -22,7 +22,7 @@ | ... | @@ -22,7 +22,7 @@ |
| 22 | (function () { | 22 | (function () { |
| 23 | 'use strict'; | 23 | 'use strict'; |
| 24 | 24 | ||
| 25 | - var randomService; | 25 | + var randomService, ps; |
| 26 | var fn; | 26 | var fn; |
| 27 | 27 | ||
| 28 | // Internal state; | 28 | // Internal state; |
| ... | @@ -107,11 +107,12 @@ | ... | @@ -107,11 +107,12 @@ |
| 107 | 107 | ||
| 108 | angular.module('ovTopo2') | 108 | angular.module('ovTopo2') |
| 109 | .factory('Topo2NodeModel', | 109 | .factory('Topo2NodeModel', |
| 110 | - ['Topo2Model', 'FnService', 'RandomService', | 110 | + ['Topo2Model', 'FnService', 'RandomService', 'Topo2PrefsService', |
| 111 | - function (Model, _fn_, _RandomService_) { | 111 | + function (Model, _fn_, _RandomService_, _ps_) { |
| 112 | 112 | ||
| 113 | randomService = _RandomService_; | 113 | randomService = _RandomService_; |
| 114 | fn = _fn_; | 114 | fn = _fn_; |
| 115 | + ps = _ps_; | ||
| 115 | 116 | ||
| 116 | return Model.extend({ | 117 | return Model.extend({ |
| 117 | initialize: function () { | 118 | initialize: function () { |
| ... | @@ -125,7 +126,7 @@ | ... | @@ -125,7 +126,7 @@ |
| 125 | id = this.get('id'), | 126 | id = this.get('id'), |
| 126 | friendlyName = props ? props.name : id, | 127 | friendlyName = props ? props.name : id, |
| 127 | labels = ['', friendlyName, id], | 128 | labels = ['', friendlyName, id], |
| 128 | - nli = nodeLabelIndex, | 129 | + nli = ps.get('dlbls'), |
| 129 | idx = (nli < labels.length) ? nli : 0; | 130 | idx = (nli < labels.length) ? nli : 0; |
| 130 | 131 | ||
| 131 | return labels[idx]; | 132 | return labels[idx]; |
| ... | @@ -150,6 +151,14 @@ | ... | @@ -150,6 +151,14 @@ |
| 150 | text: text | 151 | text: text |
| 151 | }; | 152 | }; |
| 152 | }, | 153 | }, |
| 154 | + iconBox: function(dim, labelWidth) { | ||
| 155 | + return { | ||
| 156 | + x: -dim / 2, | ||
| 157 | + y: -dim / 2, | ||
| 158 | + width: dim + labelWidth, | ||
| 159 | + height: dim | ||
| 160 | + }; | ||
| 161 | + }, | ||
| 153 | svgClassName: function () { | 162 | svgClassName: function () { |
| 154 | return fn.classNames('node', | 163 | return fn.classNames('node', |
| 155 | this.nodeType, | 164 | this.nodeType, |
| ... | @@ -159,6 +168,21 @@ | ... | @@ -159,6 +168,21 @@ |
| 159 | } | 168 | } |
| 160 | ); | 169 | ); |
| 161 | }, | 170 | }, |
| 171 | + update: function () { | ||
| 172 | + this.updateLabel(); | ||
| 173 | + }, | ||
| 174 | + updateLabel: function () { | ||
| 175 | + var node = this.el, | ||
| 176 | + label = this.trimLabel(this.label()), | ||
| 177 | + labelWidth; | ||
| 178 | + | ||
| 179 | + node.select('text').text(label); | ||
| 180 | + labelWidth = label ? this.computeLabelWidth(node) : 0; | ||
| 181 | + | ||
| 182 | + node.select('rect') | ||
| 183 | + .transition() | ||
| 184 | + .attr(this.iconBox(devIconDim, labelWidth)); | ||
| 185 | + }, | ||
| 162 | createNode: function () { | 186 | createNode: function () { |
| 163 | 187 | ||
| 164 | var node = angular.extend({}, this.attributes); | 188 | var node = angular.extend({}, this.attributes); | ... | ... |
| 1 | +/* | ||
| 2 | +* Copyright 2016-present Open Networking Laboratory | ||
| 3 | +* | ||
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | +* you may not use this file except in compliance with the License. | ||
| 6 | +* You may obtain a copy of the License at | ||
| 7 | +* | ||
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | +* | ||
| 10 | +* Unless required by applicable law or agreed to in writing, software | ||
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | +* See the License for the specific language governing permissions and | ||
| 14 | +* limitations under the License. | ||
| 15 | +*/ | ||
| 16 | + | ||
| 17 | +(function () { | ||
| 18 | + | ||
| 19 | + // Injected Services | ||
| 20 | + var ps; | ||
| 21 | + | ||
| 22 | + var defaultPrefsState = { | ||
| 23 | + insts: 1, | ||
| 24 | + summary: 1, | ||
| 25 | + detail: 1, | ||
| 26 | + hosts: 0, | ||
| 27 | + offdev: 1, | ||
| 28 | + dlbls: 0, | ||
| 29 | + porthl: 1, | ||
| 30 | + bg: 0, | ||
| 31 | + spr: 0, | ||
| 32 | + ovidx: 1, // default to traffic overlay | ||
| 33 | + toolbar: 0 | ||
| 34 | + }; | ||
| 35 | + | ||
| 36 | + function topo2Prefs() { | ||
| 37 | + return ps.getPrefs('topo_prefs', defaultPrefsState); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + function get(key) { | ||
| 41 | + var preferences = topo2Prefs(); | ||
| 42 | + return preferences[key]; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + function set(key, value) { | ||
| 46 | + var preferences = topo2Prefs(); | ||
| 47 | + preferences[key] = value; | ||
| 48 | + ps.setPrefs('topo_prefs', preferences); | ||
| 49 | + return preferences[key]; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + angular.module('ovTopo2') | ||
| 53 | + .factory('Topo2PrefsService', | ||
| 54 | + ['PrefsService', | ||
| 55 | + | ||
| 56 | + function (_ps_) { | ||
| 57 | + | ||
| 58 | + ps = _ps_; | ||
| 59 | + | ||
| 60 | + return { | ||
| 61 | + get: get, | ||
| 62 | + set: set | ||
| 63 | + }; | ||
| 64 | + } | ||
| 65 | + ]); | ||
| 66 | +})(); |
| ... | @@ -135,10 +135,12 @@ | ... | @@ -135,10 +135,12 @@ |
| 135 | <script src="app/view/topo2/topo2Force.js"></script> | 135 | <script src="app/view/topo2/topo2Force.js"></script> |
| 136 | <script src="app/view/topo2/topo2Host.js"></script> | 136 | <script src="app/view/topo2/topo2Host.js"></script> |
| 137 | <script src="app/view/topo2/topo2Instance.js"></script> | 137 | <script src="app/view/topo2/topo2Instance.js"></script> |
| 138 | + <script src="app/view/topo2/topo2KeyCommands.js"></script> | ||
| 138 | <script src="app/view/topo2/topo2Layout.js"></script> | 139 | <script src="app/view/topo2/topo2Layout.js"></script> |
| 139 | <script src="app/view/topo2/topo2Link.js"></script> | 140 | <script src="app/view/topo2/topo2Link.js"></script> |
| 140 | <script src="app/view/topo2/topo2Model.js"></script> | 141 | <script src="app/view/topo2/topo2Model.js"></script> |
| 141 | <script src="app/view/topo2/topo2NodeModel.js"></script> | 142 | <script src="app/view/topo2/topo2NodeModel.js"></script> |
| 143 | + <script src="app/view/topo2/topo2Prefs.js"></script> | ||
| 142 | <script src="app/view/topo2/topo2Region.js"></script> | 144 | <script src="app/view/topo2/topo2Region.js"></script> |
| 143 | <script src="app/view/topo2/topo2Select.js"></script> | 145 | <script src="app/view/topo2/topo2Select.js"></script> |
| 144 | <script src="app/view/topo2/topo2SubRegion.js"></script> | 146 | <script src="app/view/topo2/topo2SubRegion.js"></script> | ... | ... |
-
Please register or login to post a comment