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 | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame^] | 20 | var ks, t2ps, t2ms; |
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 | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | function init(t2fs) { |
| 31 | topo2ForceService = t2fs; |
| 32 | bindCommands(); |
| 33 | } |
| 34 | |
| 35 | function bindCommands() { |
| 36 | |
| 37 | ks.keyBindings(actionMap); |
| 38 | |
| 39 | ks.gestureNotes([ |
| 40 | ['click', 'Select the item and show details'], |
| 41 | ['shift-click', 'Toggle selection state'], |
| 42 | ['drag', 'Reposition (and pin) device / host'], |
| 43 | ['cmd-scroll', 'Zoom in / out'], |
| 44 | ['cmd-drag', 'Pan'] |
| 45 | ]); |
| 46 | } |
| 47 | |
| 48 | function cycleDeviceLabels() { |
| 49 | var deviceLabelIndex = t2ps.get('dlbls') + 1; |
| 50 | t2ps.set('dlbls', deviceLabelIndex % 3); |
| 51 | topo2ForceService.updateNodes(); |
| 52 | } |
| 53 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame^] | 54 | function openMapSelection() { |
| 55 | t2ms.openMapSelection(); |
| 56 | } |
| 57 | |
| 58 | function toggleMap(x) { |
| 59 | t2ms.toggle(x); |
| 60 | } |
| 61 | |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 62 | angular.module('ovTopo2') |
| 63 | .factory('Topo2KeyCommandService', |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame^] | 64 | ['KeyService', 'Topo2PrefsService', 'Topo2MapService', |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 65 | |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame^] | 66 | function (_ks_, _t2ps_, _t2ms_) { |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 67 | |
| 68 | t2ps = _t2ps_; |
Steven Burrows | e3a1884 | 2016-09-22 15:33:33 +0100 | [diff] [blame^] | 69 | t2ms = _t2ms_; |
Steven Burrows | 37549ee | 2016-09-21 14:41:39 +0100 | [diff] [blame] | 70 | ks = _ks_; |
| 71 | |
| 72 | return { |
| 73 | init: init, |
| 74 | bindCommands: bindCommands |
| 75 | }; |
| 76 | } |
| 77 | ]); |
| 78 | })(); |