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