blob: 0f54273c46bebcde18d0fbe4b60b63a39e37e77f [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 Burrowsea1d1ec2017-02-23 15:39:25 +000020 var ks, flash, wss, t2ps, t2ms, ps, t2is, t2sp, t2vs, t2rs, t2fs, t2sls;
Steven Burrows37549ee2016-09-21 14:41:39 +010021
22 // Commmands
23 var actionMap = {
Steven Burrowse3a18842016-09-22 15:33:33 +010024 L: [cycleDeviceLabels, 'Cycle device labels'],
25 G: [openMapSelection, 'Select background geo map'],
26 B: [toggleMap, 'Toggle background geo map'],
Steven Burrows5570d1b2016-09-28 14:21:00 -070027 I: [toggleInstancePanel, 'Toggle ONOS Instance Panel'],
Steven Burrows1c5c8612016-10-05 13:45:13 -050028 O: [toggleSummary, 'Toggle the Summary Panel'],
29 R: [resetZoom, 'Reset pan / zoom'],
30 P: [togglePorts, 'Toggle Port Highlighting'],
31 E: [equalizeMasters, 'Equalize mastership roles'],
32 X: [resetAllNodeLocations, 'Reset Node Location'],
Steven Burrowsc0efbf02016-11-16 11:30:47 -060033 U: [unpinNode, 'Unpin node (mouse over)'],
Steven Burrowsea1d1ec2017-02-23 15:39:25 +000034 S: [toggleSpriteLayer, 'Toggle sprite layer'],
Steven Burrowsc0efbf02016-11-16 11:30:47 -060035
36 esc: handleEscape
Steven Burrows37549ee2016-09-21 14:41:39 +010037 };
38
Steven Burrows1c5c8612016-10-05 13:45:13 -050039 function init(_t2fs_) {
40 t2fs = _t2fs_;
Steven Burrows37549ee2016-09-21 14:41:39 +010041 bindCommands();
42 }
43
44 function bindCommands() {
45
46 ks.keyBindings(actionMap);
47
48 ks.gestureNotes([
49 ['click', 'Select the item and show details'],
50 ['shift-click', 'Toggle selection state'],
51 ['drag', 'Reposition (and pin) device / host'],
52 ['cmd-scroll', 'Zoom in / out'],
53 ['cmd-drag', 'Pan']
54 ]);
55 }
56
Steven Burrowsc0efbf02016-11-16 11:30:47 -060057 function handleEscape() {
Steven Burrows1aa4f582016-12-13 15:05:41 -050058
59 if (false) {
60 // TODO: Cancel show mastership
61 // TODO: Cancel Active overlay
62
63 } else if (t2rs.deselectAllNodes()) {
64 // else if we have node selections, deselect them all
65 // (work already done)
66 } else if (t2rs.deselectLink()) {
67 // else if we have a link selection, deselect it
68 // (work already done)
Steven Burrowsc0efbf02016-11-16 11:30:47 -060069 } else if (t2is.isVisible()) {
Steven Burrows1aa4f582016-12-13 15:05:41 -050070 // If the instance panel is visible, close it
71 t2is.toggle();
72 } else if (t2sp.isVisible()) {
73 // If the summary panel is visible, close it
74 t2sp.toggle();
75 }
Steven Burrowsc0efbf02016-11-16 11:30:47 -060076 }
77
Steven Burrows01ddf602016-09-28 14:21:00 -070078 var prefsState = {};
79
80 function updatePrefsState(what, b) {
81 prefsState[what] = b ? 1 : 0;
82 ps.setPrefs('topo_prefs', prefsState);
83 }
84
Steven Burrows583f4be2016-11-04 14:06:50 +010085 function deviceLabelFlashMessage(index) {
Steven Burrows583f4be2016-11-04 14:06:50 +010086 switch (index) {
87 case 0: return 'Hide device labels';
88 case 1: return 'Show friendly device labels';
89 case 2: return 'Show device ID labels';
90 }
91 }
92
Steven Burrows37549ee2016-09-21 14:41:39 +010093 function cycleDeviceLabels() {
Steven Burrows583f4be2016-11-04 14:06:50 +010094 var deviceLabelIndex = t2ps.get('dlbls') + 1,
Steven Burrowsaf96a212016-12-28 12:57:02 +000095 newDeviceLabelIndex = deviceLabelIndex % 3;
Steven Burrows583f4be2016-11-04 14:06:50 +010096
97 t2ps.set('dlbls', newDeviceLabelIndex);
Steven Burrows1c5c8612016-10-05 13:45:13 -050098 t2fs.updateNodes();
Steven Burrows583f4be2016-11-04 14:06:50 +010099 flash.flash(deviceLabelFlashMessage(newDeviceLabelIndex));
Steven Burrows37549ee2016-09-21 14:41:39 +0100100 }
101
Steven Burrowse3a18842016-09-22 15:33:33 +0100102 function openMapSelection() {
103 t2ms.openMapSelection();
104 }
105
106 function toggleMap(x) {
107 t2ms.toggle(x);
108 }
109
Steven Burrows01ddf602016-09-28 14:21:00 -0700110 function toggleInstancePanel(x) {
111 updatePrefsState('insts', t2is.toggle(x));
112 }
113
Steven Burrows5570d1b2016-09-28 14:21:00 -0700114 function toggleSummary() {
115 t2sp.toggle();
116 }
117
Steven Burrows1c5c8612016-10-05 13:45:13 -0500118 function resetZoom() {
119 t2ms.resetZoom();
120 flash.flash('Pan and zoom reset');
121 }
122
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000123 function toggleSpriteLayer() {
124 t2sls.toggle();
125 }
126
Steven Burrows1c5c8612016-10-05 13:45:13 -0500127 function togglePorts(x) {
128 updatePrefsState('porthl', t2vs.togglePortHighlights(x));
129 t2fs.updateLinks();
130 }
131
132 function equalizeMasters() {
133 wss.sendEvent('equalizeMasters');
134 flash.flash('Equalizing master roles');
135 }
136
137 function resetAllNodeLocations() {
138 t2fs.resetAllLocations();
139 flash.flash('Reset node locations');
140 }
141
142 function unpinNode() {
143 t2fs.unpin();
144 flash.flash('Unpin node');
145 }
146
Steven Burrows37549ee2016-09-21 14:41:39 +0100147 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000148 .factory('Topo2KeyCommandService', [
149 'KeyService', 'FlashService', 'WebSocketService', 'Topo2PrefsService',
150 'Topo2MapService', 'PrefsService', 'Topo2InstanceService',
151 'Topo2SummaryPanelService', 'Topo2ViewService', 'Topo2RegionService',
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000152 'Topo2SpriteLayerService',
Steven Burrows1aa4f582016-12-13 15:05:41 -0500153 function (_ks_, _flash_, _wss_, _t2ps_, _t2ms_, _ps_, _t2is_, _t2sp_,
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000154 _t2vs_, _t2rs_, _t2sls_) {
Steven Burrows1c5c8612016-10-05 13:45:13 -0500155
156 ks = _ks_;
157 flash = _flash_;
158 wss = _wss_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100159 t2ps = _t2ps_;
Steven Burrowse3a18842016-09-22 15:33:33 +0100160 t2ms = _t2ms_;
Steven Burrows01ddf602016-09-28 14:21:00 -0700161 t2is = _t2is_;
162 ps = _ps_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700163 t2sp = _t2sp_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500164 t2vs = _t2vs_;
Steven Burrows1aa4f582016-12-13 15:05:41 -0500165 t2rs = _t2rs_;
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000166 t2sls = _t2sls_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100167
168 return {
169 init: init,
170 bindCommands: bindCommands
171 };
172 }
173 ]);
174})();