blob: b89ea0932ddb386d04797f76511741c2b60e6031 [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 Burrowsb43c1a92017-03-07 17:13:28 +000020 var ks, flash, wss, t2ps, t2bgs, 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'],
Steven Burrowsb43c1a92017-03-07 17:13:28 +000025 B: [toggleBackground, 'Toggle background'],
Steven Burrows5570d1b2016-09-28 14:21:00 -070026 I: [toggleInstancePanel, 'Toggle ONOS Instance Panel'],
Steven Burrows1c5c8612016-10-05 13:45:13 -050027 O: [toggleSummary, 'Toggle the Summary Panel'],
28 R: [resetZoom, 'Reset pan / zoom'],
29 P: [togglePorts, 'Toggle Port Highlighting'],
30 E: [equalizeMasters, 'Equalize mastership roles'],
Steven Burrows892cba62017-03-10 16:31:48 +000031 X: [resetNodeLocation, 'Reset Node Location'],
Steven Burrowsc0efbf02016-11-16 11:30:47 -060032 U: [unpinNode, 'Unpin node (mouse over)'],
33
34 esc: handleEscape
Steven Burrows37549ee2016-09-21 14:41:39 +010035 };
36
Steven Burrows1c5c8612016-10-05 13:45:13 -050037 function init(_t2fs_) {
38 t2fs = _t2fs_;
Steven Burrows37549ee2016-09-21 14:41:39 +010039 bindCommands();
40 }
41
42 function bindCommands() {
43
44 ks.keyBindings(actionMap);
45
46 ks.gestureNotes([
47 ['click', 'Select the item and show details'],
48 ['shift-click', 'Toggle selection state'],
49 ['drag', 'Reposition (and pin) device / host'],
50 ['cmd-scroll', 'Zoom in / out'],
51 ['cmd-drag', 'Pan']
52 ]);
53 }
54
Steven Burrowsc0efbf02016-11-16 11:30:47 -060055 function handleEscape() {
Steven Burrows1aa4f582016-12-13 15:05:41 -050056
57 if (false) {
58 // TODO: Cancel show mastership
59 // TODO: Cancel Active overlay
60
61 } else if (t2rs.deselectAllNodes()) {
62 // else if we have node selections, deselect them all
63 // (work already done)
64 } else if (t2rs.deselectLink()) {
65 // else if we have a link selection, deselect it
66 // (work already done)
Steven Burrowsc0efbf02016-11-16 11:30:47 -060067 } else if (t2is.isVisible()) {
Steven Burrows1aa4f582016-12-13 15:05:41 -050068 // If the instance panel is visible, close it
69 t2is.toggle();
70 } else if (t2sp.isVisible()) {
71 // If the summary panel is visible, close it
72 t2sp.toggle();
73 }
Steven Burrowsc0efbf02016-11-16 11:30:47 -060074 }
75
Steven Burrows01ddf602016-09-28 14:21:00 -070076 var prefsState = {};
77
78 function updatePrefsState(what, b) {
79 prefsState[what] = b ? 1 : 0;
Simon Hunt95f4b422017-03-03 13:49:05 -080080 ps.setPrefs('topo2_prefs', prefsState);
Steven Burrows01ddf602016-09-28 14:21:00 -070081 }
82
Steven Burrows583f4be2016-11-04 14:06:50 +010083 function deviceLabelFlashMessage(index) {
Steven Burrows583f4be2016-11-04 14:06:50 +010084 switch (index) {
85 case 0: return 'Hide device labels';
86 case 1: return 'Show friendly device labels';
87 case 2: return 'Show device ID labels';
88 }
89 }
90
Steven Burrows37549ee2016-09-21 14:41:39 +010091 function cycleDeviceLabels() {
Steven Burrows583f4be2016-11-04 14:06:50 +010092 var deviceLabelIndex = t2ps.get('dlbls') + 1,
Steven Burrowsaf96a212016-12-28 12:57:02 +000093 newDeviceLabelIndex = deviceLabelIndex % 3;
Steven Burrows583f4be2016-11-04 14:06:50 +010094
95 t2ps.set('dlbls', newDeviceLabelIndex);
Steven Burrows1c5c8612016-10-05 13:45:13 -050096 t2fs.updateNodes();
Steven Burrows583f4be2016-11-04 14:06:50 +010097 flash.flash(deviceLabelFlashMessage(newDeviceLabelIndex));
Steven Burrows37549ee2016-09-21 14:41:39 +010098 }
99
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000100 function toggleBackground(x) {
101 t2bgs.toggle(x);
Steven Burrowse3a18842016-09-22 15:33:33 +0100102 }
103
Steven Burrows01ddf602016-09-28 14:21:00 -0700104 function toggleInstancePanel(x) {
105 updatePrefsState('insts', t2is.toggle(x));
106 }
107
Steven Burrows5570d1b2016-09-28 14:21:00 -0700108 function toggleSummary() {
109 t2sp.toggle();
110 }
111
Steven Burrows1c5c8612016-10-05 13:45:13 -0500112 function resetZoom() {
Steven Burrows3bbd9af2017-03-16 14:44:14 +0000113 t2bgs.resetZoom();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500114 flash.flash('Pan and zoom reset');
115 }
116
117 function togglePorts(x) {
118 updatePrefsState('porthl', t2vs.togglePortHighlights(x));
119 t2fs.updateLinks();
120 }
121
122 function equalizeMasters() {
123 wss.sendEvent('equalizeMasters');
124 flash.flash('Equalizing master roles');
125 }
126
Steven Burrows892cba62017-03-10 16:31:48 +0000127 function resetNodeLocation() {
128 t2fs.resetNodeLocation();
Steven Burrows1c5c8612016-10-05 13:45:13 -0500129 flash.flash('Reset node locations');
130 }
131
132 function unpinNode() {
133 t2fs.unpin();
134 flash.flash('Unpin node');
135 }
136
Steven Burrows37549ee2016-09-21 14:41:39 +0100137 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000138 .factory('Topo2KeyCommandService', [
139 'KeyService', 'FlashService', 'WebSocketService', 'Topo2PrefsService',
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000140 'Topo2BackgroundService', 'PrefsService', 'Topo2InstanceService',
Steven Burrowsaf96a212016-12-28 12:57:02 +0000141 'Topo2SummaryPanelService', 'Topo2ViewService', 'Topo2RegionService',
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000142 'Topo2SpriteLayerService',
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000143 function (_ks_, _flash_, _wss_, _t2ps_, _t2bgs_, _ps_, _t2is_, _t2sp_,
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000144 _t2vs_, _t2rs_, _t2sls_) {
Steven Burrows1c5c8612016-10-05 13:45:13 -0500145
146 ks = _ks_;
147 flash = _flash_;
148 wss = _wss_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100149 t2ps = _t2ps_;
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000150 t2bgs = _t2bgs_;
Steven Burrows01ddf602016-09-28 14:21:00 -0700151 t2is = _t2is_;
152 ps = _ps_;
Steven Burrows5570d1b2016-09-28 14:21:00 -0700153 t2sp = _t2sp_;
Steven Burrows1c5c8612016-10-05 13:45:13 -0500154 t2vs = _t2vs_;
Steven Burrows1aa4f582016-12-13 15:05:41 -0500155 t2rs = _t2rs_;
Steven Burrowsea1d1ec2017-02-23 15:39:25 +0000156 t2sls = _t2sls_;
Steven Burrows37549ee2016-09-21 14:41:39 +0100157
158 return {
159 init: init,
160 bindCommands: bindCommands
161 };
162 }
163 ]);
164})();