Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 16 | import { Component, OnInit, OnDestroy } from '@angular/core'; |
| 17 | import { trigger, state, style, animate, transition } from '@angular/animations'; |
| 18 | |
| 19 | import { LionService } from '../../util/lion.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 20 | import { LogService } from '../../../log.service'; |
| 21 | import { NavService } from '../nav.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 22 | |
| 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 Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 32 | state('false', style({ |
| 33 | transform: 'translateY(-100%)' |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 34 | })), |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 35 | state('true', style({ |
| 36 | transform: 'translateY(0%)' |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 37 | })), |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 38 | transition('0 => 1', animate('100ms ease-in')), |
| 39 | transition('1 => 0', animate('100ms ease-out')) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 40 | ]) |
| 41 | ] |
| 42 | }) |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 43 | export class NavComponent implements OnInit, OnDestroy { |
| 44 | lionFn; // Function |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 45 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 46 | constructor( |
| 47 | private log: LogService, |
| 48 | private lion: LionService, |
| 49 | public ns: NavService |
| 50 | ) { |
| 51 | this.log.debug('NavComponent constructed'); |
| 52 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 53 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame^] | 54 | /** |
| 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 91 | |
| 92 | } |