Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 1 | |
| 2 | import { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 3 | Component, EventEmitter, |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 4 | OnDestroy, |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 5 | OnInit, Output, |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 6 | } from '@angular/core'; |
| 7 | import { |
| 8 | DetailsPanelBaseImpl, |
| 9 | FnService, |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 10 | LionService, |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 11 | LogService, |
| 12 | WebSocketService |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 13 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 14 | import {FormControl, FormGroup} from '@angular/forms'; |
| 15 | import { MapObject } from '../../layer/maputils'; |
| 16 | |
| 17 | interface 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 | }) |
| 27 | export 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 Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 41 | protected wss: WebSocketService, |
| 42 | private lion: LionService |
| 43 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 44 | super(fs, log, wss, 'topo'); |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 45 | |
| 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 Condon | d88f366 | 2019-04-03 16:35:30 +0100 | [diff] [blame] | 77 | * Read the LION bundle for panel and set up the lionFn |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 78 | */ |
| 79 | doLion() { |
| 80 | this.lionFn = this.lion.bundle('core.view.Topo'); |
| 81 | } |
| 82 | |
| 83 | choice(mapid: Object): void { |
Sean Condon | b0a196a | 2019-04-19 09:50:44 +0100 | [diff] [blame] | 84 | if (mapid) { |
| 85 | this.chosenMap.emit(<MapObject>this.mapSelectorResponse.maps[mapid['mapid']]); |
| 86 | } else { |
| 87 | this.chosenMap.emit(<MapObject>{}); |
| 88 | } |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 89 | } |
| 90 | } |