blob: e9cb56a1ff512195d58b320e053398b8d8e161f7 [file] [log] [blame]
Sean Condon0d064ec2019-02-04 21:53:53 +00001
2import {
Sean Condon95fb5742019-04-02 12:16:55 +01003 Component, EventEmitter,
Sean Condon0d064ec2019-02-04 21:53:53 +00004 OnDestroy,
Sean Condon95fb5742019-04-02 12:16:55 +01005 OnInit, Output,
Sean Condon0d064ec2019-02-04 21:53:53 +00006} from '@angular/core';
7import {
8 DetailsPanelBaseImpl,
9 FnService,
Sean Condon95fb5742019-04-02 12:16:55 +010010 LionService,
Sean Condon0d064ec2019-02-04 21:53:53 +000011 LogService,
12 WebSocketService
Sean Condon98b6ddb2019-12-24 08:07:40 +000013} from '../../../../gui2-fw-lib/public_api';
Sean Condon0d064ec2019-02-04 21:53:53 +000014import {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,
Sean Condon0d064ec2019-02-04 21:53:53 +000041 protected wss: WebSocketService,
42 private lion: LionService
43 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010044 super(fs, log, wss, 'topo');
Sean Condon0d064ec2019-02-04 21:53:53 +000045
46 if (this.lion.ubercache.length === 0) {
47 this.lionFn = this.dummyLion;
48 this.lion.loadCbs.set('topoms', () => this.doLion());
49 } else {
50 this.doLion();
51 }
52
53 this.log.debug('Topo MapSelectorComponent constructed');
54 }
55
56 ngOnInit() {
57 this.wss.bindHandlers(new Map<string, (data) => void>([
58 ['mapSelectorResponse', (data) => {
59 this.mapSelectorResponse = data;
60 this.form.setValue({'mapid': this.mapSelectorResponse.order[0]});
61 }
62 ]
63 ]));
64 this.wss.sendEvent('mapSelectorRequest', {});
65 this.log.debug('Topo MapSelectorComponent initialized');
66 }
67
68 /**
69 * When the component is being unloaded then unbind the WSS handler.
70 */
71 ngOnDestroy(): void {
72 this.wss.unbindHandlers(['mapSelectorResponse']);
73 this.log.debug('Topo MapSelectorComponent destroyed');
74 }
75
76 /**
Sean Condond88f3662019-04-03 16:35:30 +010077 * Read the LION bundle for panel and set up the lionFn
Sean Condon0d064ec2019-02-04 21:53:53 +000078 */
79 doLion() {
80 this.lionFn = this.lion.bundle('core.view.Topo');
81 }
82
83 choice(mapid: Object): void {
Sean Condonb0a196a2019-04-19 09:50:44 +010084 if (mapid) {
85 this.chosenMap.emit(<MapObject>this.mapSelectorResponse.maps[mapid['mapid']]);
86 } else {
87 this.chosenMap.emit(<MapObject>{});
88 }
Sean Condon0d064ec2019-02-04 21:53:53 +000089 }
90}