added ansible server functionality
[appc/cdt.git] / src / app / shared / components / navigation / navigation.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5
6 Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
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
22 ============LICENSE_END============================================
23 */
24
25
26 import {Component, Input, OnInit} from '@angular/core';
27 import {Router} from '@angular/router';
28 import {EmitterService} from '../../services/emitter.service';
29 import { Subscription } from 'rxjs/Subscription';
30
31
32
33 @Component({selector: 'app-navigation', templateUrl: './navigation.component.html', styleUrls: ['./navigation.component.css']})
34 export class NavigationComponent implements OnInit {
35     navigationTabs: Array<Object> = [];
36     //@ViewChild(GoldenConfigurationComponent) goldenConfig: GoldenConfigurationComponent;
37     @Input() id: string;
38     userLoggedIn = false;
39     userId: string = localStorage['userId'];
40     subscription: Subscription;
41
42     constructor(private router: Router) {
43     };
44
45     ngOnChanges() {
46         this.subscription = EmitterService
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             {
80                 name: 'Admin',
81                 url: 'admin'
82             },
83
84             {
85                 name: 'About us',
86                 url: 'aboutUs'
87             }
88
89         ];
90     }
91
92     ngOnDestroy() {
93         if (this.subscription) {
94             this.subscription.unsubscribe();
95         }
96     }
97
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 }