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