blob: 2cb110fc12bd4b74ea772afd959b0722a5885559 [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
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 Condon28ecc5f2018-06-25 12:50:16 +010016import { Component, Input, OnInit, OnDestroy, Inject } from '@angular/core';
Sean Condon83fc39f2018-04-19 18:56:13 +010017import { LionService } from '../../util/lion.service';
18import { LogService } from '../../../log.service';
19import { NavService } from '../../nav/nav.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010020
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 Condon28ecc5f2018-06-25 12:50:16 +010029export 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 Condon83fc39f2018-04-19 18:56:13 +010034
35 constructor(
Sean Condon28ecc5f2018-06-25 12:50:16 +010036 private lion: LionService,
Sean Condon83fc39f2018-04-19 18:56:13 +010037 private log: LogService,
38 public ns: NavService,
Sean Condon28ecc5f2018-06-25 12:50:16 +010039 @Inject('Window') private window: Window,
Sean Condon83fc39f2018-04-19 18:56:13 +010040 ) {
Sean Condon28ecc5f2018-06-25 12:50:16 +010041 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 Condon83fc39f2018-04-19 18:56:13 +010044 }
45
46 ngOnInit() {
Sean Condon28ecc5f2018-06-25 12:50:16 +010047 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 Condon83fc39f2018-04-19 18:56:13 +010054 this.log.debug('MastComponent initialized');
55 }
56
Sean Condon28ecc5f2018-06-25 12:50:16 +010057 /**
58 * Nav component should never be closed, but in case it does, it's
59 * safer to tidy up after itself
Sean Condon83fc39f2018-04-19 18:56:13 +010060 */
Sean Condon28ecc5f2018-06-25 12:50:16 +010061 ngOnDestroy() {
62 this.lion.loadCbs.delete('mast');
Sean Condon83fc39f2018-04-19 18:56:13 +010063 }
64
Sean Condon28ecc5f2018-06-25 12:50:16 +010065 /**
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 Condon83fc39f2018-04-19 18:56:13 +010092}