blob: 8885a89db5888aceeeeda1f5e31a73d285d6faea [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 Burrows1c5c8612016-10-05 13:45:13 -050020 var ks, flash, wss, t2ps, t2ms, ps, t2is, t2sp, t2vs;
Steven Burrows5570d1b2016-09-28 14:21:00 -070021
Steven Burrows1c5c8612016-10-05 13:45:13 -050022 var t2fs;
Steven Burrows37549ee2016-09-21 14:41:39 +010023
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'],
Steven Burrows1c5c8612016-10-05 13:45:13 -050030 O: [toggleSummary, 'Toggle the Summary Panel'],
31 R: [resetZoom, 'Reset pan / zoom'],
32 P: [togglePorts, 'Toggle Port Highlighting'],
33 E: [equalizeMasters, 'Equalize mastership roles'],
34 X: [resetAllNodeLocations, 'Reset Node Location'],
35 U: [unpinNode, 'Unpin node (mouse over)']
Steven Burrows37549ee2016-09-21 14:41:39 +010036 };
37
Steven Burrows1c5c8612016-10-05 13:45:13 -050038 function init(_t2fs_) {
39 t2fs = _t2fs_;
Steven Burrows37549ee2016-09-21 14:41:39 +010040 bindCommands();
41 }
42
43 function bindCommands() {
44
45 ks.keyBindings(actionMap);
46
47 ks.gestureNotes([
48 ['click', 'Select the item and show details'],
49 ['shift-click', 'Toggle selection state'],
50 ['drag', 'Reposition (and pin) device / host'],
51 ['cmd-scroll', 'Zoom in / out'],
52 ['cmd-drag', 'Pan']
53 ]);
54 }
55
Steven Burrows01ddf602016-09-28 14:21:00 -070056 var prefsState = {};
57
58 function updatePrefsState(what, b) {
59 prefsState[what] = b ? 1 : 0;
60 ps.setPrefs('topo_prefs', prefsState);
61 }
62
Steven Burrows37549ee2016-09-21 14:41:39 +010063 function cycleDeviceLabels() {
64 var deviceLabelIndex = t2ps.get('dlbls') + 1;
65 t2ps.set('dlbls', deviceLabelIndex % 3);
Steven Burrows1c5c8612016-10-05 13:45:13 -050066 t2fs.updateNodes();
Steven Burrows37549ee2016-09-21 14:41:39 +010067 }
68
Steven Burrowse3a18842016-09-22 15:33:33 +010069 function openMapSelection() {
70 t2ms.openMapSelection();
71 }
72
73 function toggleMap(x) {
74 t2ms.toggle(x);
75 }
76
Steven Burrows01ddf602016-09-28 14:21:00 -070077 function toggleInstancePanel(x) {
78 updatePrefsState('insts', t2is.toggle(x));
79 }
80
Steven Burrows5570d1b2016-09-28 14:21:00 -070081 function toggleSummary() {
82 t2sp.toggle();
83 }
84
Steven Burrows1c5c8612016-10-05 13:45:13 -050085 function resetZoom() {
86 t2ms.resetZoom();
87 flash.flash('Pan and zoom reset');
88 }
89
90 function togglePorts(x) {
91 updatePrefsState('porthl', t2vs.togglePortHighlights(x));
92 t2fs.updateLinks();
93 }
94
95 function equalizeMasters() {
96 wss.sendEvent('equalizeMasters');
97 flash.flash('Equalizing master roles');
98 }
99
100 function resetAllNodeLocations() {
101 t2fs.resetAllLocations();
102 flash.flash('Reset node locations');
103 }
104
105 function unpinNode() {
106 t2fs.unpin();
107 flash.flash('Unpin node');
108 }
109
Steven Burrows37549ee2016-09-21 14:41:39 +0100110 angular.module('ovTopo2')
111 .factory('Topo2KeyCommandService',
Steven Burrows1c5c8612016-10-05 13:45:13 -0500112 ['KeyService', 'FlashService', 'WebSocketService', 'Topo2PrefsService',
113 'Topo2MapService', 'PrefsService', 'Topo2InstanceService',
114 'Topo2SummaryPanelService', 'Topo2ViewService',
115 function (_ks_, _flash_, _wss_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_, _t2vs_) {
116
117 ks = _ks_;
118 flash = _flash_;
119 wss = _wss_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100120 t2ps = _t2ps_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100121 t2ms = _t2ms_;
Steven Burrows01ddf602016-09-28 14:21:00 -0700122 t2is = _t2is_;
123 ps = _ps_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700124 t2sp = _t2sp_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500125 t2vs = _t2vs_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100126
127 return {
128 init: init,
129 bindCommands: bindCommands
130 };
131 }
132 ]);
133})();