Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 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 |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 20 | var ks, flash, wss, t2ps, t2ms, ps, t2is, t2sp, t2vs, t2rs, t2fs; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 21 | |
| 22 | // Commmands |
| 23 | var actionMap = { |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 24 | L: [cycleDeviceLabels, 'Cycle device labels'], |
| 25 | G: [openMapSelection, 'Select background geo map'], |
| 26 | B: [toggleMap, 'Toggle background geo map'], |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 27 | I: [toggleInstancePanel, 'Toggle ONOS Instance Panel'], |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 28 | O: [toggleSummary, 'Toggle the Summary Panel'], |
| 29 | R: [resetZoom, 'Reset pan / zoom'], |
| 30 | P: [togglePorts, 'Toggle Port Highlighting'], |
| 31 | E: [equalizeMasters, 'Equalize mastership roles'], |
| 32 | X: [resetAllNodeLocations, 'Reset Node Location'], |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 33 | U: [unpinNode, 'Unpin node (mouse over)'], |
| 34 | |
| 35 | esc: handleEscape |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 38 | function init(_t2fs_) { |
| 39 | t2fs = _t2fs_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 40 | bindCommands(); |
| 41 | } |
| 42 | |
| 43 | function bindCommands() { |
| 44 | |
| 45 | ks.keyBindings(actionMap); |
| 46 | |
| 47 | ks.gestureNotes([ |
| 48 | ['click', 'Select the item and show details'], |
| 49 | ['shift-click', 'Toggle selection state'], |
| 50 | ['drag', 'Reposition (and pin) device / host'], |
| 51 | ['cmd-scroll', 'Zoom in / out'], |
| 52 | ['cmd-drag', 'Pan'] |
| 53 | ]); |
| 54 | } |
| 55 | |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 56 | function handleEscape() { |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 57 | |
| 58 | if (false) { |
| 59 | // TODO: Cancel show mastership |
| 60 | // TODO: Cancel Active overlay |
| 61 | |
| 62 | } else if (t2rs.deselectAllNodes()) { |
| 63 | // else if we have node selections, deselect them all |
| 64 | // (work already done) |
| 65 | } else if (t2rs.deselectLink()) { |
| 66 | // else if we have a link selection, deselect it |
| 67 | // (work already done) |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 68 | } else if (t2is.isVisible()) { |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 69 | // If the instance panel is visible, close it |
| 70 | t2is.toggle(); |
| 71 | } else if (t2sp.isVisible()) { |
| 72 | // If the summary panel is visible, close it |
| 73 | t2sp.toggle(); |
| 74 | } |
Steven Burrows | c0efbf0 | 2016-11-16 11:30:47 -0600 | [diff] [blame] | 75 | } |
| 76 | |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 77 | var prefsState = {}; |
| 78 | |
| 79 | function updatePrefsState(what, b) { |
| 80 | prefsState[what] = b ? 1 : 0; |
| 81 | ps.setPrefs('topo_prefs', prefsState); |
| 82 | } |
| 83 | |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 84 | function deviceLabelFlashMessage(index) { |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 85 | switch (index) { |
| 86 | case 0: return 'Hide device labels'; |
| 87 | case 1: return 'Show friendly device labels'; |
| 88 | case 2: return 'Show device ID labels'; |
| 89 | } |
| 90 | } |
| 91 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 92 | function cycleDeviceLabels() { |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 93 | var deviceLabelIndex = t2ps.get('dlbls') + 1, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 94 | newDeviceLabelIndex = deviceLabelIndex % 3; |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 95 | |
| 96 | t2ps.set('dlbls', newDeviceLabelIndex); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 97 | t2fs.updateNodes(); |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame] | 98 | flash.flash(deviceLabelFlashMessage(newDeviceLabelIndex)); |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 101 | function openMapSelection() { |
| 102 | t2ms.openMapSelection(); |
| 103 | } |
| 104 | |
| 105 | function toggleMap(x) { |
| 106 | t2ms.toggle(x); |
| 107 | } |
| 108 | |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 109 | function toggleInstancePanel(x) { |
| 110 | updatePrefsState('insts', t2is.toggle(x)); |
| 111 | } |
| 112 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 113 | function toggleSummary() { |
| 114 | t2sp.toggle(); |
| 115 | } |
| 116 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 117 | function resetZoom() { |
| 118 | t2ms.resetZoom(); |
| 119 | flash.flash('Pan and zoom reset'); |
| 120 | } |
| 121 | |
| 122 | function togglePorts(x) { |
| 123 | updatePrefsState('porthl', t2vs.togglePortHighlights(x)); |
| 124 | t2fs.updateLinks(); |
| 125 | } |
| 126 | |
| 127 | function equalizeMasters() { |
| 128 | wss.sendEvent('equalizeMasters'); |
| 129 | flash.flash('Equalizing master roles'); |
| 130 | } |
| 131 | |
| 132 | function resetAllNodeLocations() { |
| 133 | t2fs.resetAllLocations(); |
| 134 | flash.flash('Reset node locations'); |
| 135 | } |
| 136 | |
| 137 | function unpinNode() { |
| 138 | t2fs.unpin(); |
| 139 | flash.flash('Unpin node'); |
| 140 | } |
| 141 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 142 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 143 | .factory('Topo2KeyCommandService', [ |
| 144 | 'KeyService', 'FlashService', 'WebSocketService', 'Topo2PrefsService', |
| 145 | 'Topo2MapService', 'PrefsService', 'Topo2InstanceService', |
| 146 | 'Topo2SummaryPanelService', 'Topo2ViewService', 'Topo2RegionService', |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 147 | function (_ks_, _flash_, _wss_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 148 | _t2vs_, _t2rs_) { |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 149 | |
| 150 | ks = _ks_; |
| 151 | flash = _flash_; |
| 152 | wss = _wss_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 153 | t2ps = _t2ps_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 154 | t2ms = _t2ms_; |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 155 | t2is = _t2is_; |
| 156 | ps = _ps_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 157 | t2sp = _t2sp_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 158 | t2vs = _t2vs_; |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 159 | t2rs = _t2rs_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 160 | |
| 161 | return { |
| 162 | init: init, |
| 163 | bindCommands: bindCommands |
| 164 | }; |
| 165 | } |
| 166 | ]); |
| 167 | })(); |