blob: 2de3c8b888ca8e5502fb8dcecdc0955ad501dd7e [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 {
17 Component,
18 OnDestroy,
Sean Condon021f0fa2018-12-06 23:31:11 -080019 OnInit, SimpleChange,
Sean Condon0c577f62018-11-18 22:40:05 +000020 ViewChild
21} from '@angular/core';
Sean Condon55c30532018-10-29 12:26:57 +000022import * as d3 from 'd3';
Sean Condonf4f54a12018-10-10 23:25:46 +010023import {
Sean Condon91481822019-01-01 13:56:14 +000024 FnService, IconService,
Sean Condon0c577f62018-11-18 22:40:05 +000025 KeysService,
Sean Condon91481822019-01-01 13:56:14 +000026 KeysToken, LionService,
Sean Condon0c577f62018-11-18 22:40:05 +000027 LogService,
28 PrefsService,
29 SvgUtilService,
30 WebSocketService,
Sean Condonf4f54a12018-10-10 23:25:46 +010031} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000032import {InstanceComponent} from '../panel/instance/instance.component';
Sean Condon0c577f62018-11-18 22:40:05 +000033import {DetailsComponent} from '../panel/details/details.component';
34import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component';
35import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component';
36import {TopologyService} from '../topology.service';
Sean Condon91481822019-01-01 13:56:14 +000037import {
Sean Condon71910542019-02-16 18:16:42 +000038 GridDisplayToggle,
Sean Condon91481822019-01-01 13:56:14 +000039 HostLabelToggle,
40 LabelToggle,
41 UiElement
42} from '../layer/forcesvg/models';
Sean Condonb2c483c2019-01-16 20:28:55 +000043import {
44 INSTANCE_TOGGLE, SUMMARY_TOGGLE, DETAILS_TOGGLE,
45 HOSTS_TOGGLE, OFFLINE_TOGGLE, PORTS_TOGGLE,
46 BKGRND_TOGGLE, CYCLELABELS_BTN, CYCLEHOSTLABEL_BTN,
Sean Condon71910542019-02-16 18:16:42 +000047 CYCLEGRIDDISPLAY_BTN, RESETZOOM_BTN, EQMASTER_BTN,
Sean Condon0d064ec2019-02-04 21:53:53 +000048 CANCEL_TRAFFIC, ALL_TRAFFIC, QUICKHELP_BTN, BKGRND_SELECT
Sean Condonb2c483c2019-01-16 20:28:55 +000049} from '../panel/toolbar/toolbar.component';
Sean Condon50855cf2018-12-23 15:37:42 +000050import {TrafficService} from '../traffic.service';
Sean Condon91481822019-01-01 13:56:14 +000051import {ZoomableDirective} from '../layer/zoomable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000052import {MapObject} from '../layer/maputils';
Sean Condonf4f54a12018-10-10 23:25:46 +010053
Sean Condonb2c483c2019-01-16 20:28:55 +000054const TOPO2_PREFS = 'topo2_prefs';
Sean Condon0d064ec2019-02-04 21:53:53 +000055const TOPO_MAPID_PREFS = 'topo_mapid';
56
Sean Condonb2c483c2019-01-16 20:28:55 +000057const PREF_BG = 'bg';
58const PREF_DETAIL = 'detail';
59const PREF_DLBLS = 'dlbls';
60const PREF_HLBLS = 'hlbls';
Sean Condon71910542019-02-16 18:16:42 +000061const PREF_GRID = 'grid';
Sean Condonb2c483c2019-01-16 20:28:55 +000062const PREF_HOSTS = 'hosts';
63const PREF_INSTS = 'insts';
64const PREF_OFFDEV = 'offdev';
65const PREF_PORTHL = 'porthl';
66const PREF_SUMMARY = 'summary';
67const PREF_TOOLBAR = 'toolbar';
68
69/**
Sean Condon0d064ec2019-02-04 21:53:53 +000070 * Model of the topo2_prefs object - this is a subset of the overall Prefs returned
Sean Condonb2c483c2019-01-16 20:28:55 +000071 * by the server
72 */
73export interface Topo2Prefs {
74 bg: number;
75 detail: number;
76 dlbls: number;
77 hlbls: number;
78 hosts: number;
79 insts: number;
80 offdev: number;
81 porthl: number;
82 spr: number;
83 ovid: string;
84 summary: number;
85 toolbar: number;
Sean Condon71910542019-02-16 18:16:42 +000086 grid: number;
Sean Condonb2c483c2019-01-16 20:28:55 +000087}
88
Sean Condonf4f54a12018-10-10 23:25:46 +010089/**
90 * ONOS GUI Topology View
91 *
92 * This Topology View component is the top level component in a hierarchy that
93 * comprises the whole Topology View
94 *
95 * There are three main parts (panels, graphical and breadcrumbs)
96 * The panel hierarchy
97 * |-- Instances Panel (shows ONOS instances)
98 * |-- Summary Panel (summary of ONOS)
99 * |-- Toolbar Panel (the toolbar)
100 * |-- Details Panel (when a node is selected in the Force graphical view (see below))
101 *
102 * The graphical hierarchy contains
103 * Topology (this)
104 * |-- No Devices Connected (only of there are no nodes to show)
105 * |-- Zoom Layer (everything beneath this can be zoomed and panned)
106 * |-- Background (container for any backgrounds - can be toggled on and off)
107 * |-- Map
108 * |-- Forces (all of the nodes and links laid out by a d3.force simulation)
109 *
110 * The breadcrumbs
111 * |-- Breadcrumb (in region view a way of navigating back up through regions)
112 */
113@Component({
114 selector: 'onos-topology',
115 templateUrl: './topology.component.html',
116 styleUrls: ['./topology.component.css']
117})
Sean Condonaa4366d2018-11-02 14:29:01 +0000118export class TopologyComponent implements OnInit, OnDestroy {
119 // These are references to the components inserted in the template
Sean Condonf4f54a12018-10-10 23:25:46 +0100120 @ViewChild(InstanceComponent) instance: InstanceComponent;
Sean Condonf4f54a12018-10-10 23:25:46 +0100121 @ViewChild(DetailsComponent) details: DetailsComponent;
Sean Condonaa4366d2018-11-02 14:29:01 +0000122 @ViewChild(BackgroundSvgComponent) background: BackgroundSvgComponent;
123 @ViewChild(ForceSvgComponent) force: ForceSvgComponent;
Sean Condon91481822019-01-01 13:56:14 +0000124 @ViewChild(ZoomableDirective) zoomDirective: ZoomableDirective;
Sean Condonf4f54a12018-10-10 23:25:46 +0100125
126 flashMsg: string = '';
Sean Condonb2c483c2019-01-16 20:28:55 +0000127 // These are used as defaults if nothing is set on the server
128 prefsState: Topo2Prefs = <Topo2Prefs>{
129 bg: 0,
130 detail: 1,
131 dlbls: 0,
132 hlbls: 2,
133 hosts: 0,
134 insts: 1,
135 offdev: 1,
136 ovid: 'traffic', // default to traffic overlay
137 porthl: 1,
138 spr: 0,
139 summary: 1,
140 toolbar: 0,
Sean Condon71910542019-02-16 18:16:42 +0000141 grid: 0
Sean Condonb2c483c2019-01-16 20:28:55 +0000142 };
Sean Condon0d064ec2019-02-04 21:53:53 +0000143
144 mapIdState: MapObject = <MapObject>{
145 id: undefined,
146 scale: 1.0
147 };
148 mapSelShown: boolean = false;
Sean Condon91481822019-01-01 13:56:14 +0000149 lionFn; // Function
Sean Condon55c30532018-10-29 12:26:57 +0000150
Sean Condon71910542019-02-16 18:16:42 +0000151 gridShown: boolean = true;
152 geoGridShown: boolean = true;
153
Sean Condonf4f54a12018-10-10 23:25:46 +0100154 constructor(
155 protected log: LogService,
156 protected fs: FnService,
157 protected ks: KeysService,
158 protected sus: SvgUtilService,
159 protected ps: PrefsService,
Sean Condon55c30532018-10-29 12:26:57 +0000160 protected wss: WebSocketService,
Sean Condonaa4366d2018-11-02 14:29:01 +0000161 protected ts: TopologyService,
Sean Condon91481822019-01-01 13:56:14 +0000162 protected trs: TrafficService,
163 protected is: IconService,
164 private lion: LionService,
Sean Condonf4f54a12018-10-10 23:25:46 +0100165 ) {
Sean Condon91481822019-01-01 13:56:14 +0000166 if (this.lion.ubercache.length === 0) {
167 this.lionFn = this.dummyLion;
168 this.lion.loadCbs.set('topo-toolbar', () => this.doLion());
169 } else {
170 this.doLion();
171 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100172
Sean Condon91481822019-01-01 13:56:14 +0000173 this.is.loadIconDef('bird');
174 this.is.loadIconDef('active');
175 this.is.loadIconDef('uiAttached');
176 this.is.loadIconDef('m_switch');
177 this.is.loadIconDef('m_roadm');
178 this.is.loadIconDef('m_router');
179 this.is.loadIconDef('m_uiAttached');
180 this.is.loadIconDef('m_endstation');
181 this.is.loadIconDef('m_ports');
182 this.is.loadIconDef('m_summary');
183 this.is.loadIconDef('m_details');
184 this.is.loadIconDef('m_map');
Sean Condon0d064ec2019-02-04 21:53:53 +0000185 this.is.loadIconDef('m_selectMap');
Sean Condon91481822019-01-01 13:56:14 +0000186 this.is.loadIconDef('m_cycleLabels');
Sean Condon71910542019-02-16 18:16:42 +0000187 this.is.loadIconDef('m_cycleGridDisplay');
Sean Condon91481822019-01-01 13:56:14 +0000188 this.is.loadIconDef('m_resetZoom');
189 this.is.loadIconDef('m_eqMaster');
190 this.is.loadIconDef('m_unknown');
191 this.is.loadIconDef('m_allTraffic');
192 this.is.loadIconDef('deviceTable');
193 this.is.loadIconDef('flowTable');
194 this.is.loadIconDef('portTable');
195 this.is.loadIconDef('groupTable');
196 this.is.loadIconDef('meterTable');
197 this.is.loadIconDef('triangleUp');
Sean Condonf4f54a12018-10-10 23:25:46 +0100198 this.log.debug('Topology component constructed');
199 }
200
Sean Condon91481822019-01-01 13:56:14 +0000201 /**
202 * Static functions must come before member variables
203 * @param index
204 */
Sean Condon021f0fa2018-12-06 23:31:11 -0800205 private static deviceLabelFlashMessage(index: number): string {
206 switch (index) {
Sean Condon91481822019-01-01 13:56:14 +0000207 case 0: return 'fl_device_labels_hide';
208 case 1: return 'fl_device_labels_show_friendly';
209 case 2: return 'fl_device_labels_show_id';
Sean Condon021f0fa2018-12-06 23:31:11 -0800210 }
211 }
212
213 private static hostLabelFlashMessage(index: number): string {
214 switch (index) {
Sean Condon91481822019-01-01 13:56:14 +0000215 case 0: return 'fl_host_labels_hide';
216 case 1: return 'fl_host_labels_show_friendly';
217 case 2: return 'fl_host_labels_show_ip';
218 case 3: return 'fl_host_labels_show_mac';
Sean Condon021f0fa2018-12-06 23:31:11 -0800219 }
220 }
221
Sean Condon71910542019-02-16 18:16:42 +0000222 private static gridDisplayFlashMessage(index: number): string {
223 switch (index) {
224 case 0: return 'fl_grid_display_hide';
225 case 1: return 'fl_grid_display_1000';
226 case 2: return 'fl_grid_display_geo';
227 case 3: return 'fl_grid_display_both';
228 }
229 }
230
Sean Condon91481822019-01-01 13:56:14 +0000231 /**
232 * Pass the list of Key Commands to the KeyService, and initialize the Topology
233 * Service - which communicates with through the WebSocket to the ONOS server
234 * to get the nodes and links.
235 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100236 ngOnInit() {
237 this.bindCommands();
Sean Condonaa4366d2018-11-02 14:29:01 +0000238 // The components from the template are handed over to TopologyService here
239 // so that WebSocket responses can be passed back in to them
240 // The handling of the WebSocket call is delegated out to the Topology
241 // Service just to compartmentalize things a bit
242 this.ts.init(this.instance, this.background, this.force);
Sean Condonb2c483c2019-01-16 20:28:55 +0000243
244 this.ps.addListener((data) => this.prefsUpdateHandler(data));
245 this.prefsState = this.ps.getPrefs(TOPO2_PREFS, this.prefsState);
Sean Condon0d064ec2019-02-04 21:53:53 +0000246 this.mapIdState = this.ps.getPrefs(TOPO_MAPID_PREFS, this.mapIdState);
Sean Condonf4f54a12018-10-10 23:25:46 +0100247 this.log.debug('Topology component initialized');
248 }
249
Sean Condon91481822019-01-01 13:56:14 +0000250 /**
Sean Condonb2c483c2019-01-16 20:28:55 +0000251 * Callback function that's called whenever new Prefs are received from WebSocket
252 *
253 * Note: At present the backend server does not filter updated by logged in user,
254 * so you might get updates pertaining to a different user
255 */
256 prefsUpdateHandler(data: any): void {
257 // Extract the TOPO2 prefs from it
Sean Condon0d064ec2019-02-04 21:53:53 +0000258 if (data[TOPO2_PREFS]) {
259 this.prefsState = data[TOPO2_PREFS];
260 }
Sean Condon0d064ec2019-02-04 21:53:53 +0000261 this.log.debug('Updated topo2 prefs', this.prefsState, this.mapIdState);
Sean Condonb2c483c2019-01-16 20:28:55 +0000262 }
263
264 /**
Sean Condon91481822019-01-01 13:56:14 +0000265 * When this component is being stopped, disconnect the TopologyService from
266 * the WebSocket
267 */
Sean Condonaa4366d2018-11-02 14:29:01 +0000268 ngOnDestroy() {
269 this.ts.destroy();
Sean Condonb2c483c2019-01-16 20:28:55 +0000270 this.ps.removeListener((data) => this.prefsUpdateHandler(data));
Sean Condonaa4366d2018-11-02 14:29:01 +0000271 this.log.debug('Topology component destroyed');
272 }
273
Sean Condon91481822019-01-01 13:56:14 +0000274 /**
275 * When ever a toolbar button is clicked, an event is sent up from toolbar
276 * component which is caught and passed on to here.
277 * @param name The name of the button that was clicked
278 */
279 toolbarButtonClicked(name: string) {
280 switch (name) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000281 case INSTANCE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000282 this.toggleInstancePanel();
283 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000284 case SUMMARY_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000285 this.toggleSummary();
286 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000287 case DETAILS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000288 this.toggleDetails();
289 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000290 case HOSTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000291 this.toggleHosts();
292 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000293 case OFFLINE_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000294 this.toggleOfflineDevices();
295 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000296 case PORTS_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000297 this.togglePorts();
298 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000299 case BKGRND_TOGGLE:
Sean Condon91481822019-01-01 13:56:14 +0000300 this.toggleBackground();
301 break;
Sean Condon0d064ec2019-02-04 21:53:53 +0000302 case BKGRND_SELECT:
303 this.mapSelShown = !this.mapSelShown;
304 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000305 case CYCLELABELS_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000306 this.cycleDeviceLabels();
307 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000308 case CYCLEHOSTLABEL_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000309 this.cycleHostLabels();
310 break;
Sean Condon71910542019-02-16 18:16:42 +0000311 case CYCLEGRIDDISPLAY_BTN:
312 this.cycleGridDisplay();
313 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000314 case RESETZOOM_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000315 this.resetZoom();
316 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000317 case EQMASTER_BTN:
Sean Condon91481822019-01-01 13:56:14 +0000318 this.equalizeMasters();
319 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000320 case CANCEL_TRAFFIC:
Sean Condon91481822019-01-01 13:56:14 +0000321 this.cancelTraffic();
322 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000323 case ALL_TRAFFIC:
Sean Condon91481822019-01-01 13:56:14 +0000324 this.monitorAllTraffic();
325 break;
Sean Condonb2c483c2019-01-16 20:28:55 +0000326 case QUICKHELP_BTN:
327 this.ks.quickHelpShown = true;
328 break;
Sean Condon91481822019-01-01 13:56:14 +0000329 default:
330 this.log.warn('Unhandled Toolbar action', name);
331 }
332 }
333
334 /**
335 * The list of key strokes that will be active in the Topology View.
336 *
337 * This action map is passed to the KeyService through the bindCommands()
338 * when this component is being initialized
339 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100340 actionMap() {
341 return {
Sean Condon50855cf2018-12-23 15:37:42 +0000342 A: [() => {this.monitorAllTraffic(); }, 'Monitor all traffic'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100343 B: [(token) => {this.toggleBackground(token); }, 'Toggle background'],
344 D: [(token) => {this.toggleDetails(token); }, 'Toggle details panel'],
Sean Condon71910542019-02-16 18:16:42 +0000345 E: [() => {this.equalizeMasters(); }, 'Equalize mastership roles'],
346 H: [() => {this.toggleHosts(); }, 'Toggle host visibility'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100347 I: [(token) => {this.toggleInstancePanel(token); }, 'Toggle ONOS Instance Panel'],
Sean Condon0d064ec2019-02-04 21:53:53 +0000348 G: [() => {this.mapSelShown = !this.mapSelShown; }, 'Show map selection dialog'],
Sean Condon71910542019-02-16 18:16:42 +0000349 L: [() => {this.cycleDeviceLabels(); }, 'Cycle device labels'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100350 M: [() => {this.toggleOfflineDevices(); }, 'Toggle offline visibility'],
Sean Condon71910542019-02-16 18:16:42 +0000351 O: [() => {this.toggleSummary(); }, 'Toggle the Summary Panel'],
352 P: [(token) => {this.togglePorts(token); }, 'Toggle Port Highlighting'],
353 Q: [() => {this.cycleGridDisplay(); }, 'Cycle grid display'],
354 R: [() => {this.resetZoom(); }, 'Reset pan / zoom'],
355 U: [() => {this.unpinNode(); }, 'Unpin node (mouse over)'],
356 X: [() => {this.resetNodeLocation(); }, 'Reset Node Location'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100357 dot: [() => {this.toggleToolbar(); }, 'Toggle Toolbar'],
Sean Condon50855cf2018-12-23 15:37:42 +0000358 0: [() => {this.cancelTraffic(); }, 'Cancel traffic monitoring'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100359 'shift-L': [() => {this.cycleHostLabels(); }, 'Cycle host labels'],
360
361 // -- instance color palette debug
Sean Condon55c30532018-10-29 12:26:57 +0000362 9: () => {
363 this.sus.cat7().testCard(d3.select('svg#topo2'));
Sean Condonf4f54a12018-10-10 23:25:46 +0100364 },
365
Sean Condonb2c483c2019-01-16 20:28:55 +0000366 esc: [() => {this.handleEscape(); }, 'Cancel commands'],
Sean Condonf4f54a12018-10-10 23:25:46 +0100367
368 // TODO update after adding in Background Service
369 // topology overlay selections
370 // F1: function () { t2tbs.fnKey(0); },
371 // F2: function () { t2tbs.fnKey(1); },
372 // F3: function () { t2tbs.fnKey(2); },
373 // F4: function () { t2tbs.fnKey(3); },
374 // F5: function () { t2tbs.fnKey(4); },
375 //
376 // _keyListener: t2tbs.keyListener.bind(t2tbs),
377
378 _helpFormat: [
379 ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B'],
380 ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', 'E', 'dot'],
381 [], // this column reserved for overlay actions
382 ],
383 };
384 }
385
386
387 bindCommands(additional?: any) {
388
389 const am = this.actionMap();
390 const add = this.fs.isO(additional);
391
Sean Condonf4f54a12018-10-10 23:25:46 +0100392 this.ks.keyBindings(am);
393
394 this.ks.gestureNotes([
395 ['click', 'Select the item and show details'],
396 ['shift-click', 'Toggle selection state'],
397 ['drag', 'Reposition (and pin) device / host'],
398 ['cmd-scroll', 'Zoom in / out'],
399 ['cmd-drag', 'Pan'],
400 ]);
401 }
402
403 handleEscape() {
404
405 if (false) {
406 // TODO: Cancel show mastership
407 // TODO: Cancel Active overlay
408 // TODO: Reinstate with components
409 } else {
Sean Condonb2c483c2019-01-16 20:28:55 +0000410 this.nodeSelected(undefined);
Sean Condonf4f54a12018-10-10 23:25:46 +0100411 this.log.debug('Handling escape');
412 // } else if (t2rs.deselectAllNodes()) {
413 // // else if we have node selections, deselect them all
414 // // (work already done)
415 // } else if (t2rs.deselectLink()) {
416 // // else if we have a link selection, deselect it
417 // // (work already done)
418 // } else if (t2is.isVisible()) {
419 // // If the instance panel is visible, close it
420 // t2is.toggle();
421 // } else if (t2sp.isVisible()) {
422 // // If the summary panel is visible, close it
423 // t2sp.toggle();
424 }
425 }
426
Sean Condonb2c483c2019-01-16 20:28:55 +0000427 /**
428 * Updates the cache of preferences locally and onwards to the PrefsService
429 * @param what The attribute of the local topo2-prefs cache to update
430 * @param b the value to update it with
431 */
432 updatePrefsState(what: string, b: number) {
433 this.prefsState[what] = b;
434 this.ps.setPrefs(TOPO2_PREFS, this.prefsState);
Sean Condonf4f54a12018-10-10 23:25:46 +0100435 }
436
Sean Condonb2c483c2019-01-16 20:28:55 +0000437 /**
438 * When the button is clicked on the toolbar or the L key is pressed
439 * 1) cycle through options
440 * 2) flash up a message
441 * 3a) Update the local prefs cache
442 * 3b) And passes on to the global prefs service which sends back to the server
443 * 3c) It also has a knock on effect of passing it on to ForceSvgComponent
444 * because prefsState.dlbls is given as an input to it
445 * 3d) This will in turn pass it down to the DeviceSvgComponent which
446 * displays the label
447 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100448 protected cycleDeviceLabels() {
Sean Condonb2c483c2019-01-16 20:28:55 +0000449 const old: LabelToggle = this.prefsState.dlbls;
Sean Condon021f0fa2018-12-06 23:31:11 -0800450 const next = LabelToggle.next(old);
Sean Condon91481822019-01-01 13:56:14 +0000451 this.flashMsg = this.lionFn(TopologyComponent.deviceLabelFlashMessage(next));
Sean Condonb2c483c2019-01-16 20:28:55 +0000452 this.updatePrefsState(PREF_DLBLS, next);
Sean Condon021f0fa2018-12-06 23:31:11 -0800453 this.log.debug('Cycling device labels', old, next);
Sean Condonf4f54a12018-10-10 23:25:46 +0100454 }
455
456 protected cycleHostLabels() {
Sean Condonb2c483c2019-01-16 20:28:55 +0000457 const old: HostLabelToggle = this.prefsState.hlbls;
Sean Condon021f0fa2018-12-06 23:31:11 -0800458 const next = HostLabelToggle.next(old);
Sean Condon91481822019-01-01 13:56:14 +0000459 this.flashMsg = this.lionFn(TopologyComponent.hostLabelFlashMessage(next));
Sean Condonb2c483c2019-01-16 20:28:55 +0000460 this.updatePrefsState(PREF_HLBLS, next);
Sean Condon021f0fa2018-12-06 23:31:11 -0800461 this.log.debug('Cycling host labels', old, next);
Sean Condonf4f54a12018-10-10 23:25:46 +0100462 }
463
Sean Condon71910542019-02-16 18:16:42 +0000464 protected cycleGridDisplay() {
465 const old: GridDisplayToggle = this.prefsState.grid;
466 const next = GridDisplayToggle.next(old);
467 this.flashMsg = this.lionFn(TopologyComponent.gridDisplayFlashMessage(next));
468 this.updatePrefsState(PREF_GRID, next);
469 this.log.debug('Cycling grid display', old, next);
470 }
471
Sean Condonb2c483c2019-01-16 20:28:55 +0000472 /**
473 * When the button is clicked on the toolbar or the B key is pressed
474 * 1) Find the inverse of the current state (held as 1 or 0)
475 * 2) Flash up a message on screen
476 * 3b) And passes on to the global prefs service which sends back to the server
477 * 3c) It also has a knock on effect of passing it on to ToolbarComponent
478 * because prefsState.bg is given as an input to it
479 * @param token
480 */
Sean Condon91481822019-01-01 13:56:14 +0000481 protected toggleBackground(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000482 const bg: boolean = !Boolean(this.prefsState.bg);
483 this.flashMsg = this.lionFn(bg ? 'show' : 'hide') +
Sean Condon91481822019-01-01 13:56:14 +0000484 ' ' + this.lionFn('fl_background_map');
Sean Condonb2c483c2019-01-16 20:28:55 +0000485 this.updatePrefsState(PREF_BG, bg ? 1 : 0);
486 this.log.debug('Toggling background', token, bg ? 'shown' : 'hidden');
Sean Condonf4f54a12018-10-10 23:25:46 +0100487 }
488
Sean Condon91481822019-01-01 13:56:14 +0000489 protected toggleDetails(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000490 const on: boolean = !Boolean(this.prefsState.detail);
491 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
492 ' ' + this.lionFn('fl_panel_details');
493 this.updatePrefsState(PREF_DETAIL, on ? 1 : 0);
494 this.log.debug('Toggling details', token);
Sean Condonf4f54a12018-10-10 23:25:46 +0100495 }
496
Sean Condon91481822019-01-01 13:56:14 +0000497 protected toggleInstancePanel(token?: KeysToken) {
Sean Condonb2c483c2019-01-16 20:28:55 +0000498 const on: boolean = !Boolean(this.prefsState.insts);
Sean Condon91481822019-01-01 13:56:14 +0000499 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
500 ' ' + this.lionFn('fl_panel_instances');
Sean Condonb2c483c2019-01-16 20:28:55 +0000501 this.updatePrefsState(PREF_INSTS, on ? 1 : 0);
Sean Condon91481822019-01-01 13:56:14 +0000502 this.log.debug('Toggling instances', token, on);
Sean Condonf4f54a12018-10-10 23:25:46 +0100503 }
504
505 protected toggleSummary() {
Sean Condonb2c483c2019-01-16 20:28:55 +0000506 const on: boolean = !Boolean(this.prefsState.summary);
Sean Condon91481822019-01-01 13:56:14 +0000507 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
508 ' ' + this.lionFn('fl_panel_summary');
Sean Condonb2c483c2019-01-16 20:28:55 +0000509 this.updatePrefsState(PREF_SUMMARY, on ? 1 : 0);
510 }
511
512 protected togglePorts(token?: KeysToken) {
513 const current: boolean = !Boolean(this.prefsState.porthl);
514 this.flashMsg = this.lionFn(current ? 'enable' : 'disable') +
515 ' ' + this.lionFn('fl_port_highlighting');
516 this.updatePrefsState(PREF_PORTHL, current ? 1 : 0);
517 this.log.debug(current ? 'Enable' : 'Disable', 'port highlighting');
518 }
519
520 protected toggleToolbar() {
521 const on: boolean = !Boolean(this.prefsState.toolbar);
522 this.updatePrefsState(PREF_TOOLBAR, on ? 1 : 0);
523 this.log.debug('toggling toolbar', on ? 'shown' : 'hidden');
524 }
525
526 protected toggleHosts() {
527 const current: boolean = !Boolean(this.prefsState.hosts);
528 this.flashMsg = this.lionFn('hosts') + ' ' +
529 this.lionFn(this.force.showHosts ? 'visible' : 'hidden');
530 this.updatePrefsState(PREF_HOSTS, current ? 1 : 0);
531 this.log.debug('toggling hosts: ', this.prefsState.hosts ? 'Show' : 'Hide');
532 }
533
534 protected toggleOfflineDevices() {
535 const on: boolean = !Boolean(this.prefsState.offdev);
536 this.flashMsg = this.lionFn(on ? 'show' : 'hide') +
537 ' ' + this.lionFn('fl_offline_devices');
538 this.updatePrefsState(PREF_OFFDEV, on ? 1 : 0);
539 this.log.debug('toggling offline devices', this.prefsState.offdev);
Sean Condonf4f54a12018-10-10 23:25:46 +0100540 }
541
542 protected resetZoom() {
Sean Condon91481822019-01-01 13:56:14 +0000543 this.zoomDirective.resetZoom();
544 this.flashMsg = this.lionFn('fl_pan_zoom_reset');
Sean Condonf4f54a12018-10-10 23:25:46 +0100545 }
546
Sean Condonf4f54a12018-10-10 23:25:46 +0100547 protected equalizeMasters() {
548 this.wss.sendEvent('equalizeMasters', null);
Sean Condon91481822019-01-01 13:56:14 +0000549 this.flashMsg = this.lionFn('fl_eq_masters');
Sean Condonf4f54a12018-10-10 23:25:46 +0100550 this.log.debug('equalizing masters');
Sean Condonf4f54a12018-10-10 23:25:46 +0100551 }
552
553 protected resetNodeLocation() {
Sean Condon91481822019-01-01 13:56:14 +0000554 // TODO: Implement reset locations
555 this.flashMsg = this.lionFn('fl_reset_node_locations');
Sean Condonf4f54a12018-10-10 23:25:46 +0100556 this.log.debug('resetting node location');
Sean Condonf4f54a12018-10-10 23:25:46 +0100557 }
558
559 protected unpinNode() {
Sean Condon91481822019-01-01 13:56:14 +0000560 // TODO: Implement this
Sean Condonf4f54a12018-10-10 23:25:46 +0100561 this.log.debug('unpinning node');
Sean Condonf4f54a12018-10-10 23:25:46 +0100562 }
563
Sean Condon91481822019-01-01 13:56:14 +0000564 /**
565 * Check to see if this is needed anymore
566 * @param what
567 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100568 protected notValid(what) {
569 this.log.warn('topo.js getActionEntry(): Not a valid ' + what);
570 }
571
Sean Condon91481822019-01-01 13:56:14 +0000572 /**
573 * Check to see if this is needed anymore
574 * @param what
575 */
Sean Condonf4f54a12018-10-10 23:25:46 +0100576 getActionEntry(key) {
577 let entry;
578
579 if (!key) {
580 this.notValid('key');
581 return null;
582 }
583
584 entry = this.actionMap()[key];
585
586 if (!entry) {
587 this.notValid('actionMap (' + key + ') entry');
588 return null;
589 }
590 return this.fs.isA(entry) || [entry, ''];
591 }
592
Sean Condon91481822019-01-01 13:56:14 +0000593 /**
594 * An event handler that updates the details panel as items are
595 * selected in the forcesvg layer
596 * @param nodeOrLink the item to display details of
597 */
598 nodeSelected(nodeOrLink: UiElement) {
599 this.details.ngOnChanges({'selectedNode':
600 new SimpleChange(undefined, nodeOrLink, true)});
Sean Condon0c577f62018-11-18 22:40:05 +0000601 }
602
Sean Condon50855cf2018-12-23 15:37:42 +0000603 /**
604 * Enable traffic monitoring
605 */
606 monitorAllTraffic() {
Sean Condon91481822019-01-01 13:56:14 +0000607 // TODO: Implement support for toggling between bits, packets and octets
608 this.flashMsg = this.lionFn('tr_fl_pstats_bits');
Sean Condon50855cf2018-12-23 15:37:42 +0000609 this.trs.init(this.force);
610 }
611
612 /**
613 * Cancel traffic monitoring
614 */
615 cancelTraffic() {
Sean Condon91481822019-01-01 13:56:14 +0000616 this.flashMsg = this.lionFn('fl_monitoring_canceled');
Sean Condon50855cf2018-12-23 15:37:42 +0000617 this.trs.destroy();
618 }
Sean Condon91481822019-01-01 13:56:14 +0000619
Sean Condon0d064ec2019-02-04 21:53:53 +0000620 changeMap(map: MapObject) {
621 this.mapSelShown = false; // Hide the MapSelector component
622 this.mapIdState = map;
623 this.ps.setPrefs(TOPO_MAPID_PREFS, this.mapIdState);
624 this.log.debug('Map has been changed to ', map);
625 }
626
Sean Condon91481822019-01-01 13:56:14 +0000627 /**
628 * Read the LION bundle for Toolbar and set up the lionFn
629 */
630 doLion() {
631 this.lionFn = this.lion.bundle('core.view.Topo');
632 }
633
634 /**
635 * A dummy implementation of the lionFn until the response is received and the LION
636 * bundle is received from the WebSocket
637 */
638 dummyLion(key: string): string {
639 return '%' + key + '%';
640 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100641}