blob: 601159d260460ee0c4e00012c203327db82ae323 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
Sean Condon91481822019-01-01 13:56:14 +00002 * Copyright 2019-present Open Networking Foundation
Sean Condonf4f54a12018-10-10 23:25:46 +01003 *
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 */
Sean Condon0c577f62018-11-18 22:40:05 +000016import {
Sean Condonff85fbe2019-03-16 14:28:46 +000017 AfterContentInit,
18 Component, HostListener, Inject, Input,
Sean Condon0c577f62018-11-18 22:40:05 +000019 OnDestroy,
Sean Condon021f0fa2018-12-06 23:31:11 -080020 OnInit, SimpleChange,
Sean Condon0c577f62018-11-18 22:40:05 +000021 ViewChild
22} from '@angular/core';
Sean Condon55c30532018-10-29 12:26:57 +000023import * as d3 from 'd3';
Sean Condonf4f54a12018-10-10 23:25:46 +010024import {
Sean Condon28884332019-03-21 14:07:00 +000025 FnService,
26 IconService,
Sean Condon0c577f62018-11-18 22:40:05 +000027 KeysService,
Sean Condon28884332019-03-21 14:07:00 +000028 KeysToken,
29 LionService,
Sean Condon0c577f62018-11-18 22:40:05 +000030 LogService,
31 PrefsService,
32 SvgUtilService,
Sean Condon28884332019-03-21 14:07:00 +000033 TopoZoomPrefs,
Sean Condon0c577f62018-11-18 22:40:05 +000034 WebSocketService,
Sean Condon28884332019-03-21 14:07:00 +000035 ZoomUtils
Sean Condonf4f54a12018-10-10 23:25:46 +010036} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000037import {InstanceComponent} from '../panel/instance/instance.component';
Sean Condon0c577f62018-11-18 22:40:05 +000038import {DetailsComponent} from '../panel/details/details.component';
39import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component';
40import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component';
41import {TopologyService} from '../topology.service';
Sean Condon91481822019-01-01 13:56:14 +000042import {
Sean Condon71910542019-02-16 18:16:42 +000043 GridDisplayToggle,
Sean Condon91481822019-01-01 13:56:14 +000044 HostLabelToggle,
45 LabelToggle,
46 UiElement
47} from '../layer/forcesvg/models';
Sean Condonb2c483c2019-01-16 20:28:55 +000048import {
Sean Condon28884332019-03-21 14:07:00 +000049 ALL_TRAFFIC,
50 BKGRND_SELECT,
51 BKGRND_TOGGLE,
52 CANCEL_TRAFFIC,
53 CYCLEGRIDDISPLAY_BTN,
54 CYCLEHOSTLABEL_BTN,
55 CYCLELABELS_BTN,
56 DETAILS_TOGGLE,
57 EQMASTER_BTN,
58 HOSTS_TOGGLE,
59 INSTANCE_TOGGLE,
60 LAYOUT_ACCESS_BTN,
61 LAYOUT_DEFAULT_BTN,
62 OFFLINE_TOGGLE,
63 PORTS_TOGGLE,
64 QUICKHELP_BTN,
65 RESETZOOM_BTN,
66 SUMMARY_TOGGLE
Sean Condonb2c483c2019-01-16 20:28:55 +000067} from '../panel/toolbar/toolbar.component';
Sean Condon50855cf2018-12-23 15:37:42 +000068import {TrafficService} from '../traffic.service';
Sean Condon91481822019-01-01 13:56:14 +000069import {ZoomableDirective} from '../layer/zoomable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000070import {MapObject} from '../layer/maputils';
Sean Condon28884332019-03-21 14:07:00 +000071import {LayoutService, LayoutType} from '../layout.service';
Sean Condonf4f54a12018-10-10 23:25:46 +010072
Sean Condonb2c483c2019-01-16 20:28:55 +000073const TOPO2_PREFS = 'topo2_prefs';
Sean Condon0d064ec2019-02-04 21:53:53 +000074const TOPO_MAPID_PREFS = 'topo_mapid';
75
Sean Condonb2c483c2019-01-16 20:28:55 +000076const PREF_BG = 'bg';
77const PREF_DETAIL = 'detail';
78const PREF_DLBLS = 'dlbls';
79const PREF_HLBLS = 'hlbls';
Sean Condon71910542019-02-16 18:16:42 +000080const PREF_GRID = 'grid';
Sean Condonb2c483c2019-01-16 20:28:55 +000081const PREF_HOSTS = 'hosts';
82const PREF_INSTS = 'insts';
83const PREF_OFFDEV = 'offdev';
84const PREF_PORTHL = 'porthl';
85const PREF_SUMMARY = 'summary';
86const PREF_TOOLBAR = 'toolbar';
Sean Condon9de21352019-04-06 19:22:27 +010087const PREF_PINNED = 'pinned';
Sean Condonb2c483c2019-01-16 20:28:55 +000088
89/**
Sean Condon0d064ec2019-02-04 21:53:53 +000090 * Model of the topo2_prefs object - this is a subset of the overall Prefs returned
Sean Condonb2c483c2019-01-16 20:28:55 +000091 * by the server
92 */
93export interface Topo2Prefs {
94 bg: number;
95 detail: number;
96 dlbls: number;
97 hlbls: number;
98 hosts: number;
99 insts: number;
100 offdev: number;
101 porthl: number;
102 spr: number;
103 ovid: string;
104 summary: number;
105 toolbar: number;
Sean Condon71910542019-02-16 18:16:42 +0000106 grid: number;
Sean Condon9de21352019-04-06 19:22:27 +0100107 pinned: number;
Sean Condonb2c483c2019-01-16 20:28:55 +0000108}
109
Sean Condonf4f54a12018-10-10 23:25:46 +0100110/**
111 * ONOS GUI Topology View
112 *
113 * This Topology View component is the top level component in a hierarchy that
114 * comprises the whole Topology View
115 *
116 * There are three main parts (panels, graphical and breadcrumbs)
117 * The panel hierarchy
118 * |-- Instances Panel (shows ONOS instances)
119 * |-- Summary Panel (summary of ONOS)
120 * |-- Toolbar Panel (the toolbar)
121 * |-- Details Panel (when a node is selected in the Force graphical view (see below))
122 *
123 * The graphical hierarchy contains
124 * Topology (this)
125 * |-- No Devices Connected (only of there are no nodes to show)
126 * |-- Zoom Layer (everything beneath this can be zoomed and panned)
127 * |-- Background (container for any backgrounds - can be toggled on and off)
128 * |-- Map
129 * |-- Forces (all of the nodes and links laid out by a d3.force simulation)
130 *
131 * The breadcrumbs
132 * |-- Breadcrumb (in region view a way of navigating back up through regions)
133 */
134@Component({
135 selector: 'onos-topology',
136 templateUrl: './topology.component.html',
137 styleUrls: ['./topology.component.css']
138})
Sean Condonff85fbe2019-03-16 14:28:46 +0000139export class TopologyComponent implements AfterContentInit, OnInit, OnDestroy {
140 @Input() bannerHeight: number = 48;
Sean Condonaa4366d2018-11-02 14:29:01 +0000141 // These are references to the components inserted in the template
Sean Condonf4f54a12018-10-10 23:25:46 +0100142 @ViewChild(InstanceComponent) instance: InstanceComponent;
Sean Condonf4f54a12018-10-10 23:25:46 +0100143 @ViewChild(DetailsComponent) details: DetailsComponent;
Sean Condonaa4366d2018-11-02 14:29:01 +0000144 @ViewChild(BackgroundSvgComponent) background: BackgroundSvgComponent;
145 @ViewChild(ForceSvgComponent) force: ForceSvgComponent;
Sean Condon91481822019-01-01 13:56:14 +0000146 @ViewChild(ZoomableDirective) zoomDirective: ZoomableDirective;
Sean Condonf4f54a12018-10-10 23:25:46 +0100147
148 flashMsg: string = '';
Sean Condonb2c483c2019-01-16 20:28:55 +0000149 // These are used as defaults if nothing is set on the server
150 prefsState: Topo2Prefs = <Topo2Prefs>{
151 bg: 0,
152 detail: 1,
153 dlbls: 0,
154 hlbls: 2,
155 hosts: 0,
156 insts: 1,
157 offdev: 1,
158 ovid: 'traffic', // default to traffic overlay
159 porthl: 1,
160 spr: 0,
161 summary: 1,
162 toolbar: 0,
Sean Condon71910542019-02-16 18:16:42 +0000163 grid: 0
Sean Condonb2c483c2019-01-16 20:28:55 +0000164 };
Sean Condon0d064ec2019-02-04 21:53:53 +0000165
166 mapIdState: MapObject = <MapObject>{
167 id: undefined,
168 scale: 1.0
169 };
170 mapSelShown: boolean = false;
Sean Condon91481822019-01-01 13:56:14 +0000171 lionFn; // Function
Sean Condon55c30532018-10-29 12:26:57 +0000172
Sean Condon71910542019-02-16 18:16:42 +0000173 gridShown: boolean = true;
174 geoGridShown: boolean = true;
175
Sean Condonf4f54a12018-10-10 23:25:46 +0100176 constructor(
177 protected log: LogService,
178 protected fs: FnService,
179 protected ks: KeysService,
180 protected sus: SvgUtilService,
181 protected ps: PrefsService,
Sean Condon55c30532018-10-29 12:26:57 +0000182 protected wss: WebSocketService,
Sean Condonaa4366d2018-11-02 14:29:01 +0000183 protected ts: TopologyService,
Sean Condon91481822019-01-01 13:56:14 +0000184 protected trs: TrafficService,
185 protected is: IconService,
186 private lion: LionService,
Sean Condon28884332019-03-21 14:07:00 +0000187 private layout: LayoutService,
Sean Condonff85fbe2019-03-16 14:28:46 +0000188 @Inject('Window') public window: any,
Sean Condonf4f54a12018-10-10 23:25:46 +0100189 ) {
Sean Condon91481822019-01-01 13:56:14 +0000190 if (this.lion.ubercache.length === 0) {
191 this.lionFn = this.dummyLion;
192 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
193 } else {
194 this.doLion();
195 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100196
Sean Condon91481822019-01-01 13:56:14 +0000197 this.is.loadIconDef('bird');
198 this.is.loadIconDef('active');
199 this.is.loadIconDef('uiAttached');
200 this.is.loadIconDef('m_switch');
201 this.is.loadIconDef('m_roadm');
202 this.is.loadIconDef('m_router');
203 this.is.loadIconDef('m_uiAttached');
204 this.is.loadIconDef('m_endstation');
205 this.is.loadIconDef('m_ports');
206 this.is.loadIconDef('m_summary');
207 this.is.loadIconDef('m_details');
208 this.is.loadIconDef('m_map');
Sean Condon0d064ec2019-02-04 21:53:53 +0000209 this.is.loadIconDef('m_selectMap');
Sean Condon91481822019-01-01 13:56:14 +0000210 this.is.loadIconDef('m_cycleLabels');
Sean Condon71910542019-02-16 18:16:42 +0000211 this.is.loadIconDef('m_cycleGridDisplay');
Sean Condon91481822019-01-01 13:56:14 +0000212 this.is.loadIconDef('m_resetZoom');
213 this.is.loadIconDef('m_eqMaster');
214 this.is.loadIconDef('m_unknown');
215 this.is.loadIconDef('m_allTraffic');
216 this.is.loadIconDef('deviceTable');
217 this.is.loadIconDef('flowTable');
218 this.is.loadIconDef('portTable');
219 this.is.loadIconDef('groupTable');
220 this.is.loadIconDef('meterTable');
221 this.is.loadIconDef('triangleUp');
Sean Condon28884332019-03-21 14:07:00 +0000222 this.is.loadIconDef('m_disjointPaths');
223 this.is.loadIconDef('m_fiberSwitch');
Sean Condonf4f54a12018-10-10 23:25:46 +0100224 this.log.debug('Topology component constructed');
225 }
226
Sean Condon91481822019-01-01 13:56:14 +0000227 /**
228 * Static functions must come before member variables
Sean Condonff85fbe2019-03-16 14:28:46 +0000229 * @param index Corresponds to LabelToggle.Enum index
Sean Condon91481822019-01-01 13:56:14 +0000230 */
Sean Condon021f0fa2018-12-06 23:31:11 -0800231 private static deviceLabelFlashMessage(index: number): string {
232 switch (index) {
Sean Condon91481822019-01-01 13:56:14 +0000233 case 0: return 'fl_device_labels_hide';
234 case 1: return 'fl_device_labels_show_friendly';
235 case 2: return 'fl_device_labels_show_id';
Sean Condon021f0fa2018-12-06 23:31:11 -0800236 }
237 }
238
239 private static hostLabelFlashMessage(index: number): string {
240 switch (index) {
Sean Condon91481822019-01-01 13:56:14 +0000241 case 0: return 'fl_host_labels_hide';
242 case 1: return 'fl_host_labels_show_friendly';
243 case 2: return 'fl_host_labels_show_ip';
244 case 3: return 'fl_host_labels_show_mac';
Sean Condon021f0fa2018-12-06 23:31:11 -0800245 }
246 }
247
Sean Condon71910542019-02-16 18:16:42 +0000248 private static gridDisplayFlashMessage(index: number): string {
249 switch (index) {
250 case 0: return 'fl_grid_display_hide';
251 case 1: return 'fl_grid_display_1000';
252 case 2: return 'fl_grid_display_geo';
253 case 3: return 'fl_grid_display_both';
254 }
255 }
256
Sean Condon91481822019-01-01 13:56:14 +0000257 /**
258 * Pass the list of Key Commands to the KeyService, and initialize the Topology
259 * Service - which communicates with through the WebSocket to the ONOS server
260 * to get the nodes and links.
261 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100262 ngOnInit() {
263 this.bindCommands();
Sean Condonaa4366d2018-11-02 14:29:01 +0000264 // The components from the template are handed over to TopologyService here
265 // so that WebSocket responses can be passed back in to them
266 // The handling of the WebSocket call is delegated out to the Topology
267 // Service just to compartmentalize things a bit
268 this.ts.init(this.instance, this.background, this.force);
Sean Condonb2c483c2019-01-16 20:28:55 +0000269
270 this.ps.addListener((data) => this.prefsUpdateHandler(data));
271 this.prefsState = this.ps.getPrefs(TOPO2_PREFS, this.prefsState);
Sean Condon0d064ec2019-02-04 21:53:53 +0000272 this.mapIdState = this.ps.getPrefs(TOPO_MAPID_PREFS, this.mapIdState);
Sean Condonff85fbe2019-03-16 14:28:46 +0000273
Sean Condonf4f54a12018-10-10 23:25:46 +0100274 this.log.debug('Topology component initialized');
275 }
276
Sean Condonff85fbe2019-03-16 14:28:46 +0000277 ngAfterContentInit(): void {
278 // Scale the window initially - then after resize
279 const zoomMapExtents = ZoomUtils.zoomToWindowSize(
280 this.bannerHeight, this.window.innerWidth, this.window.innerHeight);
281 this.zoomDirective.changeZoomLevel(zoomMapExtents, true);
282 this.log.debug('Topology zoom initialized',
283 this.bannerHeight, this.window.innerWidth, this.window.innerHeight,
284 zoomMapExtents);
285 }
286
Sean Condon91481822019-01-01 13:56:14 +0000287 /**
Sean Condonb2c483c2019-01-16 20:28:55 +0000288 * Callback function that's called whenever new Prefs are received from WebSocket
289 *
290 * Note: At present the backend server does not filter updated by logged in user,
291 * so you might get updates pertaining to a different user
292 */
293 prefsUpdateHandler(data: any): void {
294 // Extract the TOPO2 prefs from it
Sean Condon0d064ec2019-02-04 21:53:53 +0000295 if (data[TOPO2_PREFS]) {
296 this.prefsState = data[TOPO2_PREFS];
297 }
Sean Condon0d064ec2019-02-04 21:53:53 +0000298 this.log.debug('Updated topo2 prefs', this.prefsState, this.mapIdState);
Sean Condonb2c483c2019-01-16 20:28:55 +0000299 }
300
301 /**
Sean Condon91481822019-01-01 13:56:14 +0000302 * When this component is being stopped, disconnect the TopologyService from
303 * the WebSocket
304 */
Sean Condonaa4366d2018-11-02 14:29:01 +0000305 ngOnDestroy() {
306 this.ts.destroy();
Sean Condonb2c483c2019-01-16 20:28:55 +0000307 this.ps.removeListener((data) => this.prefsUpdateHandler(data));
Sean Condonaa4366d2018-11-02 14:29:01 +0000308 this.log.debug('Topology component destroyed');
309 }
310
Sean Condonff85fbe2019-03-16 14:28:46 +0000311 @HostListener('window:resize', ['$event'])
312 onResize(event) {
313 const zoomMapExtents = ZoomUtils.zoomToWindowSize(
314 this.bannerHeight, event.target.innerWidth, event.target.innerHeight);
315 this.zoomDirective.changeZoomLevel(zoomMapExtents, true);
316 this.log.debug('Topology window resize',
317 event.target.innerWidth, event.target.innerHeight, this.bannerHeight, zoomMapExtents);
318 }
319
Sean Condon91481822019-01-01 13:56:14 +0000320 /**
321 * When ever a toolbar button is clicked, an event is sent up from toolbar
322 * component which is caught and passed on to here.
323 * @param name The name of the button that was clicked
324 */
325 toolbarButtonClicked(name: string) {
326 switch (name) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000327 case INSTANCE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000328 this.toggleInstancePanel();
329 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000330 case SUMMARY_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000331 this.toggleSummary();
332 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000333 case DETAILS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000334 this.toggleDetails();
335 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000336 case HOSTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000337 this.toggleHosts();
338 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000339 case OFFLINE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000340 this.toggleOfflineDevices();
341 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000342 case PORTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000343 this.togglePorts();
344 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000345 case BKGRND_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000346 this.toggleBackground();
347 break;
Sean Condon0d064ec2019-02-04 21:53:53 +0000348 case BKGRND_SELECT:
349 this.mapSelShown = !this.mapSelShown;
350 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000351 case CYCLELABELS_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000352 this.cycleDeviceLabels();
353 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000354 case CYCLEHOSTLABEL_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000355 this.cycleHostLabels();
356 break;
Sean Condon71910542019-02-16 18:16:42 +0000357 case CYCLEGRIDDISPLAY_BTN:
358 this.cycleGridDisplay();
359 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000360 case RESETZOOM_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000361 this.resetZoom();
362 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000363 case EQMASTER_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000364 this.equalizeMasters();
365 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000366 case CANCEL_TRAFFIC:
Sean Condon91481822019-01-01 13:56:14 +0000367 this.cancelTraffic();
368 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000369 case ALL_TRAFFIC:
Sean Condon91481822019-01-01 13:56:14 +0000370 this.monitorAllTraffic();
371 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000372 case QUICKHELP_BTN:
373 this.ks.quickHelpShown = true;
374 break;
Sean Condon28884332019-03-21 14:07:00 +0000375 case LAYOUT_DEFAULT_BTN:
376 this.layout.changeLayout(LayoutType.LAYOUT_DEFAULT);
377 break;
378 case LAYOUT_ACCESS_BTN:
379 this.layout.changeLayout(LayoutType.LAYOUT_ACCESS);
380 break;
Sean Condon91481822019-01-01 13:56:14 +0000381 default:
382 this.log.warn('Unhandled Toolbar action', name);
383 }
384 }
385
386 /**
387 * The list of key strokes that will be active in the Topology View.
388 *
389 * This action map is passed to the KeyService through the bindCommands()
390 * when this component is being initialized
391 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100392 actionMap() {
393 return {
Sean Condon50855cf2018-12-23 15:37:42 +0000394 A: [() => {this.monitorAllTraffic(); }, 'Monitor all traffic'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100395 B: [(token) => {this.toggleBackground(token); }, 'Toggle background'],
396 D: [(token) => {this.toggleDetails(token); }, 'Toggle details panel'],
Sean Condon71910542019-02-16 18:16:42 +0000397 E: [() => {this.equalizeMasters(); }, 'Equalize mastership roles'],
398 H: [() => {this.toggleHosts(); }, 'Toggle host visibility'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100399 I: [(token) => {this.toggleInstancePanel(token); }, 'Toggle ONOS Instance Panel'],
Sean Condon0d064ec2019-02-04 21:53:53 +0000400 G: [() => {this.mapSelShown = !this.mapSelShown; }, 'Show map selection dialog'],
Sean Condon71910542019-02-16 18:16:42 +0000401 L: [() => {this.cycleDeviceLabels(); }, 'Cycle device labels'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100402 M: [() => {this.toggleOfflineDevices(); }, 'Toggle offline visibility'],
Sean Condon71910542019-02-16 18:16:42 +0000403 O: [() => {this.toggleSummary(); }, 'Toggle the Summary Panel'],
404 P: [(token) => {this.togglePorts(token); }, 'Toggle Port Highlighting'],
405 Q: [() => {this.cycleGridDisplay(); }, 'Cycle grid display'],
406 R: [() => {this.resetZoom(); }, 'Reset pan / zoom'],
Sean Condon9de21352019-04-06 19:22:27 +0100407 U: [() => {this.unpinOrFreezeNodes(); }, 'Unpin or freeze nodes'],
Sean Condon71910542019-02-16 18:16:42 +0000408 X: [() => {this.resetNodeLocation(); }, 'Reset Node Location'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100409 dot: [() => {this.toggleToolbar(); }, 'Toggle Toolbar'],
Sean Condon50855cf2018-12-23 15:37:42 +0000410 0: [() => {this.cancelTraffic(); }, 'Cancel traffic monitoring'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100411 'shift-L': [() => {this.cycleHostLabels(); }, 'Cycle host labels'],
412
413 // -- instance color palette debug
Sean Condon55c30532018-10-29 12:26:57 +0000414 9: () => {
415 this.sus.cat7().testCard(d3.select('svg#topo2'));
Sean Condonf4f54a12018-10-10 23:25:46 +0100416 },
417
Sean Condonb2c483c2019-01-16 20:28:55 +0000418 esc: [() => {this.handleEscape(); }, 'Cancel commands'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100419
420 // TODO update after adding in Background Service
421 // topology overlay selections
422 // F1: function () { t2tbs.fnKey(0); },
423 // F2: function () { t2tbs.fnKey(1); },
424 // F3: function () { t2tbs.fnKey(2); },
425 // F4: function () { t2tbs.fnKey(3); },
426 // F5: function () { t2tbs.fnKey(4); },
427 //
428 // _keyListener: t2tbs.keyListener.bind(t2tbs),
429
430 _helpFormat: [
431 ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B'],
432 ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', 'E', 'dot'],
433 [], // this column reserved for overlay actions
434 ],
435 };
436 }
437
438
439 bindCommands(additional?: any) {
440
441 const am = this.actionMap();
442 const add = this.fs.isO(additional);
443
Sean Condonf4f54a12018-10-10 23:25:46 +0100444 this.ks.keyBindings(am);
445
446 this.ks.gestureNotes([
447 ['click', 'Select the item and show details'],
448 ['shift-click', 'Toggle selection state'],
449 ['drag', 'Reposition (and pin) device / host'],
450 ['cmd-scroll', 'Zoom in / out'],
451 ['cmd-drag', 'Pan'],
452 ]);
453 }
454
455 handleEscape() {
456
457 if (false) {
458 // TODO: Cancel show mastership
459 // TODO: Cancel Active overlay
460 // TODO: Reinstate with components
461 } else {
Sean Condonb2c483c2019-01-16 20:28:55 +0000462 this.nodeSelected(undefined);
Sean Condonf4f54a12018-10-10 23:25:46 +0100463 this.log.debug('Handling escape');
464 // } else if (t2rs.deselectAllNodes()) {
465 // // else if we have node selections, deselect them all
466 // // (work already done)
467 // } else if (t2rs.deselectLink()) {
468 // // else if we have a link selection, deselect it
469 // // (work already done)
470 // } else if (t2is.isVisible()) {
471 // // If the instance panel is visible, close it
472 // t2is.toggle();
473 // } else if (t2sp.isVisible()) {
474 // // If the summary panel is visible, close it
475 // t2sp.toggle();
476 }
477 }
478
Sean Condonb2c483c2019-01-16 20:28:55 +0000479 /**
480 * Updates the cache of preferences locally and onwards to the PrefsService
481 * @param what The attribute of the local topo2-prefs cache to update
482 * @param b the value to update it with
483 */
484 updatePrefsState(what: string, b: number) {
485 this.prefsState[what] = b;
486 this.ps.setPrefs(TOPO2_PREFS, this.prefsState);
Sean Condonf4f54a12018-10-10 23:25:46 +0100487 }
488
Sean Condonb2c483c2019-01-16 20:28:55 +0000489 /**
490 * When the button is clicked on the toolbar or the L key is pressed
491 * 1) cycle through options
492 * 2) flash up a message
493 * 3a) Update the local prefs cache
494 * 3b) And passes on to the global prefs service which sends back to the server
495 * 3c) It also has a knock on effect of passing it on to ForceSvgComponent
496 * because prefsState.dlbls is given as an input to it
497 * 3d) This will in turn pass it down to the DeviceSvgComponent which
498 * displays the label
499 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100500 protected cycleDeviceLabels() {
Sean Condonff85fbe2019-03-16 14:28:46 +0000501 const old: LabelToggle.Enum = this.prefsState.dlbls;
Sean Condon021f0fa2018-12-06 23:31:11 -0800502 const next = LabelToggle.next(old);
Sean Condon91481822019-01-01 13:56:14 +0000503 this.flashMsg = this.lionFn(TopologyComponent.deviceLabelFlashMessage(next));
Sean Condonb2c483c2019-01-16 20:28:55 +0000504 this.updatePrefsState(PREF_DLBLS, next);
Sean Condon021f0fa2018-12-06 23:31:11 -0800505 this.log.debug('Cycling device labels', old, next);
Sean Condonf4f54a12018-10-10 23:25:46 +0100506 }
507
508 protected cycleHostLabels() {
Sean Condonff85fbe2019-03-16 14:28:46 +0000509 const old: HostLabelToggle.Enum = this.prefsState.hlbls;
Sean Condon021f0fa2018-12-06 23:31:11 -0800510 const next = HostLabelToggle.next(old);
Sean Condon91481822019-01-01 13:56:14 +0000511 this.flashMsg = this.lionFn(TopologyComponent.hostLabelFlashMessage(next));
Sean Condonb2c483c2019-01-16 20:28:55 +0000512 this.updatePrefsState(PREF_HLBLS, next);
Sean Condon021f0fa2018-12-06 23:31:11 -0800513 this.log.debug('Cycling host labels', old, next);
Sean Condonf4f54a12018-10-10 23:25:46 +0100514 }
515
Sean Condon71910542019-02-16 18:16:42 +0000516 protected cycleGridDisplay() {
Sean Condonff85fbe2019-03-16 14:28:46 +0000517 const old: GridDisplayToggle.Enum = this.prefsState.grid;
Sean Condon71910542019-02-16 18:16:42 +0000518 const next = GridDisplayToggle.next(old);
519 this.flashMsg = this.lionFn(TopologyComponent.gridDisplayFlashMessage(next));
520 this.updatePrefsState(PREF_GRID, next);
521 this.log.debug('Cycling grid display', old, next);
522 }
523
Sean Condonb2c483c2019-01-16 20:28:55 +0000524 /**
525 * When the button is clicked on the toolbar or the B key is pressed
526 * 1) Find the inverse of the current state (held as 1 or 0)
527 * 2) Flash up a message on screen
528 * 3b) And passes on to the global prefs service which sends back to the server
529 * 3c) It also has a knock on effect of passing it on to ToolbarComponent
530 * because prefsState.bg is given as an input to it
Sean Condonff85fbe2019-03-16 14:28:46 +0000531 * @param token not currently used
Sean Condonb2c483c2019-01-16 20:28:55 +0000532 */
Sean Condon91481822019-01-01 13:56:14 +0000533 protected toggleBackground(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000534 const bg: boolean = !Boolean(this.prefsState.bg);
535 this.flashMsg = this.lionFn(bg ? 'show' : 'hide') +
Sean Condon91481822019-01-01 13:56:14 +0000536 ' ' + this.lionFn('fl_background_map');
Sean Condonb2c483c2019-01-16 20:28:55 +0000537 this.updatePrefsState(PREF_BG, bg ? 1 : 0);
538 this.log.debug('Toggling background', token, bg ? 'shown' : 'hidden');
Sean Condonf4f54a12018-10-10 23:25:46 +0100539 }
540
Sean Condon91481822019-01-01 13:56:14 +0000541 protected toggleDetails(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000542 const on: boolean = !Boolean(this.prefsState.detail);
543 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
544 ' ' + this.lionFn('fl_panel_details');
545 this.updatePrefsState(PREF_DETAIL, on ? 1 : 0);
546 this.log.debug('Toggling details', token);
Sean Condonf4f54a12018-10-10 23:25:46 +0100547 }
548
Sean Condon91481822019-01-01 13:56:14 +0000549 protected toggleInstancePanel(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000550 const on: boolean = !Boolean(this.prefsState.insts);
Sean Condon91481822019-01-01 13:56:14 +0000551 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
552 ' ' + this.lionFn('fl_panel_instances');
Sean Condonb2c483c2019-01-16 20:28:55 +0000553 this.updatePrefsState(PREF_INSTS, on ? 1 : 0);
Sean Condon91481822019-01-01 13:56:14 +0000554 this.log.debug('Toggling instances', token, on);
Sean Condonf4f54a12018-10-10 23:25:46 +0100555 }
556
557 protected toggleSummary() {
Sean Condonb2c483c2019-01-16 20:28:55 +0000558 const on: boolean = !Boolean(this.prefsState.summary);
Sean Condon91481822019-01-01 13:56:14 +0000559 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
560 ' ' + this.lionFn('fl_panel_summary');
Sean Condonb2c483c2019-01-16 20:28:55 +0000561 this.updatePrefsState(PREF_SUMMARY, on ? 1 : 0);
562 }
563
564 protected togglePorts(token?: KeysToken) {
565 const current: boolean = !Boolean(this.prefsState.porthl);
566 this.flashMsg = this.lionFn(current ? 'enable' : 'disable') +
567 ' ' + this.lionFn('fl_port_highlighting');
568 this.updatePrefsState(PREF_PORTHL, current ? 1 : 0);
569 this.log.debug(current ? 'Enable' : 'Disable', 'port highlighting');
570 }
571
572 protected toggleToolbar() {
573 const on: boolean = !Boolean(this.prefsState.toolbar);
574 this.updatePrefsState(PREF_TOOLBAR, on ? 1 : 0);
575 this.log.debug('toggling toolbar', on ? 'shown' : 'hidden');
576 }
577
578 protected toggleHosts() {
579 const current: boolean = !Boolean(this.prefsState.hosts);
580 this.flashMsg = this.lionFn('hosts') + ' ' +
581 this.lionFn(this.force.showHosts ? 'visible' : 'hidden');
582 this.updatePrefsState(PREF_HOSTS, current ? 1 : 0);
583 this.log.debug('toggling hosts: ', this.prefsState.hosts ? 'Show' : 'Hide');
584 }
585
586 protected toggleOfflineDevices() {
587 const on: boolean = !Boolean(this.prefsState.offdev);
588 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
589 ' ' + this.lionFn('fl_offline_devices');
590 this.updatePrefsState(PREF_OFFDEV, on ? 1 : 0);
591 this.log.debug('toggling offline devices', this.prefsState.offdev);
Sean Condonf4f54a12018-10-10 23:25:46 +0100592 }
593
594 protected resetZoom() {
Sean Condonff85fbe2019-03-16 14:28:46 +0000595 const zoomMapExtents = ZoomUtils.zoomToWindowSize(
596 this.bannerHeight, this.window.innerWidth, this.window.innerHeight);
597 this.zoomDirective.changeZoomLevel(zoomMapExtents, false);
Sean Condon91481822019-01-01 13:56:14 +0000598 this.flashMsg = this.lionFn('fl_pan_zoom_reset');
Sean Condonf4f54a12018-10-10 23:25:46 +0100599 }
600
Sean Condonf4f54a12018-10-10 23:25:46 +0100601 protected equalizeMasters() {
602 this.wss.sendEvent('equalizeMasters', null);
Sean Condon91481822019-01-01 13:56:14 +0000603 this.flashMsg = this.lionFn('fl_eq_masters');
Sean Condonf4f54a12018-10-10 23:25:46 +0100604 this.log.debug('equalizing masters');
Sean Condonf4f54a12018-10-10 23:25:46 +0100605 }
606
Sean Condon9de21352019-04-06 19:22:27 +0100607 /**
608 * If any nodes with fixed positions had been dragged out of place
609 * then put back where they belong
610 * If there are some devices selected reset only these
611 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100612 protected resetNodeLocation() {
Sean Condon9de21352019-04-06 19:22:27 +0100613 const numNodes = this.force.resetNodeLocations();
614 this.flashMsg = this.lionFn('fl_reset_node_locations') +
615 '(' + String(numNodes) + ')';
616 this.log.debug('resetting ', numNodes, 'node(s) location');
Sean Condonf4f54a12018-10-10 23:25:46 +0100617 }
618
Sean Condon9de21352019-04-06 19:22:27 +0100619 /**
620 * Toggle floating nodes between pinned and frozen
621 * If there are floating nodes selected toggle only these
622 */
623 protected unpinOrFreezeNodes() {
624 const pinned: boolean = !Boolean(this.prefsState.pinned);
625 const numNodes = this.force.unpinOrFreezeNodes(pinned);
626 this.flashMsg = this.lionFn(pinned ?
627 'fl_pinned_floating_nodes' : 'fl_unpinned_floating_nodes') +
628 '(' + String(numNodes) + ')';
629 this.updatePrefsState(PREF_PINNED, pinned ? 1 : 0);
630 this.log.debug('Toggling pinning for floating ', numNodes, 'nodes', pinned);
Sean Condonf4f54a12018-10-10 23:25:46 +0100631 }
632
Sean Condon91481822019-01-01 13:56:14 +0000633 /**
634 * Check to see if this is needed anymore
Sean Condonff85fbe2019-03-16 14:28:46 +0000635 * @param what - a key stroke
Sean Condon91481822019-01-01 13:56:14 +0000636 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100637 protected notValid(what) {
638 this.log.warn('topo.js getActionEntry(): Not a valid ' + what);
639 }
640
Sean Condon91481822019-01-01 13:56:14 +0000641 /**
642 * Check to see if this is needed anymore
Sean Condonff85fbe2019-03-16 14:28:46 +0000643 * @param key - a key stroke
Sean Condon91481822019-01-01 13:56:14 +0000644 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100645 getActionEntry(key) {
646 let entry;
647
648 if (!key) {
649 this.notValid('key');
650 return null;
651 }
652
653 entry = this.actionMap()[key];
654
655 if (!entry) {
656 this.notValid('actionMap (' + key + ') entry');
657 return null;
658 }
659 return this.fs.isA(entry) || [entry, ''];
660 }
661
Sean Condon91481822019-01-01 13:56:14 +0000662 /**
663 * An event handler that updates the details panel as items are
664 * selected in the forcesvg layer
Sean Condond88f3662019-04-03 16:35:30 +0100665 *
666 * @param nodesOrLink the item(s) to display details of
Sean Condon91481822019-01-01 13:56:14 +0000667 */
Sean Condond88f3662019-04-03 16:35:30 +0100668 nodeSelected(nodesOrLink: UiElement[]) {
669 this.details.ngOnChanges({'selectedNodes':
670 new SimpleChange(undefined, nodesOrLink, true)});
Sean Condon0c577f62018-11-18 22:40:05 +0000671 }
672
Sean Condon50855cf2018-12-23 15:37:42 +0000673 /**
674 * Enable traffic monitoring
675 */
676 monitorAllTraffic() {
Sean Condon91481822019-01-01 13:56:14 +0000677 // TODO: Implement support for toggling between bits, packets and octets
678 this.flashMsg = this.lionFn('tr_fl_pstats_bits');
Sean Condon50855cf2018-12-23 15:37:42 +0000679 this.trs.init(this.force);
680 }
681
682 /**
683 * Cancel traffic monitoring
684 */
685 cancelTraffic() {
Sean Condon91481822019-01-01 13:56:14 +0000686 this.flashMsg = this.lionFn('fl_monitoring_canceled');
Sean Condon50855cf2018-12-23 15:37:42 +0000687 this.trs.destroy();
688 }
Sean Condon91481822019-01-01 13:56:14 +0000689
Sean Condon0d064ec2019-02-04 21:53:53 +0000690 changeMap(map: MapObject) {
691 this.mapSelShown = false; // Hide the MapSelector component
692 this.mapIdState = map;
693 this.ps.setPrefs(TOPO_MAPID_PREFS, this.mapIdState);
694 this.log.debug('Map has been changed to ', map);
695 }
696
Sean Condon1ae15802019-03-02 09:07:18 +0000697 mapExtentsZoom(zoomMapExtents: TopoZoomPrefs) {
698 // this.zoomDirective.updateZoomState(zoomPrefs.tx, zoomPrefs.ty, zoomPrefs.sc);
699 this.zoomDirective.changeZoomLevel(zoomMapExtents);
700 this.log.debug('Map zoom prefs updated', zoomMapExtents);
701 }
702
Sean Condon91481822019-01-01 13:56:14 +0000703 /**
704 * Read the LION bundle for Toolbar and set up the lionFn
705 */
706 doLion() {
707 this.lionFn = this.lion.bundle('core.view.Topo');
708 }
709
710 /**
711 * A dummy implementation of the lionFn until the response is received and the LION
712 * bundle is received from the WebSocket
713 */
714 dummyLion(key: string): string {
715 return '%' + key + '%';
716 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100717}