blob: 718562534dd70dba85098d81a4dd68d3b1d3ac76 [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 ChangeDetectionStrategy,
18 ChangeDetectorRef,
19 Component,
20 EventEmitter,
21 HostListener,
22 Input,
23 OnChanges,
24 OnInit,
Sean Condon021f0fa2018-12-06 23:31:11 -080025 Output,
26 QueryList,
Sean Condon50855cf2018-12-23 15:37:42 +000027 SimpleChange,
Sean Condon021f0fa2018-12-06 23:31:11 -080028 SimpleChanges,
29 ViewChildren
Sean Condon0c577f62018-11-18 22:40:05 +000030} from '@angular/core';
Sean Condon1ae15802019-03-02 09:07:18 +000031import {
32 LocMeta,
33 LogService,
34 MetaUi,
35 WebSocketService,
36 ZoomUtils
37} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000038import {
39 Device,
40 ForceDirectedGraph,
Sean Condon50855cf2018-12-23 15:37:42 +000041 Host,
42 HostLabelToggle,
Sean Condon0c577f62018-11-18 22:40:05 +000043 LabelToggle,
44 LayerType,
Sean Condon50855cf2018-12-23 15:37:42 +000045 Link,
46 LinkHighlight,
Sean Condon1ae15802019-03-02 09:07:18 +000047 Location,
Sean Condon50855cf2018-12-23 15:37:42 +000048 ModelEventMemo,
49 ModelEventType,
Sean Condon0c577f62018-11-18 22:40:05 +000050 Region,
51 RegionLink,
Sean Condon50855cf2018-12-23 15:37:42 +000052 SubRegion,
53 UiElement
Sean Condon0c577f62018-11-18 22:40:05 +000054} from './models';
Sean Condon50855cf2018-12-23 15:37:42 +000055import {
56 DeviceNodeSvgComponent,
57 HostNodeSvgComponent,
58 LinkSvgComponent
59} from './visuals';
Sean Condonee545762019-03-09 10:43:58 +000060import {LocationType} from '../backgroundsvg/backgroundsvg.component';
Sean Condon71910542019-02-16 18:16:42 +000061
62interface UpdateMeta {
63 id: string;
64 class: string;
65 memento: MetaUi;
66}
Sean Condonaa4366d2018-11-02 14:29:01 +000067
Sean Condonf4f54a12018-10-10 23:25:46 +010068/**
69 * ONOS GUI -- Topology Forces Graph Layer View.
Sean Condon0c577f62018-11-18 22:40:05 +000070 *
71 * The regionData is set by Topology Service on WebSocket topo2CurrentRegion callback
72 * This drives the whole Force graph
Sean Condonf4f54a12018-10-10 23:25:46 +010073 */
74@Component({
75 selector: '[onos-forcesvg]',
76 templateUrl: './forcesvg.component.html',
Sean Condon0c577f62018-11-18 22:40:05 +000077 styleUrls: ['./forcesvg.component.css'],
78 changeDetection: ChangeDetectionStrategy.OnPush,
Sean Condonf4f54a12018-10-10 23:25:46 +010079})
Sean Condon0c577f62018-11-18 22:40:05 +000080export class ForceSvgComponent implements OnInit, OnChanges {
Sean Condon021f0fa2018-12-06 23:31:11 -080081 @Input() deviceLabelToggle: LabelToggle = LabelToggle.NONE;
82 @Input() hostLabelToggle: HostLabelToggle = HostLabelToggle.NONE;
Sean Condonb2c483c2019-01-16 20:28:55 +000083 @Input() showHosts: boolean = false;
84 @Input() highlightPorts: boolean = true;
85 @Input() onosInstMastership: string = '';
86 @Input() visibleLayer: LayerType = LayerType.LAYER_DEFAULT;
87 @Input() selectedLink: RegionLink = null;
Sean Condon1ae15802019-03-02 09:07:18 +000088 @Input() scale: number = 1;
Sean Condon0c577f62018-11-18 22:40:05 +000089 @Input() regionData: Region = <Region>{devices: [ [], [], [] ], hosts: [ [], [], [] ], links: []};
Sean Condonb2c483c2019-01-16 20:28:55 +000090 @Output() linkSelected = new EventEmitter<RegionLink>();
91 @Output() selectedNodeEvent = new EventEmitter<UiElement>();
Sean Condon021f0fa2018-12-06 23:31:11 -080092 private graph: ForceDirectedGraph;
Sean Condon0c577f62018-11-18 22:40:05 +000093 private _options: { width, height } = { width: 800, height: 600 };
Sean Condonf4f54a12018-10-10 23:25:46 +010094
Sean Condon021f0fa2018-12-06 23:31:11 -080095 // References to the children of this component - these are created in the
96 // template view with the *ngFor and we get them by a query here
Sean Condon0c577f62018-11-18 22:40:05 +000097 @ViewChildren(DeviceNodeSvgComponent) devices: QueryList<DeviceNodeSvgComponent>;
Sean Condon021f0fa2018-12-06 23:31:11 -080098 @ViewChildren(HostNodeSvgComponent) hosts: QueryList<HostNodeSvgComponent>;
Sean Condon50855cf2018-12-23 15:37:42 +000099 @ViewChildren(LinkSvgComponent) links: QueryList<LinkSvgComponent>;
Sean Condonf4f54a12018-10-10 23:25:46 +0100100
Sean Condon0c577f62018-11-18 22:40:05 +0000101 constructor(
102 protected log: LogService,
Sean Condon71910542019-02-16 18:16:42 +0000103 private ref: ChangeDetectorRef,
104 protected wss: WebSocketService
Sean Condon0c577f62018-11-18 22:40:05 +0000105 ) {
106 this.selectedLink = null;
107 this.log.debug('ForceSvgComponent constructed');
108 }
109
110 /**
Sean Condon021f0fa2018-12-06 23:31:11 -0800111 * Utility for extracting a node name from an endpoint string
112 * In some cases - have to remove the port number from the end of a device
113 * name
114 * @param endPtStr The end point name
115 */
116 private static extractNodeName(endPtStr: string): string {
117 const slash: number = endPtStr.indexOf('/');
118 if (slash === -1) {
119 return endPtStr;
120 } else {
121 const afterSlash = endPtStr.substr(slash + 1);
122 if (afterSlash === 'None') {
123 return endPtStr;
124 } else {
125 return endPtStr.substr(0, slash);
126 }
127 }
128 }
129
Sean Condonee545762019-03-09 10:43:58 +0000130 /**
131 * Recursive method to compare 2 objects attribute by attribute and update
132 * the first where a change is detected
133 * @param existingNode 1st object
134 * @param updatedNode 2nd object
135 */
136 private static updateObject(existingNode: Object, updatedNode: Object): number {
137 let changed: number = 0;
138 for (const key of Object.keys(updatedNode)) {
139 const o = updatedNode[key];
140 if (key === 'id') {
141 continue;
142 } else if (o && typeof o === 'object' && o.constructor === Object) {
143 changed += ForceSvgComponent.updateObject(existingNode[key], updatedNode[key]);
144 } else if (existingNode[key] !== updatedNode[key]) {
145 changed++;
146 existingNode[key] = updatedNode[key];
147 }
148 }
149 return changed;
150 }
151
Sean Condon021f0fa2018-12-06 23:31:11 -0800152 @HostListener('window:resize', ['$event'])
153 onResize(event) {
154 this.graph.initSimulation(this.options);
155 this.log.debug('Simulation reinit after resize', event);
156 }
157
158 /**
Sean Condon0c577f62018-11-18 22:40:05 +0000159 * After the component is initialized create the Force simulation
Sean Condon021f0fa2018-12-06 23:31:11 -0800160 * The list of devices, hosts and links will not have been receieved back
161 * from the WebSocket yet as this time - they will be updated later through
162 * ngOnChanges()
Sean Condon0c577f62018-11-18 22:40:05 +0000163 */
164 ngOnInit() {
165 // Receiving an initialized simulated graph from our custom d3 service
Sean Condon50855cf2018-12-23 15:37:42 +0000166 this.graph = new ForceDirectedGraph(this.options, this.log);
Sean Condon0c577f62018-11-18 22:40:05 +0000167
168 /** Binding change detection check on each tick
Sean Condon021f0fa2018-12-06 23:31:11 -0800169 * This along with an onPush change detection strategy should enforce
170 * checking only when relevant! This improves scripting computation
171 * duration in a couple of tests I've made, consistently. Also, it makes
172 * sense to avoid unnecessary checks when we are dealing only with
173 * simulations data binding.
Sean Condon0c577f62018-11-18 22:40:05 +0000174 */
175 this.graph.ticker.subscribe((simulation) => {
176 // this.log.debug("Force simulation has ticked", simulation);
177 this.ref.markForCheck();
178 });
179 this.log.debug('ForceSvgComponent initialized - waiting for nodes and links');
180
Sean Condon0c577f62018-11-18 22:40:05 +0000181 }
182
183 /**
Sean Condon021f0fa2018-12-06 23:31:11 -0800184 * When any one of the inputs get changed by a containing component, this
185 * gets called automatically. In addition this is called manually by
186 * topology.service when a response is received from the WebSocket from the
187 * server
Sean Condon0c577f62018-11-18 22:40:05 +0000188 *
189 * The Devices, Hosts and SubRegions are all added to the Node list for the simulation
190 * The Links are added to the Link list of the simulation.
191 * Before they are added the Links are associated with Nodes based on their endPt
192 *
193 * @param changes - a list of changed @Input(s)
194 */
195 ngOnChanges(changes: SimpleChanges) {
196 if (changes['regionData']) {
197 const devices: Device[] =
198 changes['regionData'].currentValue.devices[this.visibleLayerIdx()];
199 const hosts: Host[] =
200 changes['regionData'].currentValue.hosts[this.visibleLayerIdx()];
201 const subRegions: SubRegion[] = changes['regionData'].currentValue.subRegion;
202 this.graph.nodes = [];
203 if (devices) {
204 this.graph.nodes = devices;
205 }
206 if (hosts) {
207 this.graph.nodes = this.graph.nodes.concat(hosts);
208 }
209 if (subRegions) {
210 this.graph.nodes = this.graph.nodes.concat(subRegions);
211 }
212
Sean Condon71910542019-02-16 18:16:42 +0000213 // If a node has a fixed location then assign it to fx and fy so
214 // that it doesn't get affected by forces
215 this.graph.nodes
216 .forEach((n) => {
217 const loc: Location = <Location>n['location'];
218 if (loc && loc.locType === LocationType.GEO) {
219 const position: MetaUi =
Sean Condon1ae15802019-03-02 09:07:18 +0000220 ZoomUtils.convertGeoToCanvas(
Sean Condon71910542019-02-16 18:16:42 +0000221 <LocMeta>{lng: loc.longOrX, lat: loc.latOrY});
222 n.fx = position.x;
223 n.fy = position.y;
224 this.log.debug('Found node', n.id, 'with', loc.locType);
225 }
226 });
227
Sean Condon0c577f62018-11-18 22:40:05 +0000228 // Associate the endpoints of each link with a real node
229 this.graph.links = [];
230 for (const linkIdx of Object.keys(this.regionData.links)) {
Sean Condon021f0fa2018-12-06 23:31:11 -0800231 const epA = ForceSvgComponent.extractNodeName(
232 this.regionData.links[linkIdx].epA);
Sean Condon0c577f62018-11-18 22:40:05 +0000233 this.regionData.links[linkIdx].source =
234 this.graph.nodes.find((node) =>
Sean Condon021f0fa2018-12-06 23:31:11 -0800235 node.id === epA);
236 const epB = ForceSvgComponent.extractNodeName(
237 this.regionData.links[linkIdx].epB);
Sean Condon0c577f62018-11-18 22:40:05 +0000238 this.regionData.links[linkIdx].target =
239 this.graph.nodes.find((node) =>
Sean Condon021f0fa2018-12-06 23:31:11 -0800240 node.id === epB);
Sean Condon0c577f62018-11-18 22:40:05 +0000241 this.regionData.links[linkIdx].index = Number(linkIdx);
242 }
243
244 this.graph.links = this.regionData.links;
245
246 this.graph.initSimulation(this.options);
247 this.graph.initNodes();
Sean Condon50855cf2018-12-23 15:37:42 +0000248 this.graph.initLinks();
Sean Condon0c577f62018-11-18 22:40:05 +0000249 this.log.debug('ForceSvgComponent input changed',
250 this.graph.nodes.length, 'nodes,', this.graph.links.length, 'links');
251 }
Sean Condon021f0fa2018-12-06 23:31:11 -0800252
Sean Condon021f0fa2018-12-06 23:31:11 -0800253 this.ref.markForCheck();
Sean Condon0c577f62018-11-18 22:40:05 +0000254 }
255
256 /**
257 * Get the index of LayerType so it can drive the visibility of nodes and
258 * hosts on layers
259 */
260 visibleLayerIdx(): number {
261 const layerKeys: string[] = Object.keys(LayerType);
262 for (const idx in layerKeys) {
263 if (LayerType[layerKeys[idx]] === this.visibleLayer) {
264 return Number(idx);
265 }
266 }
267 return -1;
268 }
269
270 selectLink(link: RegionLink): void {
271 this.selectedLink = link;
272 this.linkSelected.emit(link);
273 }
274
275 get options() {
276 return this._options = {
277 width: window.innerWidth,
278 height: window.innerHeight
279 };
280 }
281
Sean Condon021f0fa2018-12-06 23:31:11 -0800282 /**
283 * Iterate through all hosts and devices to deselect the previously selected
284 * node. The emit an event to the parent that lets it know the selection has
285 * changed.
286 * @param selectedNode the newly selected node
287 */
Sean Condon50855cf2018-12-23 15:37:42 +0000288 updateSelected(selectedNode: UiElement): void {
Sean Condon91481822019-01-01 13:56:14 +0000289 this.log.debug('Node or link selected', selectedNode ? selectedNode.id : 'none');
Sean Condon021f0fa2018-12-06 23:31:11 -0800290 this.devices
291 .filter((d) =>
292 selectedNode === undefined || d.device.id !== selectedNode.id)
293 .forEach((d) => d.deselect());
294 this.hosts
295 .filter((h) =>
296 selectedNode === undefined || h.host.id !== selectedNode.id)
297 .forEach((h) => h.deselect());
298
Sean Condon50855cf2018-12-23 15:37:42 +0000299 this.links
300 .filter((l) =>
301 selectedNode === undefined || l.link.id !== selectedNode.id)
302 .forEach((l) => l.deselect());
Sean Condon91481822019-01-01 13:56:14 +0000303 // Push the changes back up to parent (Topology Component)
Sean Condon021f0fa2018-12-06 23:31:11 -0800304 this.selectedNodeEvent.emit(selectedNode);
Sean Condon0c577f62018-11-18 22:40:05 +0000305 }
306
Sean Condon021f0fa2018-12-06 23:31:11 -0800307 /**
308 * We want to filter links to show only those not related to hosts if the
Sean Condon50855cf2018-12-23 15:37:42 +0000309 * 'showHosts' flag has been switched off. If 'showHosts' is true, then
Sean Condon021f0fa2018-12-06 23:31:11 -0800310 * display all links.
311 */
Sean Condon50855cf2018-12-23 15:37:42 +0000312 filteredLinks(): Link[] {
Sean Condon021f0fa2018-12-06 23:31:11 -0800313 return this.regionData.links.filter((h) =>
314 this.showHosts ||
315 ((<Host>h.source).nodeType !== 'host' &&
316 (<Host>h.target).nodeType !== 'host'));
Sean Condon0c577f62018-11-18 22:40:05 +0000317 }
Sean Condon50855cf2018-12-23 15:37:42 +0000318
319 /**
320 * When changes happen in the model, then model events are sent up through the
321 * Web Socket
322 * @param type - the type of the change
323 * @param memo - a qualifier on the type
324 * @param subject - the item that the update is for
325 * @param data - the new definition of the item
326 */
327 handleModelEvent(type: ModelEventType, memo: ModelEventMemo, subject: string, data: UiElement): void {
328 switch (type) {
329 case ModelEventType.DEVICE_ADDED_OR_UPDATED:
330 if (memo === ModelEventMemo.ADDED) {
Sean Condonee5d4b92019-03-11 19:57:34 +0000331 const loc = (<Device>data).location;
332 if (loc && loc.locType === LocationType.GEO) {
333 const position =
334 ZoomUtils.convertGeoToCanvas(<LocMeta>{ lng: loc.longOrX, lat: loc.latOrY});
335 (<Device>data).fx = position.x;
336 (<Device>data).fy = position.y;
337 this.log.debug('Using long', loc.longOrX, 'lat', loc.latOrY, '(', position.x, position.y, ')');
338 } else if (loc && loc.locType === LocationType.GRID) {
339 (<Device>data).fx = loc.longOrX;
340 (<Device>data).fy = loc.latOrY;
341 this.log.debug('Using grid', loc.longOrX, loc.latOrY);
342 } else {
343 (<Device>data).fx = null;
344 (<Device>data).fy = null;
345 // (<Device>data).x = 500;
346 // (<Device>data).y = 500;
347 }
Sean Condonee545762019-03-09 10:43:58 +0000348 this.graph.nodes.push(<Device>data);
Sean Condonee5d4b92019-03-11 19:57:34 +0000349 this.regionData.devices[this.visibleLayerIdx()].push(<Device>data);
Sean Condonee545762019-03-09 10:43:58 +0000350 this.log.debug('Device added', (<Device>data).id);
Sean Condon50855cf2018-12-23 15:37:42 +0000351 } else if (memo === ModelEventMemo.UPDATED) {
352 const oldDevice: Device =
353 this.regionData.devices[this.visibleLayerIdx()]
354 .find((d) => d.id === subject);
Sean Condonee545762019-03-09 10:43:58 +0000355 const changes = ForceSvgComponent.updateObject(oldDevice, <Device>data);
356 if (changes > 0) {
357 this.log.debug('Device ', oldDevice.id, memo, ' - ', changes, 'changes');
358 }
Sean Condon50855cf2018-12-23 15:37:42 +0000359 } else {
360 this.log.warn('Device ', memo, ' - not yet implemented', data);
361 }
Sean Condon50855cf2018-12-23 15:37:42 +0000362 break;
363 case ModelEventType.HOST_ADDED_OR_UPDATED:
364 if (memo === ModelEventMemo.ADDED) {
365 this.regionData.hosts[this.visibleLayerIdx()].push(<Host>data);
Sean Condonee545762019-03-09 10:43:58 +0000366 this.graph.nodes.push(<Host>data);
367 this.log.debug('Host added', (<Host>data).id);
Sean Condon50855cf2018-12-23 15:37:42 +0000368 } else if (memo === ModelEventMemo.UPDATED) {
369 const oldHost: Host = this.regionData.hosts[this.visibleLayerIdx()]
370 .find((h) => h.id === subject);
Sean Condonee545762019-03-09 10:43:58 +0000371 const changes = ForceSvgComponent.updateObject(oldHost, <Host>data);
372 if (changes > 0) {
373 this.log.debug('Host ', oldHost.id, memo, ' - ', changes, 'changes');
374 }
Sean Condon50855cf2018-12-23 15:37:42 +0000375 } else {
376 this.log.warn('Host change', memo, ' - unexpected');
377 }
378 break;
379 case ModelEventType.DEVICE_REMOVED:
380 if (memo === ModelEventMemo.REMOVED || memo === undefined) {
381 const removeIdx: number =
382 this.regionData.devices[this.visibleLayerIdx()]
383 .findIndex((d) => d.id === subject);
Sean Condonee545762019-03-09 10:43:58 +0000384 this.regionData.devices[this.visibleLayerIdx()].splice(removeIdx, 1);
385 this.removeRelatedLinks(subject);
386 this.log.debug('Device ', subject, 'removed. Links', this.regionData.links);
Sean Condon50855cf2018-12-23 15:37:42 +0000387 } else {
388 this.log.warn('Device removed - unexpected memo', memo);
389 }
390 break;
391 case ModelEventType.HOST_REMOVED:
392 if (memo === ModelEventMemo.REMOVED || memo === undefined) {
393 const removeIdx: number =
394 this.regionData.hosts[this.visibleLayerIdx()]
395 .findIndex((h) => h.id === subject);
Sean Condonee545762019-03-09 10:43:58 +0000396 this.regionData.hosts[this.visibleLayerIdx()].splice(removeIdx, 1);
397 this.removeRelatedLinks(subject);
398 this.log.warn('Host ', subject, 'removed');
Sean Condon50855cf2018-12-23 15:37:42 +0000399 } else {
400 this.log.warn('Host removed - unexpected memo', memo);
401 }
402 break;
403 case ModelEventType.LINK_ADDED_OR_UPDATED:
Sean Condonee545762019-03-09 10:43:58 +0000404 if (memo === ModelEventMemo.ADDED &&
405 this.regionData.links.findIndex((l) => l.id === subject) === -1) {
406 const listLen = this.regionData.links.push(<RegionLink>data);
407 const epA = ForceSvgComponent.extractNodeName(
408 this.regionData.links[listLen - 1].epA);
409 this.regionData.links[listLen - 1].source =
410 this.graph.nodes.find((node) =>
411 node.id === epA);
412 const epB = ForceSvgComponent.extractNodeName(
413 this.regionData.links[listLen - 1].epB);
414 this.regionData.links[listLen - 1].target =
415 this.graph.nodes.find((node) =>
416 node.id === epB);
417 this.log.debug('Link added', subject);
418 } else if (memo === ModelEventMemo.UPDATED) {
419 const oldLink = this.regionData.links.find((l) => l.id === subject);
420 const changes = ForceSvgComponent.updateObject(oldLink, <RegionLink>data);
421 this.log.debug('Link ', subject, '. Updated', changes, 'items');
422 } else {
423 this.log.warn('Link added or updated - unexpected memo', memo);
424 }
Sean Condon50855cf2018-12-23 15:37:42 +0000425 break;
426 default:
427 this.log.error('Unexpected model event', type, 'for', subject);
428 }
Sean Condonee545762019-03-09 10:43:58 +0000429 this.ref.markForCheck();
430 this.graph.initSimulation(this.options);
Sean Condonee5d4b92019-03-11 19:57:34 +0000431 this.graph.initNodes();
432 this.graph.initLinks();
Sean Condon50855cf2018-12-23 15:37:42 +0000433 }
434
Sean Condonee545762019-03-09 10:43:58 +0000435 private removeRelatedLinks(subject: string) {
436 const len = this.regionData.links.length;
437 for (let i = 0; i < len; i++) {
438 const linkIdx = this.regionData.links.findIndex((l) =>
439 (ForceSvgComponent.extractNodeName(l.epA) === subject ||
440 ForceSvgComponent.extractNodeName(l.epB) === subject));
441 if (linkIdx >= 0) {
442 this.regionData.links.splice(linkIdx, 1);
443 this.log.debug('Link ', linkIdx, 'removed on attempt', i);
444 }
Sean Condon50855cf2018-12-23 15:37:42 +0000445 }
446 }
447
448 /**
449 * When traffic monitoring is turned on (A key) highlights will be sent back
450 * from the WebSocket through the Traffic Service
451 * @param devices - an array of device highlights
452 * @param hosts - an array of host highlights
453 * @param links - an array of link highlights
454 */
455 handleHighlights(devices: Device[], hosts: Host[], links: LinkHighlight[]): void {
456
457 if (devices.length > 0) {
458 this.log.debug(devices.length, 'Devices highlighted');
459 devices.forEach((dh) => {
460 const deviceComponent: DeviceNodeSvgComponent = this.devices.find((d) => d.device.id === dh.id );
461 if (deviceComponent) {
462 deviceComponent.ngOnChanges(
463 {'deviceHighlight': new SimpleChange(<Device>{}, dh, true)}
464 );
465 this.log.debug('Highlighting device', deviceComponent.device.id);
466 } else {
467 this.log.warn('Device component not found', dh.id);
468 }
469 });
470 }
471 if (hosts.length > 0) {
472 this.log.debug(hosts.length, 'Hosts highlighted');
473 hosts.forEach((hh) => {
474 const hostComponent: HostNodeSvgComponent = this.hosts.find((h) => h.host.id === hh.id );
475 if (hostComponent) {
476 hostComponent.ngOnChanges(
477 {'hostHighlight': new SimpleChange(<Host>{}, hh, true)}
478 );
479 this.log.debug('Highlighting host', hostComponent.host.id);
480 }
481 });
482 }
483 if (links.length > 0) {
484 this.log.debug(links.length, 'Links highlighted');
485 links.forEach((lh) => {
486 const linkComponent: LinkSvgComponent = this.links.find((l) => l.link.id === lh.id );
487 if (linkComponent) { // A link might not be present is hosts viewing is switched off
488 linkComponent.ngOnChanges(
489 {'linkHighlight': new SimpleChange(<LinkHighlight>{}, lh, true)}
490 );
491 // this.log.debug('Highlighting link', linkComponent.link.id, lh.css, lh.label);
492 }
493 });
494 }
495 }
Sean Condon71910542019-02-16 18:16:42 +0000496
497 /**
498 * As nodes are dragged around the graph, their new location should be sent
499 * back to server
500 * @param klass The class of node e.g. 'host' or 'device'
501 * @param id - the ID of the node
502 * @param newLocation - the new Location of the node
503 */
504 nodeMoved(klass: string, id: string, newLocation: MetaUi) {
505 this.wss.sendEvent('updateMeta', <UpdateMeta>{
506 id: id,
507 class: klass,
508 memento: newLocation
509 });
510 this.log.debug(klass, id, 'has been moved to', newLocation);
511 }
Sean Condon1ae15802019-03-02 09:07:18 +0000512
513 resetNodeLocations() {
514 this.devices.forEach((d) => {
515 d.resetNodeLocation();
516 });
517 }
Sean Condonf4f54a12018-10-10 23:25:46 +0100518}
Sean Condon0c577f62018-11-18 22:40:05 +0000519