Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 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 | |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | import { |
| 20 | LionService, |
| 21 | LogService, |
| 22 | NavService |
| 23 | } from 'gui2-fw-lib'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * ONOS GUI -- Navigation Module |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 27 | * |
| 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 31 | */ |
| 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 Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 38 | state('false', style({ |
| 39 | transform: 'translateY(-100%)' |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 40 | })), |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 41 | state('true', style({ |
| 42 | transform: 'translateY(0%)' |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 43 | })), |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 44 | transition('0 => 1', animate('100ms ease-in')), |
| 45 | transition('1 => 0', animate('100ms ease-out')) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 46 | ]) |
| 47 | ] |
| 48 | }) |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 49 | export class NavComponent implements OnInit, OnDestroy { |
| 50 | lionFn; // Function |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 51 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 52 | constructor( |
| 53 | private log: LogService, |
| 54 | private lion: LionService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 55 | public ns: NavService, |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 56 | ) { |
| 57 | this.log.debug('NavComponent constructed'); |
| 58 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 59 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 60 | /** |
| 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 Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 73 | this.ns.getUiViews(); |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 74 | } |
| 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 Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 98 | } |