blob: b54304967738712591eaf8430c7636090040fb87 [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
Sean Condon5ca00262018-09-06 17:55:25 +010019import {
20 LionService,
21 LogService,
22 NavService
23} from 'gui2-fw-lib';
Sean Condon83fc39f2018-04-19 18:56:13 +010024
25/**
26 * ONOS GUI -- Navigation Module
Sean Condon5ca00262018-09-06 17:55:25 +010027 *
28 * Note: While this NavComponent could arguably be moved to the gui2-fw-lib
29 * it brings problems in recognizing the "routerlink" directives as being part
30 * of this application. So for that reason Nav must remain here for routing to work
Sean Condon83fc39f2018-04-19 18:56:13 +010031 */
32@Component({
33 selector: 'onos-nav',
34 templateUrl: './nav.component.html',
35 styleUrls: ['./nav.theme.css', './nav.component.css'],
36 animations: [
37 trigger('navState', [
Sean Condon28ecc5f2018-06-25 12:50:16 +010038 state('false', style({
39 transform: 'translateY(-100%)'
Sean Condon83fc39f2018-04-19 18:56:13 +010040 })),
Sean Condon28ecc5f2018-06-25 12:50:16 +010041 state('true', style({
42 transform: 'translateY(0%)'
Sean Condon83fc39f2018-04-19 18:56:13 +010043 })),
Sean Condon28ecc5f2018-06-25 12:50:16 +010044 transition('0 => 1', animate('100ms ease-in')),
45 transition('1 => 0', animate('100ms ease-out'))
Sean Condon83fc39f2018-04-19 18:56:13 +010046 ])
47 ]
48})
Sean Condon28ecc5f2018-06-25 12:50:16 +010049export class NavComponent implements OnInit, OnDestroy {
50 lionFn; // Function
Sean Condon83fc39f2018-04-19 18:56:13 +010051
Sean Condon28ecc5f2018-06-25 12:50:16 +010052 constructor(
53 private log: LogService,
54 private lion: LionService,
55 public ns: NavService
56 ) {
57 this.log.debug('NavComponent constructed');
58 }
Sean Condon83fc39f2018-04-19 18:56:13 +010059
Sean Condon28ecc5f2018-06-25 12:50:16 +010060 /**
61 * If LION is not ready we make do with a dummy function
62 * As soon a lion gets loaded this function will be replaced with
63 * the real thing
64 */
65 ngOnInit() {
66 if (this.lion.ubercache.length === 0) {
67 this.lionFn = this.dummyLion;
68 this.lion.loadCbs.set('nav', () => this.doLion());
69 this.log.debug('LION not available when NavComponent initialized');
70 } else {
71 this.doLion();
72 }
73 }
74
75 /**
76 * Nav component should never be closed, but in case it does, it's
77 * safer to tidy up after itself
78 */
79 ngOnDestroy() {
80 this.lion.loadCbs.delete('nav');
81 }
82
83 /**
84 * Read the LION bundle for App and set up the lionFn
85 */
86 doLion() {
87 this.lionFn = this.lion.bundle('core.fw.Nav');
88 }
89
90 /**
91 * A dummy implementation of the lionFn until the response is received and the LION
92 * bundle is received from the WebSocket
93 */
94 dummyLion(key: string): string {
95 return '%' + key + '%';
96 }
Sean Condon83fc39f2018-04-19 18:56:13 +010097
98}