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'], |
| 35 | U: [unpinNode, 'Unpin node (mouse over)'] |
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 | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 56 | var prefsState = {}; |
| 57 | |
| 58 | function updatePrefsState(what, b) { |
| 59 | prefsState[what] = b ? 1 : 0; |
| 60 | ps.setPrefs('topo_prefs', prefsState); |
| 61 | } |
| 62 | |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame^] | 63 | function deviceLabelFlashMessage(index) { |
| 64 | |
| 65 | switch (index) { |
| 66 | case 0: return 'Hide device labels'; |
| 67 | case 1: return 'Show friendly device labels'; |
| 68 | case 2: return 'Show device ID labels'; |
| 69 | } |
| 70 | } |
| 71 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 72 | function cycleDeviceLabels() { |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame^] | 73 | var deviceLabelIndex = t2ps.get('dlbls') + 1, |
| 74 | newDeviceLabelIndex = deviceLabelIndex % 3; |
| 75 | |
| 76 | t2ps.set('dlbls', newDeviceLabelIndex); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 77 | t2fs.updateNodes(); |
Steven Burrows | 583f4be | 2016-11-04 14:06:50 +0100 | [diff] [blame^] | 78 | flash.flash(deviceLabelFlashMessage(newDeviceLabelIndex)); |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 81 | function openMapSelection() { |
| 82 | t2ms.openMapSelection(); |
| 83 | } |
| 84 | |
| 85 | function toggleMap(x) { |
| 86 | t2ms.toggle(x); |
| 87 | } |
| 88 | |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 89 | function toggleInstancePanel(x) { |
| 90 | updatePrefsState('insts', t2is.toggle(x)); |
| 91 | } |
| 92 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 93 | function toggleSummary() { |
| 94 | t2sp.toggle(); |
| 95 | } |
| 96 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 97 | function resetZoom() { |
| 98 | t2ms.resetZoom(); |
| 99 | flash.flash('Pan and zoom reset'); |
| 100 | } |
| 101 | |
| 102 | function togglePorts(x) { |
| 103 | updatePrefsState('porthl', t2vs.togglePortHighlights(x)); |
| 104 | t2fs.updateLinks(); |
| 105 | } |
| 106 | |
| 107 | function equalizeMasters() { |
| 108 | wss.sendEvent('equalizeMasters'); |
| 109 | flash.flash('Equalizing master roles'); |
| 110 | } |
| 111 | |
| 112 | function resetAllNodeLocations() { |
| 113 | t2fs.resetAllLocations(); |
| 114 | flash.flash('Reset node locations'); |
| 115 | } |
| 116 | |
| 117 | function unpinNode() { |
| 118 | t2fs.unpin(); |
| 119 | flash.flash('Unpin node'); |
| 120 | } |
| 121 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 122 | angular.module('ovTopo2') |
| 123 | .factory('Topo2KeyCommandService', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 124 | ['KeyService', 'FlashService', 'WebSocketService', 'Topo2PrefsService', |
| 125 | 'Topo2MapService', 'PrefsService', 'Topo2InstanceService', |
| 126 | 'Topo2SummaryPanelService', 'Topo2ViewService', |
| 127 | function (_ks_, _flash_, _wss_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_, _t2vs_) { |
| 128 | |
| 129 | ks = _ks_; |
| 130 | flash = _flash_; |
| 131 | wss = _wss_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 132 | t2ps = _t2ps_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 133 | t2ms = _t2ms_; |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 134 | t2is = _t2is_; |
| 135 | ps = _ps_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 136 | t2sp = _t2sp_; |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 137 | t2vs = _t2vs_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 138 | |
| 139 | return { |
| 140 | init: init, |
| 141 | bindCommands: bindCommands |
| 142 | }; |
| 143 | } |
| 144 | ]); |
| 145 | })(); |