blob: 1b0b10f7defe59427b19fd315e7f23ac16e0487b [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 Burrows01ddf602016-09-28 14:21:00 -070020 var ks, t2ps, t2ms, ps, t2is;
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 Burrows01ddf602016-09-28 14:21:00 -070028 I: [toggleInstancePanel, 'Toggle ONOS Instance Panel']
Steven Burrows37549ee2016-09-21 14:41:39 +010029 };
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 Burrows01ddf602016-09-28 14:21:00 -070049 var prefsState = {};
50
51 function updatePrefsState(what, b) {
52 prefsState[what] = b ? 1 : 0;
53 ps.setPrefs('topo_prefs', prefsState);
54 }
55
Steven Burrows37549ee2016-09-21 14:41:39 +010056 function cycleDeviceLabels() {
57 var deviceLabelIndex = t2ps.get('dlbls') + 1;
58 t2ps.set('dlbls', deviceLabelIndex % 3);
59 topo2ForceService.updateNodes();
60 }
61
Steven Burrowse3a18842016-09-22 15:33:33 +010062 function openMapSelection() {
63 t2ms.openMapSelection();
64 }
65
66 function toggleMap(x) {
67 t2ms.toggle(x);
68 }
69
Steven Burrows01ddf602016-09-28 14:21:00 -070070 function toggleInstancePanel(x) {
71 updatePrefsState('insts', t2is.toggle(x));
72 }
73
Steven Burrows37549ee2016-09-21 14:41:39 +010074 angular.module('ovTopo2')
75 .factory('Topo2KeyCommandService',
Steven Burrows01ddf602016-09-28 14:21:00 -070076 ['KeyService', 'Topo2PrefsService', 'Topo2MapService', 'PrefsService',
77 'Topo2InstanceService',
78 function (_ks_, _t2ps_, _t2ms_, _ps_, _t2is_) {
Steven Burrows37549ee2016-09-21 14:41:39 +010079
80 t2ps = _t2ps_;
Steven Burrowse3a18842016-09-22 15:33:33 +010081 t2ms = _t2ms_;
Steven Burrows01ddf602016-09-28 14:21:00 -070082 t2is = _t2is_;
83 ps = _ps_;
Steven Burrows37549ee2016-09-21 14:41:39 +010084 ks = _ks_;
85
86 return {
87 init: init,
88 bindCommands: bindCommands
89 };
90 }
91 ]);
92})();