blob: 85715755d1a4ea980f46807266deae73369bd004 [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 Burrows5570d1b2016-09-28 14:21:00 -070020 var ks, t2ps, t2ms, ps, t2is, t2sp;
21
Steven Burrows37549ee2016-09-21 14:41:39 +010022 var topo2ForceService;
23
24 // Commmands
25 var actionMap = {
Steven Burrowse3a18842016-09-22 15:33:33 +010026 L: [cycleDeviceLabels, 'Cycle device labels'],
27 G: [openMapSelection, 'Select background geo map'],
28 B: [toggleMap, 'Toggle background geo map'],
Steven Burrows5570d1b2016-09-28 14:21:00 -070029 I: [toggleInstancePanel, 'Toggle ONOS Instance Panel'],
30 O: [toggleSummary, 'Toggle the Summary Panel']
Steven Burrows37549ee2016-09-21 14:41:39 +010031 };
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 Burrows01ddf602016-09-28 14:21:00 -070051 var prefsState = {};
52
53 function updatePrefsState(what, b) {
54 prefsState[what] = b ? 1 : 0;
55 ps.setPrefs('topo_prefs', prefsState);
56 }
57
Steven Burrows37549ee2016-09-21 14:41:39 +010058 function cycleDeviceLabels() {
59 var deviceLabelIndex = t2ps.get('dlbls') + 1;
60 t2ps.set('dlbls', deviceLabelIndex % 3);
61 topo2ForceService.updateNodes();
62 }
63
Steven Burrowse3a18842016-09-22 15:33:33 +010064 function openMapSelection() {
65 t2ms.openMapSelection();
66 }
67
68 function toggleMap(x) {
69 t2ms.toggle(x);
70 }
71
Steven Burrows01ddf602016-09-28 14:21:00 -070072 function toggleInstancePanel(x) {
73 updatePrefsState('insts', t2is.toggle(x));
74 }
75
Steven Burrows5570d1b2016-09-28 14:21:00 -070076 function toggleSummary() {
77 t2sp.toggle();
78 }
79
Steven Burrows37549ee2016-09-21 14:41:39 +010080 angular.module('ovTopo2')
81 .factory('Topo2KeyCommandService',
Steven Burrows01ddf602016-09-28 14:21:00 -070082 ['KeyService', 'Topo2PrefsService', 'Topo2MapService', 'PrefsService',
Steven Burrows5570d1b2016-09-28 14:21:00 -070083 'Topo2InstanceService', 'Topo2SummaryPanelService',
84 function (_ks_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_) {
Steven Burrows37549ee2016-09-21 14:41:39 +010085 t2ps = _t2ps_;
Steven Burrowse3a18842016-09-22 15:33:33 +010086 t2ms = _t2ms_;
Steven Burrows01ddf602016-09-28 14:21:00 -070087 t2is = _t2is_;
88 ps = _ps_;
Steven Burrows37549ee2016-09-21 14:41:39 +010089 ks = _ks_;
Steven Burrows5570d1b2016-09-28 14:21:00 -070090 t2sp = _t2sp_;
Steven Burrows37549ee2016-09-21 14:41:39 +010091
92 return {
93 init: init,
94 bindCommands: bindCommands
95 };
96 }
97 ]);
98})();