Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. |
IBM602-PC0F1E3C\Arundathi | 435e57f | 2018-07-13 15:34:30 +0530 | [diff] [blame] | 5 | |
| 6 | Copyright (C) 2018 IBM Intellectual Property. All rights reserved. |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 7 | =================================================================== |
| 8 | |
| 9 | Unless otherwise specified, all software contained herein is licensed |
| 10 | under the Apache License, Version 2.0 (the License); |
| 11 | you may not use this software except in compliance with the License. |
| 12 | You may obtain a copy of the License at |
| 13 | |
| 14 | http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | |
| 16 | Unless required by applicable law or agreed to in writing, software |
| 17 | distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | See the License for the specific language governing permissions and |
| 20 | limitations under the License. |
| 21 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 22 | ============LICENSE_END============================================ |
| 23 | */ |
| 24 | |
| 25 | |
asgar | af56b68 | 2019-03-08 19:52:33 +0530 | [diff] [blame^] | 26 | import {Component, Input, OnInit} from '@angular/core'; |
| 27 | import {Router} from '@angular/router'; |
| 28 | import {EmitterService} from '../../services/emitter.service'; |
IBM602-PC0F1E3C\Arundathi | 435e57f | 2018-07-13 15:34:30 +0530 | [diff] [blame] | 29 | import { Subscription } from 'rxjs/Subscription'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 30 | |
| 31 | |
asgar | af56b68 | 2019-03-08 19:52:33 +0530 | [diff] [blame^] | 32 | |
| 33 | @Component({selector: 'app-navigation', templateUrl: './navigation.component.html', styleUrls: ['./navigation.component.css']}) |
| 34 | export class NavigationComponent implements OnInit { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 35 | navigationTabs: Array<Object> = []; |
| 36 | //@ViewChild(GoldenConfigurationComponent) goldenConfig: GoldenConfigurationComponent; |
| 37 | @Input() id: string; |
| 38 | userLoggedIn = false; |
| 39 | userId: string = localStorage['userId']; |
IBM602-PC0F1E3C\Arundathi | 435e57f | 2018-07-13 15:34:30 +0530 | [diff] [blame] | 40 | subscription: Subscription; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 41 | |
| 42 | constructor(private router: Router) { |
| 43 | }; |
| 44 | |
| 45 | ngOnChanges() { |
IBM602-PC0F1E3C\Arundathi | 435e57f | 2018-07-13 15:34:30 +0530 | [diff] [blame] | 46 | this.subscription = EmitterService |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 47 | .get(this.id) |
| 48 | .subscribe((value) => { |
| 49 | if (value != null && value != '' && value != undefined && value != 'undefined') { |
| 50 | this.userId = value; |
| 51 | this.userLoggedIn = true; |
| 52 | localStorage['userId'] = this.userId; |
| 53 | } else { |
| 54 | this.logout(); |
| 55 | } |
| 56 | |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | ngOnInit() { |
| 61 | this.userId = localStorage['userId']; |
| 62 | if (this.userId != undefined && this.userId != '') { |
| 63 | this.userLoggedIn = true; |
| 64 | } |
| 65 | |
| 66 | this.navigationTabs = [ |
| 67 | |
| 68 | { |
| 69 | name: 'Home', |
| 70 | url: '/home' |
| 71 | }, { |
| 72 | name: 'MY VNFs', |
| 73 | url: 'vnfs' |
| 74 | }, |
| 75 | { |
| 76 | name: 'Test', |
| 77 | url: 'test', |
| 78 | }, |
| 79 | { |
asgar | af56b68 | 2019-03-08 19:52:33 +0530 | [diff] [blame^] | 80 | name: 'Admin', |
| 81 | url: 'admin' |
| 82 | }, |
| 83 | |
| 84 | { |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 85 | name: 'About us', |
| 86 | url: 'aboutUs' |
| 87 | } |
| 88 | |
| 89 | ]; |
| 90 | } |
| 91 | |
IBM602-PC0F1E3C\Arundathi | 435e57f | 2018-07-13 15:34:30 +0530 | [diff] [blame] | 92 | ngOnDestroy() { |
| 93 | if (this.subscription) { |
| 94 | this.subscription.unsubscribe(); |
| 95 | } |
| 96 | } |
| 97 | |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 98 | |
| 99 | gotoDetail(url) { |
| 100 | |
| 101 | if (url == 'vnfs') { |
| 102 | if (localStorage['userId'] != undefined && localStorage['userId'] != '' && localStorage['userId'] != null) { |
| 103 | this.router.navigate(['/vnfs/list']); |
| 104 | } else { |
| 105 | this.router.navigate(url); |
| 106 | } |
| 107 | } else { |
| 108 | this.router.navigate(url); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | } |
| 113 | |
| 114 | logout() { |
| 115 | window.localStorage.clear(); |
| 116 | sessionStorage.clear(); |
| 117 | localStorage.clear(); |
| 118 | this.userLoggedIn = false; |
| 119 | //window.location.replace("/home"); |
| 120 | this.router.navigate(['home']); |
| 121 | |
| 122 | |
| 123 | } |
| 124 | |
| 125 | } |