blob: 7614e679248671119bf61ab69ad0df21df62e85f [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
2 * Copyright 2015-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, OnInit, OnDestroy } from '@angular/core';
17import { trigger, state, style, animate, transition } from '@angular/animations';
18
19import { LionService } from '../../util/lion.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010020import { LogService } from '../../../log.service';
21import { NavService } from '../nav.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010022
23/**
24 * ONOS GUI -- Navigation Module
25 */
26@Component({
27 selector: 'onos-nav',
28 templateUrl: './nav.component.html',
29 styleUrls: ['./nav.theme.css', './nav.component.css'],
30 animations: [
31 trigger('navState', [
Sean Condon28ecc5f2018-06-25 12:50:16 +010032 state('false', style({
33 transform: 'translateY(-100%)'
Sean Condon83fc39f2018-04-19 18:56:13 +010034 })),
Sean Condon28ecc5f2018-06-25 12:50:16 +010035 state('true', style({
36 transform: 'translateY(0%)'
Sean Condon83fc39f2018-04-19 18:56:13 +010037 })),
Sean Condon28ecc5f2018-06-25 12:50:16 +010038 transition('0 => 1', animate('100ms ease-in')),
39 transition('1 => 0', animate('100ms ease-out'))
Sean Condon83fc39f2018-04-19 18:56:13 +010040 ])
41 ]
42})
Sean Condon28ecc5f2018-06-25 12:50:16 +010043export class NavComponent implements OnInit, OnDestroy {
44 lionFn; // Function
Sean Condon83fc39f2018-04-19 18:56:13 +010045
Sean Condon28ecc5f2018-06-25 12:50:16 +010046 constructor(
47 private log: LogService,
48 private lion: LionService,
49 public ns: NavService
50 ) {
51 this.log.debug('NavComponent constructed');
52 }
Sean Condon83fc39f2018-04-19 18:56:13 +010053
Sean Condon28ecc5f2018-06-25 12:50:16 +010054 /**
55 * If LION is not ready we make do with a dummy function
56 * As soon a lion gets loaded this function will be replaced with
57 * the real thing
58 */
59 ngOnInit() {
60 if (this.lion.ubercache.length === 0) {
61 this.lionFn = this.dummyLion;
62 this.lion.loadCbs.set('nav', () => this.doLion());
63 this.log.debug('LION not available when NavComponent initialized');
64 } else {
65 this.doLion();
66 }
67 }
68
69 /**
70 * Nav component should never be closed, but in case it does, it's
71 * safer to tidy up after itself
72 */
73 ngOnDestroy() {
74 this.lion.loadCbs.delete('nav');
75 }
76
77 /**
78 * Read the LION bundle for App and set up the lionFn
79 */
80 doLion() {
81 this.lionFn = this.lion.bundle('core.fw.Nav');
82 }
83
84 /**
85 * A dummy implementation of the lionFn until the response is received and the LION
86 * bundle is received from the WebSocket
87 */
88 dummyLion(key: string): string {
89 return '%' + key + '%';
90 }
Sean Condon83fc39f2018-04-19 18:56:13 +010091
92}