blob: 218285b7729536ec2db6ca448e5817b57ecf3d4a [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
Sean Condonf4f54a12018-10-10 23:25:46 +01002 * Copyright 2018-present Open Networking Foundation
Sean Condon83fc39f2018-04-19 18:56:13 +01003 *
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,
Sean Condon87b78502018-09-17 20:53:24 +010055 public ns: NavService,
Sean Condon28ecc5f2018-06-25 12:50:16 +010056 ) {
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 }
Sean Condon87b78502018-09-17 20:53:24 +010073 this.ns.getUiViews();
Sean Condon28ecc5f2018-06-25 12:50:16 +010074 }
75
76 /**
77 * Nav component should never be closed, but in case it does, it's
78 * safer to tidy up after itself
79 */
80 ngOnDestroy() {
81 this.lion.loadCbs.delete('nav');
82 }
83
84 /**
85 * Read the LION bundle for App and set up the lionFn
86 */
87 doLion() {
88 this.lionFn = this.lion.bundle('core.fw.Nav');
89 }
90
91 /**
92 * A dummy implementation of the lionFn until the response is received and the LION
93 * bundle is received from the WebSocket
94 */
95 dummyLion(key: string): string {
96 return '%' + key + '%';
97 }
Sean Condon83fc39f2018-04-19 18:56:13 +010098}