-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.component.ts
More file actions
115 lines (101 loc) · 3.38 KB
/
app.component.ts
File metadata and controls
115 lines (101 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {Component, ViewEncapsulation} from '@angular/core';
import {TranslateService} from 'ng2-translate';
import {AuthService} from './user/auth.service';
import './app.component.scss';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
// Remove Encapsulation to enable global scss support
// https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-include-SCSS-in-components
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
//Tooltips are set to null, so we can ngIf them
tooltips: any = null;
primaryNav: any;
secondaryNav: any;
constructor(public auth: AuthService, public translate: TranslateService) {
this.initializeTranslateServiceConfig();
this.initTooltips();
this.initNav();
}
/** @function initNav
*
* Initializes the Primary Navigation
* */
initNav() {
this.translate.get('primary-nav').subscribe(data => {
this.primaryNav = [
{
link: "/dashboard",
icon: "fa fa-th",
name: data.dashboard,
login: true
},
{
link: "/about",
icon: "fa fa-question",
name: data.about,
login: true
},
{
link: "/login",
icon: "fa fa-sign-in",
name: data.login,
login: false
},
{
link: undefined,
icon: "fa fa-sign-out",
name: data.logout,
login: true
}
]
this.secondaryNav = [
{
link: "/impressum",
icon: "fa fa-question-circle",
name: data.impressum
}
]
});
}
/** @function initTooltips
*
* Initializes the Tooltips for this application
* We need to go this way if the tooltips are loaded asynchronously
* Otherwise it won't display them correctly
*
* */
initTooltips() {
this.translate.get('primary-nav').subscribe((data: any) => {
this.tooltips = [];
this.tooltips['dashboard'] = data.dashboard;
this.tooltips['about'] = data.about;
this.tooltips['login'] = data.login;
this.tooltips['logout'] = data.logout;
this.tooltips['impressum'] = data.impressum;
});
}
/** @function loginStatus
*
* Returns the Login Status of the current User
*
* */
loginStatus() {
return AuthService.isLoggedIn;
}
/** @function initializeTranslateServiceConfig
*
* Initializes the Translate Service
* */
initializeTranslateServiceConfig() {
var userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(de|en)/gi.test(userLang) ? userLang : 'en';
// this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
this.translate.use(userLang);
}
}