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 | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame^] | 20 | var ks, t2ps, t2ms, ps, t2is, t2sp; |
| 21 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 22 | var topo2ForceService; |
| 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'], |
| 30 | O: [toggleSummary, 'Toggle the Summary Panel'] |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | function init(t2fs) { |
| 34 | topo2ForceService = t2fs; |
| 35 | bindCommands(); |
| 36 | } |
| 37 | |
| 38 | function bindCommands() { |
| 39 | |
| 40 | ks.keyBindings(actionMap); |
| 41 | |
| 42 | ks.gestureNotes([ |
| 43 | ['click', 'Select the item and show details'], |
| 44 | ['shift-click', 'Toggle selection state'], |
| 45 | ['drag', 'Reposition (and pin) device / host'], |
| 46 | ['cmd-scroll', 'Zoom in / out'], |
| 47 | ['cmd-drag', 'Pan'] |
| 48 | ]); |
| 49 | } |
| 50 | |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 51 | var prefsState = {}; |
| 52 | |
| 53 | function updatePrefsState(what, b) { |
| 54 | prefsState[what] = b ? 1 : 0; |
| 55 | ps.setPrefs('topo_prefs', prefsState); |
| 56 | } |
| 57 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 58 | function cycleDeviceLabels() { |
| 59 | var deviceLabelIndex = t2ps.get('dlbls') + 1; |
| 60 | t2ps.set('dlbls', deviceLabelIndex % 3); |
| 61 | topo2ForceService.updateNodes(); |
| 62 | } |
| 63 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 64 | function openMapSelection() { |
| 65 | t2ms.openMapSelection(); |
| 66 | } |
| 67 | |
| 68 | function toggleMap(x) { |
| 69 | t2ms.toggle(x); |
| 70 | } |
| 71 | |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 72 | function toggleInstancePanel(x) { |
| 73 | updatePrefsState('insts', t2is.toggle(x)); |
| 74 | } |
| 75 | |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame^] | 76 | function toggleSummary() { |
| 77 | t2sp.toggle(); |
| 78 | } |
| 79 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 80 | angular.module('ovTopo2') |
| 81 | .factory('Topo2KeyCommandService', |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 82 | ['KeyService', 'Topo2PrefsService', 'Topo2MapService', 'PrefsService', |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame^] | 83 | 'Topo2InstanceService', 'Topo2SummaryPanelService', |
| 84 | function (_ks_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_) { |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 85 | t2ps = _t2ps_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame] | 86 | t2ms = _t2ms_; |
Steven Burrows | 01ddf60 | 2016-09-28 14:21:00 -0700 | [diff] [blame] | 87 | t2is = _t2is_; |
| 88 | ps = _ps_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 89 | ks = _ks_; |
Steven Burrows | 5570d1b | 2016-09-28 14:21:00 -0700 | [diff] [blame^] | 90 | t2sp = _t2sp_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 91 | |
| 92 | return { |
| 93 | init: init, |
| 94 | bindCommands: bindCommands |
| 95 | }; |
| 96 | } |
| 97 | ]); |
| 98 | })(); |