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