blob: ea6436d9e4ac0699655ca97934d0295778a53fb0 [file] [log] [blame]
Steven Burrows37549ee2016-09-21 14:41:39 +01001/*
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 Burrowse3a18842016-09-22 15:33:33 +010020 var ks, t2ps, t2ms;
Steven Burrows37549ee2016-09-21 14:41:39 +010021 var topo2ForceService;
22
23 // Commmands
24 var actionMap = {
Steven Burrowse3a18842016-09-22 15:33:33 +010025 L: [cycleDeviceLabels, 'Cycle device labels'],
26 G: [openMapSelection, 'Select background geo map'],
27 B: [toggleMap, 'Toggle background geo map'],
Steven Burrows37549ee2016-09-21 14:41:39 +010028 };
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 Burrowse3a18842016-09-22 15:33:33 +010054 function openMapSelection() {
55 t2ms.openMapSelection();
56 }
57
58 function toggleMap(x) {
59 t2ms.toggle(x);
60 }
61
Steven Burrows37549ee2016-09-21 14:41:39 +010062 angular.module('ovTopo2')
63 .factory('Topo2KeyCommandService',
Steven Burrowse3a18842016-09-22 15:33:33 +010064 ['KeyService', 'Topo2PrefsService', 'Topo2MapService',
Steven Burrows37549ee2016-09-21 14:41:39 +010065
Steven Burrowse3a18842016-09-22 15:33:33 +010066 function (_ks_, _t2ps_, _t2ms_) {
Steven Burrows37549ee2016-09-21 14:41:39 +010067
68 t2ps = _t2ps_;
Steven Burrowse3a18842016-09-22 15:33:33 +010069 t2ms = _t2ms_;
Steven Burrows37549ee2016-09-21 14:41:39 +010070 ks = _ks_;
71
72 return {
73 init: init,
74 bindCommands: bindCommands
75 };
76 }
77 ]);
78})();