blob: c97e0ca50a5285e44c7155ead46bcbc70ca477a8 [file] [log] [blame]
Sean Condon0d064ec2019-02-04 21:53:53 +00001
2import {
3 Component, EventEmitter, OnChanges,
4 OnDestroy,
5 OnInit, Output, SimpleChanges,
6} from '@angular/core';
7import {
8 DetailsPanelBaseImpl,
9 FnService,
10 LionService, LoadingService,
11 LogService,
12 WebSocketService
13} from 'gui2-fw-lib';
14import {FormControl, FormGroup} from '@angular/forms';
15import { MapObject } from '../../layer/maputils';
16
17interface MapSelection {
18 order: string[];
19 maps: Object[];
20}
21
22@Component({
23 selector: 'onos-mapselector',
24 templateUrl: './mapselector.component.html',
25 styleUrls: ['./mapselector.component.css', './mapselector.theme.css', '../../topology.common.css']
26})
27export class MapSelectorComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy {
28 @Output() chosenMap = new EventEmitter<MapObject>();
29 lionFn; // Function
30 mapSelectorResponse: MapSelection = <MapSelection>{
31 order: [],
32 maps: []
33 };
34 form = new FormGroup({
35 mapid: new FormControl(this.mapSelectorResponse.order[0]),
36 });
37
38 constructor(
39 protected fs: FnService,
40 protected log: LogService,
41 protected ls: LoadingService,
42 protected wss: WebSocketService,
43 private lion: LionService
44 ) {
45 super(fs, ls, log, wss, 'topo');
46
47 if (this.lion.ubercache.length === 0) {
48 this.lionFn = this.dummyLion;
49 this.lion.loadCbs.set('topoms', () => this.doLion());
50 } else {
51 this.doLion();
52 }
53
54 this.log.debug('Topo MapSelectorComponent constructed');
55 }
56
57 ngOnInit() {
58 this.wss.bindHandlers(new Map<string, (data) => void>([
59 ['mapSelectorResponse', (data) => {
60 this.mapSelectorResponse = data;
61 this.form.setValue({'mapid': this.mapSelectorResponse.order[0]});
62 }
63 ]
64 ]));
65 this.wss.sendEvent('mapSelectorRequest', {});
66 this.log.debug('Topo MapSelectorComponent initialized');
67 }
68
69 /**
70 * When the component is being unloaded then unbind the WSS handler.
71 */
72 ngOnDestroy(): void {
73 this.wss.unbindHandlers(['mapSelectorResponse']);
74 this.log.debug('Topo MapSelectorComponent destroyed');
75 }
76
77 /**
78 * Read the LION bundle for Details panel and set up the lionFn
79 */
80 doLion() {
81 this.lionFn = this.lion.bundle('core.view.Topo');
82 }
83
84 choice(mapid: Object): void {
85 this.chosenMap.emit(<MapObject>this.mapSelectorResponse.maps[mapid['mapid']]);
86 }
87}