Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 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 | */ |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 16 | import { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 17 | AfterContentInit, |
| 18 | Component, HostListener, Inject, Input, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 19 | OnDestroy, |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 20 | OnInit, SimpleChange, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 21 | ViewChild |
| 22 | } from '@angular/core'; |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 23 | import * as d3 from 'd3'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 24 | import { |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 25 | FnService, |
| 26 | IconService, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 27 | KeysService, |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 28 | KeysToken, |
| 29 | LionService, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 30 | LogService, |
| 31 | PrefsService, |
| 32 | SvgUtilService, |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 33 | TopoZoomPrefs, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 34 | WebSocketService, |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 35 | ZoomUtils |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 36 | } from 'gui2-fw-lib'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 37 | import {InstanceComponent} from '../panel/instance/instance.component'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 38 | import {DetailsComponent} from '../panel/details/details.component'; |
| 39 | import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component'; |
| 40 | import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component'; |
| 41 | import {TopologyService} from '../topology.service'; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 42 | import { |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 43 | GridDisplayToggle, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 44 | HostLabelToggle, |
| 45 | LabelToggle, |
| 46 | UiElement |
| 47 | } from '../layer/forcesvg/models'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 48 | import { |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 49 | 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 Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 67 | } from '../panel/toolbar/toolbar.component'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 68 | import {TrafficService} from '../traffic.service'; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 69 | import {ZoomableDirective} from '../layer/zoomable.directive'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 70 | import {MapObject} from '../layer/maputils'; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 71 | import {LayoutService, LayoutType} from '../layout.service'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 72 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 73 | const TOPO2_PREFS = 'topo2_prefs'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 74 | const TOPO_MAPID_PREFS = 'topo_mapid'; |
| 75 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 76 | const PREF_BG = 'bg'; |
| 77 | const PREF_DETAIL = 'detail'; |
| 78 | const PREF_DLBLS = 'dlbls'; |
| 79 | const PREF_HLBLS = 'hlbls'; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 80 | const PREF_GRID = 'grid'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 81 | const PREF_HOSTS = 'hosts'; |
| 82 | const PREF_INSTS = 'insts'; |
| 83 | const PREF_OFFDEV = 'offdev'; |
| 84 | const PREF_PORTHL = 'porthl'; |
| 85 | const PREF_SUMMARY = 'summary'; |
| 86 | const PREF_TOOLBAR = 'toolbar'; |
| 87 | |
| 88 | /** |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 89 | * Model of the topo2_prefs object - this is a subset of the overall Prefs returned |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 90 | * by the server |
| 91 | */ |
| 92 | export interface Topo2Prefs { |
| 93 | bg: number; |
| 94 | detail: number; |
| 95 | dlbls: number; |
| 96 | hlbls: number; |
| 97 | hosts: number; |
| 98 | insts: number; |
| 99 | offdev: number; |
| 100 | porthl: number; |
| 101 | spr: number; |
| 102 | ovid: string; |
| 103 | summary: number; |
| 104 | toolbar: number; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 105 | grid: number; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 108 | /** |
| 109 | * ONOS GUI Topology View |
| 110 | * |
| 111 | * This Topology View component is the top level component in a hierarchy that |
| 112 | * comprises the whole Topology View |
| 113 | * |
| 114 | * There are three main parts (panels, graphical and breadcrumbs) |
| 115 | * The panel hierarchy |
| 116 | * |-- Instances Panel (shows ONOS instances) |
| 117 | * |-- Summary Panel (summary of ONOS) |
| 118 | * |-- Toolbar Panel (the toolbar) |
| 119 | * |-- Details Panel (when a node is selected in the Force graphical view (see below)) |
| 120 | * |
| 121 | * The graphical hierarchy contains |
| 122 | * Topology (this) |
| 123 | * |-- No Devices Connected (only of there are no nodes to show) |
| 124 | * |-- Zoom Layer (everything beneath this can be zoomed and panned) |
| 125 | * |-- Background (container for any backgrounds - can be toggled on and off) |
| 126 | * |-- Map |
| 127 | * |-- Forces (all of the nodes and links laid out by a d3.force simulation) |
| 128 | * |
| 129 | * The breadcrumbs |
| 130 | * |-- Breadcrumb (in region view a way of navigating back up through regions) |
| 131 | */ |
| 132 | @Component({ |
| 133 | selector: 'onos-topology', |
| 134 | templateUrl: './topology.component.html', |
| 135 | styleUrls: ['./topology.component.css'] |
| 136 | }) |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 137 | export class TopologyComponent implements AfterContentInit, OnInit, OnDestroy { |
| 138 | @Input() bannerHeight: number = 48; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 139 | // These are references to the components inserted in the template |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 140 | @ViewChild(InstanceComponent) instance: InstanceComponent; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 141 | @ViewChild(DetailsComponent) details: DetailsComponent; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 142 | @ViewChild(BackgroundSvgComponent) background: BackgroundSvgComponent; |
| 143 | @ViewChild(ForceSvgComponent) force: ForceSvgComponent; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 144 | @ViewChild(ZoomableDirective) zoomDirective: ZoomableDirective; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 145 | |
| 146 | flashMsg: string = ''; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 147 | // These are used as defaults if nothing is set on the server |
| 148 | prefsState: Topo2Prefs = <Topo2Prefs>{ |
| 149 | bg: 0, |
| 150 | detail: 1, |
| 151 | dlbls: 0, |
| 152 | hlbls: 2, |
| 153 | hosts: 0, |
| 154 | insts: 1, |
| 155 | offdev: 1, |
| 156 | ovid: 'traffic', // default to traffic overlay |
| 157 | porthl: 1, |
| 158 | spr: 0, |
| 159 | summary: 1, |
| 160 | toolbar: 0, |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 161 | grid: 0 |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 162 | }; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 163 | |
| 164 | mapIdState: MapObject = <MapObject>{ |
| 165 | id: undefined, |
| 166 | scale: 1.0 |
| 167 | }; |
| 168 | mapSelShown: boolean = false; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 169 | lionFn; // Function |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 170 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 171 | gridShown: boolean = true; |
| 172 | geoGridShown: boolean = true; |
| 173 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 174 | constructor( |
| 175 | protected log: LogService, |
| 176 | protected fs: FnService, |
| 177 | protected ks: KeysService, |
| 178 | protected sus: SvgUtilService, |
| 179 | protected ps: PrefsService, |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 180 | protected wss: WebSocketService, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 181 | protected ts: TopologyService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 182 | protected trs: TrafficService, |
| 183 | protected is: IconService, |
| 184 | private lion: LionService, |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 185 | private layout: LayoutService, |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 186 | @Inject('Window') public window: any, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 187 | ) { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 188 | if (this.lion.ubercache.length === 0) { |
| 189 | this.lionFn = this.dummyLion; |
| 190 | this.lion.loadCbs.set('topo-toolbar', () => this.doLion()); |
| 191 | } else { |
| 192 | this.doLion(); |
| 193 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 194 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 195 | this.is.loadIconDef('bird'); |
| 196 | this.is.loadIconDef('active'); |
| 197 | this.is.loadIconDef('uiAttached'); |
| 198 | this.is.loadIconDef('m_switch'); |
| 199 | this.is.loadIconDef('m_roadm'); |
| 200 | this.is.loadIconDef('m_router'); |
| 201 | this.is.loadIconDef('m_uiAttached'); |
| 202 | this.is.loadIconDef('m_endstation'); |
| 203 | this.is.loadIconDef('m_ports'); |
| 204 | this.is.loadIconDef('m_summary'); |
| 205 | this.is.loadIconDef('m_details'); |
| 206 | this.is.loadIconDef('m_map'); |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 207 | this.is.loadIconDef('m_selectMap'); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 208 | this.is.loadIconDef('m_cycleLabels'); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 209 | this.is.loadIconDef('m_cycleGridDisplay'); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 210 | this.is.loadIconDef('m_resetZoom'); |
| 211 | this.is.loadIconDef('m_eqMaster'); |
| 212 | this.is.loadIconDef('m_unknown'); |
| 213 | this.is.loadIconDef('m_allTraffic'); |
| 214 | this.is.loadIconDef('deviceTable'); |
| 215 | this.is.loadIconDef('flowTable'); |
| 216 | this.is.loadIconDef('portTable'); |
| 217 | this.is.loadIconDef('groupTable'); |
| 218 | this.is.loadIconDef('meterTable'); |
| 219 | this.is.loadIconDef('triangleUp'); |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 220 | this.is.loadIconDef('m_disjointPaths'); |
| 221 | this.is.loadIconDef('m_fiberSwitch'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 222 | this.log.debug('Topology component constructed'); |
| 223 | } |
| 224 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 225 | /** |
| 226 | * Static functions must come before member variables |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 227 | * @param index Corresponds to LabelToggle.Enum index |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 228 | */ |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 229 | private static deviceLabelFlashMessage(index: number): string { |
| 230 | switch (index) { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 231 | case 0: return 'fl_device_labels_hide'; |
| 232 | case 1: return 'fl_device_labels_show_friendly'; |
| 233 | case 2: return 'fl_device_labels_show_id'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
| 237 | private static hostLabelFlashMessage(index: number): string { |
| 238 | switch (index) { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 239 | case 0: return 'fl_host_labels_hide'; |
| 240 | case 1: return 'fl_host_labels_show_friendly'; |
| 241 | case 2: return 'fl_host_labels_show_ip'; |
| 242 | case 3: return 'fl_host_labels_show_mac'; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 246 | private static gridDisplayFlashMessage(index: number): string { |
| 247 | switch (index) { |
| 248 | case 0: return 'fl_grid_display_hide'; |
| 249 | case 1: return 'fl_grid_display_1000'; |
| 250 | case 2: return 'fl_grid_display_geo'; |
| 251 | case 3: return 'fl_grid_display_both'; |
| 252 | } |
| 253 | } |
| 254 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 255 | /** |
| 256 | * Pass the list of Key Commands to the KeyService, and initialize the Topology |
| 257 | * Service - which communicates with through the WebSocket to the ONOS server |
| 258 | * to get the nodes and links. |
| 259 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 260 | ngOnInit() { |
| 261 | this.bindCommands(); |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 262 | // The components from the template are handed over to TopologyService here |
| 263 | // so that WebSocket responses can be passed back in to them |
| 264 | // The handling of the WebSocket call is delegated out to the Topology |
| 265 | // Service just to compartmentalize things a bit |
| 266 | this.ts.init(this.instance, this.background, this.force); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 267 | |
| 268 | this.ps.addListener((data) => this.prefsUpdateHandler(data)); |
| 269 | this.prefsState = this.ps.getPrefs(TOPO2_PREFS, this.prefsState); |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 270 | this.mapIdState = this.ps.getPrefs(TOPO_MAPID_PREFS, this.mapIdState); |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 271 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 272 | this.log.debug('Topology component initialized'); |
| 273 | } |
| 274 | |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 275 | ngAfterContentInit(): void { |
| 276 | // Scale the window initially - then after resize |
| 277 | const zoomMapExtents = ZoomUtils.zoomToWindowSize( |
| 278 | this.bannerHeight, this.window.innerWidth, this.window.innerHeight); |
| 279 | this.zoomDirective.changeZoomLevel(zoomMapExtents, true); |
| 280 | this.log.debug('Topology zoom initialized', |
| 281 | this.bannerHeight, this.window.innerWidth, this.window.innerHeight, |
| 282 | zoomMapExtents); |
| 283 | } |
| 284 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 285 | /** |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 286 | * Callback function that's called whenever new Prefs are received from WebSocket |
| 287 | * |
| 288 | * Note: At present the backend server does not filter updated by logged in user, |
| 289 | * so you might get updates pertaining to a different user |
| 290 | */ |
| 291 | prefsUpdateHandler(data: any): void { |
| 292 | // Extract the TOPO2 prefs from it |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 293 | if (data[TOPO2_PREFS]) { |
| 294 | this.prefsState = data[TOPO2_PREFS]; |
| 295 | } |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 296 | this.log.debug('Updated topo2 prefs', this.prefsState, this.mapIdState); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /** |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 300 | * When this component is being stopped, disconnect the TopologyService from |
| 301 | * the WebSocket |
| 302 | */ |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 303 | ngOnDestroy() { |
| 304 | this.ts.destroy(); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 305 | this.ps.removeListener((data) => this.prefsUpdateHandler(data)); |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 306 | this.log.debug('Topology component destroyed'); |
| 307 | } |
| 308 | |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 309 | @HostListener('window:resize', ['$event']) |
| 310 | onResize(event) { |
| 311 | const zoomMapExtents = ZoomUtils.zoomToWindowSize( |
| 312 | this.bannerHeight, event.target.innerWidth, event.target.innerHeight); |
| 313 | this.zoomDirective.changeZoomLevel(zoomMapExtents, true); |
| 314 | this.log.debug('Topology window resize', |
| 315 | event.target.innerWidth, event.target.innerHeight, this.bannerHeight, zoomMapExtents); |
| 316 | } |
| 317 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 318 | /** |
| 319 | * When ever a toolbar button is clicked, an event is sent up from toolbar |
| 320 | * component which is caught and passed on to here. |
| 321 | * @param name The name of the button that was clicked |
| 322 | */ |
| 323 | toolbarButtonClicked(name: string) { |
| 324 | switch (name) { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 325 | case INSTANCE_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 326 | this.toggleInstancePanel(); |
| 327 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 328 | case SUMMARY_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 329 | this.toggleSummary(); |
| 330 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 331 | case DETAILS_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 332 | this.toggleDetails(); |
| 333 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 334 | case HOSTS_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 335 | this.toggleHosts(); |
| 336 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 337 | case OFFLINE_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 338 | this.toggleOfflineDevices(); |
| 339 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 340 | case PORTS_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 341 | this.togglePorts(); |
| 342 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 343 | case BKGRND_TOGGLE: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 344 | this.toggleBackground(); |
| 345 | break; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 346 | case BKGRND_SELECT: |
| 347 | this.mapSelShown = !this.mapSelShown; |
| 348 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 349 | case CYCLELABELS_BTN: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 350 | this.cycleDeviceLabels(); |
| 351 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 352 | case CYCLEHOSTLABEL_BTN: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 353 | this.cycleHostLabels(); |
| 354 | break; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 355 | case CYCLEGRIDDISPLAY_BTN: |
| 356 | this.cycleGridDisplay(); |
| 357 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 358 | case RESETZOOM_BTN: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 359 | this.resetZoom(); |
| 360 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 361 | case EQMASTER_BTN: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 362 | this.equalizeMasters(); |
| 363 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 364 | case CANCEL_TRAFFIC: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 365 | this.cancelTraffic(); |
| 366 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 367 | case ALL_TRAFFIC: |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 368 | this.monitorAllTraffic(); |
| 369 | break; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 370 | case QUICKHELP_BTN: |
| 371 | this.ks.quickHelpShown = true; |
| 372 | break; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 373 | case LAYOUT_DEFAULT_BTN: |
| 374 | this.layout.changeLayout(LayoutType.LAYOUT_DEFAULT); |
| 375 | break; |
| 376 | case LAYOUT_ACCESS_BTN: |
| 377 | this.layout.changeLayout(LayoutType.LAYOUT_ACCESS); |
| 378 | break; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 379 | default: |
| 380 | this.log.warn('Unhandled Toolbar action', name); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * The list of key strokes that will be active in the Topology View. |
| 386 | * |
| 387 | * This action map is passed to the KeyService through the bindCommands() |
| 388 | * when this component is being initialized |
| 389 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 390 | actionMap() { |
| 391 | return { |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 392 | A: [() => {this.monitorAllTraffic(); }, 'Monitor all traffic'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 393 | B: [(token) => {this.toggleBackground(token); }, 'Toggle background'], |
| 394 | D: [(token) => {this.toggleDetails(token); }, 'Toggle details panel'], |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 395 | E: [() => {this.equalizeMasters(); }, 'Equalize mastership roles'], |
| 396 | H: [() => {this.toggleHosts(); }, 'Toggle host visibility'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 397 | I: [(token) => {this.toggleInstancePanel(token); }, 'Toggle ONOS Instance Panel'], |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 398 | G: [() => {this.mapSelShown = !this.mapSelShown; }, 'Show map selection dialog'], |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 399 | L: [() => {this.cycleDeviceLabels(); }, 'Cycle device labels'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 400 | M: [() => {this.toggleOfflineDevices(); }, 'Toggle offline visibility'], |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 401 | O: [() => {this.toggleSummary(); }, 'Toggle the Summary Panel'], |
| 402 | P: [(token) => {this.togglePorts(token); }, 'Toggle Port Highlighting'], |
| 403 | Q: [() => {this.cycleGridDisplay(); }, 'Cycle grid display'], |
| 404 | R: [() => {this.resetZoom(); }, 'Reset pan / zoom'], |
| 405 | U: [() => {this.unpinNode(); }, 'Unpin node (mouse over)'], |
| 406 | X: [() => {this.resetNodeLocation(); }, 'Reset Node Location'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 407 | dot: [() => {this.toggleToolbar(); }, 'Toggle Toolbar'], |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 408 | 0: [() => {this.cancelTraffic(); }, 'Cancel traffic monitoring'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 409 | 'shift-L': [() => {this.cycleHostLabels(); }, 'Cycle host labels'], |
| 410 | |
| 411 | // -- instance color palette debug |
Sean Condon | 55c3053 | 2018-10-29 12:26:57 +0000 | [diff] [blame] | 412 | 9: () => { |
| 413 | this.sus.cat7().testCard(d3.select('svg#topo2')); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 414 | }, |
| 415 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 416 | esc: [() => {this.handleEscape(); }, 'Cancel commands'], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 417 | |
| 418 | // TODO update after adding in Background Service |
| 419 | // topology overlay selections |
| 420 | // F1: function () { t2tbs.fnKey(0); }, |
| 421 | // F2: function () { t2tbs.fnKey(1); }, |
| 422 | // F3: function () { t2tbs.fnKey(2); }, |
| 423 | // F4: function () { t2tbs.fnKey(3); }, |
| 424 | // F5: function () { t2tbs.fnKey(4); }, |
| 425 | // |
| 426 | // _keyListener: t2tbs.keyListener.bind(t2tbs), |
| 427 | |
| 428 | _helpFormat: [ |
| 429 | ['I', 'O', 'D', 'H', 'M', 'P', 'dash', 'B'], |
| 430 | ['X', 'Z', 'N', 'L', 'shift-L', 'U', 'R', 'E', 'dot'], |
| 431 | [], // this column reserved for overlay actions |
| 432 | ], |
| 433 | }; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | bindCommands(additional?: any) { |
| 438 | |
| 439 | const am = this.actionMap(); |
| 440 | const add = this.fs.isO(additional); |
| 441 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 442 | this.ks.keyBindings(am); |
| 443 | |
| 444 | this.ks.gestureNotes([ |
| 445 | ['click', 'Select the item and show details'], |
| 446 | ['shift-click', 'Toggle selection state'], |
| 447 | ['drag', 'Reposition (and pin) device / host'], |
| 448 | ['cmd-scroll', 'Zoom in / out'], |
| 449 | ['cmd-drag', 'Pan'], |
| 450 | ]); |
| 451 | } |
| 452 | |
| 453 | handleEscape() { |
| 454 | |
| 455 | if (false) { |
| 456 | // TODO: Cancel show mastership |
| 457 | // TODO: Cancel Active overlay |
| 458 | // TODO: Reinstate with components |
| 459 | } else { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 460 | this.nodeSelected(undefined); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 461 | this.log.debug('Handling escape'); |
| 462 | // } else if (t2rs.deselectAllNodes()) { |
| 463 | // // else if we have node selections, deselect them all |
| 464 | // // (work already done) |
| 465 | // } else if (t2rs.deselectLink()) { |
| 466 | // // else if we have a link selection, deselect it |
| 467 | // // (work already done) |
| 468 | // } else if (t2is.isVisible()) { |
| 469 | // // If the instance panel is visible, close it |
| 470 | // t2is.toggle(); |
| 471 | // } else if (t2sp.isVisible()) { |
| 472 | // // If the summary panel is visible, close it |
| 473 | // t2sp.toggle(); |
| 474 | } |
| 475 | } |
| 476 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 477 | /** |
| 478 | * Updates the cache of preferences locally and onwards to the PrefsService |
| 479 | * @param what The attribute of the local topo2-prefs cache to update |
| 480 | * @param b the value to update it with |
| 481 | */ |
| 482 | updatePrefsState(what: string, b: number) { |
| 483 | this.prefsState[what] = b; |
| 484 | this.ps.setPrefs(TOPO2_PREFS, this.prefsState); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 485 | } |
| 486 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 487 | /** |
| 488 | * When the button is clicked on the toolbar or the L key is pressed |
| 489 | * 1) cycle through options |
| 490 | * 2) flash up a message |
| 491 | * 3a) Update the local prefs cache |
| 492 | * 3b) And passes on to the global prefs service which sends back to the server |
| 493 | * 3c) It also has a knock on effect of passing it on to ForceSvgComponent |
| 494 | * because prefsState.dlbls is given as an input to it |
| 495 | * 3d) This will in turn pass it down to the DeviceSvgComponent which |
| 496 | * displays the label |
| 497 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 498 | protected cycleDeviceLabels() { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 499 | const old: LabelToggle.Enum = this.prefsState.dlbls; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 500 | const next = LabelToggle.next(old); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 501 | this.flashMsg = this.lionFn(TopologyComponent.deviceLabelFlashMessage(next)); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 502 | this.updatePrefsState(PREF_DLBLS, next); |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 503 | this.log.debug('Cycling device labels', old, next); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | protected cycleHostLabels() { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 507 | const old: HostLabelToggle.Enum = this.prefsState.hlbls; |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 508 | const next = HostLabelToggle.next(old); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 509 | this.flashMsg = this.lionFn(TopologyComponent.hostLabelFlashMessage(next)); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 510 | this.updatePrefsState(PREF_HLBLS, next); |
Sean Condon | 021f0fa | 2018-12-06 23:31:11 -0800 | [diff] [blame] | 511 | this.log.debug('Cycling host labels', old, next); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 514 | protected cycleGridDisplay() { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 515 | const old: GridDisplayToggle.Enum = this.prefsState.grid; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 516 | const next = GridDisplayToggle.next(old); |
| 517 | this.flashMsg = this.lionFn(TopologyComponent.gridDisplayFlashMessage(next)); |
| 518 | this.updatePrefsState(PREF_GRID, next); |
| 519 | this.log.debug('Cycling grid display', old, next); |
| 520 | } |
| 521 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 522 | /** |
| 523 | * When the button is clicked on the toolbar or the B key is pressed |
| 524 | * 1) Find the inverse of the current state (held as 1 or 0) |
| 525 | * 2) Flash up a message on screen |
| 526 | * 3b) And passes on to the global prefs service which sends back to the server |
| 527 | * 3c) It also has a knock on effect of passing it on to ToolbarComponent |
| 528 | * because prefsState.bg is given as an input to it |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 529 | * @param token not currently used |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 530 | */ |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 531 | protected toggleBackground(token?: KeysToken) { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 532 | const bg: boolean = !Boolean(this.prefsState.bg); |
| 533 | this.flashMsg = this.lionFn(bg ? 'show' : 'hide') + |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 534 | ' ' + this.lionFn('fl_background_map'); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 535 | this.updatePrefsState(PREF_BG, bg ? 1 : 0); |
| 536 | this.log.debug('Toggling background', token, bg ? 'shown' : 'hidden'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 537 | } |
| 538 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 539 | protected toggleDetails(token?: KeysToken) { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 540 | const on: boolean = !Boolean(this.prefsState.detail); |
| 541 | this.flashMsg = this.lionFn(on ? 'show' : 'hide') + |
| 542 | ' ' + this.lionFn('fl_panel_details'); |
| 543 | this.updatePrefsState(PREF_DETAIL, on ? 1 : 0); |
| 544 | this.log.debug('Toggling details', token); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 547 | protected toggleInstancePanel(token?: KeysToken) { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 548 | const on: boolean = !Boolean(this.prefsState.insts); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 549 | this.flashMsg = this.lionFn(on ? 'show' : 'hide') + |
| 550 | ' ' + this.lionFn('fl_panel_instances'); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 551 | this.updatePrefsState(PREF_INSTS, on ? 1 : 0); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 552 | this.log.debug('Toggling instances', token, on); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | protected toggleSummary() { |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 556 | const on: boolean = !Boolean(this.prefsState.summary); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 557 | this.flashMsg = this.lionFn(on ? 'show' : 'hide') + |
| 558 | ' ' + this.lionFn('fl_panel_summary'); |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 559 | this.updatePrefsState(PREF_SUMMARY, on ? 1 : 0); |
| 560 | } |
| 561 | |
| 562 | protected togglePorts(token?: KeysToken) { |
| 563 | const current: boolean = !Boolean(this.prefsState.porthl); |
| 564 | this.flashMsg = this.lionFn(current ? 'enable' : 'disable') + |
| 565 | ' ' + this.lionFn('fl_port_highlighting'); |
| 566 | this.updatePrefsState(PREF_PORTHL, current ? 1 : 0); |
| 567 | this.log.debug(current ? 'Enable' : 'Disable', 'port highlighting'); |
| 568 | } |
| 569 | |
| 570 | protected toggleToolbar() { |
| 571 | const on: boolean = !Boolean(this.prefsState.toolbar); |
| 572 | this.updatePrefsState(PREF_TOOLBAR, on ? 1 : 0); |
| 573 | this.log.debug('toggling toolbar', on ? 'shown' : 'hidden'); |
| 574 | } |
| 575 | |
| 576 | protected toggleHosts() { |
| 577 | const current: boolean = !Boolean(this.prefsState.hosts); |
| 578 | this.flashMsg = this.lionFn('hosts') + ' ' + |
| 579 | this.lionFn(this.force.showHosts ? 'visible' : 'hidden'); |
| 580 | this.updatePrefsState(PREF_HOSTS, current ? 1 : 0); |
| 581 | this.log.debug('toggling hosts: ', this.prefsState.hosts ? 'Show' : 'Hide'); |
| 582 | } |
| 583 | |
| 584 | protected toggleOfflineDevices() { |
| 585 | const on: boolean = !Boolean(this.prefsState.offdev); |
| 586 | this.flashMsg = this.lionFn(on ? 'show' : 'hide') + |
| 587 | ' ' + this.lionFn('fl_offline_devices'); |
| 588 | this.updatePrefsState(PREF_OFFDEV, on ? 1 : 0); |
| 589 | this.log.debug('toggling offline devices', this.prefsState.offdev); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | protected resetZoom() { |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 593 | const zoomMapExtents = ZoomUtils.zoomToWindowSize( |
| 594 | this.bannerHeight, this.window.innerWidth, this.window.innerHeight); |
| 595 | this.zoomDirective.changeZoomLevel(zoomMapExtents, false); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 596 | this.flashMsg = this.lionFn('fl_pan_zoom_reset'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 599 | protected equalizeMasters() { |
| 600 | this.wss.sendEvent('equalizeMasters', null); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 601 | this.flashMsg = this.lionFn('fl_eq_masters'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 602 | this.log.debug('equalizing masters'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | protected resetNodeLocation() { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 606 | // TODO: Implement reset locations |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 607 | this.force.resetNodeLocations(); |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 608 | this.flashMsg = this.lionFn('fl_reset_node_locations'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 609 | this.log.debug('resetting node location'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | protected unpinNode() { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 613 | // TODO: Implement this |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 614 | this.log.debug('unpinning node'); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 615 | } |
| 616 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 617 | /** |
| 618 | * Check to see if this is needed anymore |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 619 | * @param what - a key stroke |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 620 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 621 | protected notValid(what) { |
| 622 | this.log.warn('topo.js getActionEntry(): Not a valid ' + what); |
| 623 | } |
| 624 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 625 | /** |
| 626 | * Check to see if this is needed anymore |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 627 | * @param key - a key stroke |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 628 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 629 | getActionEntry(key) { |
| 630 | let entry; |
| 631 | |
| 632 | if (!key) { |
| 633 | this.notValid('key'); |
| 634 | return null; |
| 635 | } |
| 636 | |
| 637 | entry = this.actionMap()[key]; |
| 638 | |
| 639 | if (!entry) { |
| 640 | this.notValid('actionMap (' + key + ') entry'); |
| 641 | return null; |
| 642 | } |
| 643 | return this.fs.isA(entry) || [entry, '']; |
| 644 | } |
| 645 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 646 | /** |
| 647 | * An event handler that updates the details panel as items are |
| 648 | * selected in the forcesvg layer |
Sean Condon | d88f366 | 2019-04-03 16:35:30 +0100 | [diff] [blame] | 649 | * |
| 650 | * @param nodesOrLink the item(s) to display details of |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 651 | */ |
Sean Condon | d88f366 | 2019-04-03 16:35:30 +0100 | [diff] [blame] | 652 | nodeSelected(nodesOrLink: UiElement[]) { |
| 653 | this.details.ngOnChanges({'selectedNodes': |
| 654 | new SimpleChange(undefined, nodesOrLink, true)}); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 657 | /** |
| 658 | * Enable traffic monitoring |
| 659 | */ |
| 660 | monitorAllTraffic() { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 661 | // TODO: Implement support for toggling between bits, packets and octets |
| 662 | this.flashMsg = this.lionFn('tr_fl_pstats_bits'); |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 663 | this.trs.init(this.force); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Cancel traffic monitoring |
| 668 | */ |
| 669 | cancelTraffic() { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 670 | this.flashMsg = this.lionFn('fl_monitoring_canceled'); |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 671 | this.trs.destroy(); |
| 672 | } |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 673 | |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 674 | changeMap(map: MapObject) { |
| 675 | this.mapSelShown = false; // Hide the MapSelector component |
| 676 | this.mapIdState = map; |
| 677 | this.ps.setPrefs(TOPO_MAPID_PREFS, this.mapIdState); |
| 678 | this.log.debug('Map has been changed to ', map); |
| 679 | } |
| 680 | |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 681 | mapExtentsZoom(zoomMapExtents: TopoZoomPrefs) { |
| 682 | // this.zoomDirective.updateZoomState(zoomPrefs.tx, zoomPrefs.ty, zoomPrefs.sc); |
| 683 | this.zoomDirective.changeZoomLevel(zoomMapExtents); |
| 684 | this.log.debug('Map zoom prefs updated', zoomMapExtents); |
| 685 | } |
| 686 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 687 | /** |
| 688 | * Read the LION bundle for Toolbar and set up the lionFn |
| 689 | */ |
| 690 | doLion() { |
| 691 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * A dummy implementation of the lionFn until the response is received and the LION |
| 696 | * bundle is received from the WebSocket |
| 697 | */ |
| 698 | dummyLion(key: string): string { |
| 699 | return '%' + key + '%'; |
| 700 | } |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 701 | } |