Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-present Open Networking Foundation |
| 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 | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 16 | import { Component, Input, OnInit, OnDestroy, Inject } from '@angular/core'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 17 | import { LionService } from '../../util/lion.service'; |
| 18 | import { LogService } from '../../../log.service'; |
| 19 | import { NavService } from '../../nav/nav.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * ONOS GUI -- Masthead Component |
| 23 | */ |
| 24 | @Component({ |
| 25 | selector: 'onos-mast', |
| 26 | templateUrl: './mast.component.html', |
| 27 | styleUrls: ['./mast.component.css', './mast.theme.css'] |
| 28 | }) |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 29 | export class MastComponent implements OnInit, OnDestroy { |
| 30 | @Input() username: string; |
| 31 | |
| 32 | lionFn; // Function |
| 33 | viewMap = new Map<string, string>([]); // A map of app names |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 34 | |
| 35 | constructor( |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 36 | private lion: LionService, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 37 | private log: LogService, |
| 38 | public ns: NavService, |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 39 | @Inject('Window') private window: Window, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 40 | ) { |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 41 | this.viewMap.set('apps', 'https://wiki.onosproject.org/display/ONOS/GUI+Application+View'); |
| 42 | this.viewMap.set('device', 'https://wiki.onosproject.org/display/ONOS/GUI+Device+View'); |
| 43 | this.viewMap.set('', 'https://wiki.onosproject.org/display/ONOS/The+ONOS+Web+GUI'); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | ngOnInit() { |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 47 | if (this.lion.ubercache.length === 0) { |
| 48 | this.lionFn = this.dummyLion; |
| 49 | this.lion.loadCbs.set('mast', () => this.doLion()); |
| 50 | this.log.debug('LION not available when MastComponent initialized'); |
| 51 | } else { |
| 52 | this.doLion(); |
| 53 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 54 | this.log.debug('MastComponent initialized'); |
| 55 | } |
| 56 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 57 | /** |
| 58 | * Nav component should never be closed, but in case it does, it's |
| 59 | * safer to tidy up after itself |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 60 | */ |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 61 | ngOnDestroy() { |
| 62 | this.lion.loadCbs.delete('mast'); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 65 | /** |
| 66 | * Read the LION bundle for App and set up the lionFn |
| 67 | */ |
| 68 | doLion() { |
| 69 | this.lionFn = this.lion.bundle('core.fw.Mast'); |
| 70 | if (this.username === undefined) { |
| 71 | this.username = this.lionFn('unknown_user'); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * A dummy implementation of the lionFn until the response is received and the LION |
| 77 | * bundle is received from the WebSocket |
| 78 | */ |
| 79 | dummyLion(key: string): string { |
| 80 | return '%' + key + '%'; |
| 81 | } |
| 82 | |
| 83 | directTo() { |
| 84 | const curId = this.window.location.pathname.replace('/', ''); |
| 85 | let helpUrl: string = this.viewMap.get(curId); |
| 86 | if (helpUrl === undefined) { |
| 87 | helpUrl = this.viewMap.get(''); |
| 88 | this.log.warn('No help file linked for view:', curId); |
| 89 | } |
| 90 | this.window.open(helpUrl); |
| 91 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 92 | } |