blob: 7271bb1fc016f8b20c301906d76a33c7bebf6b07 [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
IBM602-PC0F1E3C\Arundathi435e57f2018-07-13 15:34:30 +05305
6Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
Skip Wonnell2c977e22018-03-01 08:30:15 -06007===================================================================
8
9Unless otherwise specified, all software contained herein is licensed
10under the Apache License, Version 2.0 (the License);
11you may not use this software except in compliance with the License.
12You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing, software
17distributed under the License is distributed on an "AS IS" BASIS,
18WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19See the License for the specific language governing permissions and
20limitations under the License.
21
Skip Wonnell2c977e22018-03-01 08:30:15 -060022============LICENSE_END============================================
23*/
24
25
asgaraf56b682019-03-08 19:52:33 +053026import {Component, Input, OnInit} from '@angular/core';
27import {Router} from '@angular/router';
28import {EmitterService} from '../../services/emitter.service';
IBM602-PC0F1E3C\Arundathi435e57f2018-07-13 15:34:30 +053029import { Subscription } from 'rxjs/Subscription';
Skip Wonnell2c977e22018-03-01 08:30:15 -060030
31
asgaraf56b682019-03-08 19:52:33 +053032
33@Component({selector: 'app-navigation', templateUrl: './navigation.component.html', styleUrls: ['./navigation.component.css']})
34export class NavigationComponent implements OnInit {
Skip Wonnell2c977e22018-03-01 08:30:15 -060035 navigationTabs: Array<Object> = [];
36 //@ViewChild(GoldenConfigurationComponent) goldenConfig: GoldenConfigurationComponent;
37 @Input() id: string;
38 userLoggedIn = false;
39 userId: string = localStorage['userId'];
IBM602-PC0F1E3C\Arundathi435e57f2018-07-13 15:34:30 +053040 subscription: Subscription;
Skip Wonnell2c977e22018-03-01 08:30:15 -060041
42 constructor(private router: Router) {
43 };
44
45 ngOnChanges() {
IBM602-PC0F1E3C\Arundathi435e57f2018-07-13 15:34:30 +053046 this.subscription = EmitterService
Skip Wonnell2c977e22018-03-01 08:30:15 -060047 .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 {
asgaraf56b682019-03-08 19:52:33 +053080 name: 'Admin',
81 url: 'admin'
82 },
83
84 {
Skip Wonnell2c977e22018-03-01 08:30:15 -060085 name: 'About us',
86 url: 'aboutUs'
87 }
88
89 ];
90 }
91
IBM602-PC0F1E3C\Arundathi435e57f2018-07-13 15:34:30 +053092 ngOnDestroy() {
93 if (this.subscription) {
94 this.subscription.unsubscribe();
95 }
96 }
97
Skip Wonnell2c977e22018-03-01 08:30:15 -060098
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}